X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Faggregate%2Funit_core_component_loading.t;h=7415a254148240ab8858357ce2d25971638e9c2f;hb=a987f40a116b21ecb196b0c43442499222e27507;hp=2586f2d0d2f3c21f9f34fd2a4bee5f5c02679889;hpb=5d50f369bffa3625ca983b72fc8bc013c8a1e802;p=catagits%2FCatalyst-Runtime.git diff --git a/t/aggregate/unit_core_component_loading.t b/t/aggregate/unit_core_component_loading.t index 2586f2d..7415a25 100644 --- a/t/aggregate/unit_core_component_loading.t +++ b/t/aggregate/unit_core_component_loading.t @@ -1,8 +1,5 @@ -# 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 -# One test for components in inner packages -use Test::More tests => 2 + 6 * 24 + 8 + 1; +# way too many tests to count +use Test::More; use strict; use warnings; @@ -11,6 +8,7 @@ use File::Spec; use File::Path; my $libdir = 'test_trash'; +local @INC = @INC; unshift(@INC, $libdir); my $appclass = 'TestComponents'; @@ -54,7 +52,7 @@ sub write_component_file { } sub make_component_file { - my ($type, $prefix, $name) = @_; + my ($libdir, $appclass, $type, $prefix, $name) = @_; my $compbase = "Catalyst::${type}"; my $fullname = "${appclass}::${prefix}::${name}"; @@ -78,9 +76,13 @@ EOF } foreach my $component (@components) { - make_component_file($component->{type}, - $component->{prefix}, - $component->{name}); + make_component_file( + $libdir, + $appclass, + $component->{type}, + $component->{prefix}, + $component->{name}, + ); } my $shut_up_deprecated_warnings = q{ @@ -89,12 +91,16 @@ my $shut_up_deprecated_warnings = q{ eval "package $appclass; use Catalyst; $shut_up_deprecated_warnings __PACKAGE__->setup"; +is_deeply( + [ sort $appclass->locate_components ], + [ map { $appclass . '::' . $_->{prefix} . '::' . $_->{name} } @components ], 'locate_components finds the components correctly' +); + can_ok( $appclass, 'components'); my $complist = $appclass->components; -# the +1 below is for the app class itself -is(scalar keys %$complist, 24+1, "Correct number of components loaded"); +is(scalar keys %$complist, 24, "Correct number of components loaded"); foreach (keys %$complist) { @@ -138,32 +144,58 @@ $appclass = 'ExtraOptions'; push @components, { type => 'View', prefix => 'Extra', name => 'Foo' }; foreach my $component (@components) { - make_component_file($component->{type}, - $component->{prefix}, - $component->{name}); + make_component_file( + $libdir, + $appclass, + $component->{type}, + $component->{prefix}, + $component->{name}, + ); } -eval qq( -package $appclass; -use Catalyst; -$shut_up_deprecated_warnings -__PACKAGE__->config->{ setup_components } = { - search_extra => [ '::Extra' ], - except => [ "${appclass}::Controller::Foo" ] -}; -__PACKAGE__->setup; -); +SKIP: { + # FIXME - any backcompat planned? + skip "search_extra has been removed", 5; + eval qq( + package $appclass; + use Catalyst; + $shut_up_deprecated_warnings + __PACKAGE__->config->{ setup_components } = { + search_extra => [ '::Extra' ], + except => [ "${appclass}::Controller::Foo" ] + }; + __PACKAGE__->setup; + ); + + { + my $config = { + search_extra => [ '::Extra' ], + except => [ "${appclass}::Controller::Foo" ] + }; + my @components_located = $appclass->locate_components($config); + my @components_expected; + for (@components) { + my $name = $appclass . '::' . $_->{prefix} . '::' . $_->{name}; + push @components_expected, $name if $name ne "${appclass}::Controller::Foo"; + } + is_deeply( + [ sort @components_located ], + [ sort @components_expected ], + 'locate_components finds the components correctly' + ); + } -can_ok( $appclass, 'components'); + can_ok( $appclass, 'components'); -$complist = $appclass->components; + $complist = $appclass->components; -is(scalar keys %$complist, 24+1, "Correct number of components loaded"); + is(scalar keys %$complist, 24+1, "Correct number of components loaded"); -ok( !exists $complist->{ "${appclass}::Controller::Foo" }, 'Controller::Foo was skipped' ); -ok( exists $complist->{ "${appclass}::Extra::Foo" }, 'Extra::Foo was loaded' ); + ok( !exists $complist->{ "${appclass}::Controller::Foo" }, 'Controller::Foo was skipped' ); + ok( exists $complist->{ "${appclass}::Extra::Foo" }, 'Extra::Foo was loaded' ); -rmtree($libdir); + rmtree($libdir); +} $appclass = "ComponentOnce"; @@ -206,8 +238,13 @@ 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', +# FIXME we need a much better way of components being able to generate +# sub-components of themselves (e.g. bring back expand_component_modules?) +# as otherwise we _have_ to construct / call the COMPONENT method +# explicitly to get all the sub-components built for Devel::InnerPackage +# to find them. See FIXME in Catalyst::IOC::Container +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"; @@ -224,3 +261,5 @@ eval "package $appclass; use Catalyst; __PACKAGE__->setup"; isa_ok($appclass->controller('Test'), 'Catalyst::Controller'); rmtree($libdir); + +done_testing;