Commit | Line | Data |
5e3121a8 |
1 | use Test::More; |
fbcc39ad |
2 | use strict; |
3 | use warnings; |
f06ed530 |
4 | use FindBin; |
5 | use lib "$FindBin::Bin/../lib"; |
6 | use TestAppComponent; |
fbcc39ad |
7 | |
f06ed530 |
8 | my @complist = map { "TestAppComponent::$_"; } qw/C::Controller M::Model V::View/; |
fbcc39ad |
9 | |
f06ed530 |
10 | is(ref TestAppComponent->comp('TestAppComponent::V::View'), 'TestAppComponent::V::View', 'Explicit return ok'); |
fbcc39ad |
11 | |
f06ed530 |
12 | is(ref TestAppComponent->comp('C::Controller'), 'TestAppComponent::C::Controller', 'Two-part return ok'); |
fbcc39ad |
13 | |
f06ed530 |
14 | is(ref TestAppComponent->comp('Model'), 'TestAppComponent::M::Model', 'Single part return ok'); |
fbcc39ad |
15 | |
f06ed530 |
16 | is_deeply([ TestAppComponent->comp() ], \@complist, 'Empty return ok'); |
fbcc39ad |
17 | |
2f381252 |
18 | # Is this desired behaviour? |
f06ed530 |
19 | is_deeply([ TestAppComponent->comp('Foo') ], \@complist, 'Fallthrough return ok'); |
2f381252 |
20 | |
21 | # regexp behavior |
22 | { |
f06ed530 |
23 | is_deeply( [ map { ref $_ } TestAppComponent->comp( qr{Model} ) ], [ 'TestAppComponent::M::Model' ], 'regexp ok' ); |
2f381252 |
24 | |
25 | { |
26 | my $warnings = 0; |
27 | no warnings 'redefine'; |
28 | local *Catalyst::Log::warn = sub { $warnings++ }; |
29 | |
b697c138 |
30 | is_deeply( [ TestAppComponent->comp('::M::Model$') ], \@complist, 'no results for regexp fallback'); |
2f381252 |
31 | ok( $warnings, 'regexp fallback warnings' ); |
2f381252 |
32 | } |
33 | |
34 | } |
35 | |
36 | # multiple returns |
37 | { |
f06ed530 |
38 | # already sorted |
39 | my @expected = qw( TestAppComponent::C::Controller TestAppComponent::M::Model ); |
40 | my @got = map { ref $_ } sort TestAppComponent->comp( qr{::[MC]::} ); |
deca8181 |
41 | is_deeply( \@got, \@expected, 'multiple results from regexp ok' ); |
2f381252 |
42 | } |
43 | |
44 | # failed search |
45 | { |
f06ed530 |
46 | is_deeply( scalar TestAppComponent->comp( qr{DNE} ), 0, 'no results for failed search' ); |
2f381252 |
47 | } |
48 | |
49 | |
50 | #checking @args passed to ACCEPT_CONTEXT |
51 | { |
52 | my $args; |
53 | |
15a32cd5 |
54 | { |
55 | no warnings 'once'; |
f06ed530 |
56 | *TestAppComponent::M::Model::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args}; |
15a32cd5 |
57 | } |
58 | |
f06ed530 |
59 | my $c = bless {}, 'TestAppComponent'; |
2f381252 |
60 | |
f06ed530 |
61 | $c->component('TestAppComponent::M::Model', qw/foo bar/); |
2f381252 |
62 | is_deeply($args, [qw/foo bar/], 'args passed to ACCEPT_CONTEXT ok'); |
63 | |
15a32cd5 |
64 | $c->component('M::Model', qw/foo2 bar2/); |
2f381252 |
65 | is_deeply($args, [qw/foo2 bar2/], 'args passed to ACCEPT_CONTEXT ok'); |
5d50f369 |
66 | } |
2f381252 |
67 | |
5e3121a8 |
68 | done_testing; |