Make WordPress Core


Ignore:
Timestamp:
07/22/2024 10:22:03 PM (17 months ago)
Author:
dmsnell
Message:

HTML API: Add missing tags in IN BODY insertion mode to HTML Processor.

As part of work to add more spec support to the HTML API, this patch adds
support for the remaining missing tags in the IN BODY insertion mode. Not
all of the added tags are supported, because in some cases they reset the
insertion mode and are reprocessed where they will be rejected.

This patch also improves the support of get_modifiable_text(), removing
a leading newline inside a LISTING, PRE, or TEXTAREA element.

Developed in https://github.com/WordPress/wordpress-develop/pull/6972
Discussed in https://core.trac.wordpress.org/ticket/61576

Props dmsnell, jonsurrell, westonruter.
See #61576.

File:
1 edited

Legend:

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

    r58677 r58779  
    1 <?php
    2 /**
    3  * Unit tests for the HTML API indicating that changes are needed to the
    4  * WP_HTML_Processor class before specific features are added to the API.
    5  *
    6  * Note! Duplication of test cases and the helper function in this file are intentional.
    7  * This test file exists to warn developers of related areas of code that need to update
    8  * together when adding support for new elements to the HTML Processor. For example,
    9  * when adding support for the LI element it's necessary to update the function which
    10  * generates implied end tags. This is because each element might bring with it semantic
    11  * rules that impact the way the document should be parsed.
    12  *
    13  * Without these tests a developer needs to investigate all possible places they
    14  * might need to update when adding support for more elements and risks overlooking
    15  * important parts that, in the absence of the related support, will lead to errors.
    16  *
    17  * @package WordPress
    18  * @subpackage HTML-API
    19  *
    20  * @since 6.4.0
    21  *
    22  * @group html-api
    23  *
    24  * @coversDefaultClass WP_HTML_Processor
    25  */
    26 class Tests_HtmlApi_WpHtmlSupportRequiredHtmlProcessor extends WP_UnitTestCase {
    27     /**
    28      * Fails to assert if the HTML Processor handles the given tag.
    29      *
    30      * This test helper is used throughout this test file for one purpose only: to
    31      * fail a test if the HTML Processor handles the given tag. In other words, it
    32      * ensures that the HTML Processor aborts when encountering the given tag.
    33      *
    34      * This is used to ensure that when support for a new tag is added to the
    35      * HTML Processor it receives full support and not partial support, which
    36      * could lead to a variety of issues.
    37      *
    38      * Do not remove this helper function as it provides semantic meaning to the
    39      * assertions in the tests in this file and its behavior is incredibly specific
    40      * and limited and doesn't warrant adding a new abstraction into WP_UnitTestCase.
    41      *
    42      * @param string $tag_name the HTML Processor should abort when encountering this tag, e.g. "BUTTON".
    43      */
    44     private function ensure_support_is_added_everywhere( $tag_name ) {
    45         $processor = WP_HTML_Processor::create_fragment( "<$tag_name>" );
    46 
    47         $this->assertFalse( $processor->step(), "Must support terminating elements in specific scope check before adding support for the {$tag_name} element." );
    48     }
    49 
    50     /**
    51      * Generating implied end tags walks up the stack of open elements
    52      * as long as any of the following missing elements is the current node.
    53      *
    54      * @since 6.4.0
    55      *
    56      * @ticket 58907
    57      *
    58      * @covers WP_HTML_Processor::generate_implied_end_tags
    59      */
    60     public function test_generate_implied_end_tags_needs_support() {
    61         $this->ensure_support_is_added_everywhere( 'RB' );
    62         $this->ensure_support_is_added_everywhere( 'RP' );
    63         $this->ensure_support_is_added_everywhere( 'RT' );
    64         $this->ensure_support_is_added_everywhere( 'RTC' );
    65     }
    66 
    67     /**
    68      * Generating implied end tags thoroughly walks up the stack of open elements
    69      * as long as any of the following missing elements is the current node.
    70      *
    71      * @since 6.4.0
    72      *
    73      * @ticket 58907
    74      *
    75      * @covers WP_HTML_Processor::generate_implied_end_tags_thoroughly
    76      */
    77     public function test_generate_implied_end_tags_thoroughly_needs_support() {
    78         $this->ensure_support_is_added_everywhere( 'CAPTION' );
    79         $this->ensure_support_is_added_everywhere( 'COLGROUP' );
    80         $this->ensure_support_is_added_everywhere( 'RB' );
    81         $this->ensure_support_is_added_everywhere( 'RP' );
    82         $this->ensure_support_is_added_everywhere( 'RT' );
    83         $this->ensure_support_is_added_everywhere( 'RTC' );
    84         $this->ensure_support_is_added_everywhere( 'TBODY' );
    85         $this->ensure_support_is_added_everywhere( 'TD' );
    86         $this->ensure_support_is_added_everywhere( 'TFOOT' );
    87         $this->ensure_support_is_added_everywhere( 'TH' );
    88         $this->ensure_support_is_added_everywhere( 'HEAD' );
    89         $this->ensure_support_is_added_everywhere( 'TR' );
    90     }
    91 }
Note: See TracChangeset for help on using the changeset viewer.