From 4ab65a5c7d7a878eaf8212717c5daa9b99672ad0 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 24 May 2023 16:04:16 +0200 Subject: [PATCH] Make test more semantic --- .../blocks/render-comment-template-test.php | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/phpunit/blocks/render-comment-template-test.php b/phpunit/blocks/render-comment-template-test.php index 8834ef1cde1f0f..b5064499063aec 100644 --- a/phpunit/blocks/render-comment-template-test.php +++ b/phpunit/blocks/render-comment-template-test.php @@ -78,15 +78,23 @@ public function set_up() { } public function test_rendering_comment_template_sets_comment_id_context() { - $render_block_callback = static function( $block_content, $block ) { + $parsed_comment_author_name_block = parse_blocks( '' )[0]; + $comment_author_name_block = new WP_Block( + $parsed_comment_author_name_block, + array( + 'commentId' => self::$comment_ids[0], + ) + ); + $comment_author_name_block_markup = $comment_author_name_block->render(); + + $render_block_callback = static function( $block_content, $block ) use ( $parsed_comment_author_name_block ) { // Insert a Comment Author Name block (which requires `commentId` // block context to work) after the Comment Content block. if ( 'core/comment-content' !== $block['blockName'] ) { return $block_content; } - $inserted_block_markup = ''; - $inserted_blocks = parse_blocks( $inserted_block_markup ); - $inserted_content = render_block( $inserted_blocks[0] ); + + $inserted_content = render_block( $parsed_comment_author_name_block ); return $inserted_content . $block_content; }; @@ -103,9 +111,6 @@ public function test_rendering_comment_template_sets_comment_id_context() { $markup = $block->render(); remove_filter( 'render_block', $render_block_callback ); - $this->assertSame( - str_replace( array( "\n", "\t" ), '', '
  1. Hello world

' ), - str_replace( array( "\n", "\t" ), '', $markup ) - ); + $this->assertStringContainsString( $comment_author_name_block_markup, $markup ); } }