mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
1 changed file
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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', | ||
) | ||
); | ||
|
@@ -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 | ||
|
@@ -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', | ||
) | ||
); | ||
|
@@ -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() | ||
); | ||
} | ||
} |