Make WordPress Core


Ignore:
Timestamp:
08/26/2021 03:54:29 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Move wp_list_pluck() tests to their own file.

The tests were partially duplicated in two separate files.

Follow-up to [431/tests], [28900], [38928], [42527].

See #53363, #53987.

File:
1 edited

Legend:

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

    r51568 r51663  
    22
    33/**
    4  * Test wp_filter_object_list(), wp_list_filter(), wp_list_pluck().
     4 * Test wp_filter_object_list().
    55 *
    66 * @group functions.php
    77 * @covers ::wp_filter_object_list
    8  * @covers ::wp_list_pluck
    98 */
    109class Tests_Functions_wpListFilter extends WP_UnitTestCase {
     
    136135    }
    137136
    138     function test_wp_list_pluck() {
    139         $list = wp_list_pluck( $this->object_list, 'name' );
    140         $this->assertSame(
    141             array(
    142                 'foo' => 'foo',
    143                 'bar' => 'bar',
    144                 'baz' => 'baz',
    145             ),
    146             $list
    147         );
    148 
    149         $list = wp_list_pluck( $this->array_list, 'name' );
    150         $this->assertSame(
    151             array(
    152                 'foo' => 'foo',
    153                 'bar' => 'bar',
    154                 'baz' => 'baz',
    155             ),
    156             $list
    157         );
    158     }
    159 
    160     /**
    161      * @ticket 28666
    162      */
    163     function test_wp_list_pluck_index_key() {
    164         $list = wp_list_pluck( $this->array_list, 'name', 'id' );
    165         $this->assertSame(
    166             array(
    167                 'f' => 'foo',
    168                 'b' => 'bar',
    169                 'z' => 'baz',
    170             ),
    171             $list
    172         );
    173     }
    174 
    175     /**
    176      * @ticket 28666
    177      */
    178     function test_wp_list_pluck_object_index_key() {
    179         $list = wp_list_pluck( $this->object_list, 'name', 'id' );
    180         $this->assertSame(
    181             array(
    182                 'f' => 'foo',
    183                 'b' => 'bar',
    184                 'z' => 'baz',
    185             ),
    186             $list
    187         );
    188     }
    189 
    190     /**
    191      * @ticket 28666
    192      */
    193     function test_wp_list_pluck_missing_index_key() {
    194         $list = wp_list_pluck( $this->array_list, 'name', 'nonexistent' );
    195         $this->assertSame(
    196             array(
    197                 0 => 'foo',
    198                 1 => 'bar',
    199                 2 => 'baz',
    200             ),
    201             $list
    202         );
    203     }
    204 
    205     /**
    206      * @ticket 28666
    207      */
    208     function test_wp_list_pluck_partial_missing_index_key() {
    209         $array_list = $this->array_list;
    210         unset( $array_list['bar']['id'] );
    211         $list = wp_list_pluck( $array_list, 'name', 'id' );
    212         $this->assertSame(
    213             array(
    214                 'f' => 'foo',
    215                 0   => 'bar',
    216                 'z' => 'baz',
    217             ),
    218             $list
    219         );
    220     }
    221 
    222     /**
    223      * @ticket 28666
    224      */
    225     function test_wp_list_pluck_mixed_index_key() {
    226         $mixed_list        = $this->array_list;
    227         $mixed_list['bar'] = (object) $mixed_list['bar'];
    228         $list              = wp_list_pluck( $mixed_list, 'name', 'id' );
    229         $this->assertSame(
    230             array(
    231                 'f' => 'foo',
    232                 'b' => 'bar',
    233                 'z' => 'baz',
    234             ),
    235             $list
    236         );
    237     }
    238 
    239     /**
    240      * @ticket 16895
    241      */
    242     function test_wp_list_pluck_containing_references() {
    243         $ref_list = array(
    244             & $this->object_list['foo'],
    245             & $this->object_list['bar'],
    246         );
    247 
    248         $this->assertInstanceOf( 'stdClass', $ref_list[0] );
    249         $this->assertInstanceOf( 'stdClass', $ref_list[1] );
    250 
    251         $list = wp_list_pluck( $ref_list, 'name' );
    252         $this->assertSame(
    253             array(
    254                 'foo',
    255                 'bar',
    256             ),
    257             $list
    258         );
    259 
    260         $this->assertInstanceOf( 'stdClass', $ref_list[0] );
    261         $this->assertInstanceOf( 'stdClass', $ref_list[1] );
    262     }
    263 
    264     /**
    265      * @ticket 16895
    266      */
    267     function test_wp_list_pluck_containing_references_keys() {
    268         $ref_list = array(
    269             & $this->object_list['foo'],
    270             & $this->object_list['bar'],
    271         );
    272 
    273         $this->assertInstanceOf( 'stdClass', $ref_list[0] );
    274         $this->assertInstanceOf( 'stdClass', $ref_list[1] );
    275 
    276         $list = wp_list_pluck( $ref_list, 'name', 'id' );
    277         $this->assertSame(
    278             array(
    279                 'f' => 'foo',
    280                 'b' => 'bar',
    281             ),
    282             $list
    283         );
    284 
    285         $this->assertInstanceOf( 'stdClass', $ref_list[0] );
    286         $this->assertInstanceOf( 'stdClass', $ref_list[1] );
    287     }
    288 
    289137    function test_filter_object_list_nested_array_and() {
    290138        $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'blue' ) ), 'AND' );
Note: See TracChangeset for help on using the changeset viewer.