Opened 4 weeks ago
Closed 4 weeks ago
#66287 closed enhancement (fixed)
REST API: Add unit test coverage for WP_REST_Icon_Collections_Controller
| Reported by: | noruzzaman | Owned by: | wildworks |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | REST API | Version: | trunk |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
Description
Following the introduction of the Icon Collections REST API endpoint (/wp/v2/icon-collections) and recent visibility updates in WordPress Core, this ticket adds comprehensive unit test coverage for WP_REST_Icon_Collections_Controller.
Proposed Changes
Backport the unit test suite developed and reviewed in Gutenberg PR https://github.com/WordPress/gutenberg/pull/83168 (reviewed by @t-hamano):
- Verify route registration for
/wp/v2/icon-collectionsand/wp/v2/icon-collections/(?P<slug>[a-z0-9](?:[a-z0-9_-]*[a-z0-9])?). - Assert permission checks (
edit_postscapability required; 401 unauthenticated, 403 unauthorized). - Assert public and non-public collection visibility filtering in
GET /wp/v2/icon-collections(omits non-public collections liketest-privateand built-incore-admin). - Assert
GET /wp/v2/icon-collections/<slug>returns collection data or 404 with error coderest_icon_collection_not_foundfor non-public or invalid collections. - Assert
_fieldsfiltering, schema compliance, and context parameter enum validation.
Pull Request
A pull request will be linked shortly.
Change History (4)
This ticket was mentioned in PR #14195 on WordPress/wordpress-develop by @noruzzaman.
4 weeks ago
#1
- Keywords has-unit-tests added
@noruzzaman commented on PR #14195:
4 weeks ago
#2
Hi @t-hamano,
Thank you for the review!
In ff96a4e161, I have updated test_get_item_schema() to align with Gutenberg:
- Added schema
titleandtypeassertions (assertSame( 'icon-collection', $schema['title'] )andassertSame( 'object', $schema['type'] )). - Added
readonlyflag assertions on all properties (slug,label,description). - Retained the
OPTIONS /wp/v2/icon-collectionsrequest dispatch andassertCount( 3, $properties ).
WordPress Coding Standards (phpcs --standard=WordPress-Core) and PHP syntax checks pass 100% cleanly.
@rejaulalomkhan commented on PR #14195:
4 weeks ago
#3
Test report
Tested ff96a4e locally against trunk:
tests/phpunit/tests/icons/wpRestIconCollectionsController.php: 22 tests pass on single site and multisite (PHP 8.3), and with--order-by=reverse.- The whole
iconsgroup (148 tests) passes. - PHP 8.5: the test file passes, no deprecations.
- PHPCS: no issues.
I also checked that the new tests catch regressions: making get_item_permissions_check() return true makes test_get_item_requires_permissions fail as expected. core-admin is a built-in collection in icon-library-manifest.php, so the data provider case covers real core data.
LGTM from a testing perspective.
AI assistance: Claude Code (Claude Opus 5.5) was used to run the checks above; I reviewed the results.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Backports comprehensive unit test coverage for
WP_REST_Icon_Collections_Controllerfrom Gutenberg PR https://github.com/WordPress/gutenberg/pull/83168 (reviewed by @t-hamano).Changes:
edit_postscapability (test_get_item_requires_permissions)._fieldsparameter on both collection and single item endpoints (test_get_items_fields_parameter,test_get_item_fields_parameter).rest-visibility-privateand built-incore-admin) are omitted from collection listing (test_get_items_omits_non_public_collections).rest_icon_collection_not_founderror via data provider (test_get_item_returns_404_for_non_public_collection).contexttoview(test_get_collection_params).