-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tag Processor: Add bookmark invalidation logic #47559
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c110725
Tag Processor: Add bookmark invalidation logic
ockham 90fef0a
Add since PHPDoc
ockham 8d35826
Add has_bookmark method
ockham 0503eb6
Add basic unit test coverage for has_bookmark
ockham 7e2a5bd
Re-write bookmark updating logic
ockham 1d17cb5
Avoid double negation
ockham ecee379
Rename test file to include -bookmark suffix
ockham 83f274c
Verbing weirds language
ockham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' ) ); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I still think this would read better as:
If
$bookmark->start
is ever after$bookmark->end
, I'd rather make it fail in some way rather than try to salvage it with a defensive condition.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.
While we did inline
$update_head
and$update_tail
here, we didn't otherwise change the condition -- it existed like that prior to this PR. For that reason, I'd like to keep it as is 😬 I know it shouldn't make a difference outside of any pathological cases, but since this PR has been sitting for a while, I'd like to de-risk it as much as possible.Aside: I kinda like that it's symmetrical to the condition right below:
I feel it helps me visualize better that the bookmark is either fully past the diff, or enclosed by it.
I'm open to changing this in a follow-up though 😊