mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
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
176 lines
4.3 KiB
PHP
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'] );
|
|
}
|
|
}
|