Skip to content

Commit

Permalink
Add test codifying set_attribute bug modifying breadcrumbs.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsnell committed Oct 12, 2023
1 parent 9fb592e commit 1d45bdd
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,49 @@ public function test_finds_correct_tag_given_breadcrumbs( $html, $breadcrumbs, $
$this->assertTrue( $p->get_attribute( 'target' ), "Found {$p->get_tag()} element didn't contain the necessary 'target' attribute." );
}

/**
* Ensures that updates to a tag's attributes doesn't shift
* the current position into the input HTML document.
*
* @ticket 59607
*/
public function test_remains_stable_when_editing_attributes() {
$p = WP_HTML_Processor::create_fragment( '<div><button>First<button><b here>Second' );
$p->next_tag( array( 'breadcrumbs' => array( 'BUTTON', 'B' ) ) );

$this->assertSame(
array( 'HTML', 'BODY', 'DIV', 'BUTTON', 'B' ),
$p->get_breadcrumbs(),
'Found the wrong nested structure at the matched tag.'
);

$p->set_attribute( 'a-name', 'a-value' );

$this->assertTrue(
$p->get_attribute( 'here' ),
'Should have found the B tag but could not find expected "here" attribute.'
);

$this->assertSame(
array( 'HTML', 'BODY', 'DIV', 'BUTTON', 'B' ),
$p->get_breadcrumbs(),
'Found the wrong nested structure at the matched tag.'
);

$p->get_updated_html();

$this->assertTrue(
$p->get_attribute( 'here' ),
'Should have stayed at the B tag but could not find expected "here" attribute.'
);

$this->assertSame(
array( 'HTML', 'BODY', 'DIV', 'BUTTON', 'B' ),
$p->get_breadcrumbs(),
'Found the wrong nested structure at the matched tag after updating attributes.'
);
}

/**
* @ticket 58517
*
Expand Down

0 comments on commit 1d45bdd

Please sign in to comment.