Opened 93 minutes ago
Last modified 84 minutes ago
#66601 new enhancement
Tests: Add unit tests for the server-side rendering of the Comments block
| Reported by: | hmbashar | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Editor | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
The Comments block (core/comments) is rendered on the server by the functions in src/wp-includes/blocks/comments.php. They have no tests.
This ticket adds tests that cover:
render_block_core_comments(): nothing without the post ID in the context, or for a post with closed comments and no comments; the static version of the block; and the legacy version with the comments template, its wrapper classes (also for thecore/post-commentsblock), the restoring of the global post, and the script of the reply link;comments_block_form_defaults(): the button and the field of the comment form, for block themes and for other themes;register_legacy_post_comments_block(): thecore/post-commentsblock type that is registered again with the render callback.
Change History (1)
This ticket was mentioned in PR #15815 on WordPress/wordpress-develop by @hmbashar.
84 minutes ago
#1
- Keywords has-patch has-unit-tests added
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Summary
Adds tests for the server-side rendering of the Comments block (
render_block_core_comments(),comments_block_form_defaults()andregister_legacy_post_comments_block()), which had no tests.render_block_core_comments(): nothing without the post ID in the context or for a post with closed comments and no comments (closed comments with comments, and open comments without comments, are rendered); the static version with the inner blocks; the legacy version with the comments of the post of the context, the wrapper classes (the legacy class and the text alignment), thecore/post-commentsblock always being legacy, the script of the reply link (only for the legacy version) and the restoring of the global post.comments_block_form_defaults(): unchanged for a theme that is not a block theme, and the button and the field of the form for a block theme. It is hooked tocomment_form_defaults.register_legacy_post_comments_block(): thecore/post-commentsblock type with its render callback, context, attributes and supports, registered again when it exists or not, and theblock_type_metadatafilter.The tests restore the
core/post-commentsblock type and the script queue.Testing
Mutation check: 30 changes to the three functions were each caught by a test, except the
setup_postdata()call of the legacy version, which does not change the output of the comments template.enqueue_legacy_post_comments_block_styles()is not tested: it keeps a static flag, so it can only run once in a process.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.