Skip to content

Commit 415ba5b

Browse files
committed
Add positive identification tests
1 parent 6a2ae42 commit 415ba5b

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ public function data_html_target_with_breadcrumbs() {
348348
array( 'HTML', 'BODY', 'DIV', 'DIV', 'DIV', 'DIV', 'DIV', 'DIV', 'DIV', 'DIV', 'DIV', 'STRONG', 'EM', 'CODE' ),
349349
2,
350350
),
351+
'EM inside H3 after unclosed P' => array( '<p><h3><em target>Important Message</em></h3>', array( 'HTML', 'BODY', 'H3', 'EM' ), 1 ),
352+
'H4 after H2' => array( '<h2>Major</h2><h4 target>Minor</h4>', array( 'HTML', 'BODY', 'H4' ), 1 ),
351353
);
352354
}
353355

@@ -383,29 +385,29 @@ public function test_reports_if_tag_matches_breadcrumbs_of_various_specificity(
383385
public function data_html_with_breadcrumbs_of_various_specificity() {
384386
return array(
385387
// Test with void elements.
386-
'Inner IMG' => array( '<div><span><figure><img target></figure></span></div>', array( 'span', 'figure', 'img' ), true ),
387-
'Inner IMG wildcard' => array( '<div><span><figure><img target></figure></span></div>', array( 'span', '*', 'img' ), true ),
388-
'Inner IMG no wildcard' => array( '<div><span><figure><img target></figure></span></div>', array( 'span', 'img' ), false ),
389-
'Full specification' => array( '<div><span><figure><img target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'img' ), true ),
390-
'Invalid Full specification' => array( '<div><span><figure><img target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'img' ), false ),
388+
'Inner IMG' => array( '<div><span><figure><img target></figure></span></div>', array( 'span', 'figure', 'img' ), true ),
389+
'Inner IMG wildcard' => array( '<div><span><figure><img target></figure></span></div>', array( 'span', '*', 'img' ), true ),
390+
'Inner IMG no wildcard' => array( '<div><span><figure><img target></figure></span></div>', array( 'span', 'img' ), false ),
391+
'Full specification' => array( '<div><span><figure><img target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'img' ), true ),
392+
'Invalid Full specification' => array( '<div><span><figure><img target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'img' ), false ),
391393

392394
// Test also with non-void elements that open and close.
393-
'Inner P' => array( '<div><span><figure><p target></figure></span></div>', array( 'span', 'figure', 'p' ), true ),
394-
'Inner P wildcard' => array( '<div><span><figure><p target></figure></span></div>', array( 'span', '*', 'p' ), true ),
395-
'Inner P no wildcard' => array( '<div><span><figure><p target></figure></span></div>', array( 'span', 'p' ), false ),
396-
'Full specification (P)' => array( '<div><span><figure><p target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'p' ), true ),
397-
'Invalid Full specification (P)' => array( '<div><span><figure><p target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'p' ), false ),
395+
'Inner P' => array( '<div><span><figure><p target></figure></span></div>', array( 'span', 'figure', 'p' ), true ),
396+
'Inner P wildcard' => array( '<div><span><figure><p target></figure></span></div>', array( 'span', '*', 'p' ), true ),
397+
'Inner P no wildcard' => array( '<div><span><figure><p target></figure></span></div>', array( 'span', 'p' ), false ),
398+
'Full specification (P)' => array( '<div><span><figure><p target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'p' ), true ),
399+
'Invalid Full specification (P)' => array( '<div><span><figure><p target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'p' ), false ),
398400

399401
// Ensure that matches aren't on tag closers.
400-
'Inner P' => array( '<div><span><figure></p target></figure></span></div>', array( 'span', 'figure', 'p' ), false ),
401-
'Inner P wildcard' => array( '<div><span><figure></p target></figure></span></div>', array( 'span', '*', 'p' ), false ),
402-
'Inner P no wildcard' => array( '<div><span><figure></p target></figure></span></div>', array( 'span', 'p' ), false ),
403-
'Full specification (P)' => array( '<div><span><figure></p target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'p' ), false ),
404-
'Invalid Full specification (P)' => array( '<div><span><figure></p target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'p' ), false ),
402+
'Inner P (Closer)' => array( '<div><span><figure></p target></figure></span></div>', array( 'span', 'figure', 'p' ), false ),
403+
'Inner P wildcard (Closer)' => array( '<div><span><figure></p target></figure></span></div>', array( 'span', '*', 'p' ), false ),
404+
'Inner P no wildcard (Closer)' => array( '<div><span><figure></p target></figure></span></div>', array( 'span', 'p' ), false ),
405+
'Full specification (P) (Closer)' => array( '<div><span><figure></p target></figure></span></div>', array( 'html', 'body', 'div', 'span', 'figure', 'p' ), false ),
406+
'Invalid Full specification (P) (Closer)' => array( '<div><span><figure></p target></figure></span></div>', array( 'html', 'div', 'span', 'figure', 'p' ), false ),
405407

406408
// Test wildcard behaviors.
407-
'Single wildcard element' => array( '<figure><code><div><p><span><img target></span></p></div></code></figure>', array( '*' ), true ),
408-
'Child of wildcard element' => array( '<figure><code><div><p><span><img target></span></p></div></code></figure>', array( 'SPAN', '*' ), true ),
409+
'Single wildcard element' => array( '<figure><code><div><p><span><img target></span></p></div></code></figure>', array( '*' ), true ),
410+
'Child of wildcard element' => array( '<figure><code><div><p><span><img target></span></p></div></code></figure>', array( 'SPAN', '*' ), true ),
409411
);
410412
}
411413

tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function test_in_body_button_with_button_in_scope_as_ancestor() {
134134
*
135135
* @param string $tag_name Name of H1 - H6 element under test.
136136
*/
137-
public function test_heading_element_closes_open_p_tag( $tag_name ) {
137+
public function test_in_body_heading_element_closes_open_p_tag( $tag_name ) {
138138
$processor = WP_HTML_Processor::create_fragment(
139139
"<p>Open<{$tag_name}>Closed P</{$tag_name}><img></p>"
140140
);
@@ -161,12 +161,12 @@ public function test_heading_element_closes_open_p_tag( $tag_name ) {
161161
*/
162162
public function data_heading_elements() {
163163
return array(
164-
array( 'H1' ),
165-
array( 'H2' ),
166-
array( 'H3' ),
167-
array( 'H4' ),
168-
array( 'H5' ),
169-
array( 'H5' ),
164+
'H1' => array( 'H1' ),
165+
'H2' => array( 'H2' ),
166+
'H3' => array( 'H3' ),
167+
'H4' => array( 'H4' ),
168+
'H5' => array( 'H5' ),
169+
'H6' => array( 'H5' ),
170170
);
171171
}
172172

@@ -178,7 +178,7 @@ public function data_heading_elements() {
178178
* @param string $first_heading H1 - H6 element appearing (unclosed) before the second.
179179
* @param string $second_heading H1 - H6 element appearing after the first.
180180
*/
181-
public function test_heading_element_closes_other_heading_elements( $first_heading, $second_heading ) {
181+
public function test_in_body_heading_element_closes_other_heading_elements( $first_heading, $second_heading ) {
182182
$processor = WP_HTML_Processor::create_fragment(
183183
"<div><{$first_heading} first> then <{$second_heading} second> and end </{$second_heading}><img></{$first_heading}></div>"
184184
);
@@ -217,11 +217,8 @@ public function data_heading_combinations() {
217217
$combinations = array();
218218

219219
// Create all unique pairs of H1 - H6 elements.
220-
for ( $first = 0; $first < count( $headings ); $first++ ) {
221-
for ( $second = $first; $second < count( $headings ); $second++ ) {
222-
$first_tag = $headings[ $first ];
223-
$second_tag = $headings[ $second ];
224-
220+
foreach ( $headings as $first_tag ) {
221+
foreach ( $headings as $second_tag ) {
225222
$combinations[ "{$first_tag} then {$second_tag}" ] = array( $first_tag, $second_tag );
226223
}
227224
}

0 commit comments

Comments
 (0)