removed component resolution regex fallback
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_component.t
1 use Test::More;
2 use strict;
3 use warnings;
4
5 use_ok('Catalyst');
6
7 my @complist = map { "MyApp::$_"; } qw/C::Controller M::Model V::View/;
8
9 {
10   package MyApp;
11
12   use base qw/Catalyst/;
13
14   __PACKAGE__->components({ map { ($_, $_) } @complist });
15
16   # this is so $c->log->warn will work
17   __PACKAGE__->setup_log;
18 }
19
20 is(MyApp->comp('MyApp::V::View'), 'MyApp::V::View', 'Explicit return ok');
21
22 is(MyApp->comp('C::Controller'), 'MyApp::C::Controller', 'Two-part return ok');
23
24 is(MyApp->comp('Model'), 'MyApp::M::Model', 'Single part return ok');
25
26 is_deeply([ MyApp->comp() ], \@complist, 'Empty return ok');
27
28 # Is this desired behaviour?
29 is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok');
30
31 # regexp behavior
32 {
33     is_deeply( [ MyApp->comp( qr{Model} ) ], [ 'MyApp::M::Model' ], 'regexp ok' );
34
35     {
36         my $warnings = 0;
37         no warnings 'redefine';
38         local *Catalyst::Log::warn = sub { $warnings++ };
39
40         is_deeply( [ MyApp->comp('::M::Model') ], \@complist, 'no results for regexp fallback');
41         ok( $warnings, 'regexp fallback warnings' );
42     }
43 }
44
45 # multiple returns
46 {
47     my @expected = sort qw( MyApp::C::Controller MyApp::M::Model );
48     my @got = sort MyApp->comp( qr{::[MC]::} );
49     is_deeply( \@got, \@expected, 'multiple results from regexp ok' );
50 }
51
52 # failed search
53 {
54     is_deeply( scalar MyApp->comp( qr{DNE} ), 0, 'no results for failed search' );
55 }
56
57
58 #checking @args passed to ACCEPT_CONTEXT
59 {
60     my $args;
61
62     {
63         no warnings 'once';
64         *MyApp::M::Model::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args};
65     }
66
67     my $c = bless {}, 'MyApp';
68
69     $c->component('MyApp::M::Model', qw/foo bar/);
70     is_deeply($args, [qw/foo bar/], 'args passed to ACCEPT_CONTEXT ok');
71
72     $c->component('M::Model', qw/foo2 bar2/);
73     is_deeply($args, [qw/foo2 bar2/], 'args passed to ACCEPT_CONTEXT ok');
74 }
75
76 done_testing;