TWMC: Fix bug where redirect was followed on a 500 response
[catagits/Test-WWW-Mechanize-Catalyst.git] / t / redirect.t
CommitLineData
affa35d5 1#!perl
6bc86362 2use strict;
3use warnings;
4use lib 'lib';
affa35d5 5use Test::More tests => 28;
6bc86362 6use lib 't/lib';
7use Test::WWW::Mechanize::Catalyst 'Catty';
8
9my $root = "http://localhost";
10
11my $m;
12foreach my $where (qw{hi greetings bonjour}) {
13 $m = Test::WWW::Mechanize::Catalyst->new;
14 $m->get_ok( "$root/$where", "got something when we $where" );
15
16 is( $m->base, "http://localhost/hello", "check got to hello 1/4" );
17 is( $m->ct, "text/html", "check got to hello 2/4" );
18 $m->title_is( "Hello",, "check got to hello 3/4" );
19 $m->content_contains( "Hi there",, "check got to hello 4/4" );
20
21 # check that the previous response is still there
22 my $prev = $m->response->previous;
23 ok( $prev, "have a previous" );
24 is( $prev->code, 302, "was a redirect" );
25 like( $prev->header('Location'), '/hello$/', "to the right place" );
26}
27
28# extra checks for bonjour (which is a double redirect)
29my $prev = $m->response->previous->previous;
30ok( $prev, "have a previous previous" );
31is( $prev->code, 302, "was a redirect" );
32like( $prev->header('Location'), '/hi$/', "to the right place" );
affa35d5 33
34$m->get("$root/redirect_with_500");
35is ($m->status, 500, "Redirect not followed on 500");