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 6 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
25 changes: 18 additions & 7 deletions tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@
* @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 @@ -155,7 +162,7 @@
? WP_HTML_Processor::create_fragment( $html, "<{$fragment_context}>" )
: WP_HTML_Processor::create_full_parser( $html );
if ( null === $processor ) {
return null;
throw new WP_HTML_Unsupported_Exception( "Could not create a parser with the given fragment context: {$fragment_context}.", '', 0, '', array(), array() );
}

/*
Expand All @@ -170,8 +177,8 @@
$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,12 +342,16 @@
}
}

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

if ( null !== $processor->get_last_error() ) {
throw new WP_HTML_Unsupported_Exception( "Parser error: {$processor->get_last_error()}", '', 0, '', array(), array() );
}

if ( $processor->paused_at_incomplete_token() ) {
return null;
throw new WP_HTML_Unsupported_Exception( "Paused at incomplete token.", '', 0, '', array(), array() );

Check failure on line 354 in tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

String "Paused at incomplete token." does not require double quotes; use single quotes instead
}

if ( '' !== $text_node ) {
Expand Down
Loading