From e79e137c32738c988524aac8695ae085b1ccd370 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Tue, 7 Mar 2017 05:26:51 +0000 Subject: [PATCH] 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 --- tests/phpunit/tests/query/results.php | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/phpunit/tests/query/results.php b/tests/phpunit/tests/query/results.php index 53a23f2669..bcff83916b 100644 --- a/tests/phpunit/tests/query/results.php +++ b/tests/phpunit/tests/query/results.php @@ -365,6 +365,23 @@ class Tests_Query_Results extends WP_UnitTestCase { ), 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 */ @@ -419,6 +436,37 @@ class Tests_Query_Results extends WP_UnitTestCase { $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 31194