WP_Query: Add missing tests for combinations of `orderby` and include parameters.

This commit adds some missing test cases for combinations of `orderby` and other parameters (`post_parent__in` and `post_name__in`).

Followup to [40056] for `orderby` and `post__in`.

The interaction of these parameters is perhaps counterintuitive because `orderby` does not affect the returned results.  This is overall probably the best design, and it's now better tested and documented.

Props fibonaccina.
See #39055.


git-svn-id: https://develop.svn.wordpress.org/trunk@40237 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
James Nylen 2017-03-07 05:26:51 +00:00
parent 154d0d15b7
commit e79e137c32
1 changed files with 48 additions and 0 deletions

View File

@ -365,6 +365,23 @@ class Tests_Query_Results extends WP_UnitTestCase {
), wp_list_pluck( $posts, 'post_title' ) ); ), wp_list_pluck( $posts, 'post_title' ) );
} }
/**
* @ticket 39055
*/
function test_query_orderby_post_parent__in_with_order_desc() {
$post_parent__in_array = array( self::$parent_two, self::$parent_one );
$expected_returned_array = array( 'child-three', 'child-four', 'child-one', 'child-two' );
$posts = $this->q->query( array(
'post_parent__in' => $post_parent__in_array,
'orderby' => 'post_parent__in',
'order' => 'desc',
) );
// order=desc does not influence the order of returned results (returns same order as order=asc)
$this->assertEquals( $expected_returned_array, wp_list_pluck( $posts, 'post_title' ) );
}
/** /**
* @ticket 39055 * @ticket 39055
*/ */
@ -419,6 +436,37 @@ class Tests_Query_Results extends WP_UnitTestCase {
$this->assertSame( $expected_returned_array, $q->posts ); $this->assertSame( $expected_returned_array, $q->posts );
} }
/**
* @ticket 39055
*/
function test_query_orderby_post_name__in_with_order_asc() {
$post_name__in_array = array( 'parent-two', 'parent-one', 'parent-three' );
$q = new WP_Query( array(
'post_name__in' => $post_name__in_array,
'orderby' => 'post_name__in',
'order' => 'asc'
) );
$this->assertSame( $post_name__in_array, array_unique( wp_list_pluck( $q->posts, 'post_title' ) ) );
}
/**
* @ticket 39055
*/
function test_query_orderby_post_name__in_with_order_desc() {
$post_name__in_array = array( 'parent-two', 'parent-one', 'parent-three' );
$q = new WP_Query( array(
'post_name__in' => $post_name__in_array,
'orderby' => 'post_name__in',
'order' => 'desc'
) );
// order=desc does not influence the order of returned results (returns same order as order=asc)
$this->assertSame( $post_name__in_array, array_unique( wp_list_pluck( $q->posts, 'post_title' ) ) );
}
/** /**
* @ticket 27252 * @ticket 27252
* @ticket 31194 * @ticket 31194