Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 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/date/query.php

    r42056 r42343  
    3535
    3636    public function test_construct_relation_or_lowercase() {
    37         $q = new WP_Date_Query( array(
    38             'relation' => 'or',
    39         ) );
     37        $q = new WP_Date_Query(
     38            array(
     39                'relation' => 'or',
     40            )
     41        );
    4042
    4143        $this->assertSame( 'OR', $q->relation );
     
    4345
    4446    public function test_construct_relation_invalid() {
    45         $q = new WP_Date_Query( array(
    46             'relation' => 'foo',
    47         ) );
     47        $q = new WP_Date_Query(
     48            array(
     49                'relation' => 'foo',
     50            )
     51        );
    4852
    4953        $this->assertSame( 'AND', $q->relation );
     
    5155
    5256    public function test_construct_query_not_an_array_of_arrays() {
    53         $q = new WP_Date_Query( array(
    54             'before' => array(
    55                 'year' => 2008,
    56                 'month' => 6,
    57             ),
    58         ) );
    59 
    60         $expected = array(
    61             0 => array(
     57        $q = new WP_Date_Query(
     58            array(
    6259                'before' => array(
    63                     'year' => 2008,
     60                    'year'  => 2008,
    6461                    'month' => 6,
    6562                ),
    66                 'column' => 'post_date',
    67                 'compare' => '=',
    68                 'relation' => 'AND',
    69             ),
    70             'column' => 'post_date',
    71             'compare' => '=',
    72             'relation' => 'AND',
    73         );
    74 
    75         $this->assertSame( $expected, $q->queries );
    76     }
    77 
    78     public function test_construct_query_contains_non_arrays() {
    79         $q = new WP_Date_Query( array(
    80             'foo',
    81             'bar',
    82             array(
    83                 'before' => array(
    84                     'year' => 2008,
     63            )
     64        );
     65
     66        $expected = array(
     67            0          => array(
     68                'before'   => array(
     69                    'year'  => 2008,
    8570                    'month' => 6,
    8671                ),
    87             ),
    88         ) );
     72                'column'   => 'post_date',
     73                'compare'  => '=',
     74                'relation' => 'AND',
     75            ),
     76            'column'   => 'post_date',
     77            'compare'  => '=',
     78            'relation' => 'AND',
     79        );
     80
     81        $this->assertSame( $expected, $q->queries );
     82    }
     83
     84    public function test_construct_query_contains_non_arrays() {
     85        $q = new WP_Date_Query(
     86            array(
     87                'foo',
     88                'bar',
     89                array(
     90                    'before' => array(
     91                        'year'  => 2008,
     92                        'month' => 6,
     93                    ),
     94                ),
     95            )
     96        );
    8997
    9098        $expected = array(
    9199            array(
    92                 'before' => array(
    93                     'year' => 2008,
     100                'before'   => array(
     101                    'year'  => 2008,
    94102                    'month' => 6,
    95103                ),
    96                 'column' => 'post_date',
     104                'column'   => 'post_date',
     105                'compare'  => '=',
     106                'relation' => 'AND',
     107            ),
     108            'column'   => 'post_date',
     109            'compare'  => '=',
     110            'relation' => 'AND',
     111        );
     112
     113        $this->assertEquals( $expected, $q->queries );
     114    }
     115
     116    public function test_get_compare_empty() {
     117        $q = new WP_Date_Query( array() );
     118        $this->assertSame( '=', $q->get_compare( array() ) );
     119    }
     120
     121    public function test_get_compare_equals() {
     122        $q = new WP_Date_Query( array() );
     123
     124        $found = $q->get_compare(
     125            array(
    97126                'compare' => '=',
    98                 'relation' => 'AND',
    99             ),
    100             'column' => 'post_date',
    101             'compare' => '=',
    102             'relation' => 'AND',
    103         );
    104 
    105         $this->assertEquals( $expected, $q->queries );
    106     }
    107 
    108     public function test_get_compare_empty() {
    109         $q = new WP_Date_Query( array() );
    110         $this->assertSame( '=', $q->get_compare( array() ) );
    111     }
    112 
    113     public function test_get_compare_equals() {
    114         $q = new WP_Date_Query( array() );
    115 
    116         $found = $q->get_compare( array(
    117             'compare' => '=',
    118         ) );
     127            )
     128        );
    119129        $this->assertSame( '=', $found );
    120130    }
     
    123133        $q = new WP_Date_Query( array() );
    124134
    125         $found = $q->get_compare( array(
    126             'compare' => '!=',
    127         ) );
     135        $found = $q->get_compare(
     136            array(
     137                'compare' => '!=',
     138            )
     139        );
    128140        $this->assertSame( '!=', $found );
    129141    }
     
    132144        $q = new WP_Date_Query( array() );
    133145
    134         $found = $q->get_compare( array(
    135             'compare' => '>',
    136         ) );
     146        $found = $q->get_compare(
     147            array(
     148                'compare' => '>',
     149            )
     150        );
    137151        $this->assertSame( '>', $found );
    138152    }
     
    141155        $q = new WP_Date_Query( array() );
    142156
    143         $found = $q->get_compare( array(
    144             'compare' => '>=',
    145         ) );
     157        $found = $q->get_compare(
     158            array(
     159                'compare' => '>=',
     160            )
     161        );
    146162        $this->assertSame( '>=', $found );
    147163    }
     
    150166        $q = new WP_Date_Query( array() );
    151167
    152         $found = $q->get_compare( array(
    153             'compare' => '<',
    154         ) );
     168        $found = $q->get_compare(
     169            array(
     170                'compare' => '<',
     171            )
     172        );
    155173        $this->assertSame( '<', $found );
    156174    }
     
    159177        $q = new WP_Date_Query( array() );
    160178
    161         $found = $q->get_compare( array(
    162             'compare' => '<=',
    163         ) );
     179        $found = $q->get_compare(
     180            array(
     181                'compare' => '<=',
     182            )
     183        );
    164184        $this->assertSame( '<=', $found );
    165185    }
     
    168188        $q = new WP_Date_Query( array() );
    169189
    170         $found = $q->get_compare( array(
    171             'compare' => 'IN',
    172         ) );
     190        $found = $q->get_compare(
     191            array(
     192                'compare' => 'IN',
     193            )
     194        );
    173195        $this->assertSame( 'IN', $found );
    174196    }
     
    177199        $q = new WP_Date_Query( array() );
    178200
    179         $found = $q->get_compare( array(
    180             'compare' => 'NOT IN',
    181         ) );
     201        $found = $q->get_compare(
     202            array(
     203                'compare' => 'NOT IN',
     204            )
     205        );
    182206        $this->assertSame( 'NOT IN', $found );
    183207    }
     
    186210        $q = new WP_Date_Query( array() );
    187211
    188         $found = $q->get_compare( array(
    189             'compare' => 'BETWEEN',
    190         ) );
     212        $found = $q->get_compare(
     213            array(
     214                'compare' => 'BETWEEN',
     215            )
     216        );
    191217        $this->assertSame( 'BETWEEN', $found );
    192218    }
     
    195221        $q = new WP_Date_Query( array() );
    196222
    197         $found = $q->get_compare( array(
    198             'compare' => 'BETWEEN',
    199         ) );
     223        $found = $q->get_compare(
     224            array(
     225                'compare' => 'BETWEEN',
     226            )
     227        );
    200228        $this->assertSame( 'BETWEEN', $found );
    201229    }
     
    367395        $q = new WP_Date_Query( array() );
    368396
    369         $found = $q->build_value( 'BETWEEN', array(
    370             2 => 4,
    371             3 => 5,
    372         ) );
     397        $found = $q->build_value(
     398            'BETWEEN', array(
     399                2 => 4,
     400                3 => 5,
     401            )
     402        );
    373403
    374404        $this->assertSame( '4 AND 5', $found );
     
    425455        $q = new WP_Date_Query( array() );
    426456
    427         $found = $q->build_value( 'NOT BETWEEN', array(
    428             2 => 4,
    429             3 => 5,
    430         ) );
     457        $found = $q->build_value(
     458            'NOT BETWEEN', array(
     459                2 => 4,
     460                3 => 5,
     461            )
     462        );
    431463
    432464        $this->assertSame( '4 AND 5', $found );
     
    471503
    472504        // This might be a fragile test if it takes longer than 1 second to run
    473         $found = $q->build_mysql_datetime( 'foo' );
     505        $found    = $q->build_mysql_datetime( 'foo' );
    474506        $expected = gmdate( 'Y-m-d H:i:s', false );
    475507        $this->assertSame( $expected, $found );
     
    479511        $q = new WP_Date_Query( array() );
    480512
    481         $found = $q->build_mysql_datetime( array(
    482             'year' => 2011,
    483         ), true );
     513        $found = $q->build_mysql_datetime(
     514            array(
     515                'year' => 2011,
     516            ), true
     517        );
    484518        $this->assertSame( '2011-12-31 23:59:59', $found );
    485519    }
     
    488522        $q = new WP_Date_Query( array() );
    489523
    490         $found = $q->build_mysql_datetime( array(
    491             'year' => 2011,
    492         ), false );
     524        $found = $q->build_mysql_datetime(
     525            array(
     526                'year' => 2011,
     527            ), false
     528        );
    493529        $this->assertSame( '2011-01-01 00:00:00', $found );
    494530    }
     
    497533        $q = new WP_Date_Query( array() );
    498534
    499         $found = $q->build_mysql_datetime( array(
    500             'year' => 2011,
    501         ), false );
     535        $found = $q->build_mysql_datetime(
     536            array(
     537                'year' => 2011,
     538            ), false
     539        );
    502540        $this->assertSame( '2011-01-01 00:00:00', $found );
    503541    }
     
    650688     * @expectedIncorrectUsage WP_Date_Query
    651689     */
    652     public function test_validate_date_query_before_after(){
     690    public function test_validate_date_query_before_after() {
    653691        // Valid values.
    654692        $valid_args = array(
     
    697735     * @expectedIncorrectUsage WP_Date_Query
    698736     */
    699     public function test_validate_date_query_before_after_with_month(){
     737    public function test_validate_date_query_before_after_with_month() {
    700738        // Both are valid.
    701739        $args = array(
     
    704742                'year'  => 2014,
    705743            ),
    706             'month' => 10,
     744            'month'  => 10,
    707745        );
    708746        $this->assertTrue( $this->q->validate_date_values( $args ) );
     
    714752                'year'  => 2014,
    715753            ),
    716             'month' => 10,
     754            'month'  => 10,
    717755        );
    718756        $this->assertFalse( $this->q->validate_date_values( $args ) );
     
    724762                'year'  => 2014,
    725763            ),
    726             'month' => 14,
     764            'month'  => 14,
    727765        );
    728766        $this->assertFalse( $this->q->validate_date_values( $args ) );
     
    734772                'year'  => 2014,
    735773            ),
    736             'month' => 14,
     774            'month'  => 14,
    737775        );
    738776        $this->assertFalse( $this->q->validate_date_values( $args ) );
     
    784822                'week' => 54,
    785823                'year' => 2009,
    786             )
     824            ),
    787825        );
    788826
     
    9831021        $p2 = self::factory()->post->create( array( 'post_date' => '2013-01-12 00:00:00' ) );
    9841022
    985         $q = new WP_Query( array(
    986             'date_query' => array(
    987                 array(
    988                     'compare' => 'BETWEEN',
    989                     'year' => array( 2012, 2014 ),
     1023        $q = new WP_Query(
     1024            array(
     1025                'date_query' => array(
     1026                    array(
     1027                        'compare' => 'BETWEEN',
     1028                        'year'    => array( 2012, 2014 ),
     1029                    ),
    9901030                ),
    991             ),
    992             'fields' => 'ids',
    993         ) );
     1031                'fields'     => 'ids',
     1032            )
     1033        );
    9941034
    9951035        $this->assertEquals( array( $p2 ), $q->posts );
     
    10031043        $p2 = self::factory()->post->create( array( 'post_date' => '2015-01-10 00:00:00' ) );
    10041044
    1005         $q = new WP_Query( array(
    1006             'date_query' => array(
    1007                 array(
    1008                     'compare' => 'BETWEEN',
    1009                     'day' => array( 9, 11 ),
     1045        $q = new WP_Query(
     1046            array(
     1047                'date_query' => array(
     1048                    array(
     1049                        'compare' => 'BETWEEN',
     1050                        'day'     => array( 9, 11 ),
     1051                    ),
    10101052                ),
    1011             ),
    1012             'fields' => 'ids',
    1013         ) );
     1053                'fields'     => 'ids',
     1054            )
     1055        );
    10141056
    10151057        $this->assertEquals( array( $p2 ), $q->posts );
     
    10241066        $p2 = self::factory()->post->create( array( 'post_date' => '2015-01-10 00:00:00' ) );
    10251067
    1026         $q = new WP_Query( array(
    1027             'date_query' => array(
    1028                 array(
    1029                     'compare' => 'BETWEEN',
    1030                     'day' => array( 9, 32 ),
     1068        $q = new WP_Query(
     1069            array(
     1070                'date_query' => array(
     1071                    array(
     1072                        'compare' => 'BETWEEN',
     1073                        'day'     => array( 9, 32 ),
     1074                    ),
    10311075                ),
    1032             ),
    1033             'fields' => 'ids',
    1034         ) );
     1076                'fields'     => 'ids',
     1077            )
     1078        );
    10351079
    10361080        // MySQL ignores the invalid clause.
     
    10381082    }
    10391083
    1040     /** Helpers **********************************************************/
     1084    /** Helpers */
    10411085
    10421086    public function date_query_valid_columns_callback( $columns ) {
Note: See TracChangeset for help on using the changeset viewer.