Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML API: Improve skipped test reporting with unsupported exception #7285

Closed
Closed
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ class Tests_HtmlApi_Html5lib extends WP_UnitTestCase {
* @param string $expected_tree Tree structure of parsed HTML.
*/
public function test_parse( ?string $fragment_context, string $html, string $expected_tree ) {
$processed_tree = self::build_tree_representation( $fragment_context, $html );
try {
$processed_tree = self::build_tree_representation( $fragment_context, $html );
} catch ( WP_HTML_Unsupported_Exception $e ) {
$this->markTestSkipped( "Unsupported markup: {$e->getMessage()}" );
return;
}

if ( null === $processed_tree ) {
$this->markTestSkipped( 'Test includes unsupported markup.' );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably inaccurate now, the unsupported markup messages should appear above.

I'd like to improve the other error cases because returning null can't express all of them. I've been thinking about adding more classes to handle them.

return;
}
$fragment_detail = $fragment_context ? " in context <{$fragment_context}>" : '';

Expand Down Expand Up @@ -170,8 +176,8 @@ private static function build_tree_representation( ?string $fragment_context, st
$text_node = '';

while ( $processor->next_token() ) {
if ( ! is_null( $processor->get_last_error() ) ) {
return null;
if ( null !== $processor->get_last_error() ) {
break;
}

$token_name = $processor->get_token_name();
Expand Down Expand Up @@ -335,7 +341,11 @@ static function ( $a, $b ) {
}
}

if ( ! is_null( $processor->get_last_error() ) ) {
if ( null !== $processor->get_unsupported_exception() ) {
throw $processor->get_unsupported_exception();
}

if ( null !== $processor->get_last_error() ) {
return null;
}

Expand Down
Loading