WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/04/2020 04:41:47 PM (16 months ago)
Author:
whyisjake
Message:

REST API: Ensure that all properties of get_endpoint_args_for_item_schema are listed.

  • Add new var $valid_schema_properties to match rest_validate_value_from_schema()
  • Unit test to ensure all valid properties exists, and non-valid properties are ignored

Fixes: #50301.
Props: pentatonicfunk, TimothyBlynJacobs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-controller.php

    r47753 r47911  
    246246
    247247        $this->assertEquals( 'a', $args['somedefault']['default'] );
     248    }
     249
     250    /**
     251     * @ticket 50301
     252     */
     253    public function test_get_endpoint_args_for_item_schema_arg_properties() {
     254
     255        $controller = new WP_REST_Test_Controller();
     256        $args       = $controller->get_endpoint_args_for_item_schema();
     257
     258        foreach ( array( 'minLength', 'maxLength', 'pattern' ) as $property ) {
     259            $this->assertArrayHasKey( $property, $args['somestring'] );
     260        }
     261
     262        foreach ( array( 'minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum' ) as $property ) {
     263            $this->assertArrayHasKey( $property, $args['someinteger'] );
     264        }
     265
     266        $this->assertArrayHasKey( 'items', $args['somearray'] );
     267
     268        foreach ( array( 'properties', 'additionalProperties' ) as $property ) {
     269            $this->assertArrayHasKey( $property, $args['someobject'] );
     270        }
     271
     272        // ignored properties
     273        $this->assertArrayNotHasKey( 'ignored_prop', $args['someobject'] );
     274
    248275    }
    249276
     
    268295                'someargoptions',
    269296                'somedefault',
     297                'somearray',
     298                'someobject',
    270299            ),
    271300            $fields
     
    299328                    'someargoptions',
    300329                    'somedefault',
     330                    'somearray',
     331                    'someobject',
    301332                ),
    302333            ),
Note: See TracChangeset for help on using the changeset viewer.