Comments: Show the "awaiting moderation" message when comment cookies are disabled.

The "Your comment is awaiting moderation." message relied upon the comment author cookie being set. However, since it's now possible to opt-out of that cookie, submitting a comment won't show the comment preview when the comment is placed in moderation.

To avoid this issue, we now include a hash in the redirect URL, allowing the site to identify that a preview of the moderated comment should be displayed.

Props imath, tomdxw, birgire, lakenh, azaozz, pento.
Fixes #43857.



git-svn-id: https://develop.svn.wordpress.org/trunk@44659 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2019-01-21 01:33:50 +00:00
parent 19645a4790
commit 9dfde992ee
4 changed files with 96 additions and 7 deletions

View File

@@ -831,6 +831,42 @@ class Tests_Comment_CommentsTemplate extends WP_UnitTestCase {
return $commenter;
}
/**
* @ticket 43857
*/
public function test_comments_list_should_include_just_posted_unapproved_comment() {
$now = time();
$p = self::factory()->post->create();
$c = self::factory()->comment->create(
array(
'comment_post_ID' => $p,
'comment_content' => '1',
'comment_approved' => '0',
'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ),
'comment_author_email' => 'foo@bar.mail',
)
);
$comment = get_comment( $c );
$this->go_to(
add_query_arg(
array(
'unapproved' => $comment->comment_ID,
'moderation-hash' => wp_hash( $comment->comment_date_gmt ),
),
get_comment_link( $comment )
)
);
$found = get_echo( 'comments_template' );
// Find the found comment in the markup.
preg_match( '|id="comment-([0-9]+)|', $found, $matches );
$found_cid = (int) $matches[1];
$this->assertSame( $c, $found_cid );
}
/**
* @ticket 35378
*/