1 ## ============================================================================
2 ## Test to make sure that subclassed controllers (catalyst controllers
3 ## that inherit from a custom base catalyst controller) don't experienc
4 ## any namespace collision in the values under config.
5 ## ============================================================================
7 use Test::More tests => 9;
14 ## ----------------------------------------------------------------------------
15 ## First We define a base controller that inherits from Catalyst::Controller
16 ## We add something to the config that we expect all children classes to
18 ## ----------------------------------------------------------------------------
21 package base_controller;
23 use base 'Catalyst::Controller';
25 __PACKAGE__->config( base_key => 'base_value' );
28 ## ----------------------------------------------------------------------------
29 ## Next we instantiate two classes that inherit from the base controller. We
30 ## Add some local config information to these.
31 ## ----------------------------------------------------------------------------
36 use base 'base_controller';
38 __PACKAGE__->config( key_a => 'value_a' );
45 use base 'base_controller';
47 __PACKAGE__->config( key_b => 'value_b' );
50 ## Okay, we expect that the base controller has a config with one key
51 ## and that the two children controllers inherit that config key and then
52 ## add one more. So the base controller has one config value and the two
53 ## children each have two.
55 ## ----------------------------------------------------------------------------
56 ## THE TESTS. Basically we first check to make sure that all the children of
57 ## the base_controller properly inherit the {base_key => 'base_value'} info
58 ## and that each of the children also has it's local config data and that none
59 ## of the classes have data that is unexpected.
60 ## ----------------------------------------------------------------------------
63 # First round, does everything have what we expect to find? If these tests fail there is something
64 # wrong with the way config is storing it's information.
66 ok( base_controller->config->{base_key} eq 'base_value', 'base_controller has expected config value for "base_key"') or
67 diag('"base_key" defined as "'.base_controller->config->{base_key}.'" and not "base_value" in config');
69 ok( controller_a->config->{base_key} eq 'base_value', 'controller_a has expected config value for "base_key"') or
70 diag('"base_key" defined as "'.controller_a->config->{base_key}.'" and not "base_value" in config');
72 ok( controller_a->config->{key_a} eq 'value_a', 'controller_a has expected config value for "key_a"') or
73 diag('"key_a" defined as "'.controller_a->config->{key_a}.'" and not "value_a" in config');
75 ok( controller_b->config->{base_key} eq 'base_value', 'controller_b has expected config value for "base_key"') or
76 diag('"base_key" defined as "'.controller_b->config->{base_key}.'" and not "base_value" in config');
78 ok( controller_b->config->{key_b} eq 'value_b', 'controller_b has expected config value for "key_b"') or
79 diag('"key_b" defined as "'.controller_b->config->{key_b}.'" and not "value_b" in config');
81 # second round, does each controller have the expected number of config values? If this test fails there is
82 # probably some data collision between the controllers.
84 ok( scalar(keys %{base_controller->config}) == 1, 'base_controller has the expected number of config values') or
85 diag("base_controller should have 1 config value, but it has ".scalar(keys %{base_controller->config}));
87 ok( scalar(keys %{controller_a->config}) == 2, 'controller_a has the expected number of config values') or
88 diag("controller_a should have 2 config value, but it has ".scalar(keys %{base_controller->config}));
90 ok( scalar(keys %{controller_b->config}) == 2, 'controller_b has the expected number of config values') or
91 diag("controller_a should have 2 config value, but it has ".scalar(keys %{base_controller->config}));