Ignore certain tidy warnings in assertValidHtmlDocument
authorMarius Hoch <hoo@online.de>
Thu, 23 Jan 2014 20:02:34 +0000 (21:02 +0100)
committerHashar <hashar@free.fr>
Tue, 28 Jan 2014 10:46:45 +0000 (10:46 +0000)
Those aren't really useful, especially as tidy often
cries about parameters missing which have been
deprecated since HTML 4, so that these warnings have
no value for us.

Change-Id: Ic27c597aa988079ed08e152861bf1dee9581b829

tests/phpunit/MediaWikiTestCase.php

index 95b5047..87e214c 100644 (file)
@@ -1003,7 +1003,18 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        $this->markTestSkipped( 'Tidy extension not installed' );
                }
 
-               $ok = MWTidy::checkErrors( $html, $errors );
-               $this->assertTrue( $ok, 'HTML validation errors: ' . $errors );
+               $errorBuffer = '';
+               MWTidy::checkErrors( $html, $errorBuffer );
+               $allErrors = preg_split( '/[\r\n]+/', $errorBuffer );
+
+               // Filter Tidy warnings which aren't useful for us.
+               // Tidy eg. often cries about parameters missing which have actually
+               // been deprecated since HTML4, thus we should not care about them.
+               $errors = preg_grep(
+                       '/^(.*Warning: (trimming empty|.* lacks ".*?" attribute).*|\s*)$/m',
+                       $allErrors, PREG_GREP_INVERT
+               );
+
+               $this->assertEmpty( $errors, implode( "\n", $errors ) );
        }
 }