From a400f913e0b56252892ce5888ce46a9080e8fbd6 Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Fri, 15 Jul 2016 19:20:07 -0400 Subject: [PATCH] Enable additional balancer tests (those starting with ``) Change-Id: Ie854cf99f7e72bcca1bb8565ace558a43dcb6379 --- tests/phpunit/includes/tidy/BalancerTest.php | 37 +++++++++++++------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/tests/phpunit/includes/tidy/BalancerTest.php b/tests/phpunit/includes/tidy/BalancerTest.php index f2e41bdc26..740ddb9d43 100644 --- a/tests/phpunit/includes/tidy/BalancerTest.php +++ b/tests/phpunit/includes/tidy/BalancerTest.php @@ -48,15 +48,16 @@ class BalancerTest extends MediaWikiTestCase { // for providers, and filter out HTML constructs which // the balancer doesn't support. $tests = []; - $start = ''; - $end = ''; + $okre = "~ \A + (?i:)? + + .* + + \z ~xs"; foreach ( $json as $filename => $cases ) { foreach ( $cases as $case ) { $html = $case['document']['html']; - if ( - substr( $html, 0, strlen( $start ) ) !== $start || - substr( $html, -strlen( $end ) ) !== $end - ) { + if ( !preg_match( $okre, $html ) ) { // Skip tests which involve stuff in the or // weird doctypes. continue; @@ -70,6 +71,8 @@ class BalancerTest extends MediaWikiTestCase { $html = $case['document']['noQuirksBodyHtml']; // Normalize case of SVG attributes. $html = str_replace( 'foreignObject', 'foreignobject', $html ); + // Normalize case of MathML attributes. + $html = str_replace( 'definitionURL', 'definitionurl', $html ); if ( isset( $case['document']['props']['comment'] ) && @@ -83,11 +86,17 @@ class BalancerTest extends MediaWikiTestCase { // Skip tests involving quoting. continue; } - if ( stripos( $case['data'], '' ) === false + ) { + // Skip tests involving unusual doctypes. continue; } - if ( preg_match( ',|)$:', $case['data'] ) || - preg_match( '::', $case['data'] ) + preg_match( '::', $case['data'] ) || + preg_match( ':|

:', $case['data'] ) ) { // Skip tests with funny tag or attribute names, // which are really tests of the HTML tokenizer, not @@ -127,7 +137,7 @@ class BalancerTest extends MediaWikiTestCase { continue; } if ( - stripos( $case['data'], 'encoding=" text/html "' ) !== false + preg_match( ':encoding=" text/html "|type=" hidden":', $case['data'] ) ) { // The Sanitizer normalizes whitespace in attribute // values, which makes this test case invalid. @@ -137,9 +147,12 @@ class BalancerTest extends MediaWikiTestCase { // Skip tests with ASCII null, etc. continue; } + $data = preg_replace( + '~~i', '', $case['data'] + ); $tests[] = [ $filename, # use better description? - $case['data'], + $data, $html ]; } -- 2.20.1