mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Improve method consistency in WP_Comment_Query.
* Introduce a `__construct()` method, which can accept an array of query vars. * Move query logic out of `query()` method and into a new `get_comments()` method. * Ensure that `$this->comments` is set whenever `get_comments()` returns a value. * Introduce a `parse_query()` method, where query vars are parsed with default values and the 'parse_comment_query' action is fired. These changes bring `WP_Comment_Query` syntax closer to that of `WP_Query`. Props westonruter, morganestes, boonebgorges. Fixes #24826. git-svn-id: https://develop.svn.wordpress.org/trunk@31793 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1587,4 +1587,49 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
|
||||
$this->assertEqualSets( array_merge( $c1, $c3 ), $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 24826
|
||||
*/
|
||||
public function test_comment_query_object() {
|
||||
$comment_id = $this->factory->comment->create();
|
||||
|
||||
$query1 = new WP_Comment_Query();
|
||||
$this->assertNull( $query1->query_vars );
|
||||
$this->assertEmpty( $query1->comments );
|
||||
$comments = $query1->query( array( 'status' => 'all' ) );
|
||||
$this->assertInternalType( 'array', $query1->query_vars );
|
||||
$this->assertNotEmpty( $query1->comments );
|
||||
$this->assertInternalType( 'array', $query1->comments );
|
||||
|
||||
$query2 = new WP_Comment_Query( array( 'status' => 'all' ) );
|
||||
$this->assertNotEmpty( $query2->query_vars );
|
||||
$this->assertNotEmpty( $query2->comments );
|
||||
$this->assertEquals( $query2->comments, $query1->get_comments() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 22400
|
||||
*/
|
||||
public function test_comment_cache_key_should_ignore_custom_params() {
|
||||
global $wpdb;
|
||||
|
||||
$p = $this->factory->post->create();
|
||||
$c = $this->factory->comment->create( array( 'comment_post_ID' => $p ) );
|
||||
|
||||
$q1 = new WP_Comment_Query();
|
||||
$q1->query( array(
|
||||
'post_id' => $p,
|
||||
) );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
|
||||
$q2 = new WP_Comment_Query();
|
||||
$q2->query( array(
|
||||
'post_id' => $p,
|
||||
'foo' => 'bar',
|
||||
) );
|
||||
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user