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 66 67 68 69 70 71 72 73 74 75
|
#!perl -T
use strict;
use warnings;
use Test::Builder::Tester;
use Test::More;
use Test::WWW::Mechanize;
use URI::file;
BEGIN {
my $module = 'HTML::Tidy5 1.00';
if ( not eval "use $module; 1;" ) {
plan skip_all => "Optional $module is not installed, cannot test html_tidy_ok" if $@;
}
plan tests => 7;
}
GOOD_GET: {
my $mech = Test::WWW::Mechanize->new;
isa_ok( $mech, 'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/bad.html' )->as_string;
$mech->get_ok( $uri, 'Fetching the file from disk' );
test_out( "not ok 1 - checking HTML ($uri)" );
test_fail( +6 );
test_err( "# HTML::Tidy5 messages for $uri" );
test_err( '# (1:1) Warning: missing <!DOCTYPE> declaration' );
test_err( '# (8:33) Warning: discarding unexpected </b>' );
test_err( '# (8:9) Warning: missing </a>' );
test_err( '# 3 messages on the page' );
$mech->html_tidy_ok( 'checking HTML' );
test_test( 'Proper html_tidy_ok results' );
}
CONTENT_FOR_VALIDATION: {
my $mech = My::Subclass->new;
isa_ok( $mech, 'My::Subclass' );
isa_ok( $mech, 'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/bad.html' )->as_string;
$mech->get_ok( $uri, 'Fetching the file from disk' );
test_out( "not ok 1 - checking HTML ($uri)" );
test_fail( +4 );
test_err( "# HTML::Tidy5 messages for $uri" );
test_err( '# (9:9) Warning: missing </a>' );
test_err( '# 1 message on the page' );
$mech->html_tidy_ok( 'checking HTML' );
test_test( 'Proper html_tidy_ok results after modifying the contents before tidying' );
}
done_testing();
exit 0;
package My::Subclass;
use parent 'Test::WWW::Mechanize';
sub content_for_tidy {
my $self = shift;
my $content = $self->content;
# Fix the missing DOCTYPE.
$content = "<!DOCTYPE html>\n$content";
# Change the </b> to something innocuous.
$content =~ s{</b>}{<br/>};
# We're still leaving the unclosed </a>.
return $content;
}
|