X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fredirect.t;h=a1a1603fd8d4921a8950d58c5069e2dfd603e44c;hb=60f2b4d9f5424b3b73780eada1bbfd64a006e625;hp=d7e25d4ad80fb69b164887bd64ee74d3663276f2;hpb=6bc863629dfa3bec1d938eb5a7af7ef68fd3849f;p=catagits%2FTest-WWW-Mechanize-Catalyst.git diff --git a/t/redirect.t b/t/redirect.t index d7e25d4..a1a1603 100644 --- a/t/redirect.t +++ b/t/redirect.t @@ -1,10 +1,13 @@ -#!perl -T +#!perl use strict; use warnings; use lib 'lib'; -use Test::More tests => 27; +use Test::More; use lib 't/lib'; use Test::WWW::Mechanize::Catalyst 'Catty'; +use HTTP::Request::Common; +use URI; +use Test::utf8; my $root = "http://localhost"; @@ -30,3 +33,43 @@ my $prev = $m->response->previous->previous; ok( $prev, "have a previous previous" ); is( $prev->code, 302, "was a redirect" ); like( $prev->header('Location'), '/hi$/', "to the right place" ); + +$m->get("$root/redirect_with_500"); +is ($m->status, 500, "Redirect not followed on 500"); + +my $req = GET "$root/redirect_to_utf8_upgraded_string"; +my $loc = $m->_do_catalyst_request($req)->header('Location'); +my $uri = URI->new_abs( $loc, $req->uri )->as_string; +is_sane_utf8($uri); +isnt_flagged_utf8($uri); + +# Check for max_redirects support +{ + $m = Test::WWW::Mechanize::Catalyst->new(max_redirect => 1); + is( $m->max_redirect, 1, 'max_redirect set' ); + + $m->get( "$root/bonjour" ); + ok( !$m->success, "get /bonjour with max_redirect=1 is not a success" ); + is( $m->response->redirects, 1, 'redirects only once' ); + like( $m->response->header('Client-Warning'), qr/Redirect loop detected/i, + 'sets Client-Warning header' ); +} + +# Make sure we can handle max_redirects=0 +{ + $m = Test::WWW::Mechanize::Catalyst->new(max_redirect => 0); + $m->get( "$root/hello" ); + ok( $m->success, "get /hello with max_redirect=0 succeeds" ); + is( $m->response->redirects, 0, 'no redirects' ); + ok( !$m->response->header('Client-Warning'), 'no Client-Warning header' ); + + # shouldn't be redirected if max_redirect == 0 + $m->get( "$root/bonjour" ); + ok( !$m->success, "get /bonjour with max_redirect=0 is not a success" ); + is( $m->response->redirects, 0, 'no redirects' ); + like( $m->response->header('Client-Warning'), qr/Redirect loop detected/i, + 'sets Client-Warning header' ); +} + +done_testing; +