X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Funit_core_component.t;h=53d6567815ecf20616e1669306128f3d5ca7bf5e;hb=9b1db775e21c29d58957aa1eb7f1446c83b4967a;hp=151763b5b86d266621c104d4d65a55c430027c62;hpb=e96dc5be8bf154ff2e0df6640b972727235c3c86;p=catagits%2FCatalyst-Runtime.git diff --git a/t/unit_core_component.t b/t/unit_core_component.t index 151763b..53d6567 100644 --- a/t/unit_core_component.t +++ b/t/unit_core_component.t @@ -1,4 +1,4 @@ -use Test::More tests => 11; +use Test::More tests => 22; use strict; use warnings; @@ -23,16 +23,6 @@ is(MyApp->comp('C::Controller'), 'MyApp::C::Controller', 'Two-part return ok'); is(MyApp->comp('Model'), 'MyApp::M::Model', 'Single part return ok'); -# regexp fallback -{ - my $warnings = 0; - no warnings 'redefine'; - local *Catalyst::Log::warn = sub { $warnings++ }; - - is(MyApp->comp('::M::'), 'MyApp::M::Model', 'Regex return ok'); - ok( $warnings, 'regexp fallback for comp() warns' ); -} - is_deeply([ MyApp->comp() ], \@complist, 'Empty return ok'); # Is this desired behaviour? @@ -41,12 +31,37 @@ is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok'); # 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' ); + my @expected = sort qw( MyApp::C::Controller MyApp::M::Model ); + my @got = sort MyApp->comp( qr{::[MC]::} ); + is_deeply( \@got, \@expected, 'multiple results from regexp ok' ); } # failed search @@ -54,3 +69,25 @@ is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok'); 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'); +} +