Commit | Line | Data |
78330ec0 |
1 | package TestAppComponents; |
2 | use warnings; |
3 | use strict; |
4 | use base 'Catalyst'; |
5 | |
6 | sub 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 | |
45 | for my $component (TestAppComponents->locate_components) { |
46 | my $classname = "$component"; |
47 | eval <<COMPONENT; |
48 | package $classname; |
49 | use warnings; |
50 | use strict; |
51 | use base 'Catalyst::Component'; |
52 | |
53 | 1; |
54 | COMPONENT |
55 | } |
56 | |
57 | package main; |
58 | use strict; |
59 | use warnings; |
60 | |
61 | use Test::More; |
62 | |
63 | my @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 | |
81 | my @controllers = @comps[0..7]; |
82 | my @models = @comps[8..15]; |
83 | my @views = @comps[16..23]; |
84 | my $container = TestAppComponents->container; |
85 | |
86 | is_deeply( |
87 | [ sort $container->get_sub_container('controller')->get_service_list ], |
88 | [ sort @controllers ], |
89 | 'controllers are in the container', |
90 | ); |
91 | |
92 | is_deeply( |
89b6b254 |
93 | [ sort TestAppComponents->controllers ], |
94 | [ sort @controllers ], |
95 | 'controllers are listed correctly by $c->controllers()', |
96 | ); |
97 | |
98 | is_deeply( |
78330ec0 |
99 | [ sort $container->get_sub_container('model')->get_service_list ], |
100 | [ sort @models ], |
101 | 'models are in the container', |
102 | ); |
103 | |
104 | is_deeply( |
89b6b254 |
105 | [ sort TestAppComponents->models ], |
106 | [ sort @models ], |
107 | 'models are listed correctly by $c->models()', |
108 | ); |
109 | |
110 | is_deeply( |
78330ec0 |
111 | [ sort $container->get_sub_container('view')->get_service_list ], |
112 | [ sort @views ], |
113 | 'views are in the container', |
114 | ); |
115 | |
116 | is_deeply( |
89b6b254 |
117 | [ sort TestAppComponents->views ], |
118 | [ sort @views ], |
119 | 'views are listed correctly by $c->views()', |
120 | ); |
121 | |
122 | is_deeply( |
78330ec0 |
123 | [ sort keys %{ TestAppComponents->components } ], |
124 | [ sort @comps ], |
125 | 'all components are in the components accessor' |
126 | ); |
127 | |
128 | done_testing(); |