Skip to content

Commit dde9c80

Browse files
committed
Build/Test Tools: Ensure assertEqualHTML fallback render can be reached.
`assertEqualHTML` catches `Exception`s and attempts to re-parse the HTML with the `Dom\HtmlDocument` class. Ensure that the fallback render is reachable by throwing `Exception` instead of `Error` in the tree builder function. Developed in #9273. Follow-up to [60295]. Props jonsurrell, bernhard-reiter, dmsnell. Fixes #63527. git-svn-id: https://develop.svn.wordpress.org/trunk@60707 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 4b9559e commit dde9c80

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

tests/phpunit/includes/build-visual-html-tree.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*
4141
* @since 6.9.0
4242
*
43-
* @throws WP_HTML_Unsupported_Exception|Error If the markup could not be parsed.
43+
* @throws WP_HTML_Unsupported_Exception|Exception If the markup could not be parsed.
4444
*
4545
* @param string $html Given test HTML.
4646
* @param string|null $fragment_context Context element in which to parse HTML, such as BODY or SVG.
@@ -51,7 +51,7 @@ function build_visual_html_tree( string $html, ?string $fragment_context ): stri
5151
? WP_HTML_Processor::create_fragment( $html, $fragment_context )
5252
: WP_HTML_Processor::create_full_parser( $html );
5353
if ( null === $processor ) {
54-
throw new Error( 'Could not create a parser.' );
54+
throw new Exception( 'Could not create a parser.' );
5555
}
5656
$tree_indent = ' ';
5757

@@ -280,7 +280,7 @@ static function ( $a, $b ) {
280280
default:
281281
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
282282
$serialized_token_type = var_export( $processor->get_token_type(), true );
283-
throw new Error( "Unhandled token type for tree construction: {$serialized_token_type}" );
283+
throw new Exception( "Unhandled token type for tree construction: {$serialized_token_type}" );
284284
}
285285
}
286286

@@ -289,11 +289,11 @@ static function ( $a, $b ) {
289289
}
290290

291291
if ( null !== $processor->get_last_error() ) {
292-
throw new Error( "Parser error: {$processor->get_last_error()}" );
292+
throw new Exception( "Parser error: {$processor->get_last_error()}" );
293293
}
294294

295295
if ( $processor->paused_at_incomplete_token() ) {
296-
throw new Error( 'Paused at incomplete token.' );
296+
throw new Exception( 'Paused at incomplete token.' );
297297
}
298298

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

0 commit comments

Comments
 (0)