Commit latest CPAN ver of TWMC to repo
[catagits/Test-WWW-Mechanize-Catalyst.git] / t / simple.t
CommitLineData
6bc86362 1#!perl -T
2use strict;
3use warnings;
4use lib 'lib';
5use Encode qw();
6use Test::More tests => 39;
7use lib 't/lib';
8use Test::WWW::Mechanize::Catalyst 'Catty';
9
10my $root = "http://localhost";
11
12my $m = Test::WWW::Mechanize::Catalyst->new( autocheck => 0 );
13
14$m->get_ok("$root/");
15is( $m->ct, "text/html" );
16$m->title_is("Root");
17$m->content_contains("This is the root page");
18
19$m->follow_link_ok( { text => 'Hello' } );
20is( $m->base, "http://localhost/hello/" );
21is( $m->ct, "text/html" );
22$m->title_is("Hello");
23$m->content_contains( Encode::decode( 'utf-8', "Hi there! ☺" ) );
24
25#use Devel::Peek; Dump $m->content;
26#Dump(Encode::decode('utf-8', "Hi there! ☺"));
27#exit;
28
29$m->get_ok("/");
30is( $m->ct, "text/html" );
31$m->title_is("Root");
32$m->content_contains("This is the root page");
33
34$m->get_ok("http://example.com/");
35is( $m->ct, "text/html" );
36$m->title_is("Root");
37$m->content_contains("This is the root page");
38
39$m->get_ok("/hello/");
40is( $m->ct, "text/html" );
41$m->title_is("Hello");
42$m->content_contains( Encode::decode( 'utf-8', "Hi there! ☺" ) );
43
44SKIP: {
45 eval { require Compress::Zlib; };
46 skip "Compress::Zlib needed to test gzip encoding", 4 if $@;
47 $m->get_ok("/gzipped/");
48 is( $m->ct, "text/html" );
49 $m->title_is("Hello");
50 $m->content_contains( Encode::decode( 'utf-8', "Hi there! ☺" ) );
51}
52
53$m->get("$root/die/");
54is( $m->status, 500 );
55is( $m->ct, "" );
56$m->title_is(undef);
57$m->content_is("");
58
59$m->get("/die/");
60is( $m->status, 500 );
61is( $m->ct, "" );
62$m->title_is(undef);
63$m->content_is("");
64
65$m->{catalyst_debug} = 1;
66$m->get("$root/die/");
67is( $m->status, 500 );
68is( $m->ct, "text/html" );
69$m->title_like(qr/Catty on Catalyst/);
70$m->content_like(qr/Caught exception in Catty/);
71$m->content_like(qr/erk/);
72$m->content_like(qr/This is the die page/);
73