-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tag Processor: Add bookmark invalidation logic (#47559)
Invalidate bookmarks in a `WP_HTML_Tag_Processor` instance if the tags that they're pointing to have been replaced. While `WP_HTML_Tag_Processor` currently only supports changing a given tag's attributes, we plan to also provide methods to make broader changes (possibly through a subclass of `WP_HTML_Tag_Processor`). An API like that will have the potential of replacing a tag that a bookmark points to. As a preparation, we thus need to make sure that all bookmarks affected by a HTML replacement are invalidated (i.e. released). Co-authored-by: Dennis Snell <[email protected]>
- Loading branch information
Showing
2 changed files
with
67 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
phpunit/html-api/class-gutenberg-html-tag-processor-6-3-bookmark-test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* Unit tests covering Gutenberg_HTML_Tag_Processor_6_3 functionality. | ||
* | ||
* @package WordPress | ||
* @subpackage HTML | ||
*/ | ||
|
||
require_once __DIR__ . '/../../lib/compat/wordpress-6.3/html-api/class-gutenberg-html-tag-processor-6-3.php'; | ||
|
||
/** | ||
* @group html-api | ||
* | ||
* @coversDefaultClass Gutenberg_HTML_Tag_Processor_6_3 | ||
*/ | ||
class Gutenberg_HTML_Tag_Processor_6_3_Bookmark_Test extends WP_UnitTestCase { | ||
/** | ||
* @covers has_bookmark | ||
*/ | ||
public function test_has_bookmark_returns_false_if_bookmark_does_not_exist() { | ||
$p = new Gutenberg_HTML_Tag_Processor_6_3( '<div>Test</div>' ); | ||
$this->assertFalse( $p->has_bookmark( 'my-bookmark' ) ); | ||
} | ||
|
||
/** | ||
* @covers has_bookmark | ||
*/ | ||
public function test_has_bookmark_returns_true_if_bookmark_exists() { | ||
$p = new Gutenberg_HTML_Tag_Processor_6_3( '<div>Test</div>' ); | ||
$p->next_tag(); | ||
$p->set_bookmark( 'my-bookmark' ); | ||
$this->assertTrue( $p->has_bookmark( 'my-bookmark' ) ); | ||
} | ||
|
||
/** | ||
* @covers has_bookmark | ||
*/ | ||
public function test_has_bookmark_returns_false_if_bookmark_has_been_released() { | ||
$p = new Gutenberg_HTML_Tag_Processor_6_3( '<div>Test</div>' ); | ||
$p->next_tag(); | ||
$p->set_bookmark( 'my-bookmark' ); | ||
$p->release_bookmark( 'my-bookmark' ); | ||
$this->assertFalse( $p->has_bookmark( 'my-bookmark' ) ); | ||
} | ||
} |
0ff570f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in 0ff570f.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4233785746
📝 Reported issues:
specs/editor/various/autosave.test.js