From 415ba5bd1f8c21db899fcc18d677174b71b6234a Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Thu, 19 Oct 2023 20:02:19 -0500 Subject: [PATCH] Add positive identification tests --- .../html-api/wpHtmlProcessorBreadcrumbs.php | 36 ++++++++++--------- .../html-api/wpHtmlProcessorSemanticRules.php | 23 ++++++------ 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php b/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php index c0a7bc46459d3..b74b7a128cd3d 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php @@ -348,6 +348,8 @@ public function data_html_target_with_breadcrumbs() { array( 'HTML', 'BODY', 'DIV', 'DIV', 'DIV', 'DIV', 'DIV', 'DIV', 'DIV', 'DIV', 'DIV', 'STRONG', 'EM', 'CODE' ), 2, ), + 'EM inside H3 after unclosed P' => array( '

Important Message

', array( 'HTML', 'BODY', 'H3', 'EM' ), 1 ), + 'H4 after H2' => array( '

Major

Minor

', array( 'HTML', 'BODY', 'H4' ), 1 ), ); } @@ -383,29 +385,29 @@ public function test_reports_if_tag_matches_breadcrumbs_of_various_specificity( public function data_html_with_breadcrumbs_of_various_specificity() { return array( // Test with void elements. - 'Inner IMG' => array( '
', array( 'span', 'figure', 'img' ), true ), - 'Inner IMG wildcard' => array( '
', array( 'span', '*', 'img' ), true ), - 'Inner IMG no wildcard' => array( '
', array( 'span', 'img' ), false ), - 'Full specification' => array( '
', array( 'html', 'body', 'div', 'span', 'figure', 'img' ), true ), - 'Invalid Full specification' => array( '
', array( 'html', 'div', 'span', 'figure', 'img' ), false ), + 'Inner IMG' => array( '
', array( 'span', 'figure', 'img' ), true ), + 'Inner IMG wildcard' => array( '
', array( 'span', '*', 'img' ), true ), + 'Inner IMG no wildcard' => array( '
', array( 'span', 'img' ), false ), + 'Full specification' => array( '
', array( 'html', 'body', 'div', 'span', 'figure', 'img' ), true ), + 'Invalid Full specification' => array( '
', array( 'html', 'div', 'span', 'figure', 'img' ), false ), // Test also with non-void elements that open and close. - 'Inner P' => array( '

', array( 'span', 'figure', 'p' ), true ), - 'Inner P wildcard' => array( '

', array( 'span', '*', 'p' ), true ), - 'Inner P no wildcard' => array( '

', array( 'span', 'p' ), false ), - 'Full specification (P)' => array( '

', array( 'html', 'body', 'div', 'span', 'figure', 'p' ), true ), - 'Invalid Full specification (P)' => array( '

', array( 'html', 'div', 'span', 'figure', 'p' ), false ), + 'Inner P' => array( '

', array( 'span', 'figure', 'p' ), true ), + 'Inner P wildcard' => array( '

', array( 'span', '*', 'p' ), true ), + 'Inner P no wildcard' => array( '

', array( 'span', 'p' ), false ), + 'Full specification (P)' => array( '

', array( 'html', 'body', 'div', 'span', 'figure', 'p' ), true ), + 'Invalid Full specification (P)' => array( '

', array( 'html', 'div', 'span', 'figure', 'p' ), false ), // Ensure that matches aren't on tag closers. - 'Inner P' => array( '

', array( 'span', 'figure', 'p' ), false ), - 'Inner P wildcard' => array( '

', array( 'span', '*', 'p' ), false ), - 'Inner P no wildcard' => array( '

', array( 'span', 'p' ), false ), - 'Full specification (P)' => array( '

', array( 'html', 'body', 'div', 'span', 'figure', 'p' ), false ), - 'Invalid Full specification (P)' => array( '

', array( 'html', 'div', 'span', 'figure', 'p' ), false ), + 'Inner P (Closer)' => array( '

', array( 'span', 'figure', 'p' ), false ), + 'Inner P wildcard (Closer)' => array( '

', array( 'span', '*', 'p' ), false ), + 'Inner P no wildcard (Closer)' => array( '

', array( 'span', 'p' ), false ), + 'Full specification (P) (Closer)' => array( '

', array( 'html', 'body', 'div', 'span', 'figure', 'p' ), false ), + 'Invalid Full specification (P) (Closer)' => array( '

', array( 'html', 'div', 'span', 'figure', 'p' ), false ), // Test wildcard behaviors. - 'Single wildcard element' => array( '

', array( '*' ), true ), - 'Child of wildcard element' => array( '

', array( 'SPAN', '*' ), true ), + 'Single wildcard element' => array( '

', array( '*' ), true ), + 'Child of wildcard element' => array( '

', array( 'SPAN', '*' ), true ), ); } diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php b/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php index 831d98fd00a5f..cf2dd527ff2ef 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php @@ -134,7 +134,7 @@ public function test_in_body_button_with_button_in_scope_as_ancestor() { * * @param string $tag_name Name of H1 - H6 element under test. */ - public function test_heading_element_closes_open_p_tag( $tag_name ) { + public function test_in_body_heading_element_closes_open_p_tag( $tag_name ) { $processor = WP_HTML_Processor::create_fragment( "

Open<{$tag_name}>Closed P

" ); @@ -161,12 +161,12 @@ public function test_heading_element_closes_open_p_tag( $tag_name ) { */ public function data_heading_elements() { return array( - array( 'H1' ), - array( 'H2' ), - array( 'H3' ), - array( 'H4' ), - array( 'H5' ), - array( 'H5' ), + 'H1' => array( 'H1' ), + 'H2' => array( 'H2' ), + 'H3' => array( 'H3' ), + 'H4' => array( 'H4' ), + 'H5' => array( 'H5' ), + 'H6' => array( 'H5' ), ); } @@ -178,7 +178,7 @@ public function data_heading_elements() { * @param string $first_heading H1 - H6 element appearing (unclosed) before the second. * @param string $second_heading H1 - H6 element appearing after the first. */ - public function test_heading_element_closes_other_heading_elements( $first_heading, $second_heading ) { + public function test_in_body_heading_element_closes_other_heading_elements( $first_heading, $second_heading ) { $processor = WP_HTML_Processor::create_fragment( "
<{$first_heading} first> then <{$second_heading} second> and end
" ); @@ -217,11 +217,8 @@ public function data_heading_combinations() { $combinations = array(); // Create all unique pairs of H1 - H6 elements. - for ( $first = 0; $first < count( $headings ); $first++ ) { - for ( $second = $first; $second < count( $headings ); $second++ ) { - $first_tag = $headings[ $first ]; - $second_tag = $headings[ $second ]; - + foreach ( $headings as $first_tag ) { + foreach ( $headings as $second_tag ) { $combinations[ "{$first_tag} then {$second_tag}" ] = array( $first_tag, $second_tag ); } }