From 8cb68431704a751aae1ec7c955d0b54cafa00ecf Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 14 Sep 2015 22:38:02 +0000 Subject: [PATCH] Ensure that the count cache for `all` is in sync with `comment-{$post_id}` values. These are the values most often relied-upon by the list table for comments. Adds unit tests. See #33875. git-svn-id: https://develop.svn.wordpress.org/trunk@34136 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/comment-functions.php | 1 + .../phpunit/tests/comment/wpCountComments.php | 41 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/comment-functions.php b/src/wp-includes/comment-functions.php index b1127fa9d1..b54528d56c 100644 --- a/src/wp-includes/comment-functions.php +++ b/src/wp-includes/comment-functions.php @@ -1916,6 +1916,7 @@ function wp_update_comment_count_now($post_id) { clean_post_cache( $post ); + wp_cache_delete( 'comments-0', 'counts' ); wp_cache_delete( "comments-{$post_id}", 'counts' ); /** diff --git a/tests/phpunit/tests/comment/wpCountComments.php b/tests/phpunit/tests/comment/wpCountComments.php index a80f16933d..5017a6abb6 100644 --- a/tests/phpunit/tests/comment/wpCountComments.php +++ b/tests/phpunit/tests/comment/wpCountComments.php @@ -106,7 +106,17 @@ class Tests_WP_Count_Comments extends WP_UnitTestCase { $this->assertEquals( 0, $count1->{'post-trashed'} ); $this->assertEquals( 1, $count1->total_comments ); + $all_count1 = wp_count_comments(); + + $this->assertEquals( 1, $all_count1->approved ); + $this->assertEquals( 0, $all_count1->moderated ); + $this->assertEquals( 0, $all_count1->spam ); + $this->assertEquals( 0, $all_count1->trash ); + $this->assertEquals( 0, $all_count1->{'post-trashed'} ); + $this->assertEquals( 1, $all_count1->total_comments ); + wp_spam_comment( $comment_id ); + $count2 = wp_count_comments( $post_id ); $this->assertEquals( 0, $count2->approved ); @@ -116,7 +126,17 @@ class Tests_WP_Count_Comments extends WP_UnitTestCase { $this->assertEquals( 0, $count2->{'post-trashed'} ); $this->assertEquals( 1, $count2->total_comments ); + $all_count2 = wp_count_comments(); + + $this->assertEquals( 0, $all_count2->approved ); + $this->assertEquals( 0, $all_count2->moderated ); + $this->assertEquals( 1, $all_count2->spam ); + $this->assertEquals( 0, $all_count2->trash ); + $this->assertEquals( 0, $all_count2->{'post-trashed'} ); + $this->assertEquals( 1, $all_count2->total_comments ); + wp_trash_comment( $comment_id ); + $count3 = wp_count_comments( $post_id ); $this->assertEquals( 0, $count3->approved ); @@ -125,8 +145,18 @@ class Tests_WP_Count_Comments extends WP_UnitTestCase { $this->assertEquals( 1, $count3->trash ); $this->assertEquals( 0, $count3->{'post-trashed'} ); $this->assertEquals( 0, $count3->total_comments ); - + + $all_count3 = wp_count_comments(); + + $this->assertEquals( 0, $all_count3->approved ); + $this->assertEquals( 0, $all_count3->moderated ); + $this->assertEquals( 0, $all_count3->spam ); + $this->assertEquals( 1, $all_count3->trash ); + $this->assertEquals( 0, $all_count3->{'post-trashed'} ); + $this->assertEquals( 0, $all_count3->total_comments ); + wp_untrash_comment( $comment_id ); + $count4 = wp_count_comments( $post_id ); $this->assertEquals( 0, $count4->approved ); @@ -135,5 +165,14 @@ class Tests_WP_Count_Comments extends WP_UnitTestCase { $this->assertEquals( 0, $count4->trash ); $this->assertEquals( 0, $count4->{'post-trashed'} ); $this->assertEquals( 1, $count4->total_comments ); + + $all_count4 = wp_count_comments(); + + $this->assertEquals( 0, $all_count4->approved ); + $this->assertEquals( 0, $all_count4->moderated ); + $this->assertEquals( 1, $all_count4->spam ); + $this->assertEquals( 0, $all_count4->trash ); + $this->assertEquals( 0, $all_count4->{'post-trashed'} ); + $this->assertEquals( 1, $all_count4->total_comments ); } }