Make WordPress Core


Ignore:
Timestamp:
01/18/2018 05:17:23 AM (7 years ago)
Author:
dd32
Message:

General: Allow wp_list_pluck() to operate on arrays of references without overwriting the referenced items.

Fixes #16895.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions/listFilter.php

    r42526 r42527  
    211211    }
    212212
     213    /**
     214     * @ticket 16895
     215     */
     216    function test_wp_list_pluck_containing_references() {
     217        $ref_list = array(
     218            & $this->object_list['foo'],
     219            & $this->object_list['bar'],
     220        );
     221
     222        $this->assertInstanceOf( 'stdClass', $ref_list[0] );
     223        $this->assertInstanceOf( 'stdClass', $ref_list[1] );
     224
     225        $list = wp_list_pluck( $ref_list, 'name' );
     226        $this->assertEquals(
     227            array(
     228                'foo',
     229                'bar',
     230            ),
     231            $list
     232        );
     233
     234        $this->assertInstanceOf( 'stdClass', $ref_list[0] );
     235        $this->assertInstanceOf( 'stdClass', $ref_list[1] );
     236    }
     237
     238    /**
     239     * @ticket 16895
     240     */
     241    function test_wp_list_pluck_containing_references_keys() {
     242        $ref_list = array(
     243            & $this->object_list['foo'],
     244            & $this->object_list['bar'],
     245        );
     246
     247        $this->assertInstanceOf( 'stdClass', $ref_list[0] );
     248        $this->assertInstanceOf( 'stdClass', $ref_list[1] );
     249
     250        $list = wp_list_pluck( $ref_list, 'name', 'id' );
     251        $this->assertEquals(
     252            array(
     253                'f' => 'foo',
     254                'b' => 'bar',
     255            ),
     256            $list
     257        );
     258
     259        $this->assertInstanceOf( 'stdClass', $ref_list[0] );
     260        $this->assertInstanceOf( 'stdClass', $ref_list[1] );
     261    }
     262
    213263    function test_filter_object_list_nested_array_and() {
    214264        $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'blue' ) ), 'AND' );
Note: See TracChangeset for help on using the changeset viewer.