Make WordPress Core

Changeset 58971


Ignore:
Timestamp:
09/03/2024 04:25:16 PM (2 years ago)
Author:
dmsnell
Message:

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 https://github.com/WordPress/wordpress-develop/pull/7285
Discussed in https://core.trac.wordpress.org/ticket/61646

Follow-up to [58714].

Props dmsnell, jonsurrell.
See #61646.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

    r58970 r58971  
    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.' );
    61                 }
     66                        return;
     67                }
     68
    6269                $fragment_detail = $fragment_context ? " in context <{$fragment_context}>" : '';
    6370
     
    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
     
    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
     
    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
Note: See TracChangeset for help on using the changeset viewer.