From 38c35566742373bc0effa40df1e102813075271c Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 12 Feb 2017 18:06:32 +0000 Subject: [PATCH] WP_Query: Add tests for the combination of `orderby=post__in` and `order`. This commit adds test cases for the interaction (or more accurately, lack of interaction) between `orderby=post__in` and the `order` parameter. Props fibonaccina. See #39055. git-svn-id: https://develop.svn.wordpress.org/trunk@40056 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/query/results.php | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/phpunit/tests/query/results.php b/tests/phpunit/tests/query/results.php index 58d603441c..53a23f2669 100644 --- a/tests/phpunit/tests/query/results.php +++ b/tests/phpunit/tests/query/results.php @@ -365,6 +365,60 @@ class Tests_Query_Results extends WP_UnitTestCase { ), wp_list_pluck( $posts, 'post_title' ) ); } + /** + * @ticket 39055 + */ + function test_query_orderby_post__in_with_no_order_specified() { + $post__in_array = array( self::$post_ids[2], self::$post_ids[0], self::$post_ids[1] ); + $expected_returned_array = array( self::$post_ids[2], self::$post_ids[0], self::$post_ids[1] ); + + $q = new WP_Query( array( + 'post__in' => $post__in_array, + 'orderby' => 'post__in', + 'fields' => 'ids' + ) ); + + // Expect post ids in the same order as post__in array when no 'order' param is passed in + $this->assertSame( $expected_returned_array, $q->posts ); + } + + /** + * @ticket 39055 + */ + function test_query_orderby_post__in_with_order_asc() { + $post__in_array = array( self::$post_ids[2], self::$post_ids[0], self::$post_ids[1] ); + $expected_returned_array = array( self::$post_ids[2], self::$post_ids[0], self::$post_ids[1] ); + + $q = new WP_Query( array( + 'post__in' => $post__in_array, + 'orderby' => 'post__in', + 'order' => 'asc', + 'fields' => 'ids' + ) ); + + // Expect post ids in the same order as post__in array when order=asc is passed in + $this->assertSame( $expected_returned_array, $q->posts ); + } + + /** + * @ticket 39055 + */ + function test_query_orderby_post__in_with_order_desc() { + $post__in_array = array( self::$post_ids[1], self::$post_ids[2], self::$post_ids[0] ); + $expected_returned_array = array( self::$post_ids[1], self::$post_ids[2], self::$post_ids[0] ); + + $q = new WP_Query( array( + 'post__in' => $post__in_array, + 'orderby' => 'post__in', + 'order' => 'desc', + 'fields' => 'ids' + ) ); + + // Note that results are returned in the order specified in the post__in array + // Order=desc does not have an effect on the order of returned results + $this->assertSame( $expected_returned_array, $q->posts ); + } + /** * @ticket 27252 * @ticket 31194