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

    r42000 r42343  
    1414    public function test_type_number() {
    1515        $schema = array(
    16             'type'    => 'number',
     16            'type' => 'number',
    1717        );
    1818        $this->assertEquals( 1, rest_sanitize_value_from_schema( 1, $schema ) );
     
    5858    public function test_format_email() {
    5959        $schema = array(
    60             'type'  => 'string',
     60            'type'   => 'string',
    6161            'format' => 'email',
    6262        );
     
    6868    public function test_format_ip() {
    6969        $schema = array(
    70             'type'  => 'string',
     70            'type'   => 'string',
    7171            'format' => 'ip',
    7272        );
     
    7979    public function test_type_array() {
    8080        $schema = array(
    81             'type' => 'array',
     81            'type'  => 'array',
    8282            'items' => array(
    8383                'type' => 'number',
     
    9090    public function test_type_array_nested() {
    9191        $schema = array(
    92             'type' => 'array',
    93             'items' => array(
    94                 'type' => 'array',
     92            'type'  => 'array',
     93            'items' => array(
     94                'type'  => 'array',
    9595                'items' => array(
    9696                    'type' => 'number',
     
    104104    public function test_type_array_as_csv() {
    105105        $schema = array(
    106             'type' => 'array',
     106            'type'  => 'array',
    107107            'items' => array(
    108108                'type' => 'number',
     
    139139    public function test_type_array_is_associative() {
    140140        $schema = array(
    141             'type' => 'array',
     141            'type'  => 'array',
    142142            'items' => array(
    143143                'type' => 'string',
    144144            ),
    145145        );
    146         $this->assertEquals( array( '1', '2' ), rest_sanitize_value_from_schema( array( 'first' => '1', 'second' => '2' ), $schema ) );
     146        $this->assertEquals(
     147            array( '1', '2' ), rest_sanitize_value_from_schema(
     148                array(
     149                    'first'  => '1',
     150                    'second' => '2',
     151                ), $schema
     152            )
     153        );
    147154    }
    148155
     
    152159            'properties' => array(
    153160                'a' => array(
    154                     'type' => 'number'
     161                    'type' => 'number',
    155162                ),
    156163            ),
     
    158165        $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => 1 ), $schema ) );
    159166        $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => '1' ), $schema ) );
    160         $this->assertEquals( array( 'a' => 1, 'b' => 1 ), rest_sanitize_value_from_schema( array( 'a' => '1', 'b' => 1 ), $schema ) );
     167        $this->assertEquals(
     168            array(
     169                'a' => 1,
     170                'b' => 1,
     171            ), rest_sanitize_value_from_schema(
     172                array(
     173                    'a' => '1',
     174                    'b' => 1,
     175                ), $schema
     176            )
     177        );
    161178    }
    162179
    163180    public function test_type_object_strips_additional_properties() {
     181        $schema = array(
     182            'type'                 => 'object',
     183            'properties'           => array(
     184                'a' => array(
     185                    'type' => 'number',
     186                ),
     187            ),
     188            'additionalProperties' => false,
     189        );
     190        $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => 1 ), $schema ) );
     191        $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => '1' ), $schema ) );
     192        $this->assertEquals(
     193            array( 'a' => 1 ), rest_sanitize_value_from_schema(
     194                array(
     195                    'a' => '1',
     196                    'b' => 1,
     197                ), $schema
     198            )
     199        );
     200    }
     201
     202    public function test_type_object_nested() {
    164203        $schema = array(
    165204            'type'       => 'object',
    166205            'properties' => array(
    167206                'a' => array(
    168                     'type' => 'number',
    169                 ),
    170             ),
    171             'additionalProperties' => false,
    172         );
    173         $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => 1 ), $schema ) );
    174         $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => '1' ), $schema ) );
    175         $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => '1', 'b' => 1 ), $schema ) );
    176     }
    177 
    178     public function test_type_object_nested() {
    179         $schema = array(
    180             'type' => 'object',
    181             'properties' => array(
    182                 'a' => array(
    183                     'type'  => 'object',
     207                    'type'       => 'object',
    184208                    'properties' => array(
    185209                        'b' => array( 'type' => 'number' ),
    186210                        'c' => array( 'type' => 'number' ),
    187                     )
    188                 )
     211                    ),
     212                ),
    189213            ),
    190214        );
     
    236260            'properties' => array(
    237261                'a' => array(
    238                     'type' => 'number'
     262                    'type' => 'number',
    239263                ),
    240264            ),
Note: See TracChangeset for help on using the changeset viewer.