Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 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/rest-api/rest-request-validation.php

    r39931 r42343  
    1313
    1414    public function test_validate_within_min_max_range_inclusive() {
    15         $request = new WP_REST_Request( 'GET', '/wp/v2/foo', array(
    16             'args' => array(
    17                 'minmaxrange' => array(
    18                     'type'    => 'integer',
    19                     'minimum' => 2,
    20                     'maximum' => 10,
     15        $request = new WP_REST_Request(
     16            'GET', '/wp/v2/foo', array(
     17                'args' => array(
     18                    'minmaxrange' => array(
     19                        'type'    => 'integer',
     20                        'minimum' => 2,
     21                        'maximum' => 10,
     22                    ),
    2123                ),
    22             ),
    23         ) );
    24         $ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );
     24            )
     25        );
     26        $ret     = rest_validate_request_arg( 1, $request, 'minmaxrange' );
    2527        $this->assertEquals( 'minmaxrange must be between 2 (inclusive) and 10 (inclusive)', $ret->get_error_message() );
    2628        $ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
     
    3335
    3436    public function test_validate_within_min_max_range_min_exclusive() {
    35         $request = new WP_REST_Request( 'GET', '/wp/v2/foo', array(
    36             'args' => array(
    37                 'minmaxrange' => array(
    38                     'type'             => 'integer',
    39                     'minimum'          => 2,
    40                     'maximum'          => 10,
    41                     'exclusiveMinimum' => true,
     37        $request = new WP_REST_Request(
     38            'GET', '/wp/v2/foo', array(
     39                'args' => array(
     40                    'minmaxrange' => array(
     41                        'type'             => 'integer',
     42                        'minimum'          => 2,
     43                        'maximum'          => 10,
     44                        'exclusiveMinimum' => true,
     45                    ),
    4246                ),
    43             ),
    44         ) );
    45         $ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );
     47            )
     48        );
     49        $ret     = rest_validate_request_arg( 1, $request, 'minmaxrange' );
    4650        $this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (inclusive)', $ret->get_error_message() );
    4751        $ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
     
    5862
    5963    public function test_validate_within_min_max_range_max_exclusive() {
    60         $request = new WP_REST_Request( 'GET', '/wp/v2/foo', array(
    61             'args' => array(
    62                 'minmaxrange' => array(
    63                     'type'             => 'integer',
    64                     'minimum'          => 2,
    65                     'maximum'          => 10,
    66                     'exclusiveMaximum' => true,
     64        $request = new WP_REST_Request(
     65            'GET', '/wp/v2/foo', array(
     66                'args' => array(
     67                    'minmaxrange' => array(
     68                        'type'             => 'integer',
     69                        'minimum'          => 2,
     70                        'maximum'          => 10,
     71                        'exclusiveMaximum' => true,
     72                    ),
    6773                ),
    68             ),
    69         ) );
    70         $ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );
     74            )
     75        );
     76        $ret     = rest_validate_request_arg( 1, $request, 'minmaxrange' );
    7177        $this->assertEquals( 'minmaxrange must be between 2 (inclusive) and 10 (exclusive)', $ret->get_error_message() );
    7278        $ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
     
    8389
    8490    public function test_validate_within_min_max_range_both_exclusive() {
    85         $request = new WP_REST_Request( 'GET', '/wp/v2/foo', array(
    86             'args' => array(
    87                 'minmaxrange' => array(
    88                     'type'             => 'integer',
    89                     'minimum'          => 2,
    90                     'maximum'          => 10,
    91                     'exclusiveMinimum' => true,
    92                     'exclusiveMaximum' => true,
     91        $request = new WP_REST_Request(
     92            'GET', '/wp/v2/foo', array(
     93                'args' => array(
     94                    'minmaxrange' => array(
     95                        'type'             => 'integer',
     96                        'minimum'          => 2,
     97                        'maximum'          => 10,
     98                        'exclusiveMinimum' => true,
     99                        'exclusiveMaximum' => true,
     100                    ),
    93101                ),
    94             ),
    95         ) );
    96         $ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );
     102            )
     103        );
     104        $ret     = rest_validate_request_arg( 1, $request, 'minmaxrange' );
    97105        $this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
    98106        $ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
     
    109117
    110118    public function test_validate_greater_than_min_inclusive() {
    111         $request = new WP_REST_Request( 'GET', '/wp/v2/foo', array(
    112             'args' => array(
    113                 'greaterthanmin' => array(
    114                     'type'             => 'integer',
    115                     'minimum'          => 2,
     119        $request = new WP_REST_Request(
     120            'GET', '/wp/v2/foo', array(
     121                'args' => array(
     122                    'greaterthanmin' => array(
     123                        'type'    => 'integer',
     124                        'minimum' => 2,
     125                    ),
    116126                ),
    117             ),
    118         ) );
    119         $ret = rest_validate_request_arg( 1, $request, 'greaterthanmin' );
     127            )
     128        );
     129        $ret     = rest_validate_request_arg( 1, $request, 'greaterthanmin' );
    120130        $this->assertEquals( 'greaterthanmin must be greater than or equal to 2', $ret->get_error_message() );
    121131        $ret = rest_validate_request_arg( 2, $request, 'greaterthanmin' );
     
    124134
    125135    public function test_validate_greater_than_min_exclusive() {
    126         $request = new WP_REST_Request( 'GET', '/wp/v2/foo', array(
    127             'args' => array(
    128                 'greaterthanmin' => array(
    129                     'type'             => 'integer',
    130                     'minimum'          => 2,
    131                     'exclusiveMinimum' => true,
     136        $request = new WP_REST_Request(
     137            'GET', '/wp/v2/foo', array(
     138                'args' => array(
     139                    'greaterthanmin' => array(
     140                        'type'             => 'integer',
     141                        'minimum'          => 2,
     142                        'exclusiveMinimum' => true,
     143                    ),
    132144                ),
    133             ),
    134         ) );
    135         $ret = rest_validate_request_arg( 1, $request, 'greaterthanmin' );
     145            )
     146        );
     147        $ret     = rest_validate_request_arg( 1, $request, 'greaterthanmin' );
    136148        $this->assertEquals( 'greaterthanmin must be greater than 2', $ret->get_error_message() );
    137149        $ret = rest_validate_request_arg( 2, $request, 'greaterthanmin' );
     
    142154
    143155    public function test_validate_less_than_max_inclusive() {
    144         $request = new WP_REST_Request( 'GET', '/wp/v2/foo', array(
    145             'args' => array(
    146                 'lessthanmax' => array(
    147                     'type'             => 'integer',
    148                     'maximum'          => 10,
     156        $request = new WP_REST_Request(
     157            'GET', '/wp/v2/foo', array(
     158                'args' => array(
     159                    'lessthanmax' => array(
     160                        'type'    => 'integer',
     161                        'maximum' => 10,
     162                    ),
    149163                ),
    150             ),
    151         ) );
    152         $ret = rest_validate_request_arg( 11, $request, 'lessthanmax' );
     164            )
     165        );
     166        $ret     = rest_validate_request_arg( 11, $request, 'lessthanmax' );
    153167        $this->assertEquals( 'lessthanmax must be less than or equal to 10', $ret->get_error_message() );
    154168        $ret = rest_validate_request_arg( 10, $request, 'lessthanmax' );
     
    157171
    158172    public function test_validate_less_than_max_exclusive() {
    159         $request = new WP_REST_Request( 'GET', '/wp/v2/foo', array(
    160             'args' => array(
    161                 'lessthanmax' => array(
    162                     'type'             => 'integer',
    163                     'maximum'          => 10,
    164                     'exclusiveMaximum' => true,
     173        $request = new WP_REST_Request(
     174            'GET', '/wp/v2/foo', array(
     175                'args' => array(
     176                    'lessthanmax' => array(
     177                        'type'             => 'integer',
     178                        'maximum'          => 10,
     179                        'exclusiveMaximum' => true,
     180                    ),
    165181                ),
    166             ),
    167         ) );
    168         $ret = rest_validate_request_arg( 11, $request, 'lessthanmax' );
     182            )
     183        );
     184        $ret     = rest_validate_request_arg( 11, $request, 'lessthanmax' );
    169185        $this->assertEquals( 'lessthanmax must be less than 10', $ret->get_error_message() );
    170186        $ret = rest_validate_request_arg( 10, $request, 'lessthanmax' );
Note: See TracChangeset for help on using the changeset viewer.