diff --git a/tests/phpunit/tests/blocks/renderCommentTemplate.php b/tests/phpunit/tests/blocks/renderCommentTemplate.php index 97ff1b8604a35..62678389042e8 100644 --- a/tests/phpunit/tests/blocks/renderCommentTemplate.php +++ b/tests/phpunit/tests/blocks/renderCommentTemplate.php @@ -44,6 +44,7 @@ public function set_up() { array( 'comment_author' => 'Test', 'comment_author_email' => 'test@example.org', + 'comment_author_url' => 'http://example.com/author-url/', 'comment_content' => 'Hello world', ) ); @@ -80,6 +81,37 @@ function test_build_comment_query_vars_from_block_with_context() { ); } + /** + * @ticket 55567 + * @covers ::build_comment_query_vars_from_block + */ + function test_build_comment_query_vars_from_block_with_context_no_pagination() { + update_option( 'page_comments', false ); + $parsed_blocks = parse_blocks( + '' + ); + + $block = new WP_Block( + $parsed_blocks[0], + array( + 'postId' => self::$custom_post->ID, + ) + ); + + $this->assertEquals( + build_comment_query_vars_from_block( $block ), + array( + 'orderby' => 'comment_date_gmt', + 'order' => 'ASC', + 'status' => 'approve', + 'no_found_rows' => false, + 'post_id' => self::$custom_post->ID, + 'hierarchical' => 'threaded', + ) + ); + update_option( 'page_comments', true ); + } + /** * @ticket 55505 * @covers ::build_comment_query_vars_from_block @@ -125,6 +157,7 @@ function test_build_comment_query_vars_from_block_sets_cpage_var() { array( 'comment_author' => 'Test', 'comment_author_email' => 'test@example.org', + 'comment_author_url' => 'http://example.com/author-url/', 'comment_content' => 'Hello world', ) ); @@ -143,4 +176,78 @@ function test_build_comment_query_vars_from_block_sets_cpage_var() { $this->assertSame( $comment_query_max_num_pages, $actual['paged'] ); $this->assertSame( $comment_query_max_num_pages, get_query_var( 'cpage' ) ); } + + /** + * Test rendering a single comment + * + * @ticket 55567 + */ + function test_rendering_comment_template() { + $parsed_blocks = parse_blocks( + '' + ); + + $block = new WP_Block( + $parsed_blocks[0], + array( + 'postId' => self::$custom_post->ID, + ) + ); + + $this->assertEquals( + '
  1. Hello world
', + $block->render() + ); + } + + /** + * Test rendering 3 nested comments: + * + * └─ comment 1 + *   └─ comment 2 + *    └─ comment 3 + * + * @ticket 55567 + */ + function test_rendering_comment_template_nested() { + $first_level_ids = self::factory()->comment->create_post_comments( + self::$custom_post->ID, + 1, + array( + 'comment_parent' => self::$comment_ids[0], + 'comment_author' => 'Test', + 'comment_author_email' => 'test@example.org', + 'comment_author_url' => 'http://example.com/author-url/', + 'comment_content' => 'Hello world', + ) + ); + + $second_level_ids = self::factory()->comment->create_post_comments( + self::$custom_post->ID, + 1, + array( + 'comment_parent' => $first_level_ids[0], + 'comment_author' => 'Test', + 'comment_author_email' => 'test@example.org', + 'comment_author_url' => 'http://example.com/author-url/', + 'comment_content' => 'Hello world', + ) + ); + + $parsed_blocks = parse_blocks( + '' + ); + + $block = new WP_Block( + $parsed_blocks[0], + array( + 'postId' => self::$custom_post->ID, + ) + ); + + $this->assertEquals( + '
  1. Hello world
    1. Hello world
      1. Hello world
', + $block->render() + ); + } }