Make WordPress Core

Opened 13 months ago

Closed 13 months ago

Last modified 12 months ago

#55643 closed task (blessed) (fixed)

Backport updates of Comment blocks tests

Reported by: darerodz's profile darerodz Owned by: hellofromtonya's profile hellofromTonya
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)

ockham commented on PR #2649:


13 months 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 🙂

gziolo commented on PR #2649:


13 months ago
#3

I applied changed to modified tests in https://github.com/WordPress/wordpress-develop/pull/2651 to make CI pass.

#4 @costdev
13 months ago

  • Milestone changed from Awaiting Review to 6.0
  • Type changed from enhancement to task (blessed)
  • Version set to trunk

ockham commented on PR #2649:


13 months 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.

ockham commented on PR #2649:


13 months 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() )
+ );
+ }

}

}}}

ockham commented on PR #2649:


13 months ago
#7

I rebased, but can't push to @DAreRodz's fork 😅

I might file a fresh PR with my diff later today.

ockham commented on PR #2657:


13 months ago
#9

cc/ @adamziel and @gziolo for possible inclusion in RC1.

ockham commented on PR #2649:


13 months ago
#10

I rebased, but can't push to @DAreRodz's fork 😅

I might file a fresh PR with my diff later today.

https://github.com/WordPress/wordpress-develop/pull/2657

gziolo commented on PR #2657:


13 months 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 @costdev
13 months 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:


13 months 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:


13 months 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:


13 months 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:


13 months 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 @hellofromTonya
13 months 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.

#19 @hellofromTonya
13 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 53353:

Editor: Add unit test for Comment Template block.

Backport of 2 tests from Gutenberg for the Comment Template block:

  • test line and paragraph breaks are converted into HTML tags.
  • test rendering of unapproved comment preview.

Follow-up to [53298], [53172], [53138].

Props bernhard-reiter, darerodz, gziolo, peterwilsoncc, hellofromTonya.
Fixes #55643.
See #55634.

#21 @hellofromTonya
12 months ago

In 53432:

Build/Test Tools: Add tests and fix comments odd/even instabilities (test leaks).

[53353] Add unit test for Comment Template block.

[53353] The odd / even class attribute global variables are causing issues in comments tests when a new test is added or an existing test is modified. To stabilize the odd / even comment tests, the comment global variables are added to the base test class' tear_down() using the same patterns as the other global resets. This change ensures each comment test starts at the same state. In doing so, the expected odd / even class attributes are no longer affected by previous tests, i.e. test leaks.

Also moves the comment globals reset from the base test case to the test's tear_down(). Why? To avoid risks to extenders' tests as it's too late in the 6.0 cycle for a dev note.

Follow-up to [53298], [53172], [53138].

Props bernhard-reiter, darerodz, gziolo, hellofromTonya, zieladam, peterwilsoncc.
Merges [53353] and [53430] to the 6.0 branch.
Fixes #54725,#55643.

#22 @hellofromTonya
12 months ago

In 53434:

Build/Test Tools: Follow-up to r53432.

Removes comments global resets from base test case.

Follow-up to [53432].

See #54725,#55643.

Note: See TracTickets for help on using tickets.