Skip to content

Commit

Permalink
Add positive identification tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsnell committed Nov 15, 2023
1 parent 6a2ae42 commit 415ba5b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
36 changes: 19 additions & 17 deletions tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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( '<p><h3><em target>Important Message</em></h3>', array( 'HTML', 'BODY', 'H3', 'EM' ), 1 ),
'H4 after H2' => array( '<h2>Major</h2><h4 target>Minor</h4>', array( 'HTML', 'BODY', 'H4' ), 1 ),
);
}

Expand Down Expand Up @@ -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( '<div><span><figure><img target></figure></span></div>', array( 'span', 'figure', 'img' ), true ),
'Inner IMG wildcard' => array( '<div><span><figure><img target></figure></span></div>', array( 'span', '*', 'img' ), true ),
'Inner IMG no wildcard' => array( '<div><span><figure><img target></figure></span></div>', array( 'span', 'img' ), false ),
'Full specification' => array( '<div><span><figure><img target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'img' ), true ),
'Invalid Full specification' => array( '<div><span><figure><img target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'img' ), false ),
'Inner IMG' => array( '<div><span><figure><img target></figure></span></div>', array( 'span', 'figure', 'img' ), true ),
'Inner IMG wildcard' => array( '<div><span><figure><img target></figure></span></div>', array( 'span', '*', 'img' ), true ),
'Inner IMG no wildcard' => array( '<div><span><figure><img target></figure></span></div>', array( 'span', 'img' ), false ),
'Full specification' => array( '<div><span><figure><img target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'img' ), true ),
'Invalid Full specification' => array( '<div><span><figure><img target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'img' ), false ),

// Test also with non-void elements that open and close.
'Inner P' => array( '<div><span><figure><p target></figure></span></div>', array( 'span', 'figure', 'p' ), true ),
'Inner P wildcard' => array( '<div><span><figure><p target></figure></span></div>', array( 'span', '*', 'p' ), true ),
'Inner P no wildcard' => array( '<div><span><figure><p target></figure></span></div>', array( 'span', 'p' ), false ),
'Full specification (P)' => array( '<div><span><figure><p target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'p' ), true ),
'Invalid Full specification (P)' => array( '<div><span><figure><p target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'p' ), false ),
'Inner P' => array( '<div><span><figure><p target></figure></span></div>', array( 'span', 'figure', 'p' ), true ),
'Inner P wildcard' => array( '<div><span><figure><p target></figure></span></div>', array( 'span', '*', 'p' ), true ),
'Inner P no wildcard' => array( '<div><span><figure><p target></figure></span></div>', array( 'span', 'p' ), false ),
'Full specification (P)' => array( '<div><span><figure><p target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'p' ), true ),
'Invalid Full specification (P)' => array( '<div><span><figure><p target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'p' ), false ),

// Ensure that matches aren't on tag closers.
'Inner P' => array( '<div><span><figure></p target></figure></span></div>', array( 'span', 'figure', 'p' ), false ),
'Inner P wildcard' => array( '<div><span><figure></p target></figure></span></div>', array( 'span', '*', 'p' ), false ),
'Inner P no wildcard' => array( '<div><span><figure></p target></figure></span></div>', array( 'span', 'p' ), false ),
'Full specification (P)' => array( '<div><span><figure></p target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'p' ), false ),
'Invalid Full specification (P)' => array( '<div><span><figure></p target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'p' ), false ),
'Inner P (Closer)' => array( '<div><span><figure></p target></figure></span></div>', array( 'span', 'figure', 'p' ), false ),
'Inner P wildcard (Closer)' => array( '<div><span><figure></p target></figure></span></div>', array( 'span', '*', 'p' ), false ),
'Inner P no wildcard (Closer)' => array( '<div><span><figure></p target></figure></span></div>', array( 'span', 'p' ), false ),
'Full specification (P) (Closer)' => array( '<div><span><figure></p target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'p' ), false ),
'Invalid Full specification (P) (Closer)' => array( '<div><span><figure></p target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'p' ), false ),

// Test wildcard behaviors.
'Single wildcard element' => array( '<figure><code><div><p><span><img target></span></p></div></code></figure>', array( '*' ), true ),
'Child of wildcard element' => array( '<figure><code><div><p><span><img target></span></p></div></code></figure>', array( 'SPAN', '*' ), true ),
'Single wildcard element' => array( '<figure><code><div><p><span><img target></span></p></div></code></figure>', array( '*' ), true ),
'Child of wildcard element' => array( '<figure><code><div><p><span><img target></span></p></div></code></figure>', array( 'SPAN', '*' ), true ),
);
}

Expand Down
23 changes: 10 additions & 13 deletions tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"<p>Open<{$tag_name}>Closed P</{$tag_name}><img></p>"
);
Expand All @@ -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' ),
);
}

Expand All @@ -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(
"<div><{$first_heading} first> then <{$second_heading} second> and end </{$second_heading}><img></{$first_heading}></div>"
);
Expand Down Expand Up @@ -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 );
}
}
Expand Down

0 comments on commit 415ba5b

Please sign in to comment.