Skip to content

Commit 849dbec

Browse files
committed
Correct A reconstruction test
1 parent 1c4a5c7 commit 849dbec

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,28 +193,30 @@ public function test_reconstructs_formatting_from_unclosed_a_elements() {
193193
* @ticket 61576
194194
*/
195195
public function test_reconstructs_unclosed_a_elements() {
196-
$processor = WP_HTML_Processor::create_fragment( '<a><div><a></div></a>' );
196+
$processor = WP_HTML_Processor::create_fragment( '<div><a></div>Found me!' );
197197

198-
$processor->next_tag( 'DIV' );
198+
// First, there's an A tag inside the DIV.
199+
$this->assertTrue( $processor->next_tag( 'A' ) );
199200
$this->assertSame(
200-
array( 'HTML', 'BODY', 'DIV' ),
201+
array( 'HTML', 'BODY', 'DIV', 'A' ),
201202
$processor->get_breadcrumbs(),
202-
'Failed to construct breadcrumbs properly - the DIV should have closed the A element.'
203203
);
204204

205-
// When the DIV re-opens, it reconstructs an unclosed A, then the A in the text is a second A.
206-
$processor->next_tag( 'A' );
205+
/*
206+
* There's a second A tag containing the text outside the DIV.
207+
* When the DIV closes, the unclosed A is reconstructed from inside the DIV
208+
* to contain the following text.
209+
*/
210+
$this->assertTrue( $processor->next_tag( 'A' ) );
207211
$this->assertSame(
208-
array( 'HTML', 'BODY', 'DIV', 'A' ),
209-
'Failed to create proper breadcrumbs for recreated A element.'
212+
array( 'HTML', 'BODY', 'A' ),
213+
$processor->get_breadcrumbs(),
210214
);
211215

212-
// This is the one that's second in the raw text.
213-
$processor->next_tag( 'A' );
214-
$this->assertSame(
215-
array( 'HTML', 'BODY', 'DIV', 'A' ),
216-
'Failed to create proper breadcrumbs for explicit A element - this A should have closed the reconstructed A.'
217-
);
216+
// Finally, the trailing text is inside the A.
217+
$processor->next_token();
218+
$this->assertSame( '#text', $processor->get_token_type() );
219+
$this->assertSame( 'Found me!', $processor->get_modifiable_text() );
218220
}
219221

220222
/**

0 commit comments

Comments
 (0)