X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Faggregate%2Funit_core_mvc.t;h=280a7b9f6f9746a24ab1472d572f582af344587c;hb=06316b0d1f745d8a2775cabcae87737831f308f1;hp=fa1683c196b67fbc3e949982e1bcd406759beff5;hpb=e10b40fdbf404819d60169dee88175777d1bf109;p=catagits%2FCatalyst-Runtime.git diff --git a/t/aggregate/unit_core_mvc.t b/t/aggregate/unit_core_mvc.t index fa1683c..280a7b9 100644 --- a/t/aggregate/unit_core_mvc.t +++ b/t/aggregate/unit_core_mvc.t @@ -2,13 +2,16 @@ use Test::More; use strict; use warnings; +{ + no warnings 'redefine'; + *Catalyst::Utils::ensure_class_loaded = sub { }; +} + use Moose::Meta::Class; -use_ok('Catalyst'); +our @complist_suffix = qw/C::Controller M::Model V::View Controller::C Model::M View::V Controller::Model::Dummy::Model Model::Dummy::Model/; -our @complist = - map { "MyMVCTestApp::$_"; } - qw/C::Controller M::Model V::View Controller::C Model::M View::V Controller::Model::Dummy::Model Model::Dummy::Model/; +our @complist = map { "MyMVCTestApp::$_" } @complist_suffix; foreach my $comp (@complist) { Moose::Meta::Class->create( @@ -17,7 +20,6 @@ foreach my $comp (@complist) { ); } our $warnings = 0; -our $loaded = 0; Moose::Meta::Class->create('Some::Test::Object'); @@ -31,23 +33,27 @@ Moose::Meta::Class->create( use base qw/Catalyst/; - sub locate_components { - return (@::complist, 'MyMVCTestApp::Model::Test::Object'); - } - no warnings 'redefine'; - *Catalyst::Log::warn = sub { $::warnings++ }; - *Catalyst::Utils::ensure_class_loaded = sub { - my $class = shift; - $::loaded++ - if Class::MOP::is_class_loaded($class) && $class =~ /^MyMVCTestApp/ + + local *Catalyst::IOC::Container::build_locate_components_service = sub { + my $self = shift; + + return Bread::Board::BlockInjection->new( + lifecycle => 'Singleton', + name => 'locate_components', + block => sub { + return [@complist, 'MyMVCTestApp::Model::Test::Object']; + + }, + ); }; + local *Catalyst::Log::warn = sub { $warnings++ }; __PACKAGE__->setup; } ok( $warnings, 'Issues deprecated warnings' ); -is( $loaded, scalar @complist + 1, 'Loaded all components' ); +is( @{[ MyMVCTestApp->component_list ]}, scalar @complist + 1, 'Loaded all components' ); is( MyMVCTestApp->view('View'), 'MyMVCTestApp::V::View', 'V::View ok' ); @@ -86,10 +92,12 @@ is_deeply( [ sort MyMVCTestApp->models ], 'models ok'); { - $warnings = 0; + 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( MyMVCTestApp->view , undef, 'view() w/o a default is undef' ); + ok( $warnings, 'warnings thrown for view() w/o a default' ); } is ( bless ({stash=>{current_view=>'V'}}, 'MyMVCTestApp')->view , 'MyMVCTestApp::View::V', 'current_view ok'); @@ -101,15 +109,12 @@ is ( bless ({stash=>{current_view_instance=> $view, current_view=>'MyMVCTestApp: 'current_view_instance precedes current_view ok'); { - $warnings = 0; - - ok( my $model = MyMVCTestApp->model ); - - ok( (($model =~ /^MyMVCTestApp\::(M|Model)\::/) || - $model->isa('Some::Test::Object')), - 'model() with no defaults returns *something*' ); + my $warnings = 0; + no warnings 'redefine'; + local *Catalyst::Log::warn = sub { $warnings++ }; - ok( $warnings, 'model() w/o a default is random, warnings thrown' ); + is( MyMVCTestApp->model, undef, 'model() w/o a default is undef' ); + ok( $warnings, 'warnings thrown for model() w/o a default' ); } is ( bless ({stash=>{current_model=>'M'}}, 'MyMVCTestApp')->model , 'MyMVCTestApp::Model::M', 'current_model ok'); @@ -129,13 +134,66 @@ is ( bless ({stash=>{current_model_instance=> $model, current_model=>'MyMVCTestA is( get('/foo/test_controller'), 'bar', 'controller() with empty args returns current controller' ); } -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'); +our @complist_default_view = + map { "MyMVCTestAppDefaultView::$_" } @complist_suffix; + +{ + package MyMVCTestAppDefaultView; + + use base qw/Catalyst/; + no warnings 'redefine'; -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'); + local *Catalyst::IOC::Container::build_locate_components_service = sub { + my $self = shift; + + return Bread::Board::BlockInjection->new( + lifecycle => 'Singleton', + name => 'locate_components', + block => sub { + return \@complist_default_view; + }, + ); + }; + local *Catalyst::Log::warn = sub { $warnings++ }; + + __PACKAGE__->config( default_view => 'V' ); + + __PACKAGE__->setup; +} + +is( bless ({stash=>{}}, 'MyMVCTestAppDefaultView')->view, 'MyMVCTestAppDefaultView::View::V', 'default_view ok' ); +is( MyMVCTestAppDefaultView->view , 'MyMVCTestAppDefaultView::View::V', 'default_view in class method ok' ); + +our @complist_default_model = + map { "MyMVCTestAppDefaultModel::$_" } @complist_suffix; + +{ + package MyMVCTestAppDefaultModel; + + use base qw/Catalyst/; + + no warnings 'redefine'; + + local *Catalyst::IOC::Container::build_locate_components_service = sub { + my $self = shift; + + return Bread::Board::BlockInjection->new( + lifecycle => 'Singleton', + name => 'locate_components', + block => sub { + return \@complist_default_model; + }, + ); + }; + local *Catalyst::Log::warn = sub { $warnings++ }; + + __PACKAGE__->config( default_model => 'M' ); + + __PACKAGE__->setup; +} + +is( bless ({stash=>{}}, 'MyMVCTestAppDefaultModel')->model , 'MyMVCTestAppDefaultModel::Model::M', 'default_model ok' ); +is( MyMVCTestAppDefaultModel->model , 'MyMVCTestAppDefaultModel::Model::M', 'default_model in class method ok' ); # regexp behavior tests { @@ -148,7 +206,9 @@ is ( MyMVCTestApp->model , 'MyMVCTestApp::Model::M', 'default_model in class met is_deeply( [ MyMVCTestApp->model( qr{Test} ) ], [ MyMVCTestApp->components->{'MyMVCTestApp::Model::Test::Object'} ], 'Object returned' ); { - $warnings = 0; + my $warnings = 0; + no warnings 'redefine'; + local *Catalyst::Log::warn = sub { $warnings++ }; # object w/ regexp fallback is( MyMVCTestApp->model( 'Test' ), undef, 'no regexp fallback' ); @@ -212,6 +272,8 @@ is ( MyMVCTestApp->model , 'MyMVCTestApp::Model::M', 'default_model in class met use base qw/Catalyst/; + no warnings 'redefine'; + __PACKAGE__->config( { disable_component_resolution_regex_fallback => 1 } ); __PACKAGE__->components( { map { ( ref($_)||$_ , $_ ) }