Make WordPress Core


Ignore:
Timestamp:
03/24/2014 06:54:38 PM (11 years ago)
Author:
wonderboymusic
Message:

When using WP_Query's "fields" => "ids" (or "fields" => "id=>parent"), the returned values should be an array of integers, not array of integers represented by strings.

Adds unit tests. All other unit tests pass.

Props danielbachhuber.
Fixes #27252.

File:
1 edited

Legend:

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

    r27395 r27686  
    4747        $this->parent_two = $this->factory->post->create( array( 'post_title' => 'parent-two', 'post_date' => '2007-01-01 00:00:00' ) );
    4848        $this->parent_three = $this->factory->post->create( array( 'post_title' => 'parent-three', 'post_date' => '2007-01-01 00:00:00' ) );
    49         $this->factory->post->create( array( 'post_title' => 'child-one', 'post_parent' => $this->parent_one, 'post_date' => '2007-01-01 00:00:01' ) );
    50         $this->factory->post->create( array( 'post_title' => 'child-two', 'post_parent' => $this->parent_one, 'post_date' => '2007-01-01 00:00:02' ) );
    51         $this->factory->post->create( array( 'post_title' => 'child-three', 'post_parent' => $this->parent_two, 'post_date' => '2007-01-01 00:00:03' ) );
    52         $this->factory->post->create( array( 'post_title' => 'child-four', 'post_parent' => $this->parent_two, 'post_date' => '2007-01-01 00:00:04' ) );
     49        $this->child_one = $this->factory->post->create( array( 'post_title' => 'child-one', 'post_parent' => $this->parent_one, 'post_date' => '2007-01-01 00:00:01' ) );
     50        $this->child_two = $this->factory->post->create( array( 'post_title' => 'child-two', 'post_parent' => $this->parent_one, 'post_date' => '2007-01-01 00:00:02' ) );
     51        $this->child_three = $this->factory->post->create( array( 'post_title' => 'child-three', 'post_parent' => $this->parent_two, 'post_date' => '2007-01-01 00:00:03' ) );
     52        $this->child_four = $this->factory->post->create( array( 'post_title' => 'child-four', 'post_parent' => $this->parent_two, 'post_date' => '2007-01-01 00:00:04' ) );
    5353
    5454        unset( $this->q );
     
    371371    }
    372372
     373    /**
     374     * @ticket 27252
     375     */
     376    function test_query_fields_integers() {
     377
     378        $parents = array(
     379            (int) $this->parent_one,
     380            (int) $this->parent_two
     381        );
     382        $posts1 = $this->q->query( array(
     383            'post__in'  => $parents,
     384            'fields'    => 'ids',
     385            'orderby'   => 'post__in',
     386        ) );
     387
     388        $this->assertSame( $parents, $posts1 );
     389
     390        $children = array(
     391            (int) $this->child_one => (int) $this->parent_one,
     392            (int) $this->child_two => (int) $this->parent_one
     393        );
     394
     395        $posts2 = $this->q->query( array(
     396            'post__in'  => array_keys( $children ),
     397            'fields'    => 'id=>parent',
     398            'orderby'   => 'post__in',
     399        ) );
     400
     401        $this->assertSame( $children, $posts2 );
     402
     403    }
     404
    373405    function test_exlude_from_search_empty() {
    374406        global $wp_post_types;
Note: See TracChangeset for help on using the changeset viewer.