File: content.t

package info (click to toggle)
libwww-mechanize-perl 1.71-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 620 kB
  • sloc: perl: 3,272; makefile: 4
file content (65 lines) | stat: -rw-r--r-- 1,198 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!perl

use warnings;
use strict;
use Test::More tests => 5;

=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/';
$mech->update_html($html);

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

=cut

SKIP: {
    eval 'use HTML::TreeBuilder';
    skip 'HTML::TreeBuilder 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"' );
}

=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');