Skip to content

Tests: Add unit tests for the server-side rendering of the Post Template block - #15675

Closed
hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66544-post-template-block-tests
Closed

hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66544-post-template-block-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Adds unit tests for block_core_post_template_uses_featured_image(), render_block_core_post_template() and register_block_core_post_template() in src/wp-includes/blocks/post-template.php, which were not referenced by any test. No behavior is changed.

The new test class tests/phpunit/tests/blocks/renderPostTemplate.php (35 tests) covers:

  • The search of the featured image in the inner blocks: a core/post-featured-image block, or a core/cover block with useFeaturedImage (not another block with that attribute), also when the block is nested.
  • Nothing is rendered when there are no posts. A list item with the wp-block-post classes of the post (escaped) is rendered for each post, with the inner blocks that get the postId and postType context.
  • The query of the block (order, number of posts, offset), the page of the request (query-page, or query-<id>-page for a query with an ID, and not the page of another query), and the main query when the block inherits it (with its own order and number).
  • The data-wp-key of the items for the enhanced pagination.
  • The classes of the list: the flex layout (is-flex-container and the columns), the link color, the grid (columns-N and has-native-responsive-grid), and none for other cases.
  • The inner blocks are rendered with the block name core/null, the filter of the context is removed, and the post data is restored (a different post than the last one of the list is used to check it).
  • The block is registered with the render callback and skip_inner_blocks.

Testing:

  • vendor/bin/phpunit --filter 'Tests_Blocks_RenderPostTemplate::'
  • vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Blocks_RenderPostTemplate::'
  • vendor/bin/phpcs tests/phpunit/tests/blocks/renderPostTemplate.php

I also temporarily broke the functions (the key of the page, the enhanced pagination, the page and the main query, the check of empty posts, each class of the list, the block name and the context of the items, the filter of the context, the classes and their escaping, the reset of the post data, the tag and the registration) and confirmed that a new test fails for each one.

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

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified in the added Post Template rendering and registration tests.

No open issues 🎉

What changed in this PR

Adds unit tests for the Post Template block’s server-side rendering and registration, addressing previously untested functions without changing production behavior.

Changes:

  • Covers featured-image detection, query ordering and pagination, and inherited queries.
  • Verifies rendered markup, layout classes, escaping, and enhanced-pagination keys.
  • Checks block context, cleanup of filters and post data, and registration settings.
File Description
tests/​phpunit/​tests/​blocks/​renderPostTemplate.php Adds 35 test cases covering Post Template rendering, helpers, and registration.

Review effort: Balanced

@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.

2 participants