Skip to content

Commit

Permalink
Tests: Add missing unit tests to Comment Template block
Browse files Browse the repository at this point in the history
Follow-up for [53138], [53172].
Props darerodz.
See #55567.



git-svn-id: https://develop.svn.wordpress.org/trunk@53258 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
gziolo committed Apr 25, 2022
1 parent 0378bdd commit dbda79e
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions tests/phpunit/tests/blocks/renderCommentTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function set_up() {
array(
'comment_author' => 'Test',
'comment_author_email' => '[email protected]',
'comment_author_url' => 'http://example.com/author-url/',
'comment_content' => 'Hello world',
)
);
Expand Down Expand Up @@ -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(
'<!-- wp:comment-template --><!-- wp:comment-author-name /--><!-- wp:comment-content /--><!-- /wp:comment-template -->'
);

$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
Expand Down Expand Up @@ -125,6 +157,7 @@ function test_build_comment_query_vars_from_block_sets_cpage_var() {
array(
'comment_author' => 'Test',
'comment_author_email' => '[email protected]',
'comment_author_url' => 'http://example.com/author-url/',
'comment_content' => 'Hello world',
)
);
Expand All @@ -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(
'<!-- wp:comment-template --><!-- wp:comment-author-name /--><!-- wp:comment-content /--><!-- /wp:comment-template -->'
);

$block = new WP_Block(
$parsed_blocks[0],
array(
'postId' => self::$custom_post->ID,
)
);

$this->assertEquals(
'<ol class="wp-block-comment-template"><li id="comment-' . self::$comment_ids[0] . '" class="comment even thread-even depth-1"><div class="has-small-font-size wp-block-comment-author-name"><a rel="external nofollow ugc" href="http://example.com/author-url/" target="_self" >Test</a></div><div class="wp-block-comment-content">Hello world</div></li></ol>',
$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' => '[email protected]',
'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' => '[email protected]',
'comment_author_url' => 'http://example.com/author-url/',
'comment_content' => 'Hello world',
)
);

$parsed_blocks = parse_blocks(
'<!-- wp:comment-template --><!-- wp:comment-author-name /--><!-- wp:comment-content /--><!-- /wp:comment-template -->'
);

$block = new WP_Block(
$parsed_blocks[0],
array(
'postId' => self::$custom_post->ID,
)
);

$this->assertEquals(
'<ol class="wp-block-comment-template"><li id="comment-' . self::$comment_ids[0] . '" class="comment odd alt thread-odd thread-alt depth-1"><div class="has-small-font-size wp-block-comment-author-name"><a rel="external nofollow ugc" href="http://example.com/author-url/" target="_self" >Test</a></div><div class="wp-block-comment-content">Hello world</div><ol><li id="comment-' . $first_level_ids[0] . '" class="comment even depth-2"><div class="has-small-font-size wp-block-comment-author-name"><a rel="external nofollow ugc" href="http://example.com/author-url/" target="_self" >Test</a></div><div class="wp-block-comment-content">Hello world</div><ol><li id="comment-' . $second_level_ids[0] . '" class="comment odd alt depth-3"><div class="has-small-font-size wp-block-comment-author-name"><a rel="external nofollow ugc" href="http://example.com/author-url/" target="_self" >Test</a></div><div class="wp-block-comment-content">Hello world</div></li></ol></li></ol></li></ol>',
$block->render()
);
}
}

0 comments on commit dbda79e

Please sign in to comment.