diff --git a/tests/phpunit/tests/comment.php b/tests/phpunit/tests/comment.php index 5b20528727..3b80334353 100644 --- a/tests/phpunit/tests/comment.php +++ b/tests/phpunit/tests/comment.php @@ -687,4 +687,82 @@ class Tests_Comment extends WP_UnitTestCase { $this->assertSame( $expected[ $field ], $length ); } } + + public function test_update_should_invalidate_comment_cache() { + global $wpdb; + + $c = self::factory()->comment->create( array( 'comment_author' => 'Foo' ) ); + + $comment = get_comment( $c ); + $this->assertSame( 'Foo', $comment->comment_author ); + + wp_update_comment( array( + 'comment_ID' => $c, + 'comment_author' => 'Bar', + ) ); + + $comment = get_comment( $c ); + + $this->assertSame( 'Bar', $comment->comment_author ); + } + + public function test_trash_should_invalidate_comment_cache() { + global $wpdb; + + $c = self::factory()->comment->create(); + + $comment = get_comment( $c ); + + wp_trash_comment( $c ); + + $comment = get_comment( $c ); + + $this->assertSame( 'trash', $comment->comment_approved ); + } + + public function test_untrash_should_invalidate_comment_cache() { + global $wpdb; + + $c = self::factory()->comment->create(); + wp_trash_comment( $c ); + + $comment = get_comment( $c ); + $this->assertSame( 'trash', $comment->comment_approved ); + + wp_untrash_comment( $c ); + + $comment = get_comment( $c ); + + $this->assertSame( '1', $comment->comment_approved ); + } + + public function test_spam_should_invalidate_comment_cache() { + global $wpdb; + + $c = self::factory()->comment->create(); + + $comment = get_comment( $c ); + + wp_spam_comment( $c ); + + $comment = get_comment( $c ); + + $this->assertSame( 'spam', $comment->comment_approved ); + } + + public function test_unspam_should_invalidate_comment_cache() { + global $wpdb; + + $c = self::factory()->comment->create(); + wp_spam_comment( $c ); + + $comment = get_comment( $c ); + $this->assertSame( 'spam', $comment->comment_approved ); + + wp_unspam_comment( $c ); + + $comment = get_comment( $c ); + + $this->assertSame( '1', $comment->comment_approved ); + } }