wordpress-develop/tests/phpunit/tests/comment/getCommentCount.php
Sergey Biryukov 5b344d17da Tests: Rename classes in phpunit/tests/comment/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623], [51639], [51646], [51650], [51651], [51860], [52264], [52265], [53489], [53863].

See #56793.

git-svn-id: https://develop.svn.wordpress.org/trunk@54704 602fd350-edb4-49c9-b593-d223f7449a82
2022-10-27 15:53:08 +00:00

176 lines
4.3 KiB
PHP

<?php
/**
* @group comment
*
* @covers ::get_comment_count
*/
class Tests_Comment_GetCommentCount extends WP_UnitTestCase {
public function test_get_comment_count() {
$count = get_comment_count();
$this->assertSame( 0, $count['approved'] );
$this->assertSame( 0, $count['awaiting_moderation'] );
$this->assertSame( 0, $count['spam'] );
$this->assertSame( 0, $count['trash'] );
$this->assertSame( 0, $count['post-trashed'] );
$this->assertSame( 0, $count['total_comments'] );
$this->assertSame( 0, $count['all'] );
}
public function test_get_comment_count_approved() {
self::factory()->comment->create(
array(
'comment_approved' => 1,
)
);
$count = get_comment_count();
$this->assertSame( 1, $count['approved'] );
$this->assertSame( 0, $count['awaiting_moderation'] );
$this->assertSame( 0, $count['spam'] );
$this->assertSame( 0, $count['trash'] );
$this->assertSame( 0, $count['post-trashed'] );
$this->assertSame( 1, $count['total_comments'] );
}
public function test_get_comment_count_awaiting() {
self::factory()->comment->create(
array(
'comment_approved' => 0,
)
);
$count = get_comment_count();
$this->assertSame( 0, $count['approved'] );
$this->assertSame( 1, $count['awaiting_moderation'] );
$this->assertSame( 0, $count['spam'] );
$this->assertSame( 0, $count['trash'] );
$this->assertSame( 0, $count['post-trashed'] );
$this->assertSame( 1, $count['total_comments'] );
}
public function test_get_comment_count_spam() {
self::factory()->comment->create(
array(
'comment_approved' => 'spam',
)
);
$count = get_comment_count();
$this->assertSame( 0, $count['approved'] );
$this->assertSame( 0, $count['awaiting_moderation'] );
$this->assertSame( 1, $count['spam'] );
$this->assertSame( 0, $count['trash'] );
$this->assertSame( 0, $count['post-trashed'] );
$this->assertSame( 1, $count['total_comments'] );
}
public function test_get_comment_count_trash() {
self::factory()->comment->create(
array(
'comment_approved' => 'trash',
)
);
$count = get_comment_count();
$this->assertSame( 0, $count['approved'] );
$this->assertSame( 0, $count['awaiting_moderation'] );
$this->assertSame( 0, $count['spam'] );
$this->assertSame( 1, $count['trash'] );
$this->assertSame( 0, $count['post-trashed'] );
$this->assertSame( 0, $count['total_comments'] );
}
public function test_get_comment_count_post_trashed() {
self::factory()->comment->create(
array(
'comment_approved' => 'post-trashed',
)
);
$count = get_comment_count();
$this->assertSame( 0, $count['approved'] );
$this->assertSame( 0, $count['awaiting_moderation'] );
$this->assertSame( 0, $count['spam'] );
$this->assertSame( 0, $count['trash'] );
$this->assertSame( 1, $count['post-trashed'] );
$this->assertSame( 0, $count['total_comments'] );
}
/**
* @ticket 19901
*
* @covers ::get_comment_count
*/
public function test_get_comment_count_validate_cache_comment_deleted() {
$comment_id = self::factory()->comment->create();
$count = get_comment_count();
$this->assertSame( 1, $count['total_comments'] );
wp_delete_comment( $comment_id, true );
$count = get_comment_count();
$this->assertSame( 0, $count['total_comments'] );
}
/**
* @ticket 19901
*
* @covers ::get_comment_count
*/
public function test_get_comment_count_validate_cache_post_deleted() {
$post_id = self::factory()->post->create();
$comment_id = self::factory()->comment->create(
array(
'comment_post_ID' => $post_id,
)
);
$count = get_comment_count( $post_id );
$this->assertSame( 1, $count['total_comments'] );
wp_delete_post( $post_id, true );
$count = get_comment_count( $post_id );
$this->assertSame( 0, $count['total_comments'] );
}
/**
* @ticket 19901
*
* @covers ::get_comment_count
*/
public function test_get_comment_count_validate_cache_comment_status() {
$comment_id = self::factory()->comment->create();
$count = get_comment_count();
$this->assertSame( 1, $count['approved'] );
$this->assertSame( 0, $count['trash'] );
$this->assertSame( 1, $count['total_comments'] );
wp_set_comment_status( $comment_id, 'trash' );
$count = get_comment_count();
$this->assertSame( 0, $count['approved'] );
$this->assertSame( 1, $count['trash'] );
$this->assertSame( 0, $count['total_comments'] );
}
}