Make WordPress Core

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-collections and /wp/v2/icon-collections/(?P<slug>[a-z0-9](?:[a-z0-9_-]*[a-z0-9])?).
  • Assert permission checks (edit_posts capability required; 401 unauthenticated, 403 unauthorized).
  • Assert public and non-public collection visibility filtering in GET /wp/v2/icon-collections (omits non-public collections like test-private and built-in core-admin).
  • Assert GET /wp/v2/icon-collections/<slug> returns collection data or 404 with error code rest_icon_collection_not_found for non-public or invalid collections.
  • Assert _fields filtering, 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

Backports comprehensive unit test coverage for WP_REST_Icon_Collections_Controller from Gutenberg PR ​https://github.com/WordPress/gutenberg/pull/83168 (reviewed by @t-hamano).

Changes:

  • Tests that getting a specific collection requires edit_posts capability (test_get_item_requires_permissions).
  • Verifies response field filtering with _fields parameter on both collection and single item endpoints (test_get_items_fields_parameter, test_get_item_fields_parameter).
  • Tests that non-public collections (rest-visibility-private and built-in core-admin) are omitted from collection listing (test_get_items_omits_non_public_collections).
  • Tests that requesting non-public collections directly returns a 404 rest_icon_collection_not_found error via data provider (test_get_item_returns_404_for_non_public_collection).
  • Verifies collection query parameters default context to view (test_get_collection_params).

​@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 title and type assertions (assertSame( 'icon-collection', $schema['title'] ) and assertSame( 'object', $schema['type'] )).
  • Added readonly flag assertions on all properties (slug, label, description).
  • Retained the OPTIONS /wp/v2/icon-collections request dispatch and assertCount( 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 icons group (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.

#4 @wildworks
4 weeks ago

  • Owner set to wildworks
  • Resolution → fixed
  • Status new → closed

In 64310:

Tests: Expand coverage for the icon collections REST endpoint.

Adds tests for permission checks, _fields filtering, the schema, and collection parameters, and verifies that the built-in non-public core-admin collection is not exposed.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14195

Props noruzzaman, rejaulalomkhan, wildworks.
Fixes #66287.

Note: See TracTickets for help on using tickets.