diff --git a/tests/phpunit/tests/blocks/renderCommentTemplate.php b/tests/phpunit/tests/blocks/renderCommentTemplate.php
index 4199537f0c..49769ee6e0 100644
--- a/tests/phpunit/tests/blocks/renderCommentTemplate.php
+++ b/tests/phpunit/tests/blocks/renderCommentTemplate.php
@@ -261,9 +261,8 @@ class Tests_Blocks_RenderReusableCommentTemplate extends WP_UnitTestCase {
*
* └─ comment 1
* └─ comment 2
- * └─ comment 3
* └─ comment 4
- * └─ comment 5
+ * └─ comment 3
*
* @ticket 55567
*/
@@ -363,6 +362,39 @@ END
);
}
+ /**
+ * Test that line and paragraph breaks are converted to HTML tags in a comment.
+ *
+ * @ticket 55643
+ */
+ function test_render_block_core_comment_content_converts_to_html() {
+ $comment_id = self::$comment_ids[0];
+ $new_content = "Paragraph One\n\nP2L1\nP2L2\n\nhttps://example.com/";
+ self::factory()->comment->update_object(
+ $comment_id,
+ array( 'comment_content' => $new_content )
+ );
+
+ $parsed_blocks = parse_blocks(
+ ''
+ );
+
+ $block = new WP_Block(
+ $parsed_blocks[0],
+ array(
+ 'postId' => self::$custom_post->ID,
+ 'comments/inherit' => true,
+ )
+ );
+
+ $expected_content = "
Paragraph One
\nP2L1
\nP2L2
\nhttps://example.com/
\n";
+
+ $this->assertSame(
+ '',
+ $block->render()
+ );
+ }
+
/**
* Test that unapproved comments are included if it is a preview.
*
@@ -404,4 +436,57 @@ END
)
);
}
+
+ /**
+ * Test rendering an unapproved comment preview.
+ *
+ * @ticket 55643
+ */
+ function test_rendering_comment_template_unmoderated_preview() {
+ $parsed_blocks = parse_blocks(
+ ''
+ );
+
+ $unapproved_comment = self::factory()->comment->create_post_comments(
+ self::$custom_post->ID,
+ 1,
+ array(
+ 'comment_author' => 'Visitor',
+ 'comment_author_email' => 'unapproved@example.org',
+ 'comment_author_url' => 'http://example.com/unapproved/',
+ 'comment_content' => 'Hi there! My comment needs moderation.',
+ 'comment_approved' => 0,
+ )
+ );
+
+ $block = new WP_Block(
+ $parsed_blocks[0],
+ array(
+ 'postId' => self::$custom_post->ID,
+ )
+ );
+
+ $commenter_filter = static function () {
+ return array(
+ 'comment_author_email' => 'unapproved@example.org',
+ );
+ };
+
+ add_filter( 'wp_get_current_commenter', $commenter_filter );
+
+ $this->assertSame(
+ '',
+ str_replace( array( "\n", "\t" ), '', $block->render() ),
+ 'Should include unapproved comments when filter applied'
+ );
+
+ remove_filter( 'wp_get_current_commenter', $commenter_filter );
+
+ // Test it again and ensure the unmoderated comment doesn't leak out.
+ $this->assertSame(
+ '',
+ str_replace( array( "\n", "\t" ), '', $block->render() ),
+ 'Should not include any unapproved comments after removing filter'
+ );
+ }
}