Skip to content

Tests: Add unit tests for the server-side rendering of the Post Terms block - #15677

Closed
hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66545-post-terms-block-tests
Closed

hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66545-post-terms-block-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Adds unit tests for render_block_core_post_terms(), block_core_post_terms_build_variations() and register_block_core_post_terms() in src/wp-includes/blocks/post-terms.php, which were not referenced by any test. No behavior is changed. This is the second part of the ticket: the Post Time To Read block is covered in a separate pull request.

The new test class tests/phpunit/tests/blocks/renderPostTerms.php (23 tests) covers:

  • The terms of the post as links (rel="tag") separated by the separator of the block (a space by default, escaped).
  • Nothing is rendered without a post or a taxonomy, for a taxonomy that does not exist or is not viewable (also when the post has terms of it), or for a post without terms.
  • The prefix and the suffix (cleaned with wp_kses_post(), and not added when they are empty).
  • The classes: taxonomy-<term>, has-text-align-*, has-link-color, both together, and for another taxonomy.
  • The variations: one for each taxonomy that is publicly queryable and in the REST API (with its name, title, description, attributes, isActive and scope), none for the others, the built-in taxonomies first, and only the category as the default.
  • The block is registered with the render and the variation callbacks.

Testing:

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

I also temporarily broke the functions (each check of the post, the taxonomy and its view, each class, the separator and its escaping, the prefix and the suffix and their cleaning and order, the post of the list, the check of an empty list, the conditions of the variations, their fields and order, and the two callbacks) and confirmed that a new test fails for each one, except for the check of the built-in taxonomies, which does not change the order because the built-in taxonomies are always registered first.

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

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.

🟡 Changes recommended

The tests leave altered block registry state for subsequent tests and fail to detect regressions in built-in taxonomy prioritization.

2 open issues
What changed in this PR

Adds PHPUnit coverage for the Post Terms block’s server-side rendering, taxonomy variations, and registration callbacks, without changing production code.

Changes:

  • Tests term rendering, empty-output conditions, separators, prefix/suffix sanitization, and CSS classes.
  • Checks taxonomy variation eligibility, fields, ordering, and defaults.
  • Verifies the registered render and variation callbacks.
File Description
tests/​phpunit/​tests/​blocks/​renderPostTerms.php Adds fixtures and tests for Post Terms rendering, variations, and registration.

Review effort: Balanced

…s variations with a custom taxonomy first.

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