attempt to get this actually right this time
[catagits/Test-WWW-Mechanize-Catalyst.git] / t / simple.t
1 #!perl
2 use strict;
3 use warnings;
4
5 use Encode qw();
6 use Test::More tests => 37;
7 use lib 't/lib';
8 BEGIN {
9     $ENV{CATALYST_DEBUG} = 0;
10     $ENV{CATTY_DEBUG} = 0;
11 }
12 use Test::WWW::Mechanize::Catalyst 'Catty';
13
14 my $root = "http://localhost";
15
16 my $m = Test::WWW::Mechanize::Catalyst->new( autocheck => 0 );
17
18 $m->get_ok("$root/");
19 is( $m->ct, "text/html" );
20 $m->title_is("Root");
21 $m->content_contains("This is the root page");
22
23 $m->follow_link_ok( { text => 'Hello' } );
24 is( $m->base, "http://localhost/hello/" );
25 is( $m->ct,   "text/html" );
26 $m->title_is("Hello");
27 my $bytes = "Hi there! ☺";
28 my $chars = Encode::decode( 'utf-8', $bytes );
29 $m->content_contains( $chars, qq{content contains "$bytes"});
30
31 #use Devel::Peek; Dump $m->content;
32 #Dump(Encode::decode('utf-8', "Hi there! ☺"));
33 #exit;
34
35 $m->get_ok("/");
36 is( $m->ct, "text/html" );
37 $m->title_is("Root");
38 $m->content_contains("This is the root page");
39
40 $m->get_ok("http://example.com/");
41 is( $m->ct, "text/html" );
42 $m->title_is("Root");
43 $m->content_contains("This is the root page");
44
45 $m->get_ok("/hello/");
46 is( $m->ct, "text/html" );
47 $m->title_is("Hello");
48 $m->content_contains( $chars, qq{content contains "$bytes"});
49
50 SKIP: {
51     eval { require Compress::Zlib; };
52     skip "Compress::Zlib needed to test gzip encoding", 4 if $@;
53     $m->get_ok("/gzipped/");
54     is( $m->ct, "text/html" );
55     $m->title_is("Hello");
56     $m->content_contains( $chars, qq{content contains "$bytes"});
57 }
58
59 $m->get("$root/die/");
60 is( $m->status, 500 );
61 $m->content_like( qr!\(en\) Please come back later!);
62 $m->content_unlike( qr!<a href="/hello/">Hello</a>.!);
63
64 $m->get("/die/");
65 is( $m->status, 500 );
66 $m->content_like( qr!\(en\) Please come back later!);
67 $m->content_unlike( qr!<a href="/hello/">Hello</a>.!);
68
69 {
70   no warnings 'redefine';
71   ${Catty::}{debug} = sub { 1 };
72   $m->{catalyst_debug} = 1;
73   $m->get("$root/die/");
74   is( $m->status, 500 );
75   is( $m->ct,     "text/html" );
76   $m->title_like(qr/Catty on Catalyst/);
77   $m->content_like(qr/Caught exception in Catty/);
78   $m->content_like(qr/erk/);
79   $m->content_like(qr/This is the die page/);
80 }