From 04d01a8eb401437d77a2ba97f9985a67819a6b3c Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Wed, 1 Jun 2016 17:15:27 +0000 Subject: [PATCH] Add tests demonstrating individual comment cache invalidation. See #36906. git-svn-id: https://develop.svn.wordpress.org/trunk@37609 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/comment.php | 78 +++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) 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 ); + } }