Merge branch 'master' into gsoc_breadboard
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_component.t
CommitLineData
5e3121a8 1use Test::More;
fbcc39ad 2use strict;
3use warnings;
f06ed530 4use FindBin;
5use lib "$FindBin::Bin/../lib";
6use TestAppComponent;
fbcc39ad 7
f06ed530 8my @complist = map { "TestAppComponent::$_"; } qw/C::Controller M::Model V::View/;
fbcc39ad 9
f06ed530 10is(ref TestAppComponent->comp('TestAppComponent::V::View'), 'TestAppComponent::V::View', 'Explicit return ok');
fbcc39ad 11
f06ed530 12is(ref TestAppComponent->comp('C::Controller'), 'TestAppComponent::C::Controller', 'Two-part return ok');
fbcc39ad 13
f06ed530 14is(ref TestAppComponent->comp('Model'), 'TestAppComponent::M::Model', 'Single part return ok');
fbcc39ad 15
f06ed530 16is_deeply([ TestAppComponent->comp() ], \@complist, 'Empty return ok');
fbcc39ad 17
2f381252 18# Is this desired behaviour?
f06ed530 19is_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 68done_testing;