perl-Test-WWW-Mechanize-Mojo / Test-WWW-Mechanize-Mojo / t / simple.t

#!perl
use strict;
use warnings;

use Encode qw();
use Test::More tests => 37;
use lib 't/lib';
use Test::WWW::Mechanize::Catalyst 'Catty';

my $root = "http://localhost";

my $m = Test::WWW::Mechanize::Catalyst->new( autocheck => 0 );

$m->get_ok("$root/");
is( $m->ct, "text/html" );
$m->title_is("Root");
$m->content_contains("This is the root page");

$m->follow_link_ok( { text => 'Hello' } );
is( $m->base, "http://localhost/hello/" );
is( $m->ct,   "text/html" );
$m->title_is("Hello");
my $bytes = "Hi there! ☺";
my $chars = Encode::decode( 'utf-8', $bytes );
$m->content_contains( $chars, qq{content contains "$bytes"});

#use Devel::Peek; Dump $m->content;
#Dump(Encode::decode('utf-8', "Hi there! ☺"));
#exit;

$m->get_ok("/");
is( $m->ct, "text/html" );
$m->title_is("Root");
$m->content_contains("This is the root page");

$m->get_ok("http://example.com/");
is( $m->ct, "text/html" );
$m->title_is("Root");
$m->content_contains("This is the root page");

$m->get_ok("/hello/");
is( $m->ct, "text/html" );
$m->title_is("Hello");
$m->content_contains( $chars, qq{content contains "$bytes"});

SKIP: {
    eval { require Compress::Zlib; };
    skip "Compress::Zlib needed to test gzip encoding", 4 if $@;
    $m->get_ok("/gzipped/");
    is( $m->ct, "text/html" );
    $m->title_is("Hello");
    $m->content_contains( $chars, qq{content contains "$bytes"});
}

$m->get("$root/die/");
is( $m->status, 500 );
$m->content_like( qr!\(en\) Please come back later!);
$m->content_unlike( qr!<a href="/hello/">Hello</a>.!);

$m->get("/die/");
is( $m->status, 500 );
$m->content_like( qr!\(en\) Please come back later!);
$m->content_unlike( qr!<a href="/hello/">Hello</a>.!);

{
  no warnings 'redefine';
  ${Catty::}{debug} = sub { 1 };
  $m->{catalyst_debug} = 1;
  $m->get("$root/die/");
  is( $m->status, 500 );
  is( $m->ct,     "text/html" );
  $m->title_like(qr/Catty on Catalyst/);
  $m->content_like(qr/Caught exception in Catty/);
  $m->content_like(qr/erk/);
  $m->content_like(qr/This is the die page/);
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.