Icons: Enforce strict name validation in register method#11245
Icons: Enforce strict name validation in register method#11245im3dabasia wants to merge 9 commits into
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
t-hamano
left a comment
There was a problem hiding this comment.
Thanks for the PR! I think there are roughly two areas for improvement.
public function test() {
$result = $this->register( 'invalid-name', array() );
$this->assertFalse( $result );
}This test appears correct at first glance, but note that the second argument is an empty array. If the second argument is empty, it will cause an error here. In other words, this test does not guarantee whether the error is caused by an invalid icon name.
Another suggestion is to use a data provider, which reduces the amount of code and allows us to cover more cases. For example:
public function test_invalid_icon_names( $icon_name ) {
$settings = array(
'label' => 'Icon',
'content' => '<svg></svg>',
);
$result = $this->register( $icon_name, $settings );
$this->assertFalse( $result );
}
public function data_invalid_icon_names() {
return array(
'non-string name' => array( 1 ),
'no namespace' => array( 'plus' ),
'uppercase characters' => array( 'Core/Plus' ),
'invalid characters' => array( 'test/_doing_it_wrong' ),
);
}|
Thanks for the continuous iterations on this PR. I have addressed the feedbacks in this commit bf30902 |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
t-hamano
left a comment
There was a problem hiding this comment.
LGTM!
Additionally, it would be great if you made the same changes to WordPress/gutenberg#76079.
|
@im3dabasia Since WordPress/gutenberg#76079 has now been merged, can you update this PR accordingly? |
|
@im3dabasia Thanks for the update! As we are currently in the phase of preparing for the 7.0 release, let's commit this PR after the 7.0 release. |
| * | ||
| * @expectedIncorrectUsage WP_Icons_Registry::register | ||
| */ | ||
| public function test_register_icon_twice() { |
There was a problem hiding this comment.
Add @ticket for new unit tests
| /** | ||
| * Should fail to register icon with invalid names. | ||
| * | ||
| * @dataProvider data_invalid_icon_names |
There was a problem hiding this comment.
This it not correctly use of dataProvider. Make sure to correct it before commit.
|
Trunk is now WordPress 7.1-alpha, so we can move this PR forward. @im3dabasia, can you address @mukeshpanchal27's review and update this PR? |
Annotate the new WP_Icons_Registry tests with @ticket 64847 so each test is traceable to its Trac ticket, matching the convention used in the sibling wpRestIconsController tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The test declared @dataProvider but ignored the injected value and looped over the provider itself, collapsing all cases into one test. Accept the provided name as a parameter so each dataset runs as its own test case. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Trac ticket: https://core.trac.wordpress.org/ticket/64847
Use of AI Tools
Copilot
Caution
Commit this PR after the
wp/7.0release branch has been created. This PR targets the 7.1 release.