Skip to content

Tests: Add unit tests for the server-side rendering of the Post Comments Link block - #15665

Closed
hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66541-post-comments-link-block-tests
Closed

hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66541-post-comments-link-block-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Adds unit tests for render_block_core_post_comments_link() and register_block_core_post_comments_link() in src/wp-includes/blocks/post-comments-link.php, which were not referenced by any test. No behavior is changed.

The new test class tests/phpunit/tests/blocks/renderPostCommentsLink.php (11 tests) covers:

  • Nothing is rendered without a postId or when the comments of the post are closed.
  • The link to the comments with the text for no comments, one comment or several comments, each with the title of the post for the screen readers.
  • The URL of the link is escaped. The function prints href= without quotes, so the tests compare the output as it is.
  • The classes: has-text-align-*, has-link-color, both together, and none for another element.
  • The block is registered with the render callback.

Testing:

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

I also temporarily broke the function (the checks of the post and of the comments, each class, the count, each text, the title, esc_url() and the render callback) and confirmed that a new test fails for each one.

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

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, huzaifaalmesbah.

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.

@huzaifaalmesbah huzaifaalmesbah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for working on this, @hmbashar! I really appreciate you taking the time to write server-side rendering unit tests for the Post Comments Link block (render_block_core_post_comments_link() and registration). Local PHPUnit suite (11 tests, 13 assertions) and PHPCS/ESLint both pass cleanly.

I left a couple of small notes inline.

AI Review: Gemini 3.8 Flash

@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