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=9d831763fb83f854dfdbc74a6802a5c61fef1ee7;hb=7064f69b1dfb59d1f3bad647b2097d0320acce8a;hpb=372b0c1b8751c29e542dbc7624f11b8c99ef5742 diff --git a/t/aggregate/live_component_controller_action_chained.t b/t/aggregate/live_component_controller_action_chained.t index 9d83176..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; @@ -10,7 +8,9 @@ our $iters; BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; } -use Test::More tests => 147*$iters; +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. # @@ -815,7 +853,7 @@ sub run_tests { my @expected = qw[ TestApp::Controller::Action::Chained::Root->rootsub TestApp::Controller::Action::Chained::Root->endpointsub - TestApp->end + TestApp::Controller::Root->end ]; my $expected = join( ", ", @expected ); @@ -847,6 +885,30 @@ sub run_tests { } # + # Complex path with multiple non-capturing pathparts + # PathPart('') CaptureArgs(0), PathPart('foo') CaptureArgs(0), PathPart('') Args(0) + # should win over PathPart('') CaptureArgs(1), PathPart('') Args(0) + # + { + my @expected = qw[ + TestApp::Controller::Action::Chained->begin + TestApp::Controller::Action::Chained->mult_nopp2_base + TestApp::Controller::Action::Chained->mult_nopp2_nocap + TestApp::Controller::Action::Chained->mult_nopp2_action + TestApp::Controller::Action::Chained->mult_nopp2_action_default + TestApp::Controller::Action::Chained->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/chained/mult_nopp2/action'), + "Complex path with multiple non-capturing pathparts" ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, '; ', 'Content OK' ); + } + + # # Higher Args() hiding more specific CaptureArgs chains sections # { @@ -908,6 +970,51 @@ sub run_tests { is( $response->content => 'a; anchor.html', 'Content OK' ); } + # CaptureArgs(1) PathPart('...') should win over CaptureArgs(2) PathPart('') + { + my @expected = qw[ + TestApp::Controller::Action::Chained->begin + TestApp::Controller::Action::Chained::CaptureArgs->base + TestApp::Controller::Action::Chained::CaptureArgs->one_arg + TestApp::Controller::Action::Chained::CaptureArgs->edit_one_arg + TestApp::Controller::Action::Chained::CaptureArgs->end + ]; + + my $expected = join( ", ", @expected ); + + # should dispatch to /base/one_args/edit_one_arg + ok( my $response = request('http://localhost/captureargs/one/edit'), + 'Correct arg order ran' ); + TODO: { + local $TODO = 'Known bug'; + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, 'base; one_arg; edit_one_arg', 'Content OK' ); + } + } + + # PathPart('...') Args(1) should win over CaptureArgs(2) PathPart('') + { + my @expected = qw[ + TestApp::Controller::Action::Chained->begin + TestApp::Controller::Action::Chained::CaptureArgs->base + TestApp::Controller::Action::Chained::CaptureArgs->test_one_arg + TestApp::Controller::Action::Chained::CaptureArgs->end + ]; + + my $expected = join( ", ", @expected ); + + # should dispatch to /base/test_one_arg + ok( my $response = request('http://localhost/captureargs/test/one'), + 'Correct pathpart/arg ran' ); + TODO: { + local $TODO = 'Known bug'; + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, 'base; test_plus_arg; one;', 'Content OK' ); + } + } + # # Args(0) should win over Args() if we actually have no arguments. { @@ -1007,9 +1114,10 @@ sub run_tests { { ok( my $content = - get('http://localhost/chained/return_arg/foo%2Fbar%3B'), + get('http://localhost/chained/capture%2Farg%3B/return_arg/foo%2Fbar%3B'), 'request with URI-encoded arg' ); like( $content, qr{foo/bar;\z}, 'args decoded' ); + like( $content, qr{capture/arg;}, 'captureargs decoded' ); } { ok( my $content = @@ -1017,5 +1125,51 @@ sub run_tests { 'request with URI-encoded arg' ); like( $content, qr{foo/bar;\z}, 'args decoded' ); } + + # Test round tripping, specifically the / character %2F in uri_for: + # not being able to feed it back action + captureargs and args into uri for + # and result in the original request uri is a major piece of suck ;) + foreach my $thing ( + ['foo', 'bar'], + ['foo%2Fbar', 'baz'], + ['foo', 'bar%2Fbaz'], + ['foo%2Fbar', 'baz%2Fquux'], + ['foo%2Fbar', 'baz%2Fquux', { foo => 'bar', 'baz' => 'quux%2Ffrood'}], + ['foo%2Fbar', 'baz%2Fquux', { foo => 'bar', 'baz%2Ffnoo' => 'quux%2Ffrood'}], + ['h%C3%BCtte', 'h%C3%BCtte', { test => 'h%C3%BCtte' } ], + ) { + my $path = '/chained/roundtrip_urifor/' . + $thing->[0] . '/' . $thing->[1]; + $path .= '?' . join('&', + map { $_ .'='. $thing->[2]->{$_}} + sort keys %{$thing->[2]}) if $thing->[2]; + 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) + 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; +