test was expecting wrong results
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_component_setup_components.t
1 use strict;
2 use warnings;
3 use Test::More;
4 use Moose::Meta::Class;
5
6 Moose::Meta::Class->create( TestAppComponents => (
7     superclasses => ['Catalyst'],
8     methods      => {
9         locate_components => \&overriden_locate_components,
10     },
11 ));
12
13 TestAppComponents->components( {} );
14
15 # this is so TestAppComponents->container will work
16 TestAppComponents->setup_config;
17
18 # this is so TestAppComponents->log->warn will work
19 TestAppComponents->setup_log;
20
21 my @comps = TestAppComponents->locate_components;
22
23 for my $component (@comps) {
24     Moose::Meta::Class->create( $component => (
25         superclasses => ['Catalyst::Component'],
26     ));
27 }
28
29 {
30     my @loaded_comps;
31     my $warnings = 0;
32
33     no warnings 'redefine', 'once';
34
35     local *Catalyst::Log::warn = sub { $warnings++ };
36     local *Catalyst::Utils::ensure_class_loaded = sub { my $class = shift; push @loaded_comps, $class; };
37
38     eval { TestAppComponents->setup_components };
39
40     ok( !$@, "setup_components doesnt die" );
41     ok( $warnings, "it warns about deprecated names" );
42     is_deeply( \@comps, \@loaded_comps, 'all components loaded' );
43 }
44
45 my @comps_copy  = @comps;
46
47 my @controllers = map { s/^TestAppComponents::(C|Controller):://; $_; } @comps_copy[0..7];
48 my @models      = map { s/^TestAppComponents::(M|Model):://; $_; }      @comps_copy[8..15];
49 my @views       = map { s/^TestAppComponents::(V|View):://; $_; }       @comps_copy[16..23];
50 my $container   = TestAppComponents->container;
51
52 is_deeply(
53     [ sort $container->get_sub_container('controller')->get_service_list ],
54     [ sort @controllers ],
55     'controllers are in the container',
56 );
57
58 is_deeply(
59     [ sort TestAppComponents->controllers ],
60     [ sort @controllers ],
61     'controllers are listed correctly by $c->controllers()',
62 );
63
64 is_deeply(
65     [ sort $container->get_sub_container('model')->get_service_list ],
66     [ sort @models ],
67     'models are in the container',
68 );
69
70 is_deeply(
71     [ sort TestAppComponents->models ],
72     [ sort @models ],
73     'models are listed correctly by $c->models()',
74 );
75
76 is_deeply(
77     [ sort $container->get_sub_container('view')->get_service_list ],
78     [ sort @views ],
79     'views are in the container',
80 );
81
82 is_deeply(
83     [ sort TestAppComponents->views ],
84     [ sort @views ],
85     'views are listed correctly by $c->views()',
86 );
87
88 is_deeply(
89     [ sort keys %{ TestAppComponents->components } ],
90     [ sort @comps ],
91     'all components are in the components accessor'
92 );
93
94 done_testing();
95
96 sub overriden_locate_components {
97     my @comps;
98     push @comps, "TestAppComponents::$_" for qw/
99         C::Bar
100         C::Foo::Bar
101         C::Foo::Foo::Bar
102         C::Foo::Foo::Foo::Bar
103         Controller::Bar::Bar::Bar::Foo
104         Controller::Bar::Bar::Foo
105         Controller::Bar::Foo
106         Controller::Foo
107         M::Bar
108         M::Foo::Bar
109         M::Foo::Foo::Bar
110         M::Foo::Foo::Foo::Bar
111         Model::Bar::Bar::Bar::Foo
112         Model::Bar::Bar::Foo
113         Model::Bar::Foo
114         Model::Foo
115         V::Bar
116         V::Foo::Bar
117         V::Foo::Foo::Bar
118         V::Foo::Foo::Foo::Bar
119         View::Bar::Bar::Bar::Foo
120         View::Bar::Bar::Foo
121         View::Bar::Foo
122         View::Foo
123     /;
124     return @comps;
125 }