diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php b/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php index 58065499f1a4d..7f1b918973fe0 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php @@ -21,18 +21,18 @@ class Tests_HtmlApi_WpHtmlProcessorHtml5lib extends WP_UnitTestCase { 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.', - 'adoption01/case4 - line 46' => 'Unimplemented: Reconstruction of active formatting elements.', - 'tests15/case1 - line 1' => 'Unimplemented: Reconstruction of active formatting elements.', - 'tests15/case2 - line 22' => 'Unimplemented: Reconstruction of active formatting elements.', - 'tests20/case38 - line 483' => 'XMP is a special token an needs a closer.', - 'tests20/case39 - line 497' => "Closing P tag implicitly creates opener, which we don't visit.", - 'tests23/case1 - line 1' => 'Unimplemented: Reconstruction of active formatting elements.', - 'tests23/case2 - line 41' => 'Unimplemented: Reconstruction of active formatting elements.', - 'tests23/case3 - line 69' => 'Unimplemented: Reconstruction of active formatting elements.', - 'tests23/case4 - line 101' => 'Unimplemented: Reconstruction of active formatting elements.', - 'tests26/case10 - line 263' => 'Newline at end of tag triggers reconstruction of active formatting elements.', + // 'adoption01/line0159' => 'Unimplemented: Reconstruction of active formatting elements.', + // 'adoption01/line0318' => 'Unimplemented: Reconstruction of active formatting elements.', + // 'adoption01/line0046' => 'Unimplemented: Reconstruction of active formatting elements.', + // 'tests15/line0001' => 'Unimplemented: Reconstruction of active formatting elements.', + // 'tests15/line0022' => 'Unimplemented: Reconstruction of active formatting elements.', + // 'tests20/line0483' => 'XMP is a special token an needs a closer.', + // 'tests20/line0497' => "Closing P tag implicitly creates opener, which we don't visit.", + // 'tests23/line0001' => 'Unimplemented: Reconstruction of active formatting elements.', + // 'tests23/line0041' => 'Unimplemented: Reconstruction of active formatting elements.', + // 'tests23/line0069' => 'Unimplemented: Reconstruction of active formatting elements.', + // 'tests23/line0101' => 'Unimplemented: Reconstruction of active formatting elements.', + // 'tests26/line0263' => 'Newline at end of tag triggers reconstruction of active formatting elements.', ); /** @@ -77,9 +77,9 @@ public function data_external_html5lib_tests() { // These tests contain no tags, which isn't yet // supported by the HTML API. - if ( 'comments01.dat' === $entry ) { - continue; - } + // if ( 'comments01.dat' === $entry ) { + // continue; + // } foreach ( self::parse_html5_dat_testfile( $test_dir . $entry ) as $k => $test ) { // strip .dat extension from filename @@ -106,21 +106,77 @@ public static function build_html5_treelike_string( $fragment_context, $html ) { } $output = "\n \n \n"; - while ( $p->next_tag() ) { - // Breadcrumbs include this tag, so skip 1 nesting level. - foreach ( $p->get_breadcrumbs() as $index => $_ ) { - if ( $index ) { - $output .= ' '; + + $has_set_current_tag = false; + while ( $p->next_token() ) { + $token_type = $p->get_token_type(); + + $p->set_bookmark('resume'); + if ( $token_type === '#tag' ) { + $p->set_bookmark('current_tag'); + $has_set_current_tag = true; + } + + if ( $has_set_current_tag ) { + $p->seek('current_tag'); + foreach ( $p->get_breadcrumbs() as $index => $_ ) { + if ( $index ) { + $output .= ' '; + } } + $p->seek('resume'); + } else { + // If we haven't found a tag, we're text under + $output .= ' '; + } + + switch ( $token_type ) { + case '#tag': + $t = strtolower( $p->get_tag() ); + $output .= "<{$t}>\n"; + break; + + case '#text': + $output .= '"' . $p->get_modifiable_text() . "\"\n"; + break; + + case '#cdata-section': + break; + case '#processing-instruction': + break; + case '#comment': + // Comments must be "<" then "!-- " then the data then " -->". + $output .= "\n"; + break; + + case '#doctype': + break; + case '#presumptuous-tag': + break; + case '#funky-comment': + break; } - $t = strtolower( $p->get_tag() ); - $output .= "<{$t}>\n"; } + // while ( $p->next_tag() ) { + // // Breadcrumbs include this tag, so skip 1 nesting level. + // foreach ( $p->get_breadcrumbs() as $index => $_ ) { + // if ( $index ) { + // $output .= ' '; + // } + // } + // $t = strtolower( $p->get_tag() ); + // $output .= "<{$t}>\n"; + // } + if ( WP_HTML_Processor::ERROR_UNSUPPORTED === $p->get_last_error() ) { return null; } + if ( $p->paused_at_incomplete_token() ) { + return null; + } + return $output; } @@ -229,13 +285,13 @@ public static function parse_html5_dat_testfile( $filename ) { // Ignore everything that doesn't look like an element. if ( '|' === $line[0] ) { $candidate = substr( $line, 2 ); - $trimmed = trim( $candidate ); - // Only take lines that look like tags - // At least 3 chars (< + tag + >) - // Tag must start with ascii alphabetic - if ( strlen( $trimmed > 2 ) && '<' === $trimmed[0] && ctype_alpha( $trimmed[1] ) ) { - $test_dom .= $candidate; - } + // $trimmed = trim( $candidate ); + // // Only take lines that look like tags + // // At least 3 chars (< + tag + >) + // // Tag must start with ascii alphabetic + // if ( strlen( $trimmed > 2 ) && '<' === $trimmed[0] && ctype_alpha( $trimmed[1] ) ) { + $test_dom .= $candidate; + // } } break; }