mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-14 09:34:41 +00:00
get_comment_count() currently increments awaiting_moderation when comments are in the trash. This occurs because case 0: will match any value passed to switch that is a string that isn't specified in the list of cases. This is terrifying.
* Cases for `0` and `1` should be `'1'` and `'0'` * Add unit tests for `get_comment_count()`. Currently, there are none. See #33414. git-svn-id: https://develop.svn.wordpress.org/trunk@33806 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
65
tests/phpunit/tests/comment/getCommentCount.php
Normal file
65
tests/phpunit/tests/comment/getCommentCount.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
class Tests_Get_Comment_Count extends WP_UnitTestCase {
|
||||
|
||||
public function test_get_comment_count() {
|
||||
$count = get_comment_count();
|
||||
|
||||
$this->assertEquals( 0, $count['approved'] );
|
||||
$this->assertEquals( 0, $count['awaiting_moderation'] );
|
||||
$this->assertEquals( 0, $count['spam'] );
|
||||
$this->assertEquals( 0, $count['total_comments'] );
|
||||
}
|
||||
|
||||
public function test_get_comment_count_approved() {
|
||||
$this->factory->comment->create( array(
|
||||
'comment_approved' => 1
|
||||
) );
|
||||
|
||||
$count = get_comment_count();
|
||||
|
||||
$this->assertEquals( 1, $count['approved'] );
|
||||
$this->assertEquals( 0, $count['awaiting_moderation'] );
|
||||
$this->assertEquals( 0, $count['spam'] );
|
||||
$this->assertEquals( 1, $count['total_comments'] );
|
||||
}
|
||||
|
||||
public function test_get_comment_count_awaiting() {
|
||||
$this->factory->comment->create( array(
|
||||
'comment_approved' => 0
|
||||
) );
|
||||
|
||||
$count = get_comment_count();
|
||||
|
||||
$this->assertEquals( 0, $count['approved'] );
|
||||
$this->assertEquals( 1, $count['awaiting_moderation'] );
|
||||
$this->assertEquals( 0, $count['spam'] );
|
||||
$this->assertEquals( 1, $count['total_comments'] );
|
||||
}
|
||||
|
||||
public function test_get_comment_count_spam() {
|
||||
$this->factory->comment->create( array(
|
||||
'comment_approved' => 'spam'
|
||||
) );
|
||||
|
||||
$count = get_comment_count();
|
||||
|
||||
$this->assertEquals( 0, $count['approved'] );
|
||||
$this->assertEquals( 0, $count['awaiting_moderation'] );
|
||||
$this->assertEquals( 1, $count['spam'] );
|
||||
$this->assertEquals( 1, $count['total_comments'] );
|
||||
}
|
||||
|
||||
public function test_get_comment_count_trash() {
|
||||
$this->factory->comment->create( array(
|
||||
'comment_approved' => 'trash'
|
||||
) );
|
||||
|
||||
$count = get_comment_count();
|
||||
|
||||
$this->assertEquals( 0, $count['approved'] );
|
||||
$this->assertEquals( 0, $count['awaiting_moderation'] );
|
||||
$this->assertEquals( 0, $count['spam'] );
|
||||
$this->assertEquals( 0, $count['total_comments'] );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user