Commit | Line | Data |
aa61c190 |
1 | use Test::More tests => 22; |
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 }); |
e96dc5be |
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 | |
6977fbff |
28 | # Is this desired behaviour? |
fbcc39ad |
29 | is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok'); |
6977fbff |
30 | |
31 | # regexp behavior |
32 | { |
33 | is_deeply( [ MyApp->comp( qr{Model} ) ], [ 'MyApp::M::Model'], 'regexp ok' ); |
75aff34d |
34 | is_deeply( [ MyApp->comp('MyApp::V::View$') ], [ 'MyApp::V::View' ], 'Explicit return ok'); |
35 | is_deeply( [ MyApp->comp('MyApp::C::Controller$') ], [ 'MyApp::C::Controller' ], 'Explicit return ok'); |
36 | is_deeply( [ MyApp->comp('MyApp::M::Model$') ], [ 'MyApp::M::Model' ], 'Explicit return ok'); |
aa61c190 |
37 | |
38 | # a couple other varieties for regexp fallback |
39 | is_deeply( [ MyApp->comp('M::Model') ], [ 'MyApp::M::Model' ], 'Explicit return ok'); |
40 | |
41 | { |
42 | my $warnings = 0; |
43 | no warnings 'redefine'; |
44 | local *Catalyst::Log::warn = sub { $warnings++ }; |
45 | |
46 | is_deeply( [ MyApp->comp('::M::Model') ], [ 'MyApp::M::Model' ], 'Explicit return ok'); |
47 | ok( $warnings, 'regexp fallback warnings' ); |
48 | |
49 | $warnings = 0; |
50 | is_deeply( [ MyApp->comp('Mode') ], [ 'MyApp::M::Model' ], 'Explicit return ok'); |
51 | ok( $warnings, 'regexp fallback warnings' ); |
52 | |
53 | $warnings = 0; |
54 | is(MyApp->comp('::M::'), 'MyApp::M::Model', 'Regex return ok'); |
55 | ok( $warnings, 'regexp fallback for comp() warns' ); |
56 | } |
57 | |
6977fbff |
58 | } |
59 | |
60 | # multiple returns |
61 | { |
62 | my @expected = qw( MyApp::C::Controller MyApp::M::Model ); |
63 | is_deeply( [ MyApp->comp( qr{::[MC]::} ) ], \@expected, 'multiple results fro regexp ok' ); |
64 | } |
65 | |
66 | # failed search |
67 | { |
68 | is_deeply( scalar MyApp->comp( qr{DNE} ), 0, 'no results for failed search' ); |
69 | } |
70 | |
aa61c190 |
71 | |
72 | #checking @args passed to ACCEPT_CONTEXT |
73 | { |
74 | my $args; |
75 | |
76 | no warnings; |
77 | *MyApp::M::Model::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args}; |
78 | |
79 | MyApp->component('MyApp::M::Model', qw/foo bar/); |
80 | is_deeply($args, [qw/foo bar/], 'args passed to ACCEPT_CONTEXT ok'); |
81 | |
82 | MyApp->component('M::Model', qw/foo2 bar2/); |
83 | is_deeply($args, [qw/foo2 bar2/], 'args passed to ACCEPT_CONTEXT ok'); |
84 | |
85 | MyApp->component('Mode', qw/foo3 bar3/); |
86 | is_deeply($args, [qw/foo3 bar3/], 'args passed to ACCEPT_CONTEXT ok'); |
87 | } |
88 | |