Permalink
Browse files

Reset the autolint object between uses

  • Loading branch information...
1 parent 8277086 commit 2be1737d4ff8673d5e67384e8a92123a07406a2b @petdance committed May 31, 2012
Showing with 51 additions and 3 deletions.
  1. +6 −0 Changes
  2. +1 −0 MANIFEST
  3. +8 −1 Mechanize.pm
  4. +23 −2 t/autolint.t
  5. +13 −0 t/fluffy.html
View
@@ -4,6 +4,12 @@ WWW::Mechanize and Test::WWW::Mechanize do not use rt.cpan.org for
bug tracking. They are now being tracked via Google Code at
http://code.google.com/p/www-mechanize/issues/list
+NEXT
+------------------------------------
+[FIXES]
+Custom lint objects don't get reset before they get used, making autolint
+with a custom lint object practically useless.
+https://github.com/petdance/test-www-mechanize/issues/25
1.40 Fri Apr 13 15:14:39 CDT 2012
------------------------------------
View
@@ -11,6 +11,7 @@ t/badlinks.html
t/click_ok.t
t/content_contains.t
t/content_lacks.t
+t/fluffy.html
t/followable_links.t
t/follow_link_ok.t
t/get_ok-parms.t
View
@@ -464,7 +464,14 @@ sub _lint_content_ok {
die "Test::WWW::Mechanize can't do linting without HTML::Lint: $@";
}
- my $lint = (ref $self->{autolint} && $self->{autolint}->isa('HTML::Lint')) ? $self->{autolint} : HTML::Lint->new();
+ my $lint = $self->{autolint};
+ if ( ref $lint && $lint->isa('HTML::Lint') ) {
+ $lint->newfile;
+ $lint->clear_errors;
+ }
+ else {
+ $lint = HTML::Lint->new();
+ }
$lint->parse( $self->content );
View
@@ -13,7 +13,7 @@ BEGIN {
if ( not eval 'use HTML::Lint;' ) {
plan skip_all => 'HTML::Lint is not installed, cannot test autolint' if $@;
}
- plan tests => 23;
+ plan tests => 27;
}
@@ -60,12 +60,33 @@ ACCESSOR_MUTATOR: {
}
}
+FLUFFY_PAGE_HAS_ERRORS: {
+ my $mech = Test::WWW::Mechanize->new( autolint => 1 );
+ isa_ok( $mech, 'Test::WWW::Mechanize' );
+
+ my $uri = URI::file->new_abs( 't/fluffy.html' )->as_string;
+
+ test_out( "not ok 1 - GET $uri" );
+ test_fail( +5 );
+ test_err( "# HTML::Lint errors for $uri" );
+ test_err( '# (10:9) <img src="/foo.gif"> tag has no HEIGHT and WIDTH attributes' );
+ test_err( '# (10:9) <img src="/foo.gif"> does not have ALT text defined' );
+ test_err( '# 2 errors on the page' );
+ $mech->get_ok( $uri );
+ test_test( 'blah' );
+}
-CUSTOM_LINTER: {
+CUSTOM_LINTER_IGNORES_FLUFFY_ERRORS: {
my $lint = HTML::Lint->new( only_types => HTML::Lint::Error::STRUCTURE );
my $mech = Test::WWW::Mechanize->new( autolint => $lint );
isa_ok( $mech, 'Test::WWW::Mechanize' );
+
+ my $uri = URI::file->new_abs( 't/fluffy.html' )->as_string;
+ $mech->get_ok( $uri );
+
+ # And if we go to another page, the autolint object has been reset.
+ $mech->get_ok( $uri );
}
GOOD_GET_GOOD_HTML: {
View
@@ -0,0 +1,13 @@
+<html>
+ <head>
+ <title>Test Page</title>
+ </head>
+ <body>
+ This page has valid structure, but contains errors that HTML::Lint
+ categorizes as fluff.
+ <a href="goodlinks.html">good</a>
+ <a href="bad2.html">Test</a>
+ <img src="/foo.gif"> <!-- No height & width -->
+ </body>
+</html>
+

0 comments on commit 2be1737

Please sign in to comment.