Skip to content

Commit

Permalink
Avoid running tests that expect anything in <head>
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Jan 10, 2024
1 parent 23942c5 commit 968a381
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
*/
class Tests_HtmlApi_WpHtmlProcessorHtml5lib extends WP_UnitTestCase {

/**
* The HTML Processor only accepts HTML in document <body>.
* Do not run tests that look for anything in document `head`.
*/
const SKIP_HEAD_TESTS = true;

const SKIP_TESTS = array(
'adoption01/case10 - line 159' => 'Unimplemented: Reconstruction of active formatting elements.',
'adoption01/case17 - line 318' => 'Unimplemented: Reconstruction of active formatting elements.',
Expand All @@ -33,8 +39,6 @@ class Tests_HtmlApi_WpHtmlProcessorHtml5lib extends WP_UnitTestCase {
* Verify the parsing results of the HTML Processor against the
* test cases in the Html5lib tests project.
*
* @ticket {TICKET_NUMBER}
*
* @dataProvider data_external_html5lib_tests
*
* @param string $fragment_context Context element in which to parse HTML, such as BODY or SVG.
Expand Down Expand Up @@ -88,7 +92,6 @@ public function data_external_html5lib_tests() {
closedir( $handle );
}


/**
* Generates the tree-like structure represented in the Html5lib tests.
*
Expand Down Expand Up @@ -153,7 +156,22 @@ public static function parse_html5_dat_testfile( $filename ) {
if ( "#data\n" === $line ) {
// Yield when switching from a previous state.
if ( $state ) {
yield array( $test_line_number, $test_context_element, $test_html, $test_dom );
$yield_test = true;

if ( self::SKIP_HEAD_TESTS ) {
$html_start = "<html>\n <head>\n <body>\n";

if (
strlen( $test_dom ) < strlen( $html_start ) ||
substr( $test_dom, 0, strlen( $html_start ) ) !== $html_start
) {
$yield_test = false;
}
}

if ( $yield_test ) {
yield array( $test_line_number, $test_context_element, $test_html, $test_dom );
}
}

// Finish previous test.
Expand Down

0 comments on commit 968a381

Please sign in to comment.