X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Faggregate%2Funit_core_mvc.t;h=c84e1d460c995051a882e37208708538ec46e4a7;hb=1e8c91ac049beb99fe82c74269fda1436b343d90;hp=876d31a146e7fd768175ad684f11c108c9ac0d34;hpb=5d50f369bffa3625ca983b72fc8bc013c8a1e802;p=catagits%2FCatalyst-Runtime.git diff --git a/t/aggregate/unit_core_mvc.t b/t/aggregate/unit_core_mvc.t index 876d31a..c84e1d4 100644 --- a/t/aggregate/unit_core_mvc.t +++ b/t/aggregate/unit_core_mvc.t @@ -1,4 +1,4 @@ -use Test::More tests => 46; +use Test::More; use strict; use warnings; @@ -24,6 +24,12 @@ my @complist = __PACKAGE__->setup_log; } +{ + package MyStringThing; + + use overload '""' => sub { $_[0]->{string} }, fallback => 1; +} + is( MyMVCTestApp->view('View'), 'MyMVCTestApp::V::View', 'V::View ok' ); is( MyMVCTestApp->controller('Controller'), @@ -117,6 +123,18 @@ is ( MyMVCTestApp->model , 'MyMVCTestApp::Model::M', 'default_model in class met # object w/ qr{} is_deeply( [ MyMVCTestApp->model( qr{Test} ) ], [ MyMVCTestApp->components->{'MyMVCTestApp::Model::Test::Object'} ], 'Object returned' ); + is_deeply([ MyMVCTestApp->model( bless({ string => 'Model' }, 'MyStringThing') ) ], [ MyMVCTestApp->components->{'MyMVCTestApp::M::Model'} ], 'Explicit model search with overloaded object'); + + { + my $warnings = 0; + no warnings 'redefine'; + local *Catalyst::Log::warn = sub { $warnings++ }; + + # object w/ regexp fallback + is_deeply( [ MyMVCTestApp->model( bless({ string => 'Test' }, 'MyStringThing') ) ], [ MyMVCTestApp->components->{'MyMVCTestApp::Model::Test::Object'} ], 'Object returned' ); + ok( $warnings, 'regexp fallback warnings' ); + } + { my $warnings = 0; no warnings 'redefine'; @@ -181,3 +199,49 @@ is ( MyMVCTestApp->model , 'MyMVCTestApp::Model::M', 'default_model in class met } + +{ + my $warn = ''; + no warnings 'redefine'; + local *Catalyst::Log::warn = sub { $warn .= $_[1] }; + + is_deeply (MyMVCTestApp->controller('MyMVCTestApp::Controller::C'), + MyMVCTestApp->components->{'MyMVCTestApp::Controller::C'}, + 'controller by fully qualified name ok'); + + # You probably meant $c->controller('C') instead of $c->controller({'MyMVCTestApp::Controller::C'}) + my ($suggested_comp_name, $orig_comp_name) = $warn =~ /You probably meant (.*) instead of (.*) /; + isnt($suggested_comp_name, $orig_comp_name, 'suggested fix in warning for fully qualified component names makes sense' ); +} + +{ + package MyApp::WithoutRegexFallback; + + use base qw/Catalyst/; + + __PACKAGE__->config( { disable_component_resolution_regex_fallback => 1 } ); + + __PACKAGE__->components( { map { ( ref($_)||$_ , $_ ) } + qw/MyApp::WithoutRegexFallback::Controller::Another::Foo/ } ); + + # allow $c->log->warn to work + __PACKAGE__->setup_log; +} + +{ + # test if non-regex component retrieval still works + is( MyApp::WithoutRegexFallback->controller('Another::Foo'), + 'MyApp::WithoutRegexFallback::Controller::Another::Foo', 'controller Another::Foo found'); +} + +{ + my $warnings = 0; + no warnings 'redefine'; + local *Catalyst::Log::warn = sub { $warnings++ }; + + # try to get nonexisting object w/o regexp fallback + is( MyApp::WithoutRegexFallback->controller('Foo'), undef, 'no controller Foo found'); + ok( !$warnings, 'no regexp fallback warnings' ); +} + +done_testing;