WWW-Mechanize

 view release on metacpan or  search on metacpan

t/content.t  view on Meta::CPAN

use warnings;
use strict;
use Test::More;
use Test::Fatal qw( dies_ok );

=head1 NAME

content.t

=head1 SYNOPSIS

Tests the transforming forms of $mech->content().

=cut

BEGIN { delete @ENV{qw( http_proxy HTTP_PROXY )}; }

BEGIN {
    use_ok('WWW::Mechanize');
}

my $html = <<'HTML';
<html>
<head>
<title>Howdy?</title>
</head>
<body>
Fine, thx!
</body>
</html>
HTML

my $mech = WWW::Mechanize->new();

# Well actually there is no base (and therefore it does not belong to us
# :-), so let's kludge a bit.
$mech->{base} = 'http://example.com/';

is( $mech->content, undef, 'content starts out as undef' );

$mech->update_html($html);

=head2 $mech->content(format => "text")

=cut

SKIP: {
    eval 'use HTML::TreeBuilder 5';
    skip 'HTML::TreeBuilder version 5 not installed', 2 if $@;

    my $text = $mech->content( format => 'text' );
    like( $text, qr/Fine/, 'Found Fine' );
    unlike( $text, qr/html/i, 'Could not find "html"' );
}

dies_ok { $mech->content( format => 'no_such_format' ) } 'Unkown format';

=head2 $mech->content(base_href => undef)

=head2 $mech->content(base_href => $basehref)

=cut

my $content = $mech->content( base_href => 'foo' );
like( $content, qr/base href="foo"/, 'Found the base href' );

$content = $mech->content( base_href => undef );
like(
    $content, qr[base href="http://example.com/"],
    'Found the new base href'
);

$mech->{res} = Test::MockResponse->new(
    raw_content      => 'this is the raw content',
    charset_none     => 'this is a slightly decoded content',
    charset_whatever => 'this is charset whatever',



( run in 1.339 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )