Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment Template Unit Test: Cover odd/even classes #40471

Merged
merged 12 commits into from
Apr 25, 2022
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