X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Faggregate%2Flive_component_controller_action_chained.t;h=f0cbc6a74c16edecd69c8a55341c2465e52c8ced;hp=efea301b4bc566d7454d97e6de1d41fe1c0e410e;hb=10542b5178b2fa036e0658111523ea68a7a04437;hpb=29076427c02971d7b3e65326131ff77ca5a43de7 diff --git a/t/aggregate/live_component_controller_action_chained.t b/t/aggregate/live_component_controller_action_chained.t index efea301..f0cbc6a 100644 --- a/t/aggregate/live_component_controller_action_chained.t +++ b/t/aggregate/live_component_controller_action_chained.t @@ -1,5 +1,3 @@ -#!perl - use strict; use warnings; @@ -11,6 +9,8 @@ our $iters; BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; } use Test::More; +use URI; +use URI::QueryParam; use Catalyst::Test 'TestApp'; if ( $ENV{CAT_BENCHMARK} ) { @@ -771,6 +771,44 @@ sub run_tests { } # + # Test throwing an error in the middle of a chain. + # + { + my @expected = qw[ + TestApp::Controller::Action::Chained->begin + TestApp::Controller::Action::Chained->chain_error_a + TestApp::Controller::Action::Chained->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/chained/chain_error/1/end/2'), + "Break a chain in the middle" ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, 'FATAL ERROR: break in the middle of a chain', 'Content OK' ); + } + + # + # Test dieing in the middle of a chain. + # + { + my @expected = qw[ + TestApp::Controller::Action::Chained->begin + TestApp::Controller::Action::Chained->chain_die_a + TestApp::Controller::Action::Chained->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/chained/chain_die/1/end/2'), + "Break a chain in the middle" ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, 'FATAL ERROR: Caught exception in TestApp::Controller::Action::Chained->chain_die_a "die in the middle of a chain"', 'Content OK' ); + } + + # # Tests that an uri_for to a chained root index action # returns the right value. # @@ -1108,11 +1146,29 @@ sub run_tests { ok( my $content = get('http://localhost/' . $path), 'request ' . $path . ' ok'); + my $exp = URI->new('http://localhost:3000' . $path); + my ($want) = $content =~ m{/chained/(.*)}; + my $got = URI->new('http://localhost:3000/chained/' . $want); # Just check that the path matches, as who the hell knows or cares # where the app is based (live tests etc) - ok( index($content, $path) > 1, 'uri can round trip through uri_for' ) + is $got->path, $exp->path, "uri $path can round trip through uri_for (path)" + or diag("Expected $path, got $content"); + is_deeply $got->query_form_hash, $exp->query_form_hash, "uri $path can round trip through uri_for (query)" or diag("Expected $path, got $content"); } + + # + # match_captures + # + { + + ok( my $response = request('http://localhost/chained/match_captures/foo/bar'), 'match_captures: falling through' ); + is($response->header('X-TestAppActionTestMatchCaptures'), 'fallthrough', 'match_captures: fell through'); + + ok($response = request('http://localhost/chained/match_captures/force/bar'), 'match_captures: *not* falling through' ); + is($response->header('X-TestAppActionTestMatchCaptures'), 'forcing', 'match_captures: forced'); + is($response->header('X-TestAppActionTestMatchCapturesHasRan'), 'yes', 'match_captures: actually ran'); + } } done_testing;