#55643 closed task (blessed) (fixed)
Backport updates of Comment blocks tests
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.0 | Priority: | normal |
Severity: | normal | Version: | 6.0 |
Component: | Editor | Keywords: | has-patch has-unit-tests commit |
Focuses: | Cc: |
Description
We have introduced fixes to some Comments blocks in Gutenberg regarding pending moderation comments and coverage of odd/even classes.
As we also updated their related PHPUnit tests, we need to backport those changes to WordPress core manually.
Related changes to the build_comment_query_vars_from_block
function were already backported in #55634.
Change History (22)
This ticket was mentioned in PR #2649 on WordPress/wordpress-develop by DAreRodz.
3 years ago
#1
- Keywords has-patch has-unit-tests added
3 years ago
#2
PHPUnit tests are currently expected to fail since some relevant changes haven't been backported from Gutenberg yet (but are scheduled for Monday, see e.g. https://github.com/WordPress/gutenberg/pull/40667#issuecomment-1113343517). cc/ @adamziel 🙂
3 years ago
#3
I applied changed to modified tests in https://github.com/WordPress/wordpress-develop/pull/2651 to make CI pass.
#4
@
3 years ago
- Milestone changed from Awaiting Review to 6.0
- Type changed from enhancement to task (blessed)
- Version set to trunk
3 years ago
#5
I applied changed to modified tests in https://github.com/WordPress/wordpress-develop/pull/2651 to make CI pass. See https://github.com/WordPress/wordpress-develop/commit/80fd6c30f6b5df690731275e973caa7c19bf4e53.
Thanks @gziolo!
With this, it seems like most changes have been applied to `renderCommentTemplate.php`, including @peterwilsoncc's suggestions.
I've noticed that two tests weren't carried over:
test_render_block_core_comment_content_converts_to_html
test_rendering_comment_template_unmoderated_preview
Furthermore, there's a small JSDoc glitch we should fix.
Maybe we can just rebase this PR and fix things here.
3 years ago
#6
I rebased, but can't push to @DAreRodz's fork 😅
Here's the diff (on top of current trunk
):
{{{diff
diff --git a/tests/phpunit/tests/blocks/renderCommentTemplate.php b/tests/phpunit/tests/blocks/renderCommentTemplate.php
index 8f70fff000..d47766153b 100644
--- a/tests/phpunit/tests/blocks/renderCommentTemplate.php
+++ b/tests/phpunit/tests/blocks/renderCommentTemplate.php
@@ -205,9 +205,8 @@ class Tests_Blocks_RenderReusableCommentTemplate extends WP_UnitTestCase {
*
- └─ comment 1
- └─ comment 2
- * └─ comment 3
- └─ comment 4
- * └─ comment 5
+ * └─ comment 3
*
- @ticket 55567 */
@@ -307,6 +306,37 @@ END
);
}
+ /
+ * Test that line and paragraph breaks are converted to HTML tags in a comment.
+ */
+ function test_render_block_core_comment_content_converts_to_html() {
+ $comment_id = self::$comment_ids[0];
+ $new_content = "Paragraph One\n\nP2L1\nP2L2\n\nhttps://example.com/";
+ self::factory()->comment->update_object(
+ $comment_id,
+ array( 'comment_content' => $new_content )
+ );
+
+ $parsed_blocks = parse_blocks(
+
+ );
+
+ $block = new WP_Block(
+ $parsed_blocks[0],
+ array(
+ 'postId' => self::$custom_post->ID,
+ 'comments/inherit' => true,
+ )
+ );
+
+ $expected_content = "<p>Paragraph One</p>\n<p>P2L1<br />\nP2L2</p>\n<p><a href=\"https://example.com/\" rel=\"nofollow ugc\">https://example.com/</a></p>\n";
+
+ $this->assertSame(
+ '<ol class="wp-block-comment-template"><li id="comment-' . self::$comment_ids[0] . '" class="comment odd alt thread-even depth-1"><div class="wp-block-comment-content">' . $expected_content . '</div></li></ol>',
+ $block->render()
+ );
+ }
+
/
- Test that unapproved comments are included if it is a preview. *
@@ -348,4 +378,53 @@ END
)
);
}
+
+ /
+ * Test rendering an unapproved comment preview.
+ */
+ function test_rendering_comment_template_unmoderated_preview() {
+ $parsed_blocks = parse_blocks(
+
+ );
+
+ $unapproved_comment = self::factory()->comment->create_post_comments(
+ self::$custom_post->ID,
+ 1,
+ array(
+ 'comment_author' => 'Visitor',
+ 'comment_author_email' => 'unapproved@…',
+ 'comment_author_url' => 'http://example.com/unapproved/',
+ 'comment_content' => 'Hi there! My comment needs moderation.',
+ 'comment_approved' => 0,
+ )
+ );
+
+ $block = new WP_Block(
+ $parsed_blocks[0],
+ array(
+ 'postId' => self::$custom_post->ID,
+ )
+ );
+
+ $commenter_filter = function () {
+ return array(
+ 'comment_author_email' => 'unapproved@…',
+ );
+ };
+
+ add_filter( 'wp_get_current_commenter', $commenter_filter );
+
+ $this->assertSame(
+ '<ol class="wp-block-comment-template"><li id="comment-' . self::$comment_ids[0] . '" class="comment even thread-odd thread-alt depth-1"><div class="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"><p>Hello world</p></div></li><li id="comment-' . $unapproved_comment[0] . '" class="comment odd alt thread-even depth-1"><div class="wp-block-comment-author-name">Visitor</div><div class="wp-block-comment-content"><p><em class="comment-awaiting-moderation">Your comment is awaiting moderation.</em></p>Hi there! My comment needs moderation.</div></li></ol>',
+ str_replace( array( "\n", "\t" ), , $block->render() )
+ );
+
+ remove_filter( 'wp_get_current_commenter', $commenter_filter );
+
+ Test it again and ensure the unmoderated comment doesn't leak out.
+ $this->assertSame(
+ '<ol class="wp-block-comment-template"><li id="comment-' . self::$comment_ids[0] . '" class="comment even thread-odd thread-alt depth-1"><div class="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"><p>Hello world</p></div></li></ol>',
+ str_replace( array( "\n", "\t" ), , $block->render() )
+ );
+ }
}
}}}
3 years ago
#7
I rebased, but can't push to @DAreRodz's fork 😅
I might file a fresh PR with my diff later today.
This ticket was mentioned in PR #2657 on WordPress/wordpress-develop by ockham.
3 years ago
#8
I rebased @DAreRodz' #2649 since a few of its changes have been merged into trunk
(https://github.com/WordPress/wordpress-develop/commit/80fd6c30f6b5df690731275e973caa7c19bf4e53).
See https://github.com/WordPress/wordpress-develop/pull/2649#issuecomment-1114874483 for more context.
Trac ticket: https://core.trac.wordpress.org/ticket/55643
3 years ago
#10
I rebased, but can't push to @DAreRodz's fork 😅
I might file a fresh PR with my diff later today.
3 years ago
#11
Let's close in favour of https://github.com/WordPress/wordpress-develop/pull/2657 👍🏻
3 years ago
#12
cc/ @adamziel and @gziolo for possible inclusion in RC1.
We can add tests also after RC1. I added it to the project board 👍🏻
#13
@
3 years ago
- Milestone changed from 6.0 to 6.1
With 6.0 RC1 starting soon, I'm moving this to the 6.1 milestone.
hellofromtonya commented on PR #2657:
3 years ago
#14
This PR along with unraveling why there's test-to-test interdependencies in the associated test class are both on my tomorrow TODO list.
hellofromtonya commented on PR #2657:
3 years ago
#15
This PR along with unraveling why there's test-to-test interdependencies in the associated test class are both on my tomorrow TODO list.
hellofromtonya commented on PR #2657:
3 years ago
#16
This PR along with unraveling why there's test-to-test interdependencies in the associated test class are both on my tomorrow TODO list.
hellofromtonya commented on PR #2657:
3 years ago
#17
I'll get this PR committed. Then in a new PR, I'll work on resolving the interdependency issues between the tests in this class, ie even
odd
class attributes instability.
#18
@
3 years ago
- Component changed from General to Editor
- Keywords commit added
- Milestone changed from 6.1 to 6.0
- Owner set to hellofromTonya
- Status changed from new to reviewing
Prepping commit
. Moving back to 6.1 to bind the work to the others in 6.0 cycle.
hellofromtonya commented on PR #2657:
3 years ago
#20
Committed via changeset https://core.trac.wordpress.org/changeset/53353.
Backport changes in Comment Template tests that were introduced in the following Gutenberg PRs:
https://github.com/WordPress/gutenberg/pull/40667
https://github.com/WordPress/gutenberg/pull/40702
https://github.com/WordPress/gutenberg/pull/40612
https://github.com/WordPress/gutenberg/pull/40471
Trac ticket: https://core.trac.wordpress.org/ticket/55643#ticket