Commit | Line | Data |
5e3121a8 |
1 | use Test::More; |
fbcc39ad |
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 }); |
2f381252 |
15 | |
16 | # this is so $c->log->warn will work |
17 | __PACKAGE__->setup_log; |
fbcc39ad |
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 | |
fbcc39ad |
26 | is_deeply([ MyApp->comp() ], \@complist, 'Empty return ok'); |
27 | |
2f381252 |
28 | # Is this desired behaviour? |
fbcc39ad |
29 | is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok'); |
2f381252 |
30 | |
31 | # regexp behavior |
32 | { |
5a53ef3d |
33 | is_deeply( [ MyApp->comp( qr{Model} ) ], [ 'MyApp::M::Model' ], 'regexp ok' ); |
2f381252 |
34 | |
35 | { |
36 | my $warnings = 0; |
37 | no warnings 'redefine'; |
38 | local *Catalyst::Log::warn = sub { $warnings++ }; |
39 | |
5a53ef3d |
40 | is_deeply( [ MyApp->comp('::M::Model') ], \@complist, 'no reulsts for regexp fallback'); |
2f381252 |
41 | ok( $warnings, 'regexp fallback warnings' ); |
2f381252 |
42 | } |
43 | |
44 | } |
45 | |
46 | # multiple returns |
47 | { |
deca8181 |
48 | my @expected = sort qw( MyApp::C::Controller MyApp::M::Model ); |
49 | my @got = sort MyApp->comp( qr{::[MC]::} ); |
50 | is_deeply( \@got, \@expected, 'multiple results from regexp ok' ); |
2f381252 |
51 | } |
52 | |
53 | # failed search |
54 | { |
55 | is_deeply( scalar MyApp->comp( qr{DNE} ), 0, 'no results for failed search' ); |
56 | } |
57 | |
58 | |
59 | #checking @args passed to ACCEPT_CONTEXT |
60 | { |
61 | my $args; |
62 | |
15a32cd5 |
63 | { |
64 | no warnings 'once'; |
65 | *MyApp::M::Model::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args}; |
66 | } |
67 | |
68 | my $c = bless {}, 'MyApp'; |
2f381252 |
69 | |
15a32cd5 |
70 | $c->component('MyApp::M::Model', qw/foo bar/); |
2f381252 |
71 | is_deeply($args, [qw/foo bar/], 'args passed to ACCEPT_CONTEXT ok'); |
72 | |
15a32cd5 |
73 | $c->component('M::Model', qw/foo2 bar2/); |
2f381252 |
74 | is_deeply($args, [qw/foo2 bar2/], 'args passed to ACCEPT_CONTEXT ok'); |
5d50f369 |
75 | } |
2f381252 |
76 | |
5e3121a8 |
77 | done_testing; |