Skip to content

Commit

Permalink
Iteration on testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Jan 16, 2024
1 parent 8b20ba0 commit 43af3a4
Showing 1 changed file with 85 additions and 29 deletions.
114 changes: 85 additions & 29 deletions tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);

/**
Expand Down Expand Up @@ -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;

Check failure on line 81 in tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Spaces must be used for mid-line alignment; tabs are not allowed
// }

foreach ( self::parse_html5_dat_testfile( $test_dir . $entry ) as $k => $test ) {
// strip .dat extension from filename
Expand All @@ -106,21 +106,77 @@ public static function build_html5_treelike_string( $fragment_context, $html ) {
}

$output = "<html>\n <head>\n <body>\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');

Check failure on line 114 in tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 spaces after opening parenthesis; 0 found

Check failure on line 114 in tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 spaces before closing parenthesis; 0 found
if ( $token_type === '#tag' ) {

Check failure on line 115 in tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Use Yoda Condition checks, you must.
$p->set_bookmark('current_tag');

Check failure on line 116 in tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 spaces after opening parenthesis; 0 found

Check failure on line 116 in tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 spaces before closing parenthesis; 0 found
$has_set_current_tag = true;
}

if ( $has_set_current_tag ) {
$p->seek('current_tag');

Check failure on line 121 in tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 spaces after opening parenthesis; 0 found

Check failure on line 121 in tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 spaces before closing parenthesis; 0 found
foreach ( $p->get_breadcrumbs() as $index => $_ ) {
if ( $index ) {
$output .= ' ';
}
}
$p->seek('resume');

Check failure on line 127 in tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 spaces after opening parenthesis; 0 found

Check failure on line 127 in tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 spaces before closing parenthesis; 0 found
} 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 .= "<!-- " . $p->get_modifiable_text() . " -->\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;
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 43af3a4

Please sign in to comment.