Commit latest CPAN ver of TWMC to repo
[catagits/Test-WWW-Mechanize-Catalyst.git] / t / redirect.t
1 #!perl -T
2 use strict;
3 use warnings;
4 use lib 'lib';
5 use Test::More tests => 27;
6 use lib 't/lib';
7 use Test::WWW::Mechanize::Catalyst 'Catty';
8
9 my $root = "http://localhost";
10
11 my $m;
12 foreach 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)
29 my $prev = $m->response->previous->previous;
30 ok( $prev, "have a previous previous" );
31 is( $prev->code, 302, "was a redirect" );
32 like( $prev->header('Location'), '/hi$/', "to the right place" );