use strict;
use warnings;
use lib 'lib';
-use Test::More tests => 30;
+use Test::More;
use lib 't/lib';
use Test::WWW::Mechanize::Catalyst 'Catty';
use HTTP::Request::Common;
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;
+