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