Skip to content

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

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

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

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

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

The new test class tests/phpunit/tests/blocks/renderPostCommentsForm.php (15 tests) covers:

  • Nothing is rendered without a postId or when the comments are closed, and the function returns null for a post that needs a password.
  • The comment form of the post inside the wrapper of the form (id="respond" and comment-respond), with the has-text-align-* and has-link-color classes of the block.
  • The script comment-reply is enqueued only when the form is rendered, and the filter of the defaults of the form is removed afterwards.
  • post_comments_form_block_form_defaults() leaves the defaults as they are for a theme that is not a block theme, and changes the submit button and the submit field for a block theme (also in the rendered form).
  • The block is registered with the render callback.

Testing:

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

I also temporarily broke the functions (each check, the classes, the filter that is removed, the post of the form, the replacement of the wrapper, the script, the check of the block theme, and the markup of the button and the field) and confirmed that a new test fails for each one. The add_filter() call of the defaults is not caught, because comment_form() already applies the same defaults for a block theme.

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 cover the server-side rendering of the Post Comments Form block (render_block_core_post_comments_form(), post_comments_form_block_form_defaults(), and block registration). Local PHPUnit suite (15 tests, 24 assertions) and PHPCS/ESLint both pass cleanly.

I left a couple of small notes inline.

AI Review: Gemini 3.8 Flash

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 leak script and block-registry state into subsequent tests, and an integration assertion cannot detect a missing defaults-filter hookup.

3 open issues
What changed in this PR

Adds unit coverage for server-side rendering of the Post Comments Form block and its helper functions, addressing Trac ticket #66541 without changing production behavior.

Changes:

  • Tests rendering conditions, wrapper classes, and the associated post.
  • Checks script enqueueing, filter cleanup, and classic- versus block-theme form defaults.
  • Verifies block registration and its render callback.
File Description
tests/​phpunit/​tests/​blocks/​renderPostCommentsForm.php Adds tests for rendering, form defaults, side effects, and block registration.

Review effort: Balanced

…rt the submit button in the post comments form tests.

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

3 participants