Skip to content

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

Closed
hmbashar wants to merge 4 commits into
WordPress:trunkfrom
hmbashar:66530-query-block-tests
Closed

hmbashar wants to merge 4 commits into
WordPress:trunkfrom
hmbashar:66530-query-block-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Adds unit tests for render_block_core_query() and register_block_core_query() in src/wp-includes/blocks/query.php, which were not referenced by any test. No behavior is changed. This is the first part of the ticket: block_core_query_disable_enhanced_pagination() is covered in a separate pull request.

The new test class tests/phpunit/tests/blocks/renderQuery.php (19 tests) covers:

  • The content is not changed, and the view script module is not enqueued, when the block is not interactive: no attributes, enhancedPagination that is false or not strictly true (a string or an integer), or a queryId that is missing, null or not scalar.
  • An interactive block (enhancedPagination true and a scalar queryId, also 0 or a string) gets data-wp-interactive, data-wp-router-region, data-wp-context and data-wp-key on its first element only, and the @wordpress/block-library/query/view script module is enqueued, also for content without an element.
  • The wp-block-query style handle is removed from the block type when the block is not interactive, kept or added back (with the other handles kept) when it is, and not changed when the style is already enqueued.
  • The block is registered with the render callback.

Testing:

  • vendor/bin/phpunit --filter Tests_Blocks_RenderQuery
  • vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter Tests_Blocks_RenderQuery
  • vendor/bin/phpcs tests/phpunit/tests/blocks/renderQuery.php

I also temporarily broke the function (each part of the check of the attributes, the enqueue, each directive and the update of the content, each condition of the styles, array_diff() and array_merge() of the handles, and the render callback) and confirmed that a new test fails for each one. The one mutant that is not caught is replacing isset() and is_scalar() of the queryId with is_scalar( $queryId ?? null ), which is the same check.

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

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