Make WordPress Core

Ticket #39055: 39055_tests.diff

File 39055_tests.diff, 3.3 KB (added by fibonaccina, 7 years ago)
  • tests/phpunit/tests/query/search.php

     
    330330        }
    331331
    332332        /**
     333         * @ticket 39055
     334         */
     335        public function test_search_order_with_include_array_when_no_order_specified() {
     336                $p1 = self::factory()->post->create( array(
     337                        'post_status' => 'publish',
     338                        'post_title'  => 'This post has foo',
     339                        'post_content' => '',
     340                        'post_excerpt' => '',
     341                ) );
     342
     343                $p2 = self::factory()->post->create( array(
     344                        'post_status'  => 'publish',
     345                        'post_title' => '',
     346                        'post_content' => 'This post has bar',
     347                        'post_excerpt' => '',
     348                ) );
     349
     350                $p3 = self::factory()->post->create( array(
     351                        'post_status'  => 'publish',
     352                        'post_title' => '',
     353                        'post_content' => '',
     354                        'post_excerpt' => 'This post has baz',
     355                ) );
     356
     357                $include_array = array ($p2, $p1, $p3);
     358
     359                $q = new WP_Query( array(
     360                        'include' => $include_array,
     361                        'orderby' => 'include',
     362                        'fields' => 'ids'
     363                ) );
     364
     365                // Expect same order as 'include' array when no 'order' param is passed in
     366                $this->assertSame( $include_array, $q->posts );
     367        }
     368
     369        /**
     370         * @ticket 39055
     371         */
     372        public function test_search_order_with_include_array_when_order_asc() {
     373                $p1 = self::factory()->post->create( array(
     374                        'post_status' => 'publish',
     375                        'post_title'  => 'This post has foo',
     376                        'post_content' => '',
     377                        'post_excerpt' => '',
     378                ) );
     379
     380                $p2 = self::factory()->post->create( array(
     381                        'post_status'  => 'publish',
     382                        'post_title' => '',
     383                        'post_content' => 'This post has bar',
     384                        'post_excerpt' => '',
     385                ) );
     386
     387                $p3 = self::factory()->post->create( array(
     388                        'post_status'  => 'publish',
     389                        'post_title' => '',
     390                        'post_content' => '',
     391                        'post_excerpt' => 'This post has baz',
     392                ) );
     393
     394                $include_array = array ($p2, $p1, $p3);
     395
     396                $q = new WP_Query( array(
     397                        'include' => $include_array,
     398                        'orderby' => 'include',
     399                        'order' => 'asc',
     400                        'fields' => 'ids'
     401                ) );
     402
     403                // Expect same order as 'include' array when order=asc is passed in
     404                $this->assertSame( $include_array, $q->posts );
     405        }
     406
     407        /**
     408         * @ticket 39055
     409         */
     410        public function test_search_order_with_include_array_when_order_desc() {
     411                $p1 = self::factory()->post->create( array(
     412                        'post_status' => 'publish',
     413                        'post_title'  => 'This post has foo',
     414                        'post_content' => '',
     415                        'post_excerpt' => '',
     416                ) );
     417
     418                $p2 = self::factory()->post->create( array(
     419                        'post_status'  => 'publish',
     420                        'post_title' => '',
     421                        'post_content' => 'This post has bar',
     422                        'post_excerpt' => '',
     423                ) );
     424
     425                $p3 = self::factory()->post->create( array(
     426                        'post_status'  => 'publish',
     427                        'post_title' => '',
     428                        'post_content' => '',
     429                        'post_excerpt' => 'This post has baz',
     430                ) );
     431
     432                $include_array = array ($p2, $p1, $p3);
     433                $expected_returned_array = array_reverse($include_array);
     434
     435                $q = new WP_Query( array(
     436                        'include' => $include_array,
     437                        'orderby' => 'include',
     438                        'order' => 'desc',
     439                        'fields' => 'ids'
     440                ) );
     441
     442                // Expect reverse order of 'include' array when order=desc is passed in
     443                $this->assertSame( $expected_returned_array, $q->posts );
     444        }
     445
     446        /**
    333447         * Unfiltered search queries for attachment post types should not inlcude
    334448         * filenames to ensure the postmeta JOINs don't happen on the front end.
    335449         *