Commit | Line | Data |
78330ec0 |
1 | use strict; |
495c46de |
2 | use warnings; |
3 | use Test::More; |
4 | use Moose::Meta::Class; |
78330ec0 |
5 | |
495c46de |
6 | Moose::Meta::Class->create( TestAppComponents => ( |
7 | superclasses => ['Catalyst'], |
8 | methods => { |
9 | locate_components => \&overriden_locate_components, |
10 | }, |
11 | )); |
78330ec0 |
12 | |
495c46de |
13 | TestAppComponents->components( {} ); |
78330ec0 |
14 | |
495c46de |
15 | # this is so TestAppComponents->container will work |
16 | TestAppComponents->setup_config; |
78330ec0 |
17 | |
495c46de |
18 | # this is so TestAppComponents->log->warn will work |
19 | TestAppComponents->setup_log; |
78330ec0 |
20 | |
495c46de |
21 | my @comps = TestAppComponents->locate_components; |
78330ec0 |
22 | |
495c46de |
23 | for my $component (@comps) { |
24 | Moose::Meta::Class->create( $component => ( |
25 | superclasses => ['Catalyst::Component'], |
26 | )); |
78330ec0 |
27 | } |
28 | |
78330ec0 |
29 | { |
30 | my @loaded_comps; |
31 | my $warnings = 0; |
32 | |
495c46de |
33 | no warnings 'redefine', 'once'; |
78330ec0 |
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" ); |
bdde1c83 |
42 | |
43 | # FIXME - do I need the original sort in locate_components service? |
44 | is_deeply( [ sort @comps ], [ sort @loaded_comps ], 'all components loaded' ); |
78330ec0 |
45 | } |
46 | |
b423664b |
47 | my @comps_copy = @comps; |
48 | |
49 | my @controllers = map { s/^TestAppComponents::(C|Controller):://; $_; } @comps_copy[0..7]; |
50 | my @models = map { s/^TestAppComponents::(M|Model):://; $_; } @comps_copy[8..15]; |
51 | my @views = map { s/^TestAppComponents::(V|View):://; $_; } @comps_copy[16..23]; |
78330ec0 |
52 | my $container = TestAppComponents->container; |
53 | |
54 | is_deeply( |
55 | [ sort $container->get_sub_container('controller')->get_service_list ], |
56 | [ sort @controllers ], |
57 | 'controllers are in the container', |
58 | ); |
59 | |
60 | is_deeply( |
89b6b254 |
61 | [ sort TestAppComponents->controllers ], |
62 | [ sort @controllers ], |
63 | 'controllers are listed correctly by $c->controllers()', |
64 | ); |
65 | |
66 | is_deeply( |
78330ec0 |
67 | [ sort $container->get_sub_container('model')->get_service_list ], |
68 | [ sort @models ], |
69 | 'models are in the container', |
70 | ); |
71 | |
72 | is_deeply( |
89b6b254 |
73 | [ sort TestAppComponents->models ], |
74 | [ sort @models ], |
75 | 'models are listed correctly by $c->models()', |
76 | ); |
77 | |
78 | is_deeply( |
78330ec0 |
79 | [ sort $container->get_sub_container('view')->get_service_list ], |
80 | [ sort @views ], |
81 | 'views are in the container', |
82 | ); |
83 | |
84 | is_deeply( |
89b6b254 |
85 | [ sort TestAppComponents->views ], |
86 | [ sort @views ], |
87 | 'views are listed correctly by $c->views()', |
88 | ); |
89 | |
90 | is_deeply( |
78330ec0 |
91 | [ sort keys %{ TestAppComponents->components } ], |
92 | [ sort @comps ], |
93 | 'all components are in the components accessor' |
94 | ); |
95 | |
96 | done_testing(); |
495c46de |
97 | |
98 | sub overriden_locate_components { |
99 | my @comps; |
100 | push @comps, "TestAppComponents::$_" for qw/ |
101 | C::Bar |
102 | C::Foo::Bar |
103 | C::Foo::Foo::Bar |
104 | C::Foo::Foo::Foo::Bar |
105 | Controller::Bar::Bar::Bar::Foo |
106 | Controller::Bar::Bar::Foo |
107 | Controller::Bar::Foo |
108 | Controller::Foo |
109 | M::Bar |
110 | M::Foo::Bar |
111 | M::Foo::Foo::Bar |
112 | M::Foo::Foo::Foo::Bar |
113 | Model::Bar::Bar::Bar::Foo |
114 | Model::Bar::Bar::Foo |
115 | Model::Bar::Foo |
116 | Model::Foo |
117 | V::Bar |
118 | V::Foo::Bar |
119 | V::Foo::Foo::Bar |
120 | V::Foo::Foo::Foo::Bar |
121 | View::Bar::Bar::Bar::Foo |
122 | View::Bar::Bar::Foo |
123 | View::Bar::Foo |
124 | View::Foo |
125 | /; |
126 | return @comps; |
127 | } |