Commit | Line | Data |
5e707396 |
1 | ## ============================================================================\r |
2 | ## Test to make sure that subclassed controllers (catalyst controllers\r |
3 | ## that inherit from a custom base catalyst controller) don't experienc\r |
4 | ## any namespace collision in the values under config.\r |
5 | ## ============================================================================\r |
6 | \r |
7 | use Test::More tests => 9;\r |
8 | \r |
9 | use strict;\r |
10 | use warnings;\r |
11 | \r |
12 | use_ok('Catalyst');\r |
13 | \r |
14 | ## ----------------------------------------------------------------------------\r |
15 | ## First We define a base controller that inherits from Catalyst::Controller\r |
16 | ## We add something to the config that we expect all children classes to\r |
17 | ## be able to find.\r |
18 | ## ----------------------------------------------------------------------------\r |
19 | \r |
20 | {\r |
21 | package base_controller;\r |
22 | \r |
23 | use base 'Catalyst::Controller';\r |
24 | \r |
25 | __PACKAGE__->config( base_key => 'base_value' );\r |
26 | }\r |
27 | \r |
28 | ## ----------------------------------------------------------------------------\r |
29 | ## Next we instantiate two classes that inherit from the base controller. We\r |
30 | ## Add some local config information to these.\r |
31 | ## ----------------------------------------------------------------------------\r |
32 | \r |
33 | {\r |
34 | package controller_a;\r |
35 | \r |
36 | use base 'base_controller';\r |
37 | \r |
38 | __PACKAGE__->config( key_a => 'value_a' );\r |
39 | }\r |
40 | \r |
41 | \r |
42 | {\r |
43 | package controller_b;\r |
44 | \r |
45 | use base 'base_controller';\r |
46 | \r |
47 | __PACKAGE__->config( key_b => 'value_b' );\r |
48 | }\r |
49 | \r |
50 | ## Okay, we expect that the base controller has a config with one key\r |
51 | ## and that the two children controllers inherit that config key and then\r |
52 | ## add one more. So the base controller has one config value and the two\r |
53 | ## children each have two.\r |
54 | \r |
55 | ## ----------------------------------------------------------------------------\r |
56 | ## THE TESTS. Basically we first check to make sure that all the children of\r |
57 | ## the base_controller properly inherit the {base_key => 'base_value'} info\r |
58 | ## and that each of the children also has it's local config data and that none\r |
59 | ## of the classes have data that is unexpected.\r |
60 | ## ----------------------------------------------------------------------------\r |
61 | \r |
62 | \r |
63 | # First round, does everything have what we expect to find? If these tests fail there is something\r |
64 | # wrong with the way config is storing it's information.\r |
65 | \r |
66 | ok( base_controller->config->{base_key} eq 'base_value', 'base_controller has expected config value for "base_key"') or\r |
67 | diag('"base_key" defined as "'.base_controller->config->{base_key}.'" and not "base_value" in config');\r |
68 | \r |
69 | ok( controller_a->config->{base_key} eq 'base_value', 'controller_a has expected config value for "base_key"') or\r |
70 | diag('"base_key" defined as "'.controller_a->config->{base_key}.'" and not "base_value" in config');\r |
71 | \r |
72 | ok( controller_a->config->{key_a} eq 'value_a', 'controller_a has expected config value for "key_a"') or\r |
73 | diag('"key_a" defined as "'.controller_a->config->{key_a}.'" and not "value_a" in config');\r |
74 | \r |
75 | ok( controller_b->config->{base_key} eq 'base_value', 'controller_b has expected config value for "base_key"') or\r |
76 | diag('"base_key" defined as "'.controller_b->config->{base_key}.'" and not "base_value" in config');\r |
77 | \r |
78 | ok( controller_b->config->{key_b} eq 'value_b', 'controller_b has expected config value for "key_b"') or\r |
79 | diag('"key_b" defined as "'.controller_b->config->{key_b}.'" and not "value_b" in config');\r |
80 | \r |
81 | # second round, does each controller have the expected number of config values? If this test fails there is\r |
82 | # probably some data collision between the controllers.\r |
83 | \r |
84 | ok( scalar(keys %{base_controller->config}) == 1, 'base_controller has the expected number of config values') or\r |
85 | diag("base_controller should have 1 config value, but it has ".scalar(keys %{base_controller->config}));\r |
86 | \r |
87 | ok( scalar(keys %{controller_a->config}) == 2, 'controller_a has the expected number of config values') or\r |
88 | diag("controller_a should have 2 config value, but it has ".scalar(keys %{base_controller->config}));\r |
89 | \r |
90 | ok( scalar(keys %{controller_b->config}) == 2, 'controller_b has the expected number of config values') or\r |
91 | diag("controller_a should have 2 config value, but it has ".scalar(keys %{base_controller->config}));\r |