- Timestamp:
- 07/22/2024 10:22:03 PM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/html-api/wpHtmlSupportRequiredHtmlProcessor.php
r58677 r58779 1 <?php2 /**3 * Unit tests for the HTML API indicating that changes are needed to the4 * 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 update8 * 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 which10 * generates implied end tags. This is because each element might bring with it semantic11 * rules that impact the way the document should be parsed.12 *13 * Without these tests a developer needs to investigate all possible places they14 * might need to update when adding support for more elements and risks overlooking15 * important parts that, in the absence of the related support, will lead to errors.16 *17 * @package WordPress18 * @subpackage HTML-API19 *20 * @since 6.4.021 *22 * @group html-api23 *24 * @coversDefaultClass WP_HTML_Processor25 */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: to31 * fail a test if the HTML Processor handles the given tag. In other words, it32 * 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 the35 * HTML Processor it receives full support and not partial support, which36 * could lead to a variety of issues.37 *38 * Do not remove this helper function as it provides semantic meaning to the39 * assertions in the tests in this file and its behavior is incredibly specific40 * 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 elements52 * as long as any of the following missing elements is the current node.53 *54 * @since 6.4.055 *56 * @ticket 5890757 *58 * @covers WP_HTML_Processor::generate_implied_end_tags59 */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 elements69 * as long as any of the following missing elements is the current node.70 *71 * @since 6.4.072 *73 * @ticket 5890774 *75 * @covers WP_HTML_Processor::generate_implied_end_tags_thoroughly76 */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.