From: Florian Ragwitz Date: Sun, 27 Sep 2009 15:06:26 +0000 (+0000) Subject: More aggregated tests. X-Git-Tag: 5.80014~15^2~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=5d50f369bffa3625ca983b72fc8bc013c8a1e802 More aggregated tests. --- diff --git a/t/unit_controller_actions.t b/t/aggregate/unit_controller_actions.t similarity index 100% rename from t/unit_controller_actions.t rename to t/aggregate/unit_controller_actions.t diff --git a/t/unit_controller_config.t b/t/aggregate/unit_controller_config.t similarity index 100% rename from t/unit_controller_config.t rename to t/aggregate/unit_controller_config.t diff --git a/t/unit_controller_namespace.t b/t/aggregate/unit_controller_namespace.t similarity index 100% rename from t/unit_controller_namespace.t rename to t/aggregate/unit_controller_namespace.t diff --git a/t/unit_core_action.t b/t/aggregate/unit_core_action.t similarity index 100% rename from t/unit_core_action.t rename to t/aggregate/unit_core_action.t diff --git a/t/unit_core_classdata.t b/t/aggregate/unit_core_classdata.t similarity index 100% rename from t/unit_core_classdata.t rename to t/aggregate/unit_core_classdata.t diff --git a/t/unit_core_component.t b/t/aggregate/unit_core_component.t similarity index 99% rename from t/unit_core_component.t rename to t/aggregate/unit_core_component.t index 53d6567..69ac6c0 100644 --- a/t/unit_core_component.t +++ b/t/aggregate/unit_core_component.t @@ -89,5 +89,5 @@ is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok'); $c->component('Mode', qw/foo3 bar3/); is_deeply($args, [qw/foo3 bar3/], 'args passed to ACCEPT_CONTEXT ok'); -} +} diff --git a/t/unit_core_component_loading.t b/t/aggregate/unit_core_component_loading.t similarity index 99% rename from t/unit_core_component_loading.t rename to t/aggregate/unit_core_component_loading.t index 1944ab6..2586f2d 100644 --- a/t/unit_core_component_loading.t +++ b/t/aggregate/unit_core_component_loading.t @@ -41,7 +41,7 @@ my @components = ( { type => 'View', prefix => 'View', name => 'Foo' }, ); -sub write_component_file { +sub write_component_file { my ($dir_list, $module_name, $content) = @_; my $dir = File::Spec->catdir(@$dir_list); @@ -171,7 +171,7 @@ write_component_file([$libdir, $appclass, 'Model'], 'TopLevel', <next::method(\@_); no strict 'refs'; *{\__PACKAGE__ . "::whoami"} = sub { return \__PACKAGE__; }; diff --git a/t/unit_core_component_mro.t b/t/aggregate/unit_core_component_mro.t similarity index 81% rename from t/unit_core_component_mro.t rename to t/aggregate/unit_core_component_mro.t index a8699c3..8e9a064 100644 --- a/t/unit_core_component_mro.t +++ b/t/aggregate/unit_core_component_mro.t @@ -17,13 +17,13 @@ use warnings; } my $warn = ''; -{ +{ local $SIG{__WARN__} = sub { - $warn .= $_[0]; + $warn .= $_[0]; }; MyApp::MyComponent->COMPONENT('MyApp'); } -like($warn, qr/after Catalyst::Component in MyApp::Component/, +like($warn, qr/after Catalyst::Component in MyApp::Component/, 'correct warning thrown'); diff --git a/t/unit_core_engine_fixenv-iis6.t b/t/aggregate/unit_core_engine_fixenv-iis6.t similarity index 100% rename from t/unit_core_engine_fixenv-iis6.t rename to t/aggregate/unit_core_engine_fixenv-iis6.t diff --git a/t/unit_core_engine_fixenv-lighttpd.t b/t/aggregate/unit_core_engine_fixenv-lighttpd.t similarity index 100% rename from t/unit_core_engine_fixenv-lighttpd.t rename to t/aggregate/unit_core_engine_fixenv-lighttpd.t diff --git a/t/unit_core_log.t b/t/aggregate/unit_core_log.t similarity index 93% rename from t/unit_core_log.t rename to t/aggregate/unit_core_log.t index 26a52d3..c86aa82 100644 --- a/t/unit_core_log.t +++ b/t/aggregate/unit_core_log.t @@ -3,14 +3,10 @@ use warnings; use Test::More tests => 23; -my $LOG; +use Catalyst::Log; + +local *Catalyst::Log::_send_to_log; -BEGIN { - chdir 't' if -d 't'; - use lib '../lib'; - $LOG = 'Catalyst::Log'; - use_ok $LOG or die; -} my @MESSAGES; { no warnings 'redefine'; @@ -20,6 +16,8 @@ my @MESSAGES; }; } +my $LOG = 'Catalyst::Log'; + can_ok $LOG, 'new'; ok my $log = $LOG->new, '... and creating a new log object should succeed'; isa_ok $log, $LOG, '... and the object it returns'; diff --git a/t/unit_core_merge_config_hashes.t b/t/aggregate/unit_core_merge_config_hashes.t similarity index 84% rename from t/unit_core_merge_config_hashes.t rename to t/aggregate/unit_core_merge_config_hashes.t index 53f8be2..1ac737b 100644 --- a/t/unit_core_merge_config_hashes.t +++ b/t/aggregate/unit_core_merge_config_hashes.t @@ -34,10 +34,10 @@ my @tests = ( }, ); -plan tests => scalar @tests + 1; +plan tests => scalar @tests; -use_ok('Catalyst'); +use Catalyst::Component; for my $test ( @ tests ) { - is_deeply( Catalyst->merge_config_hashes( @{ $test->{ given } } ), $test->{ expects } ); + is_deeply( Catalyst::Component->merge_config_hashes( @{ $test->{ given } } ), $test->{ expects } ); } diff --git a/t/aggregate/unit_core_mvc.t b/t/aggregate/unit_core_mvc.t new file mode 100644 index 0000000..876d31a --- /dev/null +++ b/t/aggregate/unit_core_mvc.t @@ -0,0 +1,183 @@ +use Test::More tests => 46; +use strict; +use warnings; + +use_ok('Catalyst'); + +my @complist = + map { "MyMVCTestApp::$_"; } + qw/C::Controller M::Model V::View Controller::C Model::M View::V Controller::Model::Dummy::Model Model::Dummy::Model/; + +{ + + package MyMVCTestApp; + + use base qw/Catalyst/; + + __PACKAGE__->components( { map { ( ref($_)||$_ , $_ ) } @complist } ); + + my $thingie={}; + bless $thingie, 'Some::Test::Object'; + __PACKAGE__->components->{'MyMVCTestApp::Model::Test::Object'} = $thingie; + + # allow $c->log->warn to work + __PACKAGE__->setup_log; +} + +is( MyMVCTestApp->view('View'), 'MyMVCTestApp::V::View', 'V::View ok' ); + +is( MyMVCTestApp->controller('Controller'), + 'MyMVCTestApp::C::Controller', 'C::Controller ok' ); + +is( MyMVCTestApp->model('Model'), 'MyMVCTestApp::M::Model', 'M::Model ok' ); + +is( MyMVCTestApp->model('Dummy::Model'), 'MyMVCTestApp::Model::Dummy::Model', 'Model::Dummy::Model ok' ); + +isa_ok( MyMVCTestApp->model('Test::Object'), 'Some::Test::Object', 'Test::Object ok' ); + +is( MyMVCTestApp->controller('Model::Dummy::Model'), 'MyMVCTestApp::Controller::Model::Dummy::Model', 'Controller::Model::Dummy::Model ok' ); + +is( MyMVCTestApp->view('V'), 'MyMVCTestApp::View::V', 'View::V ok' ); + +is( MyMVCTestApp->controller('C'), 'MyMVCTestApp::Controller::C', 'Controller::C ok' ); + +is( MyMVCTestApp->model('M'), 'MyMVCTestApp::Model::M', 'Model::M ok' ); + +# failed search +{ + is( MyMVCTestApp->model('DNE'), undef, 'undef for invalid search' ); +} + +is_deeply( [ sort MyMVCTestApp->views ], + [ qw/V View/ ], + 'views ok' ); + +is_deeply( [ sort MyMVCTestApp->controllers ], + [ qw/C Controller Model::Dummy::Model/ ], + 'controllers ok'); + +is_deeply( [ sort MyMVCTestApp->models ], + [ qw/Dummy::Model M Model Test::Object/ ], + 'models ok'); + +{ + my $warnings = 0; + no warnings 'redefine'; + local *Catalyst::Log::warn = sub { $warnings++ }; + + like (MyMVCTestApp->view , qr/^MyMVCTestApp\::(V|View)\::/ , 'view() with no defaults returns *something*'); + ok( $warnings, 'view() w/o a default is random, warnings thrown' ); +} + +is ( bless ({stash=>{current_view=>'V'}}, 'MyMVCTestApp')->view , 'MyMVCTestApp::View::V', 'current_view ok'); + +my $view = bless {} , 'MyMVCTestApp::View::V'; +is ( bless ({stash=>{current_view_instance=> $view }}, 'MyMVCTestApp')->view , $view, 'current_view_instance ok'); + +is ( bless ({stash=>{current_view_instance=> $view, current_view=>'MyMVCTestApp::V::View' }}, 'MyMVCTestApp')->view , $view, + 'current_view_instance precedes current_view ok'); + +{ + my $warnings = 0; + no warnings 'redefine'; + local *Catalyst::Log::warn = sub { $warnings++ }; + + ok( my $model = MyMVCTestApp->model ); + + ok( (($model =~ /^MyMVCTestApp\::(M|Model)\::/) || + $model->isa('Some::Test::Object')), + 'model() with no defaults returns *something*' ); + + ok( $warnings, 'model() w/o a default is random, warnings thrown' ); +} + +is ( bless ({stash=>{current_model=>'M'}}, 'MyMVCTestApp')->model , 'MyMVCTestApp::Model::M', 'current_model ok'); + +my $model = bless {} , 'MyMVCTestApp::Model::M'; +is ( bless ({stash=>{current_model_instance=> $model }}, 'MyMVCTestApp')->model , $model, 'current_model_instance ok'); + +is ( bless ({stash=>{current_model_instance=> $model, current_model=>'MyMVCTestApp::M::Model' }}, 'MyMVCTestApp')->model , $model, + 'current_model_instance precedes current_model ok'); + +MyMVCTestApp->config->{default_view} = 'V'; +is ( bless ({stash=>{}}, 'MyMVCTestApp')->view , 'MyMVCTestApp::View::V', 'default_view ok'); +is ( MyMVCTestApp->view , 'MyMVCTestApp::View::V', 'default_view in class method ok'); + +MyMVCTestApp->config->{default_model} = 'M'; +is ( bless ({stash=>{}}, 'MyMVCTestApp')->model , 'MyMVCTestApp::Model::M', 'default_model ok'); +is ( MyMVCTestApp->model , 'MyMVCTestApp::Model::M', 'default_model in class method ok'); + +# regexp behavior tests +{ + # is_deeply is used because regexp behavior means list context + is_deeply( [ MyMVCTestApp->view( qr{^V[ie]+w$} ) ], [ 'MyMVCTestApp::V::View' ], 'regexp view ok' ); + is_deeply( [ MyMVCTestApp->controller( qr{Dummy\::Model$} ) ], [ 'MyMVCTestApp::Controller::Model::Dummy::Model' ], 'regexp controller ok' ); + is_deeply( [ MyMVCTestApp->model( qr{Dum{2}y} ) ], [ 'MyMVCTestApp::Model::Dummy::Model' ], 'regexp model ok' ); + + # object w/ qr{} + is_deeply( [ MyMVCTestApp->model( qr{Test} ) ], [ MyMVCTestApp->components->{'MyMVCTestApp::Model::Test::Object'} ], 'Object returned' ); + + { + my $warnings = 0; + no warnings 'redefine'; + local *Catalyst::Log::warn = sub { $warnings++ }; + + # object w/ regexp fallback + is_deeply( [ MyMVCTestApp->model( 'Test' ) ], [ MyMVCTestApp->components->{'MyMVCTestApp::Model::Test::Object'} ], 'Object returned' ); + ok( $warnings, 'regexp fallback warnings' ); + } + + is_deeply( [ MyMVCTestApp->view('MyMVCTestApp::V::View$') ], [ 'MyMVCTestApp::V::View' ], 'Explicit return ok'); + is_deeply( [ MyMVCTestApp->controller('MyMVCTestApp::C::Controller$') ], [ 'MyMVCTestApp::C::Controller' ], 'Explicit return ok'); + is_deeply( [ MyMVCTestApp->model('MyMVCTestApp::M::Model$') ], [ 'MyMVCTestApp::M::Model' ], 'Explicit return ok'); +} + +{ + my @expected = qw( MyMVCTestApp::C::Controller MyMVCTestApp::Controller::C ); + is_deeply( [ sort MyMVCTestApp->controller( qr{^C} ) ], \@expected, 'multiple controller returns from regexp search' ); +} + +{ + my @expected = qw( MyMVCTestApp::V::View MyMVCTestApp::View::V ); + is_deeply( [ sort MyMVCTestApp->view( qr{^V} ) ], \@expected, 'multiple view returns from regexp search' ); +} + +{ + my @expected = qw( MyMVCTestApp::M::Model MyMVCTestApp::Model::M ); + is_deeply( [ sort MyMVCTestApp->model( qr{^M} ) ], \@expected, 'multiple model returns from regexp search' ); +} + +# failed search +{ + is( scalar MyMVCTestApp->controller( qr{DNE} ), 0, '0 results for failed search' ); +} + +#checking @args passed to ACCEPT_CONTEXT +{ + my $args; + + { + no warnings 'once'; + *MyMVCTestApp::Model::M::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args}; + *MyMVCTestApp::View::V::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args}; + } + + my $c = bless {}, 'MyMVCTestApp'; + + # test accept-context with class rather than instance + MyMVCTestApp->model('M', qw/foo bar/); + is_deeply($args, [qw/foo bar/], 'MyMVCTestApp->model args passed to ACCEPT_CONTEXT ok'); + + + $c->model('M', qw/foo bar/); + is_deeply($args, [qw/foo bar/], '$c->model args passed to ACCEPT_CONTEXT ok'); + + my $x = $c->view('V', qw/foo2 bar2/); + is_deeply($args, [qw/foo2 bar2/], '$c->view args passed to ACCEPT_CONTEXT ok'); + + # regexp fallback + $c->view('::View::V', qw/foo3 bar3/); + is_deeply($args, [qw/foo3 bar3/], 'args passed to ACCEPT_CONTEXT ok'); + + +} diff --git a/t/unit_core_path_to.t b/t/aggregate/unit_core_path_to.t similarity index 100% rename from t/unit_core_path_to.t rename to t/aggregate/unit_core_path_to.t diff --git a/t/unit_core_plugin.t b/t/aggregate/unit_core_plugin.t similarity index 100% rename from t/unit_core_plugin.t rename to t/aggregate/unit_core_plugin.t diff --git a/t/unit_core_setup.t b/t/aggregate/unit_core_setup.t similarity index 100% rename from t/unit_core_setup.t rename to t/aggregate/unit_core_setup.t diff --git a/t/unit_core_setup_log.t b/t/aggregate/unit_core_setup_log.t similarity index 100% rename from t/unit_core_setup_log.t rename to t/aggregate/unit_core_setup_log.t diff --git a/t/unit_core_setup_stats.t b/t/aggregate/unit_core_setup_stats.t similarity index 97% rename from t/unit_core_setup_stats.t rename to t/aggregate/unit_core_setup_stats.t index 11ef840..fec2a99 100644 --- a/t/unit_core_setup_stats.t +++ b/t/aggregate/unit_core_setup_stats.t @@ -24,7 +24,7 @@ sub mock_app { %log_messages = (); # Flatten log messages. my $meta = Moose->init_meta( for_class => $name ); $meta->superclasses('Catalyst'); - $meta->add_method('log', sub { $mock_log }); + $meta->add_method('log', sub { $mock_log }); return $meta->name; } diff --git a/t/unit_core_uri_for.t b/t/aggregate/unit_core_uri_for.t similarity index 99% rename from t/unit_core_uri_for.t rename to t/aggregate/unit_core_uri_for.t index 3dd3a69..170e91b 100644 --- a/t/unit_core_uri_for.t +++ b/t/aggregate/unit_core_uri_for.t @@ -46,7 +46,7 @@ is( is (Catalyst::uri_for( $context, '/bar/wibble?' )->as_string, 'http://127.0.0.1/foo/bar/wibble%3F', 'Question Mark gets encoded' ); - + is( Catalyst::uri_for( $context, qw/bar wibble?/, 'with space' )->as_string, 'http://127.0.0.1/foo/yada/bar/wibble%3F/with%20space', 'Space gets encoded' ); diff --git a/t/unit_core_uri_with.t b/t/aggregate/unit_core_uri_with.t similarity index 100% rename from t/unit_core_uri_with.t rename to t/aggregate/unit_core_uri_with.t diff --git a/t/unit_dispatcher_requestargs_restore.t b/t/aggregate/unit_dispatcher_requestargs_restore.t similarity index 93% rename from t/unit_dispatcher_requestargs_restore.t rename to t/aggregate/unit_dispatcher_requestargs_restore.t index 1ffff9c..db1c132 100644 --- a/t/unit_dispatcher_requestargs_restore.t +++ b/t/aggregate/unit_dispatcher_requestargs_restore.t @@ -1,6 +1,6 @@ # Insane test case for the behavior needed by Plugin::Auhorization::ACL -# We have to localise $c->request->{arguments} in +# We have to localise $c->request->{arguments} in # Catalyst::Dispatcher::_do_forward, rather than using save and restore, # as otherwise, the calling $c->detach on an action which says # die $Catalyst:DETACH causes the request arguments to not get restored, diff --git a/t/unit_response.t b/t/aggregate/unit_response.t similarity index 100% rename from t/unit_response.t rename to t/aggregate/unit_response.t diff --git a/t/unit_utils_env_value.t b/t/aggregate/unit_utils_env_value.t similarity index 95% rename from t/unit_utils_env_value.t rename to t/aggregate/unit_utils_env_value.t index 015b455..5dd92cf 100644 --- a/t/unit_utils_env_value.t +++ b/t/aggregate/unit_utils_env_value.t @@ -1,9 +1,9 @@ use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 4; -BEGIN { use_ok("Catalyst::Utils") } +use Catalyst::Utils; ############################################################################## ### No env vars defined diff --git a/t/unit_utils_prefix.t b/t/aggregate/unit_utils_prefix.t similarity index 93% rename from t/unit_utils_prefix.t rename to t/aggregate/unit_utils_prefix.t index a1b7efa..506fbc2 100644 --- a/t/unit_utils_prefix.t +++ b/t/aggregate/unit_utils_prefix.t @@ -3,11 +3,11 @@ use strict; use warnings; -use Test::More tests => 9; +use Test::More tests => 8; use lib "t/lib"; -BEGIN { use_ok("Catalyst::Utils") }; +use Catalyst::Utils; is( Catalyst::Utils::class2prefix('MyApp::V::Foo::Bar'), 'foo/bar', 'class2prefix works with M/V/C' ); diff --git a/t/unit_utils_request.t b/t/aggregate/unit_utils_request.t similarity index 90% rename from t/unit_utils_request.t rename to t/aggregate/unit_utils_request.t index ce74d55..e02791b 100644 --- a/t/unit_utils_request.t +++ b/t/aggregate/unit_utils_request.t @@ -1,9 +1,9 @@ use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 4; -use_ok('Catalyst::Utils'); +use Catalyst::Utils; { my $url = "/dump"; diff --git a/t/unit_core_mvc.t b/t/unit_core_mvc.t deleted file mode 100644 index 8cb1fcb..0000000 --- a/t/unit_core_mvc.t +++ /dev/null @@ -1,183 +0,0 @@ -use Test::More tests => 46; -use strict; -use warnings; - -use_ok('Catalyst'); - -my @complist = - map { "MyApp::$_"; } - qw/C::Controller M::Model V::View Controller::C Model::M View::V Controller::Model::Dummy::Model Model::Dummy::Model/; - -{ - - package MyApp; - - use base qw/Catalyst/; - - __PACKAGE__->components( { map { ( ref($_)||$_ , $_ ) } @complist } ); - - my $thingie={}; - bless $thingie, 'Some::Test::Object'; - __PACKAGE__->components->{'MyApp::Model::Test::Object'} = $thingie; - - # allow $c->log->warn to work - __PACKAGE__->setup_log; -} - -is( MyApp->view('View'), 'MyApp::V::View', 'V::View ok' ); - -is( MyApp->controller('Controller'), - 'MyApp::C::Controller', 'C::Controller ok' ); - -is( MyApp->model('Model'), 'MyApp::M::Model', 'M::Model ok' ); - -is( MyApp->model('Dummy::Model'), 'MyApp::Model::Dummy::Model', 'Model::Dummy::Model ok' ); - -isa_ok( MyApp->model('Test::Object'), 'Some::Test::Object', 'Test::Object ok' ); - -is( MyApp->controller('Model::Dummy::Model'), 'MyApp::Controller::Model::Dummy::Model', 'Controller::Model::Dummy::Model ok' ); - -is( MyApp->view('V'), 'MyApp::View::V', 'View::V ok' ); - -is( MyApp->controller('C'), 'MyApp::Controller::C', 'Controller::C ok' ); - -is( MyApp->model('M'), 'MyApp::Model::M', 'Model::M ok' ); - -# failed search -{ - is( MyApp->model('DNE'), undef, 'undef for invalid search' ); -} - -is_deeply( [ sort MyApp->views ], - [ qw/V View/ ], - 'views ok' ); - -is_deeply( [ sort MyApp->controllers ], - [ qw/C Controller Model::Dummy::Model/ ], - 'controllers ok'); - -is_deeply( [ sort MyApp->models ], - [ qw/Dummy::Model M Model Test::Object/ ], - 'models ok'); - -{ - my $warnings = 0; - no warnings 'redefine'; - local *Catalyst::Log::warn = sub { $warnings++ }; - - like (MyApp->view , qr/^MyApp\::(V|View)\::/ , 'view() with no defaults returns *something*'); - ok( $warnings, 'view() w/o a default is random, warnings thrown' ); -} - -is ( bless ({stash=>{current_view=>'V'}}, 'MyApp')->view , 'MyApp::View::V', 'current_view ok'); - -my $view = bless {} , 'MyApp::View::V'; -is ( bless ({stash=>{current_view_instance=> $view }}, 'MyApp')->view , $view, 'current_view_instance ok'); - -is ( bless ({stash=>{current_view_instance=> $view, current_view=>'MyApp::V::View' }}, 'MyApp')->view , $view, - 'current_view_instance precedes current_view ok'); - -{ - my $warnings = 0; - no warnings 'redefine'; - local *Catalyst::Log::warn = sub { $warnings++ }; - - ok( my $model = MyApp->model ); - - ok( (($model =~ /^MyApp\::(M|Model)\::/) || - $model->isa('Some::Test::Object')), - 'model() with no defaults returns *something*' ); - - ok( $warnings, 'model() w/o a default is random, warnings thrown' ); -} - -is ( bless ({stash=>{current_model=>'M'}}, 'MyApp')->model , 'MyApp::Model::M', 'current_model ok'); - -my $model = bless {} , 'MyApp::Model::M'; -is ( bless ({stash=>{current_model_instance=> $model }}, 'MyApp')->model , $model, 'current_model_instance ok'); - -is ( bless ({stash=>{current_model_instance=> $model, current_model=>'MyApp::M::Model' }}, 'MyApp')->model , $model, - 'current_model_instance precedes current_model ok'); - -MyApp->config->{default_view} = 'V'; -is ( bless ({stash=>{}}, 'MyApp')->view , 'MyApp::View::V', 'default_view ok'); -is ( MyApp->view , 'MyApp::View::V', 'default_view in class method ok'); - -MyApp->config->{default_model} = 'M'; -is ( bless ({stash=>{}}, 'MyApp')->model , 'MyApp::Model::M', 'default_model ok'); -is ( MyApp->model , 'MyApp::Model::M', 'default_model in class method ok'); - -# regexp behavior tests -{ - # is_deeply is used because regexp behavior means list context - is_deeply( [ MyApp->view( qr{^V[ie]+w$} ) ], [ 'MyApp::V::View' ], 'regexp view ok' ); - is_deeply( [ MyApp->controller( qr{Dummy\::Model$} ) ], [ 'MyApp::Controller::Model::Dummy::Model' ], 'regexp controller ok' ); - is_deeply( [ MyApp->model( qr{Dum{2}y} ) ], [ 'MyApp::Model::Dummy::Model' ], 'regexp model ok' ); - - # object w/ qr{} - is_deeply( [ MyApp->model( qr{Test} ) ], [ MyApp->components->{'MyApp::Model::Test::Object'} ], 'Object returned' ); - - { - my $warnings = 0; - no warnings 'redefine'; - local *Catalyst::Log::warn = sub { $warnings++ }; - - # object w/ regexp fallback - is_deeply( [ MyApp->model( 'Test' ) ], [ MyApp->components->{'MyApp::Model::Test::Object'} ], 'Object returned' ); - ok( $warnings, 'regexp fallback warnings' ); - } - - is_deeply( [ MyApp->view('MyApp::V::View$') ], [ 'MyApp::V::View' ], 'Explicit return ok'); - is_deeply( [ MyApp->controller('MyApp::C::Controller$') ], [ 'MyApp::C::Controller' ], 'Explicit return ok'); - is_deeply( [ MyApp->model('MyApp::M::Model$') ], [ 'MyApp::M::Model' ], 'Explicit return ok'); -} - -{ - my @expected = qw( MyApp::C::Controller MyApp::Controller::C ); - is_deeply( [ sort MyApp->controller( qr{^C} ) ], \@expected, 'multiple controller returns from regexp search' ); -} - -{ - my @expected = qw( MyApp::V::View MyApp::View::V ); - is_deeply( [ sort MyApp->view( qr{^V} ) ], \@expected, 'multiple view returns from regexp search' ); -} - -{ - my @expected = qw( MyApp::M::Model MyApp::Model::M ); - is_deeply( [ sort MyApp->model( qr{^M} ) ], \@expected, 'multiple model returns from regexp search' ); -} - -# failed search -{ - is( scalar MyApp->controller( qr{DNE} ), 0, '0 results for failed search' ); -} - -#checking @args passed to ACCEPT_CONTEXT -{ - my $args; - - { - no warnings 'once'; - *MyApp::Model::M::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args}; - *MyApp::View::V::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args}; - } - - my $c = bless {}, 'MyApp'; - - # test accept-context with class rather than instance - MyApp->model('M', qw/foo bar/); - is_deeply($args, [qw/foo bar/], 'MyApp->model args passed to ACCEPT_CONTEXT ok'); - - - $c->model('M', qw/foo bar/); - is_deeply($args, [qw/foo bar/], '$c->model args passed to ACCEPT_CONTEXT ok'); - - my $x = $c->view('V', qw/foo2 bar2/); - is_deeply($args, [qw/foo2 bar2/], '$c->view args passed to ACCEPT_CONTEXT ok'); - - # regexp fallback - $c->view('::View::V', qw/foo3 bar3/); - is_deeply($args, [qw/foo3 bar3/], 'args passed to ACCEPT_CONTEXT ok'); - - -}