X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Funit_controller_config.t;h=d99471cad509ceb3510a4c807875f28a645ca268;hp=b76b02090300f79b9dd216fc691d19af759cd642;hb=4ac0b9cb8e9043db8a95f44af685c782bf9426e7;hpb=5e7073968974a588522d61b3a72b23cd87a8121a diff --git a/t/unit_controller_config.t b/t/unit_controller_config.t index b76b020..d99471c 100755 --- a/t/unit_controller_config.t +++ b/t/unit_controller_config.t @@ -1,91 +1,91 @@ -## ============================================================================ -## Test to make sure that subclassed controllers (catalyst controllers -## that inherit from a custom base catalyst controller) don't experienc -## any namespace collision in the values under config. -## ============================================================================ - -use Test::More tests => 9; - -use strict; -use warnings; - -use_ok('Catalyst'); - -## ---------------------------------------------------------------------------- -## First We define a base controller that inherits from Catalyst::Controller -## We add something to the config that we expect all children classes to -## be able to find. -## ---------------------------------------------------------------------------- - -{ - package base_controller; - - use base 'Catalyst::Controller'; - - __PACKAGE__->config( base_key => 'base_value' ); -} - -## ---------------------------------------------------------------------------- -## Next we instantiate two classes that inherit from the base controller. We -## Add some local config information to these. -## ---------------------------------------------------------------------------- - -{ - package controller_a; - - use base 'base_controller'; - - __PACKAGE__->config( key_a => 'value_a' ); -} - - -{ - package controller_b; - - use base 'base_controller'; - - __PACKAGE__->config( key_b => 'value_b' ); -} - -## Okay, we expect that the base controller has a config with one key -## and that the two children controllers inherit that config key and then -## add one more. So the base controller has one config value and the two -## children each have two. - -## ---------------------------------------------------------------------------- -## THE TESTS. Basically we first check to make sure that all the children of -## the base_controller properly inherit the {base_key => 'base_value'} info -## and that each of the children also has it's local config data and that none -## of the classes have data that is unexpected. -## ---------------------------------------------------------------------------- - - -# First round, does everything have what we expect to find? If these tests fail there is something -# wrong with the way config is storing it's information. - -ok( base_controller->config->{base_key} eq 'base_value', 'base_controller has expected config value for "base_key"') or - diag('"base_key" defined as "'.base_controller->config->{base_key}.'" and not "base_value" in config'); - -ok( controller_a->config->{base_key} eq 'base_value', 'controller_a has expected config value for "base_key"') or - diag('"base_key" defined as "'.controller_a->config->{base_key}.'" and not "base_value" in config'); - -ok( controller_a->config->{key_a} eq 'value_a', 'controller_a has expected config value for "key_a"') or - diag('"key_a" defined as "'.controller_a->config->{key_a}.'" and not "value_a" in config'); - -ok( controller_b->config->{base_key} eq 'base_value', 'controller_b has expected config value for "base_key"') or - diag('"base_key" defined as "'.controller_b->config->{base_key}.'" and not "base_value" in config'); - -ok( controller_b->config->{key_b} eq 'value_b', 'controller_b has expected config value for "key_b"') or - diag('"key_b" defined as "'.controller_b->config->{key_b}.'" and not "value_b" in config'); - -# second round, does each controller have the expected number of config values? If this test fails there is -# probably some data collision between the controllers. - -ok( scalar(keys %{base_controller->config}) == 1, 'base_controller has the expected number of config values') or - diag("base_controller should have 1 config value, but it has ".scalar(keys %{base_controller->config})); - -ok( scalar(keys %{controller_a->config}) == 2, 'controller_a has the expected number of config values') or - diag("controller_a should have 2 config value, but it has ".scalar(keys %{base_controller->config})); - -ok( scalar(keys %{controller_b->config}) == 2, 'controller_b has the expected number of config values') or - diag("controller_a should have 2 config value, but it has ".scalar(keys %{base_controller->config})); +## ============================================================================ +## Test to make sure that subclassed controllers (catalyst controllers +## that inherit from a custom base catalyst controller) don't experienc +## any namespace collision in the values under config. +## ============================================================================ + +use Test::More tests => 9; + +use strict; +use warnings; + +use_ok('Catalyst'); + +## ---------------------------------------------------------------------------- +## First We define a base controller that inherits from Catalyst::Controller +## We add something to the config that we expect all children classes to +## be able to find. +## ---------------------------------------------------------------------------- + +{ + package base_controller; + + use base 'Catalyst::Controller'; + + __PACKAGE__->config( base_key => 'base_value' ); +} + +## ---------------------------------------------------------------------------- +## Next we instantiate two classes that inherit from the base controller. We +## Add some local config information to these. +## ---------------------------------------------------------------------------- + +{ + package controller_a; + + use base 'base_controller'; + + __PACKAGE__->config( key_a => 'value_a' ); +} + + +{ + package controller_b; + + use base 'base_controller'; + + __PACKAGE__->config->{key_b} = 'value_b'; +} + +## Okay, we expect that the base controller has a config with one key +## and that the two children controllers inherit that config key and then +## add one more. So the base controller has one config value and the two +## children each have two. + +## ---------------------------------------------------------------------------- +## THE TESTS. Basically we first check to make sure that all the children of +## the base_controller properly inherit the {base_key => 'base_value'} info +## and that each of the children also has it's local config data and that none +## of the classes have data that is unexpected. +## ---------------------------------------------------------------------------- + + +# First round, does everything have what we expect to find? If these tests fail there is something +# wrong with the way config is storing it's information. + +ok( base_controller->config->{base_key} eq 'base_value', 'base_controller has expected config value for "base_key"') or + diag('"base_key" defined as "'.base_controller->config->{base_key}.'" and not "base_value" in config'); + +ok( controller_a->config->{base_key} eq 'base_value', 'controller_a has expected config value for "base_key"') or + diag('"base_key" defined as "'.controller_a->config->{base_key}.'" and not "base_value" in config'); + +ok( controller_a->config->{key_a} eq 'value_a', 'controller_a has expected config value for "key_a"') or + diag('"key_a" defined as "'.controller_a->config->{key_a}.'" and not "value_a" in config'); + +ok( controller_b->config->{base_key} eq 'base_value', 'controller_b has expected config value for "base_key"') or + diag('"base_key" defined as "'.controller_b->config->{base_key}.'" and not "base_value" in config'); + +ok( controller_b->config->{key_b} eq 'value_b', 'controller_b has expected config value for "key_b"') or + diag('"key_b" defined as "'.controller_b->config->{key_b}.'" and not "value_b" in config'); + +# second round, does each controller have the expected number of config values? If this test fails there is +# probably some data collision between the controllers. + +ok( scalar(keys %{base_controller->config}) == 1, 'base_controller has the expected number of config values') or + diag("base_controller should have 1 config value, but it has ".scalar(keys %{base_controller->config})); + +ok( scalar(keys %{controller_a->config}) == 2, 'controller_a has the expected number of config values') or + diag("controller_a should have 2 config value, but it has ".scalar(keys %{base_controller->config})); + +ok( scalar(keys %{controller_b->config}) == 2, 'controller_b has the expected number of config values') or + diag("controller_a should have 2 config value, but it has ".scalar(keys %{base_controller->config}));