Skip to content

Commit

Permalink
Comment Template Unit Test: Cover odd/even classes (#40471)
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham authored Apr 25, 2022
1 parent a442b40 commit e34aac6
Showing 1 changed file with 59 additions and 4 deletions.
63 changes: 59 additions & 4 deletions phpunit/class-block-library-comment-template-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,17 @@ function test_rendering_comment_template() {
}

/**
* Test rendering 3 nested comments:
* Test rendering nested comments:
*
* └─ comment 1
*   └─ comment 2
*    └─ comment 3
*    └─ comment 4
*   └─ comment 3
*/
function test_rendering_comment_template_nested() {
$first_level_ids = self::factory()->comment->create_post_comments(
self::$custom_post->ID,
1,
2,
array(
'comment_parent' => self::$comment_ids[0],
'comment_author' => 'Test',
Expand Down Expand Up @@ -186,9 +187,63 @@ function test_rendering_comment_template_nested() {
)
);

$top_level_ids = self::$comment_ids;
$expected = str_replace(
array( "\n", "\t" ),
'',
<<<END
<ol >
<li id="comment-{$top_level_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>
<li id="comment-{$first_level_ids[1]}" 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>
</li>
</ol>
</li>
</ol>
END
);

$this->assertEquals(
gutenberg_render_block_core_comment_template( null, null, $block ),
'<ol ><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>'
$expected
);
}
/**
Expand Down

0 comments on commit e34aac6

Please sign in to comment.