mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-04 20:54:29 +00:00
Allow comment query results to be limited to comments with comment_post_ID = 0.
Previously, this was not possible due to an overly broad `empty()` check. Passing `null`, `false`, or `''` to 'post_id', or omitting 'post_id' altogether, will continue to return comments regardless of `comment_post_ID`, as before. Passing `0` or `'0'` will limit results to comments with no associated post. Props danielbachhuber. Fixes #35090. git-svn-id: https://develop.svn.wordpress.org/trunk@36381 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -36,8 +36,12 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
$this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c5 ), $found );
|
||||
}
|
||||
|
||||
public function test_query_post_id_0() {
|
||||
/**
|
||||
* @ticket 35090
|
||||
*/
|
||||
public function test_post_id_0_should_return_comments_with_no_parent() {
|
||||
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
|
||||
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => 0, 'comment_approved' => '1' ) );
|
||||
|
||||
$q = new WP_Comment_Query();
|
||||
$found = $q->query( array(
|
||||
@@ -45,7 +49,71 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
'fields' => 'ids',
|
||||
) );
|
||||
|
||||
$this->assertEqualSets( array( $c1 ), $found );
|
||||
$this->assertEqualSets( array( $c2 ), $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35090
|
||||
*/
|
||||
public function test_post_id_string_0_should_return_comments_with_no_parent() {
|
||||
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
|
||||
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => 0, 'comment_approved' => '1' ) );
|
||||
|
||||
$q = new WP_Comment_Query();
|
||||
$found = $q->query( array(
|
||||
'post_id' => '0',
|
||||
'fields' => 'ids',
|
||||
) );
|
||||
|
||||
$this->assertEqualSets( array( $c2 ), $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35090
|
||||
*/
|
||||
public function test_post_id_null_should_be_ignored() {
|
||||
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
|
||||
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => 0, 'comment_approved' => '1' ) );
|
||||
|
||||
$q = new WP_Comment_Query();
|
||||
$found = $q->query( array(
|
||||
'post_id' => null,
|
||||
'fields' => 'ids',
|
||||
) );
|
||||
|
||||
$this->assertEqualSets( array( $c1, $c2 ), $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35090
|
||||
*/
|
||||
public function test_post_id_false_should_be_ignored() {
|
||||
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
|
||||
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => 0, 'comment_approved' => '1' ) );
|
||||
|
||||
$q = new WP_Comment_Query();
|
||||
$found = $q->query( array(
|
||||
'post_id' => false,
|
||||
'fields' => 'ids',
|
||||
) );
|
||||
|
||||
$this->assertEqualSets( array( $c1, $c2 ), $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35090
|
||||
*/
|
||||
public function test_post_id_empty_string_should_be_ignored() {
|
||||
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
|
||||
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => 0, 'comment_approved' => '1' ) );
|
||||
|
||||
$q = new WP_Comment_Query();
|
||||
$found = $q->query( array(
|
||||
'post_id' => '',
|
||||
'fields' => 'ids',
|
||||
) );
|
||||
|
||||
$this->assertEqualSets( array( $c1, $c2 ), $found );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user