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/rest-api/rest-schema-validation.php

    r42000 r42343  
    2727        public function test_type_integer() {
    2828                $schema = array(
    29                         'type' => 'integer',
     29                        'type'    => 'integer',
    3030                        'minimum' => 1,
    3131                        'maximum' => 2,
    … …  
    6565        public function test_format_email() {
    6666                $schema = array(
    67                         'type'  => 'string',
     67                        'type'   => 'string',
    6868                        'format' => 'email',
    6969                );
    … …  
    7575        public function test_format_date_time() {
    7676                $schema = array(
    77                         'type'  => 'string',
     77                        'type'   => 'string',
    7878                        'format' => 'date-time',
    7979                );
    … …  
    8888        public function test_format_ip() {
    8989                $schema = array(
    90                         'type'  => 'string',
     90                        'type'   => 'string',
    9191                        'format' => 'ip',
    9292                );
    … …  
    114114        public function test_type_array() {
    115115                $schema = array(
    116                         'type' => 'array',
     116                        'type'  => 'array',
    117117                        'items' => array(
    118118                                'type' => 'number',
    … …  
    125125        public function test_type_array_nested() {
    126126                $schema = array(
    127                         'type' => 'array',
    128                         'items' => array(
    129                                 'type' => 'array',
     127                        'type'  => 'array',
     128                        'items' => array(
     129                                'type'  => 'array',
    130130                                'items' => array(
    131131                                        'type' => 'number',
    … …  
    138138        public function test_type_array_as_csv() {
    139139                $schema = array(
    140                         'type' => 'array',
     140                        'type'  => 'array',
    141141                        'items' => array(
    142142                                'type' => 'number',
    … …  
    179179                        ),
    180180                );
    181                 $this->assertWPError( rest_validate_value_from_schema( array( 'first' => '1', 'second' => '2' ), $schema ) );
     181                $this->assertWPError(
     182                        rest_validate_value_from_schema(
     183                                array(
     184                                        'first'  => '1',
     185                                        'second' => '2',
     186                                ), $schema
     187                        )
     188                );
    182189        }
    183190
    … …  
    192199                );
    193200                $this->assertTrue( rest_validate_value_from_schema( array( 'a' => 1 ), $schema ) );
    194                 $this->assertTrue( rest_validate_value_from_schema( array( 'a' => 1, 'b' => 2 ), $schema ) );
     201                $this->assertTrue(
     202                        rest_validate_value_from_schema(
     203                                array(
     204                                        'a' => 1,
     205                                        'b' => 2,
     206                                ), $schema
     207                        )
     208                );
    195209                $this->assertWPError( rest_validate_value_from_schema( array( 'a' => 'invalid' ), $schema ) );
    196210        }
    197211
    198212        public function test_type_object_additional_properties_false() {
     213                $schema = array(
     214                        'type'                 => 'object',
     215                        'properties'           => array(
     216                                'a' => array(
     217                                        'type' => 'number',
     218                                ),
     219                        ),
     220                        'additionalProperties' => false,
     221                );
     222                $this->assertTrue( rest_validate_value_from_schema( array( 'a' => 1 ), $schema ) );
     223                $this->assertWPError(
     224                        rest_validate_value_from_schema(
     225                                array(
     226                                        'a' => 1,
     227                                        'b' => 2,
     228                                ), $schema
     229                        )
     230                );
     231        }
     232
     233        public function test_type_object_nested() {
    199234                $schema = array(
    200235                        'type'       => 'object',
    201236                        'properties' => array(
    202237                                'a' => array(
    203                                         'type' => 'number',
    204                                 ),
    205                         ),
    206                         'additionalProperties' => false,
    207                 );
    208                 $this->assertTrue( rest_validate_value_from_schema( array( 'a' => 1 ), $schema ) );
    209                 $this->assertWPError( rest_validate_value_from_schema( array( 'a' => 1, 'b' => 2 ), $schema ) );
    210         }
    211 
    212         public function test_type_object_nested() {
    213                 $schema = array(
    214                         'type' => 'object',
    215                         'properties' => array(
    216                                 'a' => array(
    217                                         'type'  => 'object',
     238                                        'type'       => 'object',
    218239                                        'properties' => array(
    219240                                                'b' => array( 'type' => 'number' ),
    220241                                                'c' => array( 'type' => 'number' ),
    221                                         )
    222                                 )
     242                                        ),
     243                                ),
    223244                        ),
    224245                );
    … …  
    234255                        )
    235256                );
    236                 $this->assertWPError( rest_validate_value_from_schema( array( 'a' => array( 'b' => 1, 'c' => 'invalid' ) ), $schema ) );
     257                $this->assertWPError(
     258                        rest_validate_value_from_schema(
     259                                array(
     260                                        'a' => array(
     261                                                'b' => 1,
     262                                                'c' => 'invalid',
     263                                        ),
     264                                ), $schema
     265                        )
     266                );
    237267                $this->assertWPError( rest_validate_value_from_schema( array( 'a' => 1 ), $schema ) );
    238268        }
    … …  
    243273                        'properties' => array(
    244274                                'a' => array(
    245                                         'type' => 'number'
     275                                        'type' => 'number',
    246276                                ),
    247277                        ),
    … …  
    252282        public function test_type_unknown() {
    253283                $schema = array(
    254                         'type'  => 'lalala',
     284                        'type' => 'lalala',
    255285                );
    256286                $this->assertTrue( rest_validate_value_from_schema( 'Best lyrics', $schema ) );
Note: See TracChangeset for help on using the changeset viewer.