X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Flive_component_controller_action_chained.t;h=411542ec58bc80fb0f521db1fe42bd020e68f446;hp=ee502146cd32ed4cbc4edcc65b42c7f0daec269e;hb=6365b5279cf3bbecd61735b3b744809983a7bfdc;hpb=8a6a6581d48a3c1c4d5f631cdb7cbda336c0e5e2 diff --git a/t/live_component_controller_action_chained.t b/t/live_component_controller_action_chained.t index ee50214..411542e 100644 --- a/t/live_component_controller_action_chained.t +++ b/t/live_component_controller_action_chained.t @@ -8,9 +8,9 @@ use lib "$FindBin::Bin/lib"; our $iters; -BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 2; } +BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; } -use Test::More tests => 101*$iters; +use Test::More tests => 118*$iters; use Catalyst::Test 'TestApp'; if ( $ENV{CAT_BENCHMARK} ) { @@ -57,7 +57,7 @@ sub run_tests { 'chained + local endpoint; missing last argument' ); is( $response->header('X-Catalyst-Executed'), $expected, 'Executed actions' ); - is( $response->header('Status'), 500, 'Status OK' ); + is( $response->code, 500, 'Status OK' ); } # @@ -235,7 +235,7 @@ sub run_tests { 'multi-action (three args, should lead to error)' ); is( $response->header('X-Catalyst-Executed'), $expected, 'Executed actions' ); - is( $response->header('Status'), 500, 'Status OK' ); + is( $response->code, 500, 'Status OK' ); } # @@ -646,7 +646,7 @@ sub run_tests { "Loose end is not callable" ); is( $response->header('X-Catalyst-Executed'), $expected, 'Executed actions' ); - is( $response->header('Status'), 500, 'Status OK' ); + is( $response->code, 500, 'Status OK' ); } # @@ -691,13 +691,29 @@ sub run_tests { } # + # Tests that an uri_for to a chained root index action + # returns the right value. + # + { + ok( my $response = request( + 'http://localhost/action/chained/to_root' ), + 'uri_for with chained root action as arg' ); + like( $response->content, + qr(URI:http://[^/]+/), + 'Correct URI generated' ); + } + + # # Test interception of recursive chains. This test was added because at # one point during the :Chained development, Catalyst used to hang on # recursive chains. # { eval { require 'TestAppChainedRecursive.pm' }; - pass( "Interception of recursive chains" ); + if ($run_number == 1) { + ok( ! $@, "Interception of recursive chains" ); + } + else { pass( "Interception of recursive chains already tested" ) } } # @@ -711,4 +727,105 @@ sub run_tests { } else { pass( "Error on absolute path part arguments already tested" ) } } + + # + # Test chained actions in the root controller + # + { + my @expected = qw[ + TestApp::Controller::Action::Chained::Root->rootsub + TestApp::Controller::Action::Chained::Root->endpointsub + TestApp->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/rootsub/1/endpointsub/2'), 'chained in root namespace' ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, '', 'Content OK' ); + } + + # + # Complex path with multiple empty pathparts + # + { + my @expected = qw[ + TestApp::Controller::Action::Chained->begin + TestApp::Controller::Action::Chained->mult_nopp_base + TestApp::Controller::Action::Chained->mult_nopp_all + TestApp::Controller::Action::Chained->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/chained/mult_nopp'), + "Complex path with multiple empty pathparts" ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, '; ', 'Content OK' ); + } + + # + # Higher Args() hiding more specific CaptureArgs chains sections + # + { + my @expected = qw[ + TestApp::Controller::Action::Chained->begin + TestApp::Controller::Action::Chained->cc_base + TestApp::Controller::Action::Chained->cc_link + TestApp::Controller::Action::Chained->cc_anchor + TestApp::Controller::Action::Chained->end + ]; + + my $expected = join ', ', @expected; + + ok( my $response = request('http://localhost/chained/choose_capture/anchor.html'), + 'Choose between an early Args() and a later more ideal chain' ); + is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions'); + is( $response->content => '; ', 'Content OK' ); + } + + # + # Less specific chain not being seen correctly due to earlier looser capture + # + { + my @expected = qw[ + TestApp::Controller::Action::Chained->begin + TestApp::Controller::Action::Chained->cc_base + TestApp::Controller::Action::Chained->cc_b + TestApp::Controller::Action::Chained->cc_b_link + TestApp::Controller::Action::Chained->cc_b_anchor + TestApp::Controller::Action::Chained->end + ]; + + my $expected = join ', ', @expected; + + ok( my $response = request('http://localhost/chained/choose_capture/b/a/anchor.html'), + 'Choose between a more specific chain and an earlier looser one' ); + is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions'); + is( $response->content => 'a; ', 'Content OK' ); + } + + # + # Check we get the looser one when it's the correct match + # + { + my @expected = qw[ + TestApp::Controller::Action::Chained->begin + TestApp::Controller::Action::Chained->cc_base + TestApp::Controller::Action::Chained->cc_a + TestApp::Controller::Action::Chained->cc_a_link + TestApp::Controller::Action::Chained->cc_a_anchor + TestApp::Controller::Action::Chained->end + ]; + + my $expected = join ', ', @expected; + + ok( my $response = request('http://localhost/chained/choose_capture/a/a/anchor.html'), + 'Choose between a more specific chain and an earlier looser one' ); + is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions'); + is( $response->content => 'a; anchor.html', 'Content OK' ); + } + }