X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flive_component_controller_action_chained.t;h=d51ba0f86ecec35baba96b3bd8708b5c668e8476;hb=d666af81cece84d49c57bb91949641937ad57091;hp=0a8d32dc6b975370bec2a4c4feaac7a66d39a729;hpb=f88e7f694016c0878e1bbf68f5653118cd61f31a;p=catagits%2FCatalyst-Runtime.git diff --git a/t/live_component_controller_action_chained.t b/t/live_component_controller_action_chained.t index 0a8d32d..d51ba0f 100644 --- a/t/live_component_controller_action_chained.t +++ b/t/live_component_controller_action_chained.t @@ -10,7 +10,7 @@ our $iters; BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 2; } -use Test::More tests => 72*$iters; +use Test::More tests => 96*$iters; use Catalyst::Test 'TestApp'; if ( $ENV{CAT_BENCHMARK} ) { @@ -504,4 +504,167 @@ sub run_tests { $expected, 'Executed actions' ); is( $response->content, '1; 2', 'Content OK' ); } + + # + # Test behaviour of auto actions returning '1' for the chain. + # + { + my @expected = qw[ + TestApp::Controller::Action::Chained->begin + TestApp::Controller::Action::Chained::Auto->auto + TestApp::Controller::Action::Chained::Auto::Foo->auto + TestApp::Controller::Action::Chained::Auto->foo + TestApp::Controller::Action::Chained::Auto::Foo->fooend + TestApp::Controller::Action::Chained->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/chained/autochain1/1/fooend/2'), + "Behaviour when auto returns 1 correct" ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, '1; 2', 'Content OK' ); + } + + # + # Test behaviour of auto actions returning '0' for the chain. + # + { + my @expected = qw[ + TestApp::Controller::Action::Chained->begin + TestApp::Controller::Action::Chained::Auto->auto + TestApp::Controller::Action::Chained::Auto::Bar->auto + TestApp::Controller::Action::Chained->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/chained/autochain2/1/barend/2'), + "Behaviour when auto returns 0 correct" ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, '1; 2', 'Content OK' ); + } + + # + # Test what auto actions are run when namespaces are changed + # horizontally. + # + { + my @expected = qw[ + TestApp::Controller::Action::Chained->begin + TestApp::Controller::Action::Chained::Auto->auto + TestApp::Controller::Action::Chained::Auto::Foo->auto + TestApp::Controller::Action::Chained::Auto::Bar->crossloose + TestApp::Controller::Action::Chained::Auto::Foo->crossend + TestApp::Controller::Action::Chained->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/chained/auto_cross/1/crossend/2'), + "Correct auto actions are run on cross controller dispatch" ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, '1; 2', 'Content OK' ); + } + + # + # Test forwarding from auto action in chain dispatch. + # + { + my @expected = qw[ + TestApp::Controller::Action::Chained->begin + TestApp::Controller::Action::Chained::Auto->auto + TestApp::Controller::Action::Chained::Auto::Forward->auto + TestApp::Controller::Action::Chained::Auto->fw3 + TestApp::Controller::Action::Chained::Auto->fw1 + TestApp::Controller::Action::Chained::Auto::Forward->forwardend + TestApp::Controller::Action::Chained->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/chained/auto_forward/1/forwardend/2'), + "Forwarding out of auto in chain" ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, '1; 2', 'Content OK' ); + } + + # + # Detaching out of the auto action of a chain. + # + { + my @expected = qw[ + TestApp::Controller::Action::Chained->begin + TestApp::Controller::Action::Chained::Auto->auto + TestApp::Controller::Action::Chained::Auto::Detach->auto + TestApp::Controller::Action::Chained::Auto->fw3 + TestApp::Controller::Action::Chained->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/chained/auto_detach/1/detachend/2'), + "Detaching out of auto in chain" ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, '1; 2', 'Content OK' ); + } + + # + # Test forwarding from auto action in chain dispatch. + # + { + my $expected = undef; + + ok( my $response = request('http://localhost/chained/loose/23'), + "Loose end is not callable" ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->header('Status'), 500, 'Status OK' ); + } + + # + # Test forwarding out of a chain. + # + { + my @expected = qw[ + TestApp::Controller::Action::Chained->begin + TestApp::Controller::Action::Chained->chain_fw_a + TestApp::Controller::Action::Chained->fw_dt_target + TestApp::Controller::Action::Chained->chain_fw_b + TestApp::Controller::Action::Chained->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/chained/chain_fw/1/end/2'), + "Forwarding out a chain" ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, '1; 2', 'Content OK' ); + } + + # + # Test detaching out of a chain. + # + { + my @expected = qw[ + TestApp::Controller::Action::Chained->begin + TestApp::Controller::Action::Chained->chain_dt_a + TestApp::Controller::Action::Chained->fw_dt_target + TestApp::Controller::Action::Chained->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/chained/chain_dt/1/end/2'), + "Forwarding out a chain" ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, '1; 2', 'Content OK' ); + } }