- Timestamp:
- 02/01/2024 01:00:56 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php
r57316 r57508 80 80 * @return array[]. 81 81 */ 82 public function data_article_container_group() {82 public static function data_article_container_group() { 83 83 $group = array(); 84 84 … … 123 123 */ 124 124 public function test_in_body_skips_unexpected_button_closer() { 125 $p = WP_HTML_Processor::create_fragment( '<div>Test</button></div>' );126 127 $p ->step();128 $this->assertSame( 'DIV', $p ->get_tag(), 'Did not stop at initial DIV tag.' );129 $this->assertFalse( $p ->is_tag_closer(), 'Did not find that initial DIV tag is an opener.' );125 $processor = WP_HTML_Processor::create_fragment( '<div>Test</button></div>' ); 126 127 $processor->step(); 128 $this->assertSame( 'DIV', $processor->get_tag(), 'Did not stop at initial DIV tag.' ); 129 $this->assertFalse( $processor->is_tag_closer(), 'Did not find that initial DIV tag is an opener.' ); 130 130 131 131 /* … … 133 133 * It should be ignored as there's no BUTTON to close. 134 134 */ 135 $this->assertTrue( $p ->step(), 'Found no further tags when it should have found the closing DIV' );136 $this->assertSame( 'DIV', $p ->get_tag(), "Did not skip unexpected BUTTON; stopped at {$p->get_tag()}." );137 $this->assertTrue( $p ->is_tag_closer(), 'Did not find that the terminal DIV tag is a closer.' );135 $this->assertTrue( $processor->step(), 'Found no further tags when it should have found the closing DIV' ); 136 $this->assertSame( 'DIV', $processor->get_tag(), "Did not skip unexpected BUTTON; stopped at {$processor->get_tag()}." ); 137 $this->assertTrue( $processor->is_tag_closer(), 'Did not find that the terminal DIV tag is a closer.' ); 138 138 } 139 139 … … 144 144 */ 145 145 public function test_in_body_button_with_no_button_in_scope() { 146 $p = WP_HTML_Processor::create_fragment( '<div><p>Click the button <button one>here</button>!</p></div><button two>not here</button>' );147 148 $this->assertTrue( $p ->next_tag( 'BUTTON' ), 'Could not find expected first button.' );149 $this->assertTrue( $p ->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' );150 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $p ->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' );146 $processor = WP_HTML_Processor::create_fragment( '<div><p>Click the button <button one>here</button>!</p></div><button two>not here</button>' ); 147 148 $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected first button.' ); 149 $this->assertTrue( $processor->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' ); 150 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' ); 151 151 152 152 /* … … 155 155 * malformed and unexpected ones. 156 156 */ 157 $this->assertTrue( $p ->next_tag( 'BUTTON' ), 'Could not find expected second button.' );158 $this->assertTrue( $p ->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' );159 $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $p ->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' );157 $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected second button.' ); 158 $this->assertTrue( $processor->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' ); 159 $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' ); 160 160 } 161 161 … … 169 169 */ 170 170 public function test_in_body_button_with_button_in_scope_as_parent() { 171 $p = WP_HTML_Processor::create_fragment( '<div><p>Click the button <button one>almost<button two>here</button>!</p></div><button three>not here</button>' );172 173 $this->assertTrue( $p ->next_tag( 'BUTTON' ), 'Could not find expected first button.' );174 $this->assertTrue( $p ->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' );175 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $p ->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' );171 $processor = WP_HTML_Processor::create_fragment( '<div><p>Click the button <button one>almost<button two>here</button>!</p></div><button three>not here</button>' ); 172 173 $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected first button.' ); 174 $this->assertTrue( $processor->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' ); 175 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' ); 176 176 177 177 /* … … 179 179 * or it may place it as a child of the first one, but it implicitly closes the open BUTTON. 180 180 */ 181 $this->assertTrue( $p ->next_tag( 'BUTTON' ), 'Could not find expected second button.' );182 $this->assertTrue( $p ->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' );183 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $p ->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' );181 $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected second button.' ); 182 $this->assertTrue( $processor->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' ); 183 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' ); 184 184 185 185 /* … … 187 187 * looking for proper handling of the open and close sequence for the BUTTON tags. 188 188 */ 189 $this->assertTrue( $p ->next_tag( 'BUTTON' ), 'Could not find expected third button.' );190 $this->assertTrue( $p ->get_attribute( 'three' ), 'Failed to match expected attribute on third button.' );191 $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $p ->get_breadcrumbs(), 'Failed to produce expected DOM nesting for third button.' );189 $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected third button.' ); 190 $this->assertTrue( $processor->get_attribute( 'three' ), 'Failed to match expected attribute on third button.' ); 191 $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for third button.' ); 192 192 } 193 193 … … 202 202 */ 203 203 public function test_in_body_button_with_button_in_scope_as_ancestor() { 204 $p = WP_HTML_Processor::create_fragment( '<div><button one><p>Click the button <span><button two>here</button>!</span></p></div><button three>not here</button>' );204 $processor = WP_HTML_Processor::create_fragment( '<div><button one><p>Click the button <span><button two>here</button>!</span></p></div><button three>not here</button>' ); 205 205 206 206 // This button finds itself normally nesting inside the DIV. 207 $this->assertTrue( $p ->next_tag( 'BUTTON' ), 'Could not find expected first button.' );208 $this->assertTrue( $p ->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' );209 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'BUTTON' ), $p ->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' );207 $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected first button.' ); 208 $this->assertTrue( $processor->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' ); 209 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' ); 210 210 211 211 /* … … 215 215 * itself a child of the most-recent open element above the most-recent BUTTON, or the DIV. 216 216 */ 217 $this->assertTrue( $p ->next_tag( 'BUTTON' ), 'Could not find expected second button.' );218 $this->assertTrue( $p ->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' );219 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'BUTTON' ), $p ->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' );217 $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected second button.' ); 218 $this->assertTrue( $processor->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' ); 219 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' ); 220 220 221 221 // The third button is back to normal, because everything has been implicitly or explicitly closed by now. 222 $this->assertTrue( $p ->next_tag( 'BUTTON' ), 'Could not find expected third button.' );223 $this->assertTrue( $p ->get_attribute( 'three' ), 'Failed to match expected attribute on third button.' );224 $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $p ->get_breadcrumbs(), 'Failed to produce expected DOM nesting for third button.' );222 $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected third button.' ); 223 $this->assertTrue( $processor->get_attribute( 'three' ), 'Failed to match expected attribute on third button.' ); 224 $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for third button.' ); 225 225 } 226 226 … … 275 275 * @return array[]. 276 276 */ 277 public function data_heading_elements() {277 public static function data_heading_elements() { 278 278 return array( 279 279 'H1' => array( 'H1' ), … … 329 329 * @return array[] 330 330 */ 331 public function data_heading_combinations() {331 public static function data_heading_combinations() { 332 332 $headings = array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ); 333 333 … … 356 356 */ 357 357 public function test_in_body_any_other_end_tag_with_unclosed_special_element() { 358 $p = WP_HTML_Processor::create_fragment( '<div><span><p></span><div>' );359 360 $p ->next_tag( 'P' );361 $this->assertSame( 'P', $p ->get_tag(), "Expected to start test on P element but found {$p->get_tag()} instead." );362 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'P' ), $p ->get_breadcrumbs(), 'Failed to produce expected DOM nesting.' );363 364 $this->assertTrue( $p ->next_tag(), 'Failed to advance past P tag to expected DIV opener.' );365 $this->assertSame( 'DIV', $p ->get_tag(), "Expected to find DIV element, but found {$p->get_tag()} instead." );366 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'DIV' ), $p ->get_breadcrumbs(), 'Failed to produce expected DOM nesting: SPAN should still be open and DIV should be its child.' );358 $processor = WP_HTML_Processor::create_fragment( '<div><span><p></span><div>' ); 359 360 $processor->next_tag( 'P' ); 361 $this->assertSame( 'P', $processor->get_tag(), "Expected to start test on P element but found {$processor->get_tag()} instead." ); 362 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'P' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting.' ); 363 364 $this->assertTrue( $processor->next_tag(), 'Failed to advance past P tag to expected DIV opener.' ); 365 $this->assertSame( 'DIV', $processor->get_tag(), "Expected to find DIV element, but found {$processor->get_tag()} instead." ); 366 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'DIV' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting: SPAN should still be open and DIV should be its child.' ); 367 367 } 368 368 … … 379 379 */ 380 380 public function test_in_body_any_other_end_tag_with_unclosed_non_special_element() { 381 $p = WP_HTML_Processor::create_fragment( '<div><span><code></span><div>' );382 383 $p ->next_tag( 'CODE' );384 $this->assertSame( 'CODE', $p ->get_tag(), "Expected to start test on CODE element but found {$p->get_tag()} instead." );385 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'CODE' ), $p ->get_breadcrumbs(), 'Failed to produce expected DOM nesting.' );386 387 $this->assertTrue( $p ->step(), 'Failed to advance past CODE tag to expected SPAN closer.' );388 $this->assertTrue( $p ->is_tag_closer(), 'Expected to find closing SPAN, but found opener instead.' );389 $this->assertSame( array( 'HTML', 'BODY', 'DIV' ), $p ->get_breadcrumbs(), 'Failed to advance past CODE tag to expected DIV opener.' );390 391 $this->assertTrue( $p ->next_tag(), 'Failed to advance past SPAN closer to expected DIV opener.' );392 $this->assertSame( 'DIV', $p ->get_tag(), "Expected to find DIV element, but found {$p->get_tag()} instead." );393 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'DIV' ), $p ->get_breadcrumbs(), 'Failed to produce expected DOM nesting: SPAN should be closed and DIV should be its sibling.' );381 $processor = WP_HTML_Processor::create_fragment( '<div><span><code></span><div>' ); 382 383 $processor->next_tag( 'CODE' ); 384 $this->assertSame( 'CODE', $processor->get_tag(), "Expected to start test on CODE element but found {$processor->get_tag()} instead." ); 385 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'CODE' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting.' ); 386 387 $this->assertTrue( $processor->step(), 'Failed to advance past CODE tag to expected SPAN closer.' ); 388 $this->assertTrue( $processor->is_tag_closer(), 'Expected to find closing SPAN, but found opener instead.' ); 389 $this->assertSame( array( 'HTML', 'BODY', 'DIV' ), $processor->get_breadcrumbs(), 'Failed to advance past CODE tag to expected DIV opener.' ); 390 391 $this->assertTrue( $processor->next_tag(), 'Failed to advance past SPAN closer to expected DIV opener.' ); 392 $this->assertSame( 'DIV', $processor->get_tag(), "Expected to find DIV element, but found {$processor->get_tag()} instead." ); 393 $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'DIV' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting: SPAN should be closed and DIV should be its sibling.' ); 394 394 } 395 395 … … 413 413 */ 414 414 public function test_br_end_tag_unsupported() { 415 $p = WP_HTML_Processor::create_fragment( '</br>' );416 417 $this->assertFalse( $p ->next_tag(), 'Found a BR tag that should not be handled.' );418 $this->assertSame( WP_HTML_Processor::ERROR_UNSUPPORTED, $p ->get_last_error() );415 $processor = WP_HTML_Processor::create_fragment( '</br>' ); 416 417 $this->assertFalse( $processor->next_tag(), 'Found a BR tag that should not be handled.' ); 418 $this->assertSame( WP_HTML_Processor::ERROR_UNSUPPORTED, $processor->get_last_error() ); 419 419 } 420 420 }
Note: See TracChangeset
for help on using the changeset viewer.