Skip to content

Tests: Add unit tests for the server-side rendering of the Pattern block - #15766

Closed
hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:test-pattern-block
Closed

hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:test-pattern-block

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Summary

Adds tests for render_block_core_pattern() and register_block_core_pattern(), which had no tests.

  • The blocks of a registered pattern, also through the rendering of the block, and a pattern inside a pattern.
  • A slug that is missing, empty, '0', not a string or not registered gives an empty string.
  • A pattern that includes itself is stopped (the message is checked with the same condition as the function, WP_DEBUG && WP_DEBUG_DISPLAY), and it can be rendered again after that.
  • The same pattern twice in a row is rendered twice.
  • The registration of the block with its render callback (the original block type is put back afterwards). The patterns of the tests are unregistered after each test.

Testing

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

Mutation check: 11 changes to the render function were caught, except two that cannot be told apart in the test environment: the default of a missing slug (an empty string and a pattern that is not registered give the same result) and forcing the debug message on (it is on already here, because WP_DEBUG_DISPLAY is true). Removing the guard against a pattern that includes itself makes the test run forever, so it is caught as well.

The autoembed step of the function is not covered on purpose: #13508 changes where autoembed() runs.

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

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.

@hmbashar
hmbashar marked this pull request as ready for review November 6, 2026 20:25
@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