-
Notifications
You must be signed in to change notification settings - Fork 3.6k
HTML API: Respect enqueued updates in get_attribute_names_with_prefix().
#12757
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
Open
dmsnell
wants to merge
4
commits into
WordPress:trunk
Choose a base branch
from
dmsnell:html-api/respect-enqueued-attributes-when-iterating-attribute-names
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+209
−4
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
92667cf
HTML API: Respect enqueued updates in `get_attribute_names_with_prefi…
dmsnell a15f45c
Remove unnecessary sort
dmsnell 8dd7b5d
Add static typing and remove context of array key name from foreach
westonruter 3ffe24f
Review updates
westonruter 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -464,6 +464,179 @@ public function test_get_attribute_names_with_prefix_returns_attribute_added_by_ | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Ensures that a new attribute added via set_attribute() is reported by | ||
| * get_attribute_names_with_prefix() immediately after being added. | ||
| * | ||
| * @ticket 64567 | ||
| * | ||
| * @covers WP_HTML_Tag_Processor::get_attribute_names_with_prefix | ||
| */ | ||
| public function test_get_attribute_names_with_prefix_immediately_reflects_new_attributes() { | ||
| $processor = new WP_HTML_Tag_Processor( '<div existing>' ); | ||
| $processor->next_tag(); | ||
|
|
||
| $this->assertSame( | ||
| array( 'existing' ), | ||
| $processor->get_attribute_names_with_prefix( '' ), | ||
| 'Failed to report existing attribute names: check test setup.' | ||
| ); | ||
|
|
||
| $processor->set_attribute( 'new', true ); | ||
|
|
||
| $this->assertSame( | ||
| array( 'new', 'existing' ), | ||
| $processor->get_attribute_names_with_prefix( '' ), | ||
| 'Failed to report newly-added attribute.' | ||
| ); | ||
|
|
||
| $this->assertSame( | ||
| array( 'existing' ), | ||
| $processor->get_attribute_names_with_prefix( 'exist' ), | ||
| 'Should have only reported existing attribute matching given prefix.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Ensures that changes enqueued for modifiable text do not get reported as added attributes. | ||
| * | ||
| * This is a fairly-specific test against an internal implementation detail, but is worth | ||
| * adding to catch potential regressions since modifiable text updates share a namespace with | ||
| * attribute updates. | ||
| * | ||
| * @ticket 64567 | ||
| * | ||
| * @covers WP_HTML_Tag_Processor::get_attribute_names_with_prefix | ||
| */ | ||
| public function test_get_attribute_names_with_prefix_ignores_immediately_added_modifiable_text() { | ||
| $processor = new WP_HTML_Tag_Processor( '<title existing></title>' ); | ||
| $processor->next_tag(); | ||
|
|
||
| $this->assertSame( | ||
| array( 'existing' ), | ||
| $processor->get_attribute_names_with_prefix( '' ), | ||
| 'Failed to report existing attribute names: check test setup.' | ||
| ); | ||
|
|
||
| $processor->set_modifiable_text( 'content!' ); | ||
|
|
||
| $this->assertSame( | ||
| array( 'existing' ), | ||
| $processor->get_attribute_names_with_prefix( '' ), | ||
| 'Failed to report that the attributes were unchanged.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Ensures that an attribute removed via remove_attribute() is no longer reported | ||
| * by get_attribute_names_with_prefix() immediately after being removed. | ||
| * | ||
| * @ticket 64567 | ||
| * | ||
| * @covers WP_HTML_Tag_Processor::get_attribute_names_with_prefix | ||
| */ | ||
| public function test_get_attribute_names_with_prefix_immediately_reflects_removed_attributes() { | ||
| $processor = new WP_HTML_Tag_Processor( '<div existing data-removed>' ); | ||
| $processor->next_tag(); | ||
|
|
||
| $this->assertSame( | ||
| array( 'existing', 'data-removed' ), | ||
| $processor->get_attribute_names_with_prefix( '' ), | ||
| 'Failed to report all existing attributes: check test setup.' | ||
| ); | ||
|
|
||
| $processor->remove_attribute( 'data-removed' ); | ||
|
|
||
| $this->assertSame( | ||
| array(), | ||
| $processor->get_attribute_names_with_prefix( 'data-' ), | ||
| 'Expected no custom data attributes after removing the only one.' | ||
| ); | ||
|
|
||
| $this->assertSame( | ||
| array( 'existing' ), | ||
| $processor->get_attribute_names_with_prefix( '' ), | ||
| 'Expected to report only the attribute which wasn’t removed.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Ensures that when the `class` attribute is newly added via add_class(), that | ||
| * it’s reported by get_attribute_names_with_prefix() immediately after being added. | ||
| * | ||
| * @ticket 64567 | ||
| * | ||
| * @covers WP_HTML_Tag_Processor::get_attribute_names_with_prefix | ||
| */ | ||
| public function test_get_attribute_names_with_prefix_immediately_reflects_class_after_adding_classes() { | ||
| $processor = new WP_HTML_Tag_Processor( '<div existing>' ); | ||
| $processor->next_tag(); | ||
|
|
||
| $this->assertSame( | ||
| array( 'existing' ), | ||
| $processor->get_attribute_names_with_prefix( '' ), | ||
| 'Expected to only report the existing attribute: check test setup.' | ||
| ); | ||
|
|
||
| $processor->add_class( 'added' ); | ||
|
|
||
| $this->assertSame( | ||
| array( 'class' ), | ||
| $processor->get_attribute_names_with_prefix( 'class' ), | ||
| 'Failed to report the newly-added `class` attribute.' | ||
| ); | ||
| } | ||
|
Comment on lines
+563
to
+588
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to add a test case for the class removal as well? |
||
|
|
||
| /** | ||
| * Ensures get_attribute_names_with_prefix() agrees with get_attribute() | ||
| * after pending updates, returning each name once with no stale entries. | ||
| * | ||
| * @ticket 64567 | ||
| * | ||
| * @covers WP_HTML_Tag_Processor::get_attribute_names_with_prefix | ||
| */ | ||
| public function test_get_attribute_names_with_prefix_immediately_agrees_with_get_attribute_after_updates() { | ||
| $processor = new WP_HTML_Tag_Processor( '<div data-keep="1" data-drop="2">Test</div>' ); | ||
| $processor->next_tag(); | ||
|
|
||
| $this->assertSame( | ||
| array( 'data-keep', 'data-drop' ), | ||
| $processor->get_attribute_names_with_prefix( '' ), | ||
| 'Failed to find expected existing attributes: check test setup.' | ||
| ); | ||
|
|
||
| $this->assertSame( | ||
| '1', | ||
| $processor->get_attribute( 'data-keep' ), | ||
| 'Failed to find expected existing `data-keep` attribute value: check test setup.' | ||
| ); | ||
|
|
||
| $this->assertSame( | ||
| '2', | ||
| $processor->get_attribute( 'data-drop' ), | ||
| 'Failed to find expected existing `data-drop` attribute value: check test setup.' | ||
| ); | ||
|
|
||
| $processor->set_attribute( 'data-keep', 'updated' ); | ||
| $processor->set_attribute( 'data-add', 'new' ); | ||
| $processor->remove_attribute( 'data-drop' ); | ||
|
|
||
| $names = $processor->get_attribute_names_with_prefix( 'data-' ); | ||
|
westonruter marked this conversation as resolved.
|
||
|
|
||
| $this->assertSame( | ||
| array( 'data-add', 'data-keep' ), | ||
| $names, | ||
| 'Failed to report the expected attribute names after removing and adding attributes.' | ||
| ); | ||
|
|
||
| foreach ( $names as $name ) { | ||
| $this->assertNotNull( | ||
| $processor->get_attribute( $name ), | ||
| "get_attribute_names_with_prefix() reported '{$name}' but get_attribute() did not agree." | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 56299 | ||
| * | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.