X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Funit_core_component_loading.t;h=1944ab6e63b266e9009948e4d17aeeff10d3c598;hb=3433ebccdb24e3104817fe633522039965b375c5;hp=bae3c5e6d1ade154983d23d9bbf3bbeb78ed2738;hpb=7fa2c9c1b85c98786655ad5169708d8dc84e8353;p=catagits%2FCatalyst-Runtime.git diff --git a/t/unit_core_component_loading.t b/t/unit_core_component_loading.t index bae3c5e..1944ab6 100644 --- a/t/unit_core_component_loading.t +++ b/t/unit_core_component_loading.t @@ -1,7 +1,8 @@ # 2 initial tests, and 6 per component in the loop below # (do not forget to update the number of components in test 3 as well) # 5 extra tests for the loading options -use Test::More tests => 2 + 6 * 24 + 5; +# One test for components in inner packages +use Test::More tests => 2 + 6 * 24 + 8 + 1; use strict; use warnings; @@ -40,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); @@ -63,10 +64,10 @@ sub make_component_file { write_component_file(\@dir_list, $name_final, <NEXT::COMPONENT(\@_); + my \$self = shift->next::method(\@_); no strict 'refs'; *{\__PACKAGE__ . "::whoami"} = sub { return \__PACKAGE__; }; \$self; @@ -82,7 +83,11 @@ foreach my $component (@components) { $component->{name}); } -eval "package $appclass; use Catalyst; __PACKAGE__->setup"; +my $shut_up_deprecated_warnings = q{ + __PACKAGE__->log(Catalyst::Log->new('fatal')); +}; + +eval "package $appclass; use Catalyst; $shut_up_deprecated_warnings __PACKAGE__->setup"; can_ok( $appclass, 'components'); @@ -141,6 +146,7 @@ foreach my $component (@components) { eval qq( package $appclass; use Catalyst; +$shut_up_deprecated_warnings __PACKAGE__->config->{ setup_components } = { search_extra => [ '::Extra' ], except => [ "${appclass}::Controller::Foo" ] @@ -165,10 +171,13 @@ write_component_file([$libdir, $appclass, 'Model'], 'TopLevel', <NEXT::COMPONENT(\@_); + + my \$self = shift->next::method(\@_); no strict 'refs'; *{\__PACKAGE__ . "::whoami"} = sub { return \__PACKAGE__; }; + *${appclass}::Model::TopLevel::GENERATED::ACCEPT_CONTEXT = sub { + return bless {}, 'FooBarBazQuux'; + }; \$self; } @@ -184,8 +193,10 @@ write_component_file([$libdir, $appclass, 'Model', 'TopLevel'], 'Nested', <NEXT::COMPONENT(\@_); } +sub COMPONENT { \$called++;return shift->next::method(\@_); } +sub called { return \$called }; 1; EOF @@ -193,5 +204,23 @@ EOF eval "package $appclass; use Catalyst; __PACKAGE__->setup"; is($@, '', "Didn't load component twice"); +is($appclass->model('TopLevel::Nested')->called,1, 'COMPONENT called once'); + +ok($appclass->model('TopLevel::Generated'), 'Have generated model'); +is(ref($appclass->model('TopLevel::Generated')), 'FooBarBazQuux', + 'ACCEPT_CONTEXT in generated inner package fired as expected'); + +$appclass = "InnerComponent"; + +{ + package InnerComponent::Controller::Test; + use base 'Catalyst::Controller'; +} + +$INC{'InnerComponent/Controller/Test.pm'} = 1; + +eval "package $appclass; use Catalyst; __PACKAGE__->setup"; + +isa_ok($appclass->controller('Test'), 'Catalyst::Controller'); rmtree($libdir);