Skip to content

Commit f79de00

Browse files
committed
HTML API: Improve skipped test reporting with unsupported exception.
The `html5lib-tests` suite skips a number of tests due to unsupported markup. At the moment, these tests all report "Test includes unsupported markup." This patch calls the `get_unsupported_exception()` method in these skipped cases to improve the messages reported to PHPUnit so they're more informative: e.g. "Unsupported markup: Foster parenting is not supported." Developed in #7285 Discussed in https://core.trac.wordpress.org/ticket/61646 Follow-up to [58714]. Props dmsnell, jonsurrell. See #61646. git-svn-id: https://develop.svn.wordpress.org/trunk@58971 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 95eb879 commit f79de00

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,18 @@ class Tests_HtmlApi_Html5lib extends WP_UnitTestCase {
5454
* @param string $expected_tree Tree structure of parsed HTML.
5555
*/
5656
public function test_parse( ?string $fragment_context, string $html, string $expected_tree ) {
57-
$processed_tree = self::build_tree_representation( $fragment_context, $html );
57+
try {
58+
$processed_tree = self::build_tree_representation( $fragment_context, $html );
59+
} catch ( WP_HTML_Unsupported_Exception $e ) {
60+
$this->markTestSkipped( "Unsupported markup: {$e->getMessage()}" );
61+
return;
62+
}
5863

5964
if ( null === $processed_tree ) {
6065
$this->markTestSkipped( 'Test includes unsupported markup.' );
66+
return;
6167
}
68+
6269
$fragment_detail = $fragment_context ? " in context <{$fragment_context}>" : '';
6370

6471
/*
@@ -155,7 +162,7 @@ private static function build_tree_representation( ?string $fragment_context, st
155162
? WP_HTML_Processor::create_fragment( $html, "<{$fragment_context}>" )
156163
: WP_HTML_Processor::create_full_parser( $html );
157164
if ( null === $processor ) {
158-
return null;
165+
throw new WP_HTML_Unsupported_Exception( "Could not create a parser with the given fragment context: {$fragment_context}.", '', 0, '', array(), array() );
159166
}
160167

161168
/*
@@ -170,8 +177,8 @@ private static function build_tree_representation( ?string $fragment_context, st
170177
$text_node = '';
171178

172179
while ( $processor->next_token() ) {
173-
if ( ! is_null( $processor->get_last_error() ) ) {
174-
return null;
180+
if ( null !== $processor->get_last_error() ) {
181+
break;
175182
}
176183

177184
$token_name = $processor->get_token_name();
@@ -335,12 +342,16 @@ static function ( $a, $b ) {
335342
}
336343
}
337344

338-
if ( ! is_null( $processor->get_last_error() ) ) {
339-
return null;
345+
if ( null !== $processor->get_unsupported_exception() ) {
346+
throw $processor->get_unsupported_exception();
347+
}
348+
349+
if ( null !== $processor->get_last_error() ) {
350+
throw new WP_HTML_Unsupported_Exception( "Parser error: {$processor->get_last_error()}", '', 0, '', array(), array() );
340351
}
341352

342353
if ( $processor->paused_at_incomplete_token() ) {
343-
return null;
354+
throw new WP_HTML_Unsupported_Exception( 'Paused at incomplete token.', '', 0, '', array(), array() );
344355
}
345356

346357
if ( '' !== $text_node ) {

0 commit comments

Comments
 (0)