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