X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Funit_core_component.t;h=368f163c46664c028ab83a49f29f375fd3b4b682;hp=d12ad598bdc037ee8504e34820af628f05993a3f;hb=4ac0b9cb8e9043db8a95f44af685c782bf9426e7;hpb=66741f94ac93b7ba0989db3556d0e3fe36c1be87 diff --git a/t/unit_core_component.t b/t/unit_core_component.t index d12ad59..368f163 100644 --- a/t/unit_core_component.t +++ b/t/unit_core_component.t @@ -1,4 +1,4 @@ -use Test::More tests => 7; +use Test::More tests => 22; use strict; use warnings; @@ -12,6 +12,9 @@ my @complist = map { "MyApp::$_"; } qw/C::Controller M::Model V::View/; use base qw/Catalyst/; __PACKAGE__->components({ map { ($_, $_) } @complist }); + + # this is so $c->log->warn will work + __PACKAGE__->setup_log; } is(MyApp->comp('MyApp::V::View'), 'MyApp::V::View', 'Explicit return ok'); @@ -20,9 +23,70 @@ is(MyApp->comp('C::Controller'), 'MyApp::C::Controller', 'Two-part return ok'); is(MyApp->comp('Model'), 'MyApp::M::Model', 'Single part return ok'); -is(MyApp->comp('::M::'), 'MyApp::M::Model', 'Regex return ok'); - is_deeply([ MyApp->comp() ], \@complist, 'Empty return ok'); +# Is this desired behaviour? is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok'); - # Is this desired behaviour? + +# regexp behavior +{ + is_deeply( [ MyApp->comp( qr{Model} ) ], [ 'MyApp::M::Model'], 'regexp ok' ); + is_deeply( [ MyApp->comp('MyApp::V::View$') ], [ 'MyApp::V::View' ], 'Explicit return ok'); + is_deeply( [ MyApp->comp('MyApp::C::Controller$') ], [ 'MyApp::C::Controller' ], 'Explicit return ok'); + is_deeply( [ MyApp->comp('MyApp::M::Model$') ], [ 'MyApp::M::Model' ], 'Explicit return ok'); + + # a couple other varieties for regexp fallback + is_deeply( [ MyApp->comp('M::Model') ], [ 'MyApp::M::Model' ], 'Explicit return ok'); + + { + my $warnings = 0; + no warnings 'redefine'; + local *Catalyst::Log::warn = sub { $warnings++ }; + + is_deeply( [ MyApp->comp('::M::Model') ], [ 'MyApp::M::Model' ], 'Explicit return ok'); + ok( $warnings, 'regexp fallback warnings' ); + + $warnings = 0; + is_deeply( [ MyApp->comp('Mode') ], [ 'MyApp::M::Model' ], 'Explicit return ok'); + ok( $warnings, 'regexp fallback warnings' ); + + $warnings = 0; + is(MyApp->comp('::M::'), 'MyApp::M::Model', 'Regex return ok'); + ok( $warnings, 'regexp fallback for comp() warns' ); + } + +} + +# multiple returns +{ + my @expected = qw( MyApp::C::Controller MyApp::M::Model ); + is_deeply( [ MyApp->comp( qr{::[MC]::} ) ], \@expected, 'multiple results fro regexp ok' ); +} + +# failed search +{ + is_deeply( scalar MyApp->comp( qr{DNE} ), 0, 'no results for failed search' ); +} + + +#checking @args passed to ACCEPT_CONTEXT +{ + my $args; + + { + no warnings 'once'; + *MyApp::M::Model::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args}; + } + + my $c = bless {}, 'MyApp'; + + $c->component('MyApp::M::Model', qw/foo bar/); + is_deeply($args, [qw/foo bar/], 'args passed to ACCEPT_CONTEXT ok'); + + $c->component('M::Model', qw/foo2 bar2/); + is_deeply($args, [qw/foo2 bar2/], 'args passed to ACCEPT_CONTEXT ok'); + + $c->component('Mode', qw/foo3 bar3/); + is_deeply($args, [qw/foo3 bar3/], 'args passed to ACCEPT_CONTEXT ok'); +} +