diff --git a/lib/compat/wordpress-6.7/rest-api.php b/lib/compat/wordpress-6.7/rest-api.php index 475f92f965c933..2cfe0dd6838481 100644 --- a/lib/compat/wordpress-6.7/rest-api.php +++ b/lib/compat/wordpress-6.7/rest-api.php @@ -148,13 +148,13 @@ function update_comment_type_in_rest_api_6_7( $prepared_comment, $request ) { * @return array The updated array of comment types. */ if ( ! function_exists( 'update_get_avatar_comment_type' ) && gutenberg_is_experiment_enabled( 'gutenberg-block-comment' ) ) { - function update_get_avatar_comment_type( $comment_type ) { - - $comment_type[] = 'block_comment'; - return $comment_type; - - } - add_filter( 'get_avatar_comment_types', 'update_get_avatar_comment_type', 10, 1 ); + function update_get_avatar_comment_type( $comment_type ) { + + $comment_type[] = 'block_comment'; + return $comment_type; + + } + add_filter( 'get_avatar_comment_types', 'update_get_avatar_comment_type', 10, 1 ); } /** diff --git a/phpunit/bootstrap.php b/phpunit/bootstrap.php index 5d078193f0c3bf..551e00611d69e3 100644 --- a/phpunit/bootstrap.php +++ b/phpunit/bootstrap.php @@ -97,6 +97,7 @@ function fail_if_died( $message ) { 'gutenberg-form-blocks' => 1, 'gutenberg-block-experiments' => 1, 'gutenberg-media-processing' => 1, + 'gutenberg-block-comment' => 1, ), ); diff --git a/phpunit/class-block-comment-filter-test.php b/phpunit/class-block-comment-filter-test.php new file mode 100644 index 00000000000000..8583c7fe870700 --- /dev/null +++ b/phpunit/class-block-comment-filter-test.php @@ -0,0 +1,62 @@ +set_param('comment_type', 'block_comment'); + $request->set_param('comment_approved', '1'); + + $prepared_comment = array( + 'comment_type' => '', + 'comment_approved' => '0', + ); + + // Call the function + $updated_comment = update_comment_type_in_rest_api_6_7($prepared_comment, $request); + + // Assertions + $this->assertEquals('block_comment', $updated_comment['comment_type']); + $this->assertEquals('1', $updated_comment['comment_approved']); + } + + /** + * Tests that `update_get_avatar_comment_type` adds 'block_comment' to the array. + */ + public function test_update_get_avatar_comment_type() { + + // Mock comment types + $comment_types = array('comment', 'pingback'); + + // Call the function + $updated_comment_types = update_get_avatar_comment_type($comment_types); + + // Assertions + $this->assertContains('block_comment', $updated_comment_types); + } + + /** + * Tests that `update_comment_type_filter_dropdown` returns the correct options. + */ + public function test_update_comment_type_filter_dropdown() { + + // Call the function + $dropdown_options = update_comment_type_filter_dropdown(); + + // Assertions + $this->assertArrayHasKey('comment', $dropdown_options); + $this->assertArrayHasKey('block_comment', $dropdown_options); + $this->assertEquals(__('Comments'), $dropdown_options['comment']); + $this->assertEquals(__('Block Comments'), $dropdown_options['block_comment']); + } + +}