Skip to content

Commit

Permalink
add tests for update_html #218
Browse files Browse the repository at this point in the history
This commit also removes an old SKIP check that we don't need any more
because we now depend on HTML::TreeBuilder.
  • Loading branch information
simbabque committed Jul 29, 2022
1 parent 9b7828d commit 9dfac3d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
11 changes: 3 additions & 8 deletions t/content.t
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,9 @@ $mech->update_html($html);
=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"' );
}
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';

Expand Down
48 changes: 48 additions & 0 deletions t/update_html.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use warnings;
use strict;
use Test::More;

BEGIN { delete @ENV{ qw( http_proxy HTTP_PROXY ) }; }
BEGIN {
use_ok( 'WWW::Mechanize' );
}

my $html = <<'HTML';
<html>
<head>
<title>Test</title>
</head>
<body>
<form name="foo">
<input type="text" name="asdf">
</form>
</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);

like( $mech->content, qr/Test/, 'update_html has put the content in' );

is(
ref( $mech->form_name('foo') ),
'HTML::Form',
'... and we now have forms'
);

$html =~ s/foo/bar/;
$mech->update_html($html);

is(
ref( $mech->form_name('bar') ),
'HTML::Form',
'updating the HTML also updates the form'
);


done_testing;

0 comments on commit 9dfac3d

Please sign in to comment.