skipped tests for expand_modules and search_extra, updated other bits
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_component_setup_components.t
CommitLineData
78330ec0 1use strict;
495c46de 2use warnings;
3use Test::More;
4use Moose::Meta::Class;
78330ec0 5
495c46de 6Moose::Meta::Class->create( TestAppComponents => (
7 superclasses => ['Catalyst'],
8 methods => {
9 locate_components => \&overriden_locate_components,
10 },
11));
78330ec0 12
495c46de 13TestAppComponents->components( {} );
78330ec0 14
495c46de 15# this is so TestAppComponents->container will work
16TestAppComponents->setup_config;
78330ec0 17
495c46de 18# this is so TestAppComponents->log->warn will work
19TestAppComponents->setup_log;
78330ec0 20
495c46de 21my @comps = TestAppComponents->locate_components;
78330ec0 22
495c46de 23for 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" );
42 is_deeply( \@comps, \@loaded_comps, 'all components loaded' );
43}
44
b423664b 45my @comps_copy = @comps;
46
47my @controllers = map { s/^TestAppComponents::(C|Controller):://; $_; } @comps_copy[0..7];
48my @models = map { s/^TestAppComponents::(M|Model):://; $_; } @comps_copy[8..15];
49my @views = map { s/^TestAppComponents::(V|View):://; $_; } @comps_copy[16..23];
78330ec0 50my $container = TestAppComponents->container;
51
52is_deeply(
53 [ sort $container->get_sub_container('controller')->get_service_list ],
54 [ sort @controllers ],
55 'controllers are in the container',
56);
57
58is_deeply(
89b6b254 59 [ sort TestAppComponents->controllers ],
60 [ sort @controllers ],
61 'controllers are listed correctly by $c->controllers()',
62);
63
64is_deeply(
78330ec0 65 [ sort $container->get_sub_container('model')->get_service_list ],
66 [ sort @models ],
67 'models are in the container',
68);
69
70is_deeply(
89b6b254 71 [ sort TestAppComponents->models ],
72 [ sort @models ],
73 'models are listed correctly by $c->models()',
74);
75
76is_deeply(
78330ec0 77 [ sort $container->get_sub_container('view')->get_service_list ],
78 [ sort @views ],
79 'views are in the container',
80);
81
82is_deeply(
89b6b254 83 [ sort TestAppComponents->views ],
84 [ sort @views ],
85 'views are listed correctly by $c->views()',
86);
87
88is_deeply(
78330ec0 89 [ sort keys %{ TestAppComponents->components } ],
90 [ sort @comps ],
91 'all components are in the components accessor'
92);
93
94done_testing();
495c46de 95
96sub 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}