Skip to content

Commit

Permalink
Add test coverage for commentId block context present in render_block…
Browse files Browse the repository at this point in the history
…_context filter at priority 2
  • Loading branch information
ockham committed Jul 18, 2023
1 parent ec9a7ae commit d3e3ffd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/phpunit/tests/blocks/renderCommentTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ public function test_rendering_comment_template_unmoderated_preview() {
* @covers ::block_core_comment_template_render_comments
*/
public function test_rendering_comment_template_sets_comment_id_context() {
$render_block_context_callback = new MockAction();
add_filter( 'render_block_context', array( $render_block_context_callback, 'filter' ), 2, 3 );

$parsed_comment_author_name_block = parse_blocks( '<!-- wp:comment-author-name /-->' )[0];
$comment_author_name_block = new WP_Block(
$parsed_comment_author_name_block,
Expand Down Expand Up @@ -560,6 +563,19 @@ static function( $block_content, $block ) use ( $parsed_comment_author_name_bloc
$markup = $block->render();

$this->assertStringContainsString( $comment_author_name_block_markup, $markup );

$args = $render_block_context_callback->get_args();
$context = $args[0][0];
$this->assertArrayHasKey(
'commentId',
$context,
"commentId block context wasn't set for render_block_context filter at priority 2."
);
$this->assertSame(
strval( self::$comment_ids[0] ),
$context['commentId'],
"commentId block context wasn't set correctly."
);
}

/**
Expand Down

0 comments on commit d3e3ffd

Please sign in to comment.