Skip to content

Tests: Add unit tests for the server-side rendering of the Query Title block - #15752

Closed
hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66567-query-title-block-tests
Closed

hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66567-query-title-block-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Summary

Adds tests for render_block_core_query_title(), which had no tests (49 lines were not covered on Codecov).

  • Nothing is rendered without a type, or when the page is not of the type (an archive on the home page or on a search, a search on the home page or on an archive, and a post type without a post type).
  • The title of an archive with the prefix by default and without it, and the filter that removes the prefix is not left behind.
  • The title of a search, with the search term (escaped) or without it.
  • The title of a post type, from the context of the query or from the current post, with or without the prefix, and nothing for a post type that does not exist.
  • The tag of the heading for each level (0 is a paragraph), and the class of the alignment of the text.
  • The registration of the block with its render callback (the original block type is put back afterwards).

Testing

vendor/bin/phpunit --filter 'Tests_Blocks_RenderQueryTitle::'
vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Blocks_RenderQueryTitle::'
vendor/bin/phpcs tests/phpunit/tests/blocks/renderQueryTitle.php

Mutation check: 18 changes to the render function (the type checks, the prefix and its filter, the search title and term, the post type title, the level and the alignment) were each caught by a test, except one that is equivalent: dropping the check of a missing post type next to the type check is covered by the later check of the post type object, which also returns an empty string.

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Written with AI and manually reviewed by me.


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.

@github-actions

github-actions Bot commented Nov 6, 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.

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

Props hmbashar.

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.

@hmbashar hmbashar closed this Nov 7, 2026
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