From 8100b89c0f164255fdba716bf86ebcd91aa1955d Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 13 Sep 2024 12:39:59 +0200 Subject: [PATCH 1/4] Fix document-fragment test processing --- tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php b/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php index 54d60f8c78a66..4462c8d230130 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php @@ -449,7 +449,7 @@ public static function parse_html5_dat_testfile( $filename ) { * context element as context. */ case 'document-fragment': - $test_context_element = explode( ' ', $line )[0]; + $test_context_element = trim( $line ); break; /* From 4fae200e6c5698a8fa296998cf324d01f34054ab Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 13 Sep 2024 12:43:42 +0200 Subject: [PATCH 2/4] Remove outdated fragment preambles from tree output When fragments were used instead of full processors, some fake tree structure had to be prepended to the output. This is no longer necessary and breaks the fragment cases. --- tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php b/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php index 4462c8d230130..4be86aee8bc92 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php @@ -170,8 +170,8 @@ private static function build_tree_representation( ?string $fragment_context, st * and requires adjustment to initial parameters. * The full parser will not. */ - $output = $fragment_context ? "\n \n \n" : ''; - $indent_level = $fragment_context ? 2 : 0; + $output = ''; + $indent_level = 0; $indent = ' '; $was_text = null; $text_node = ''; From 08d6ae542aac5174983c7b2c8fe2b3bf7dd904cd Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 13 Sep 2024 12:45:05 +0200 Subject: [PATCH 3/4] Move static indent string to a class constant --- .../tests/html-api/wpHtmlProcessorHtml5lib.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php b/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php index 4be86aee8bc92..8221cc4dbea32 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php @@ -21,6 +21,8 @@ * @group html-api-html5lib-tests */ class Tests_HtmlApi_Html5lib extends WP_UnitTestCase { + const TREE_INDENT = ' '; + /** * Skip specific tests that may not be supported or have known issues. */ @@ -172,7 +174,6 @@ private static function build_tree_representation( ?string $fragment_context, st */ $output = ''; $indent_level = 0; - $indent = ' '; $was_text = null; $text_node = ''; @@ -225,7 +226,7 @@ private static function build_tree_representation( ?string $fragment_context, st ++$indent_level; } - $output .= str_repeat( $indent, $tag_indent ) . "<{$tag_name}>\n"; + $output .= str_repeat( self::TREE_INDENT, $tag_indent ) . "<{$tag_name}>\n"; $attribute_names = $processor->get_attribute_names_with_prefix( '' ); if ( $attribute_names ) { @@ -278,18 +279,18 @@ static function ( $a, $b ) { if ( true === $val ) { $val = ''; } - $output .= str_repeat( $indent, $tag_indent + 1 ) . "{$display_name}=\"{$val}\"\n"; + $output .= str_repeat( self::TREE_INDENT, $tag_indent + 1 ) . "{$display_name}=\"{$val}\"\n"; } } // Self-contained tags contain their inner contents as modifiable text. $modifiable_text = $processor->get_modifiable_text(); if ( '' !== $modifiable_text ) { - $output .= str_repeat( $indent, $tag_indent + 1 ) . "\"{$modifiable_text}\"\n"; + $output .= str_repeat( self::TREE_INDENT, $tag_indent + 1 ) . "\"{$modifiable_text}\"\n"; } if ( 'html' === $namespace && 'TEMPLATE' === $token_name ) { - $output .= str_repeat( $indent, $indent_level ) . "content\n"; + $output .= str_repeat( self::TREE_INDENT, $indent_level ) . "content\n"; ++$indent_level; } @@ -303,14 +304,14 @@ static function ( $a, $b ) { } $was_text = true; if ( '' === $text_node ) { - $text_node .= str_repeat( $indent, $indent_level ) . '"'; + $text_node .= str_repeat( self::TREE_INDENT, $indent_level ) . '"'; } $text_node .= $text_content; break; case '#funky-comment': // Comments must be "<" then "!-- " then the data then " -->". - $output .= str_repeat( $indent, $indent_level ) . "\n"; + $output .= str_repeat( self::TREE_INDENT, $indent_level ) . "\n"; break; case '#comment': @@ -333,7 +334,7 @@ static function ( $a, $b ) { throw new Error( "Unhandled comment type for tree construction: {$processor->get_comment_type()}" ); } // Comments must be "<" then "!-- " then the data then " -->". - $output .= str_repeat( $indent, $indent_level ) . "\n"; + $output .= str_repeat( self::TREE_INDENT, $indent_level ) . "\n"; break; default: From 278a63df59d70e15817c2691da8f0df0f913a867 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Mon, 16 Sep 2024 11:41:26 -0700 Subject: [PATCH 4/4] Change to trigger flakey-test re-run. --- tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php b/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php index 8221cc4dbea32..4862ba981e6f0 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php @@ -51,9 +51,9 @@ class Tests_HtmlApi_Html5lib extends WP_UnitTestCase { * * @dataProvider data_external_html5lib_tests * - * @param string $fragment_context Context element in which to parse HTML, such as BODY or SVG. - * @param string $html Given test HTML. - * @param string $expected_tree Tree structure of parsed HTML. + * @param string|null $fragment_context Context element in which to parse HTML, such as BODY or SVG. + * @param string $html Given test HTML. + * @param string $expected_tree Tree structure of parsed HTML. */ public function test_parse( ?string $fragment_context, string $html, string $expected_tree ) { try {