Skip to content

Query: Add unit tests for is_home on the main and secondary queries during REST requests - #14797

Open
irozum wants to merge 1 commit into
WordPress:trunkfrom
irozum:task/50213-wp-query-is-home-rest-request-tests
Open

irozum wants to merge 1 commit into
WordPress:trunkfrom
irozum:task/50213-wp-query-is-home-rest-request-tests

Conversation

@irozum

@irozum irozum commented Oct 23, 2026

Copy link
Copy Markdown

Adds unit tests for the REST clause in WP_Query::parse_query(): ( wp_is_serving_rest_request() && $this->is_main_query() ). This is a test-only change and adds no production behaviour.

Trac ticket: https://core.trac.wordpress.org/ticket/50213

Follow-up to [48053], which restricted the REST exemption to the main query so that secondary queries can still be is_home. The ticket was closed as fixed with needs-unit-tests still set, and nothing in tests/phpunit covered it.

What is tested (Tests_Query_ParseQuery)

  • test_secondary_query_during_rest_request_can_be_home: with REST_REQUEST true, a query that is not $wp_the_query has is_home === true.
  • test_main_query_during_rest_request_is_not_home: with REST_REQUEST true, the query that is $wp_the_query has is_home === false.

Why these cases

  • They are the two sides of the is_main_query() condition added in [48053]. Each test asserts a precondition on is_main_query() so a setup mistake can't pass silently.
  • REST_REQUEST is a constant, so both tests use @runInSeparateProcess with @preserveGlobalState disabled, as wpIsServingRestRequest.php does.

Verification

  • Removing && $this->is_main_query() makes only the secondary-query test fail.
  • Deleting the whole REST clause makes only the main-query test fail.
  • Tests_Query_ParseQuery passes (19 tests) and PHPCS reports no errors or warnings on the file.

Use of AI Tools

This change was written with Claude Code (Claude Sonnet 5.5), which drafted the tests and ran the verification above.

This PR is for code review only. Please do not merge it from GitHub; commits happen through Trac.

@github-actions

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.

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

Props irozum.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

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.

1 participant