Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r35950 r42343  
    88class Tests_Functions_ListFilter extends WP_UnitTestCase {
    99        var $object_list = array();
    10         var $array_list = array();
     10        var $array_list  = array();
    1111
    1212        function setUp() {
    1313                parent::setUp();
    14                 $this->array_list['foo'] = array( 'name' => 'foo', 'id' => 'f', 'field1' => true, 'field2' => true, 'field3' => true, 'field4' => array( 'red' ) );
    15                 $this->array_list['bar'] = array( 'name' => 'bar', 'id' => 'b', 'field1' => true, 'field2' => true, 'field3' => false, 'field4' => array( 'green' ) );
    16                 $this->array_list['baz'] = array( 'name' => 'baz', 'id' => 'z', 'field1' => true, 'field2' => false, 'field3' => false, 'field4' => array( 'blue' ) );
     14                $this->array_list['foo'] = array(
     15                        'name'   => 'foo',
     16                        'id'     => 'f',
     17                        'field1' => true,
     18                        'field2' => true,
     19                        'field3' => true,
     20                        'field4' => array( 'red' ),
     21                );
     22                $this->array_list['bar'] = array(
     23                        'name'   => 'bar',
     24                        'id'     => 'b',
     25                        'field1' => true,
     26                        'field2' => true,
     27                        'field3' => false,
     28                        'field4' => array( 'green' ),
     29                );
     30                $this->array_list['baz'] = array(
     31                        'name'   => 'baz',
     32                        'id'     => 'z',
     33                        'field1' => true,
     34                        'field2' => false,
     35                        'field3' => false,
     36                        'field4' => array( 'blue' ),
     37                );
    1738                foreach ( $this->array_list as $key => $value ) {
    1839                        $this->object_list[ $key ] = (object) $value;
    … …  
    2142
    2243        function test_filter_object_list_and() {
    23                 $list = wp_filter_object_list( $this->object_list, array( 'field1' => true, 'field2' => true ), 'AND' );
     44                $list = wp_filter_object_list(
     45                        $this->object_list, array(
     46                                'field1' => true,
     47                                'field2' => true,
     48                        ), 'AND'
     49                );
    2450                $this->assertEquals( 2, count( $list ) );
    2551                $this->assertArrayHasKey( 'foo', $list );
    … …  
    2854
    2955        function test_filter_object_list_or() {
    30                 $list = wp_filter_object_list( $this->object_list, array( 'field1' => true, 'field2' => true ), 'OR' );
     56                $list = wp_filter_object_list(
     57                        $this->object_list, array(
     58                                'field1' => true,
     59                                'field2' => true,
     60                        ), 'OR'
     61                );
    3162                $this->assertEquals( 3, count( $list ) );
    3263                $this->assertArrayHasKey( 'foo', $list );
    … …  
    3667
    3768        function test_filter_object_list_not() {
    38                 $list = wp_filter_object_list( $this->object_list, array( 'field2' => true, 'field3' => true ), 'NOT' );
     69                $list = wp_filter_object_list(
     70                        $this->object_list, array(
     71                                'field2' => true,
     72                                'field3' => true,
     73                        ), 'NOT'
     74                );
    3975                $this->assertEquals( 1, count( $list ) );
    4076                $this->assertArrayHasKey( 'baz', $list );
    … …  
    4278
    4379        function test_filter_object_list_and_field() {
    44                 $list = wp_filter_object_list( $this->object_list, array( 'field1' => true, 'field2' => true ), 'AND', 'name' );
    45                 $this->assertEquals( 2, count( $list ) );
    46                 $this->assertEquals( array( 'foo' => 'foo', 'bar' => 'bar' ) , $list );
     80                $list = wp_filter_object_list(
     81                        $this->object_list, array(
     82                                'field1' => true,
     83                                'field2' => true,
     84                        ), 'AND', 'name'
     85                );
     86                $this->assertEquals( 2, count( $list ) );
     87                $this->assertEquals(
     88                        array(
     89                                'foo' => 'foo',
     90                                'bar' => 'bar',
     91                        ), $list
     92                );
    4793        }
    4894
    4995        function test_filter_object_list_or_field() {
    50                 $list = wp_filter_object_list( $this->object_list, array( 'field2' => true, 'field3' => true ), 'OR', 'name' );
    51                 $this->assertEquals( 2, count( $list ) );
    52                 $this->assertEquals( array( 'foo' => 'foo', 'bar' => 'bar' ) , $list );
     96                $list = wp_filter_object_list(
     97                        $this->object_list, array(
     98                                'field2' => true,
     99                                'field3' => true,
     100                        ), 'OR', 'name'
     101                );
     102                $this->assertEquals( 2, count( $list ) );
     103                $this->assertEquals(
     104                        array(
     105                                'foo' => 'foo',
     106                                'bar' => 'bar',
     107                        ), $list
     108                );
    53109        }
    54110
    55111        function test_filter_object_list_not_field() {
    56                 $list = wp_filter_object_list( $this->object_list, array( 'field2' => true, 'field3' => true ), 'NOT', 'name' );
    57                 $this->assertEquals( 1, count( $list ) );
    58                 $this->assertEquals( array( 'baz' => 'baz' ) , $list );
     112                $list = wp_filter_object_list(
     113                        $this->object_list, array(
     114                                'field2' => true,
     115                                'field3' => true,
     116                        ), 'NOT', 'name'
     117                );
     118                $this->assertEquals( 1, count( $list ) );
     119                $this->assertEquals( array( 'baz' => 'baz' ), $list );
    59120        }
    60121
    61122        function test_wp_list_pluck() {
    62123                $list = wp_list_pluck( $this->object_list, 'name' );
    63                 $this->assertEquals( array( 'foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz' ) , $list );
     124                $this->assertEquals(
     125                        array(
     126                                'foo' => 'foo',
     127                                'bar' => 'bar',
     128                                'baz' => 'baz',
     129                        ), $list
     130                );
    64131
    65132                $list = wp_list_pluck( $this->array_list, 'name' );
    66                 $this->assertEquals( array( 'foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz' ) , $list );
     133                $this->assertEquals(
     134                        array(
     135                                'foo' => 'foo',
     136                                'bar' => 'bar',
     137                                'baz' => 'baz',
     138                        ), $list
     139                );
    67140        }
    68141
    … …  
    72145        function test_wp_list_pluck_index_key() {
    73146                $list = wp_list_pluck( $this->array_list, 'name', 'id' );
    74                 $this->assertEquals( array( 'f' => 'foo', 'b' => 'bar', 'z' => 'baz' ), $list );
     147                $this->assertEquals(
     148                        array(
     149                                'f' => 'foo',
     150                                'b' => 'bar',
     151                                'z' => 'baz',
     152                        ), $list
     153                );
    75154        }
    76155
    … …  
    80159        function test_wp_list_pluck_object_index_key() {
    81160                $list = wp_list_pluck( $this->object_list, 'name', 'id' );
    82                 $this->assertEquals( array( 'f' => 'foo', 'b' => 'bar', 'z' => 'baz' ), $list );
     161                $this->assertEquals(
     162                        array(
     163                                'f' => 'foo',
     164                                'b' => 'bar',
     165                                'z' => 'baz',
     166                        ), $list
     167                );
    83168        }
    84169
    … …  
    88173        function test_wp_list_pluck_missing_index_key() {
    89174                $list = wp_list_pluck( $this->array_list, 'name', 'nonexistent' );
    90                 $this->assertEquals( array( 0 => 'foo', 1 => 'bar', 2 => 'baz' ), $list );
     175                $this->assertEquals(
     176                        array(
     177                                0 => 'foo',
     178                                1 => 'bar',
     179                                2 => 'baz',
     180                        ), $list
     181                );
    91182        }
    92183
    … …  
    96187        function test_wp_list_pluck_partial_missing_index_key() {
    97188                $array_list = $this->array_list;
    98                 unset( $array_list[ 'bar']['id'] );
     189                unset( $array_list['bar']['id'] );
    99190                $list = wp_list_pluck( $array_list, 'name', 'id' );
    100                 $this->assertEquals( array( 'f' => 'foo', 0 => 'bar', 'z' => 'baz' ), $list );
     191                $this->assertEquals(
     192                        array(
     193                                'f' => 'foo',
     194                                0   => 'bar',
     195                                'z' => 'baz',
     196                        ), $list
     197                );
    101198        }
    102199
    … …  
    105202         */
    106203        function test_wp_list_pluck_mixed_index_key() {
    107                 $mixed_list = $this->array_list;
     204                $mixed_list        = $this->array_list;
    108205                $mixed_list['bar'] = (object) $mixed_list['bar'];
    109                 $list = wp_list_pluck( $mixed_list, 'name', 'id' );
    110                 $this->assertEquals( array( 'f' => 'foo', 'b' => 'bar', 'z' => 'baz' ), $list );
     206                $list              = wp_list_pluck( $mixed_list, 'name', 'id' );
     207                $this->assertEquals(
     208                        array(
     209                                'f' => 'foo',
     210                                'b' => 'bar',
     211                                'z' => 'baz',
     212                        ), $list
     213                );
    111214        }
    112215
    … …  
    125228
    126229        function test_filter_object_list_nested_array_or() {
    127                 $list = wp_filter_object_list( $this->object_list, array( 'field3' => true, 'field4' => array( 'blue' ) ), 'OR' );
     230                $list = wp_filter_object_list(
     231                        $this->object_list, array(
     232                                'field3' => true,
     233                                'field4' => array( 'blue' ),
     234                        ), 'OR'
     235                );
    128236                $this->assertEquals( 2, count( $list ) );
    129237                $this->assertArrayHasKey( 'foo', $list );
    … …  
    141249                $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'blue' ) ), 'AND', 'name' );
    142250                $this->assertEquals( 1, count( $list ) );
    143                 $this->assertEquals( array( 'baz' => 'baz' ) , $list );
     251                $this->assertEquals( array( 'baz' => 'baz' ), $list );
    144252        }
    145253
    … …  
    147255                $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'green' ) ), 'NOT', 'name' );
    148256                $this->assertEquals( 2, count( $list ) );
    149                 $this->assertEquals( array( 'foo' => 'foo', 'baz' => 'baz' ), $list );
     257                $this->assertEquals(
     258                        array(
     259                                'foo' => 'foo',
     260                                'baz' => 'baz',
     261                        ), $list
     262                );
    150263        }
    151264
    152265        function test_filter_object_list_nested_array_or_field() {
    153                 $list = wp_filter_object_list( $this->object_list, array( 'field3' => true, 'field4' => array( 'blue' ) ), 'OR', 'name' );
    154                 $this->assertEquals( 2, count( $list ) );
    155                 $this->assertEquals( array( 'foo' => 'foo', 'baz' => 'baz' ), $list );
     266                $list = wp_filter_object_list(
     267                        $this->object_list, array(
     268                                'field3' => true,
     269                                'field4' => array( 'blue' ),
     270                        ), 'OR', 'name'
     271                );
     272                $this->assertEquals( 2, count( $list ) );
     273                $this->assertEquals(
     274                        array(
     275                                'foo' => 'foo',
     276                                'baz' => 'baz',
     277                        ), $list
     278                );
    156279        }
    157280}
Note: See TracChangeset for help on using the changeset viewer.