Repository navigation
Tests: Add unit test coverage for WP_REST_Icon_Collections_Controller - #83168
noruzzamans wants to merge 8 commits into
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Updated as activity occurs, without notifying anyone named here. Add the |
t-hamano
left a comment
There was a problem hiding this comment.
Thanks for the PR!
Since this PR was opened, a few changes to the Icons API landed in trunk that affect these tests. Now that trunk has been merged into this branch, could you update the tests to reflect them?
In #83277, the public property moved from icons to collections, and /wp/v2/icon-collections is now served by WP_REST_Icon_Collections_Controller_Gutenberg, a subclass of the controller tested here. It hides collections registered with 'public' => false.
This is now one of the most important behaviors of the endpoint, so it would be great to cover it. For example:
public function set_up() {
parent::set_up();
wp_register_icon_collection( 'test-public', array( 'label' => 'Test Public' ) );
wp_register_icon_collection(
'test-private',
array(
'label' => 'Test Private',
'public' => false,
)
);
}
public function tear_down() {
wp_unregister_icon_collection( 'test-public' );
wp_unregister_icon_collection( 'test-private' );
parent::tear_down();
}With this in place, the custom collections the individual tests currently register could probably be replaced by test-public, which would also simplify tear_down().
Tests worth adding:
- The list includes
test-publicbut nottest-privateor the built-incore-admincollection. - Requesting
test-privatedirectly returns a404with therest_icon_collection_not_foundcode.
Once this PR is ready, it would be good to open a Core Trac ticket and a Core PR to apply the same changes to WordPress Core, and link it to this PR through the backport changelog. See the Core Backport Changelog documentation for details.
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
|
Thanks for the thorough review and helpful guidance, @t-hamano! I have updated the test suite in 2f452ce:
|
t-hamano
left a comment
There was a problem hiding this comment.
@noruzzamans Thanks for the update!
I noticed that two tests identical to the ones added in this PR already exist in another file. The code below can probably be removed as redundant.
gutenberg/phpunit/class-wp-rest-icon-controller-test.php
Lines 482 to 508 in f2a9d9d
Regarding the core backport PR, it will likely be difficult to prepare one right now since Core is slightly behind Gutenberg. I will let you know when the time comes.
|
Good catch, @t-hamano! Thank you for pointing that out. In b1a270e, I have removed the two redundant collection tests ( Understood regarding the WordPress Core backport PR — whenever Core catches up and is ready for the backport, feel free to ping me and I will gladly prepare the Trac ticket and Core PR! |
Description
Adds unit test coverage for
WP_REST_Icon_Collections_Controller(/wp/v2/icon-collections), verifying REST API route registration, permission gates, item and collection retrieval, field filtering, context filtering, schema compliance, and query parameters.Follow-up to #79686 and #77260.
Context & Problem
WP_REST_Icon_Collections_Controllerprovides the REST endpoint used to query registered icon collections in the icon picker. While the registry (WP_Icon_Collections_Registry) and icon endpoint (/wp/v2/icons) have automated tests, the icon collections REST controller itself previously had no dedicated unit tests.Test Coverage Added
This test suite (
phpunit/class-wp-rest-icon-collections-controller-test.php) covers:/wp/v2/icon-collectionsand/wp/v2/icon-collections/<slug>routes are registered.edit_postscapability (Administrator, Editor, Contributor).401 rest_cannot_view).403 rest_cannot_view).GET /wp/v2/icon-collections):coreand custom registered collections).slug,label,description)._fieldsparameter.embedcontext.GET /wp/v2/icon-collections/<slug>):coreand custom registered collections.404 rest_icon_collection_not_foundfor non-existent collections._fieldsparameter filtering on single items.context => view).Testing Instructions
Run PHPUnit tests for the new test class:
Verify PHPCS coding standards:
Scope