mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Tests: Add missing unit tests to Comment Template block
Follow-up for [53138], [53172]. Props darerodz. See #55567. git-svn-id: https://develop.svn.wordpress.org/trunk@53258 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
0378bddc1a
commit
dbda79e341
@ -44,6 +44,7 @@ class Tests_Blocks_RenderReusableCommentTemplate extends WP_UnitTestCase {
|
||||
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 @@ class Tests_Blocks_RenderReusableCommentTemplate extends WP_UnitTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
@ -125,6 +157,7 @@ class Tests_Blocks_RenderReusableCommentTemplate extends WP_UnitTestCase {
|
||||
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 @@ class Tests_Blocks_RenderReusableCommentTemplate extends WP_UnitTestCase {
|
||||
$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' => '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(
|
||||
'<!-- 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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user