Skip to content

Tests: Add unit test coverage for get_search_query() and the_search_query() - #14679

Open
rejaulalomkhan wants to merge 1 commit into
WordPress:trunkfrom
rejaulalomkhan:tests/search-query
Open

rejaulalomkhan wants to merge 1 commit into
WordPress:trunkfrom
rejaulalomkhan:tests/search-query

Conversation

@rejaulalomkhan

Copy link
Copy Markdown

Description

Adds a test class for get_search_query() and the_search_query(), which had no direct tests.

The tests cover:

  • get_search_query() escaping the query by default (Tom & "Jerry" <b>), returning it raw with $escaped = false, an empty string without a search, and reading the main query after go_to( '/?s=pizza+night' ).
  • The get_search_query filter receiving the raw query, with its result escaped afterwards.
  • the_search_query() displaying the escaped query.
  • The the_search_query filter receiving the unescaped query (already passed through get_search_query), with its result escaped once.

Each behaviour was checked against a mutated source (escaping removed, filter skipped, $escaped defaulting to false, escaping removed from or doubled in the_search_query(), its filter skipped); a test fails for every mutation.

This is a test-only change; no production code is modified.

Testing Instructions

  1. npm run test:php -- --filter Tests_General_GetSearchQuery
  2. npm run test:php -- -c tests/phpunit/multisite.xml --filter Tests_General_GetSearchQuery
  3. npm run test:php -- --group general --order-by=random

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Drafting the tests and running the checks. I reviewed the changes, ran the tests locally, and take responsibility for them.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

…h_query()`.

Covers escaped and raw search queries, an empty search, the main query,
the order of filtering and escaping in both functions, and the
arguments and return values of the `get_search_query` and
`the_search_query` filters.

See #65819.
@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 rejaulalomkhan.

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.

@huzaifaalmesbah huzaifaalmesbah left a comment

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, @rejaulalomkhan! Nice coverage for get_search_query() and the_search_query(). LGTM.

AI Review: Opus 5.5

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.

2 participants