stop using Moo as a test package
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_controller_config.t
CommitLineData
c7ded7aa 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## ============================================================================
6
7use Test::More tests => 9;
8
9use strict;
10use warnings;
11
12use_ok('Catalyst');
13
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
17## be able to find.
18## ----------------------------------------------------------------------------
19
20{
21 package base_controller;
22
23 use base 'Catalyst::Controller';
24
25 __PACKAGE__->config( base_key => 'base_value' );
26}
27
28## ----------------------------------------------------------------------------
29## Next we instantiate two classes that inherit from the base controller. We
30## Add some local config information to these.
31## ----------------------------------------------------------------------------
32
33{
34 package controller_a;
35
36 use base 'base_controller';
43c58153 37
c7ded7aa 38 __PACKAGE__->config( key_a => 'value_a' );
39}
43c58153 40
41
c7ded7aa 42{
43 package controller_b;
44
45 use base 'base_controller';
46
300633a8 47 __PACKAGE__->config->{key_b} = 'value_b';
c7ded7aa 48}
49
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.
54
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
43c58153 58## and that each of the children also has its local config data and that none
c7ded7aa 59## of the classes have data that is unexpected.
60## ----------------------------------------------------------------------------
61
62
63# First round, does everything have what we expect to find? If these tests fail there is something
43c58153 64# wrong with the way config is storing its information.
c7ded7aa 65
66ok( 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');
68
69ok( 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');
43c58153 71
c7ded7aa 72ok( 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');
74
75ok( 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');
43c58153 77
c7ded7aa 78ok( 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');
80
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.
83
84ok( 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}));
43c58153 86
c7ded7aa 87ok( 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}));
43c58153 89
c7ded7aa 90ok( 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}));