WordPress.org

Make WordPress Core

Ticket #39055: 39055_tests_current_behavior_refresh.diff

File 39055_tests_current_behavior_refresh.diff, 2.2 KB (added by fibonaccina, 4 years ago)

Relocate tests and fix indentation

  • tests/phpunit/tests/query/results.php

     
    365365                ), wp_list_pluck( $posts, 'post_title' ) );
    366366        }
    367367
     368  /**
     369   * @ticket 39055
     370   */
     371  function test_query_orderby_post__in_with_no_order_specified() {
     372    $post__in_array = array( self::$post_ids[2], self::$post_ids[0], self::$post_ids[1] );
     373    $expected_returned_array = array( self::$post_ids[0], self::$post_ids[1], self::$post_ids[2] );
     374
     375    $q = new WP_Query( array(
     376        'post__in' => $post__in_array,
     377        'orderby'  => 'post__in',
     378        'fields'   => 'ids'
     379    ) );
     380
     381    // Expect post ids from lower to higher value (default ASC) when no 'order' param is passed in
     382    $this->assertSame( $expected_returned_array, $q->posts );
     383  }
     384
     385  /**
     386   * @ticket 39055
     387   */
     388  function test_query_orderby_post__in_with_order_asc() {
     389    $post__in_array = array( self::$post_ids[2], self::$post_ids[1], self::$post_ids[0] );
     390    $expected_returned_array = array( self::$post_ids[0], self::$post_ids[1], self::$post_ids[2] );
     391
     392    $q = new WP_Query( array(
     393        'post__in' => $post__in_array,
     394        'orderby'  => 'post__in',
     395        'order'    => 'asc',
     396        'fields'   => 'ids'
     397    ) );
     398
     399    // Expect post ids from lower to higher value when order=asc is passed in
     400    $this->assertSame( $expected_returned_array, $q->posts );
     401   }
     402
     403  /**
     404   * @ticket 39055
     405   */
     406  function test_query_orderby_post__in_with_order_desc() {
     407    $post__in_array = array( self::$post_ids[1], self::$post_ids[2], self::$post_ids[0] );
     408    // Even if the input post__in array is not sorted, results are returned in sorted order
     409    $expected_returned_array = array( self::$post_ids[2], self::$post_ids[1], self::$post_ids[0] );
     410
     411    $q = new WP_Query( array(
     412        'post__in' => $post__in_array,
     413        'orderby'  => 'post__in',
     414        'order'    => 'desc',
     415        'fields'   => 'ids'
     416    ) );
     417
     418    // Expect post ids from higher to lower value when order=desc is passed in
     419    $this->assertSame( $expected_returned_array, $q->posts );
     420  }
     421
    368422        /**
    369423         * @ticket 27252
    370424         * @ticket 31194