Skip to content

Tests: Assert themes REST API has no context param - #13859

Closed
shail-mehta wants to merge 3 commits into
WordPress:trunkfrom
shail-mehta:fix/40538-themes-context-param
Closed

shail-mehta wants to merge 3 commits into
WordPress:trunkfrom
shail-mehta:fix/40538-themes-context-param

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #40538

What

Replaces the empty @doesNotPerformAssertions stub for test_context_param() in the themes REST API tests with real assertions.

Why

Per #40538, remaining read-side empty stubs should become real assertions. rest-themes-controller.php has one claimable read-side case: test_context_param(). Write-side stubs are left alone pending #66073.

How

In WP_Test_REST_Themes_Controller::test_context_param():

  • Send OPTIONS to /wp/v2/themes (collection) and /wp/v2/themes/{stylesheet} (single)
  • Assert each response is 200
  • Assert none of the registered endpoints expose a context arg

Testing instructions

  1. From the repo root, run:
node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit --filter 'WP_Test_REST_Themes_Controller::test_context_param'
  1. Confirm the test passes and is not reported as risky.

Use of AI Tools

  • Cursor

@shail-mehta
shail-mehta marked this pull request as ready for review September 30, 2026 16:08
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props shailu25, mukesh27, lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Comment on lines +1609 to +1611
foreach ( $data['endpoints'] as $endpoint ) {
$this->assertArrayNotHasKey( 'context', $endpoint['args'] );
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for replacing the empty stub with real assertions!

A small suggestion: the other test_context_param() tests in the REST API suite index the first endpoint directly rather than looping, e.g. $data['endpoints'][0]['args']['context'] in the taxonomies, pages and comments controller tests. Both themes routes register only a single READABLE endpoint, so the loop always runs once anyway.

Using [0] would match that convention. It also makes the test fail loudly if the endpoint is ever missing. With the loop, an empty endpoints array would make no assertions and the test would still pass.

Suggested change
foreach ( $data['endpoints'] as $endpoint ) {
$this->assertArrayNotHasKey( 'context', $endpoint['args'] );
}
$this->assertArrayNotHasKey( 'context', $data['endpoints'][0]['args'] );

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in this commit

Comment on lines +1619 to +1621
foreach ( $data['endpoints'] as $endpoint ) {
$this->assertArrayNotHasKey( 'context', $endpoint['args'] );
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same suggestion as on the collection loop, for the single-theme route:

Suggested change
foreach ( $data['endpoints'] as $endpoint ) {
$this->assertArrayNotHasKey( 'context', $endpoint['args'] );
}
$this->assertArrayNotHasKey( 'context', $data['endpoints'][0]['args'] );

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in this commit

wporg-sync pushed a commit that referenced this pull request Sep 30, 2026
Verify that OPTIONS responses for both the themes collection and single-theme routes omit the context argument.

Developed in: #13859

Props shailu25, mukesh27.
See #40538.


git-svn-id: https://develop.svn.wordpress.org/trunk@64023 602fd350-edb4-49c9-b593-d223f7449a82
@lancewillett

Copy link
Copy Markdown
Member

PR #13859 landed in https://core.trac.wordpress.org/changeset/64023

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Sep 30, 2026
Verify that OPTIONS responses for both the themes collection and single-theme routes omit the context argument.

Developed in: WordPress/wordpress-develop#13859

Props shailu25, mukesh27.
See #40538.

Built from https://develop.svn.wordpress.org/trunk@64023


git-svn-id: http://core.svn.wordpress.org/trunk@63183 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@shail-mehta
shail-mehta deleted the fix/40538-themes-context-param branch October 1, 2026 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants