mirror of
git://develop.git.wordpress.org/
synced 2025-01-17 21:08:44 +01:00
HTML API: Update html5lib test runner to support new features.
This patch updates the html5lib test runner following the merge of changes opening up a full HTML parser and additional fragment contents. It makes no Core code changes, but allows a more tests to complete which previously failed due to incomplete test runner support.. Developed in https://github.com/wordpress/wordpress-develop/pull/7346 Discussed in https://core.trac.wordpress.org/ticket/61646 Props jonsurrell. See #61646. git-svn-id: https://develop.svn.wordpress.org/trunk@59025 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
1637791aef
commit
ca64c851f7
@ -21,6 +21,8 @@
|
|||||||
* @group html-api-html5lib-tests
|
* @group html-api-html5lib-tests
|
||||||
*/
|
*/
|
||||||
class Tests_HtmlApi_Html5lib extends WP_UnitTestCase {
|
class Tests_HtmlApi_Html5lib extends WP_UnitTestCase {
|
||||||
|
const TREE_INDENT = ' ';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skip specific tests that may not be supported or have known issues.
|
* Skip specific tests that may not be supported or have known issues.
|
||||||
*/
|
*/
|
||||||
@ -49,9 +51,9 @@ class Tests_HtmlApi_Html5lib extends WP_UnitTestCase {
|
|||||||
*
|
*
|
||||||
* @dataProvider data_external_html5lib_tests
|
* @dataProvider data_external_html5lib_tests
|
||||||
*
|
*
|
||||||
* @param string $fragment_context Context element in which to parse HTML, such as BODY or SVG.
|
* @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 $html Given test HTML.
|
||||||
* @param string $expected_tree Tree structure of parsed HTML.
|
* @param string $expected_tree Tree structure of parsed HTML.
|
||||||
*/
|
*/
|
||||||
public function test_parse( ?string $fragment_context, string $html, string $expected_tree ) {
|
public function test_parse( ?string $fragment_context, string $html, string $expected_tree ) {
|
||||||
try {
|
try {
|
||||||
@ -170,9 +172,8 @@ class Tests_HtmlApi_Html5lib extends WP_UnitTestCase {
|
|||||||
* and requires adjustment to initial parameters.
|
* and requires adjustment to initial parameters.
|
||||||
* The full parser will not.
|
* The full parser will not.
|
||||||
*/
|
*/
|
||||||
$output = $fragment_context ? "<html>\n <head>\n <body>\n" : '';
|
$output = '';
|
||||||
$indent_level = $fragment_context ? 2 : 0;
|
$indent_level = 0;
|
||||||
$indent = ' ';
|
|
||||||
$was_text = null;
|
$was_text = null;
|
||||||
$text_node = '';
|
$text_node = '';
|
||||||
|
|
||||||
@ -225,7 +226,7 @@ class Tests_HtmlApi_Html5lib extends WP_UnitTestCase {
|
|||||||
++$indent_level;
|
++$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( '' );
|
$attribute_names = $processor->get_attribute_names_with_prefix( '' );
|
||||||
if ( $attribute_names ) {
|
if ( $attribute_names ) {
|
||||||
@ -278,18 +279,18 @@ class Tests_HtmlApi_Html5lib extends WP_UnitTestCase {
|
|||||||
if ( true === $val ) {
|
if ( true === $val ) {
|
||||||
$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.
|
// Self-contained tags contain their inner contents as modifiable text.
|
||||||
$modifiable_text = $processor->get_modifiable_text();
|
$modifiable_text = $processor->get_modifiable_text();
|
||||||
if ( '' !== $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 ) {
|
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;
|
++$indent_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,14 +304,14 @@ class Tests_HtmlApi_Html5lib extends WP_UnitTestCase {
|
|||||||
}
|
}
|
||||||
$was_text = true;
|
$was_text = true;
|
||||||
if ( '' === $text_node ) {
|
if ( '' === $text_node ) {
|
||||||
$text_node .= str_repeat( $indent, $indent_level ) . '"';
|
$text_node .= str_repeat( self::TREE_INDENT, $indent_level ) . '"';
|
||||||
}
|
}
|
||||||
$text_node .= $text_content;
|
$text_node .= $text_content;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '#funky-comment':
|
case '#funky-comment':
|
||||||
// Comments must be "<" then "!-- " then the data then " -->".
|
// Comments must be "<" then "!-- " then the data then " -->".
|
||||||
$output .= str_repeat( $indent, $indent_level ) . "<!-- {$processor->get_modifiable_text()} -->\n";
|
$output .= str_repeat( self::TREE_INDENT, $indent_level ) . "<!-- {$processor->get_modifiable_text()} -->\n";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '#comment':
|
case '#comment':
|
||||||
@ -333,7 +334,7 @@ class Tests_HtmlApi_Html5lib extends WP_UnitTestCase {
|
|||||||
throw new Error( "Unhandled comment type for tree construction: {$processor->get_comment_type()}" );
|
throw new Error( "Unhandled comment type for tree construction: {$processor->get_comment_type()}" );
|
||||||
}
|
}
|
||||||
// Comments must be "<" then "!-- " then the data then " -->".
|
// Comments must be "<" then "!-- " then the data then " -->".
|
||||||
$output .= str_repeat( $indent, $indent_level ) . "<!-- {$comment_text_content} -->\n";
|
$output .= str_repeat( self::TREE_INDENT, $indent_level ) . "<!-- {$comment_text_content} -->\n";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -449,7 +450,7 @@ class Tests_HtmlApi_Html5lib extends WP_UnitTestCase {
|
|||||||
* context element as context.
|
* context element as context.
|
||||||
*/
|
*/
|
||||||
case 'document-fragment':
|
case 'document-fragment':
|
||||||
$test_context_element = explode( ' ', $line )[0];
|
$test_context_element = trim( $line );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user