| | 90 | |
| | 91 | public function test_wp_count_comments_cache() { |
| | 92 | $post_id = $this->factory->post->create( array( |
| | 93 | 'post_status' => 'publish' |
| | 94 | ) ); |
| | 95 | $comment_id = $this->factory->comment->create( array( |
| | 96 | 'comment_approved' => '1', |
| | 97 | 'comment_post_ID' => $post_id |
| | 98 | ) ); |
| | 99 | |
| | 100 | $count1 = wp_count_comments( $post_id ); |
| | 101 | |
| | 102 | $this->assertEquals( 1, $count1->approved ); |
| | 103 | $this->assertEquals( 0, $count1->moderated ); |
| | 104 | $this->assertEquals( 0, $count1->spam ); |
| | 105 | $this->assertEquals( 0, $count1->trash ); |
| | 106 | $this->assertEquals( 0, $count1->{'post-trashed'} ); |
| | 107 | $this->assertEquals( 1, $count1->total_comments ); |
| | 108 | |
| | 109 | wp_spam_comment( $comment_id ); |
| | 110 | $count2 = wp_count_comments( $post_id ); |
| | 111 | |
| | 112 | $this->assertEquals( 0, $count2->approved ); |
| | 113 | $this->assertEquals( 0, $count2->moderated ); |
| | 114 | $this->assertEquals( 1, $count2->spam ); |
| | 115 | $this->assertEquals( 0, $count2->trash ); |
| | 116 | $this->assertEquals( 0, $count2->{'post-trashed'} ); |
| | 117 | $this->assertEquals( 1, $count2->total_comments ); |
| | 118 | |
| | 119 | wp_trash_comment( $comment_id ); |
| | 120 | $count3 = wp_count_comments( $post_id ); |
| | 121 | |
| | 122 | $this->assertEquals( 0, $count3->approved ); |
| | 123 | $this->assertEquals( 0, $count3->moderated ); |
| | 124 | $this->assertEquals( 0, $count3->spam ); |
| | 125 | $this->assertEquals( 1, $count3->trash ); |
| | 126 | $this->assertEquals( 0, $count3->{'post-trashed'} ); |
| | 127 | $this->assertEquals( 0, $count3->total_comments ); |
| | 128 | |
| | 129 | wp_untrash_comment( $comment_id ); |
| | 130 | $count4 = wp_count_comments( $post_id ); |
| | 131 | |
| | 132 | $this->assertEquals( 0, $count4->approved ); |
| | 133 | $this->assertEquals( 0, $count4->moderated ); |
| | 134 | $this->assertEquals( 1, $count4->spam ); |
| | 135 | $this->assertEquals( 0, $count4->trash ); |
| | 136 | $this->assertEquals( 0, $count4->{'post-trashed'} ); |
| | 137 | $this->assertEquals( 1, $count4->total_comments ); |
| | 138 | } |