Make WordPress Core


Ignore:
Timestamp:
03/07/2017 05:26:51 AM (8 years ago)
Author:
jnylen0
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/query/results.php

    r40056 r40237  
    369369     * @ticket 39055
    370370     */
     371    function test_query_orderby_post_parent__in_with_order_desc() {
     372        $post_parent__in_array = array( self::$parent_two, self::$parent_one );
     373        $expected_returned_array = array( 'child-three', 'child-four', 'child-one', 'child-two' );
     374
     375        $posts = $this->q->query( array(
     376            'post_parent__in' => $post_parent__in_array,
     377            'orderby'         => 'post_parent__in',
     378            'order'           => 'desc',
     379        ) );
     380
     381        // order=desc does not influence the order of returned results (returns same order as order=asc)
     382        $this->assertEquals( $expected_returned_array, wp_list_pluck( $posts, 'post_title' ) );
     383    }
     384
     385    /**
     386     * @ticket 39055
     387     */
    371388    function test_query_orderby_post__in_with_no_order_specified() {
    372389        $post__in_array = array( self::$post_ids[2], self::$post_ids[0], self::$post_ids[1] );
     
    418435        // Order=desc does not have an effect on the order of returned results
    419436        $this->assertSame( $expected_returned_array, $q->posts );
     437    }
     438
     439    /**
     440     * @ticket 39055
     441     */
     442    function test_query_orderby_post_name__in_with_order_asc() {
     443        $post_name__in_array = array( 'parent-two', 'parent-one', 'parent-three' );
     444
     445        $q = new WP_Query( array(
     446            'post_name__in' => $post_name__in_array,
     447            'orderby'       => 'post_name__in',
     448            'order'         => 'asc'
     449        ) );
     450
     451        $this->assertSame( $post_name__in_array, array_unique( wp_list_pluck( $q->posts, 'post_title' ) ) );
     452    }
     453
     454    /**
     455     * @ticket 39055
     456     */
     457    function test_query_orderby_post_name__in_with_order_desc() {
     458        $post_name__in_array = array( 'parent-two', 'parent-one', 'parent-three' );
     459
     460        $q = new WP_Query( array(
     461            'post_name__in' => $post_name__in_array,
     462            'orderby'       => 'post_name__in',
     463            'order'         => 'desc'
     464        ) );
     465
     466        // order=desc does not influence the order of returned results (returns same order as order=asc)
     467        $this->assertSame( $post_name__in_array, array_unique( wp_list_pluck( $q->posts, 'post_title' ) ) );
    420468    }
    421469
Note: See TracChangeset for help on using the changeset viewer.