Changeset 47911
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
r47758 r47911 627 627 public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) { 628 628 629 $schema = $this->get_item_schema(); 630 $schema_properties = ! empty( $schema['properties'] ) ? $schema['properties'] : array(); 631 $endpoint_args = array(); 629 $schema = $this->get_item_schema(); 630 $schema_properties = ! empty( $schema['properties'] ) ? $schema['properties'] : array(); 631 $endpoint_args = array(); 632 $valid_schema_properties = array( 633 'type', 634 'format', 635 'enum', 636 'items', 637 'properties', 638 'additionalProperties', 639 'minimum', 640 'maximum', 641 'exclusiveMinimum', 642 'exclusiveMaximum', 643 'minLength', 644 'maxLength', 645 'pattern', 646 ); 632 647 633 648 foreach ( $schema_properties as $field_id => $params ) { … … 655 670 } 656 671 657 foreach ( array( 'type', 'format', 'enum', 'items', 'properties', 'additionalProperties' )as $schema_prop ) {672 foreach ( $valid_schema_properties as $schema_prop ) { 658 673 if ( isset( $params[ $schema_prop ] ) ) { 659 674 $endpoint_args[ $field_id ][ $schema_prop ] = $params[ $schema_prop ]; -
trunk/tests/phpunit/tests/rest-api/rest-controller.php
r47753 r47911 246 246 247 247 $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 248 275 } 249 276 … … 268 295 'someargoptions', 269 296 'somedefault', 297 'somearray', 298 'someobject', 270 299 ), 271 300 $fields … … 299 328 'someargoptions', 300 329 'somedefault', 330 'somearray', 331 'someobject', 301 332 ), 302 333 ), -
trunk/tests/phpunit/tests/rest-api/rest-test-controller.php
r47753 r47911 40 40 'type' => 'string', 41 41 'description' => 'A pretty string.', 42 'minLength' => 3, 43 'maxLength' => 3, 44 'pattern' => '[a-zA-Z]+', 42 45 'context' => array( 'view' ), 43 46 ), 44 47 'someinteger' => array( 45 'type' => 'integer', 46 'context' => array( 'view' ), 48 'type' => 'integer', 49 'minimum' => 100, 50 'maximum' => 200, 51 'exclusiveMinimum' => true, 52 'exclusiveMaximum' => true, 53 'context' => array( 'view' ), 47 54 ), 48 55 'someboolean' => array( … … 94 101 'default' => 'a', 95 102 ), 103 'somearray' => array( 104 'type' => 'array', 105 'items' => array( 106 'type' => 'string', 107 ), 108 'context' => array( 'view' ), 109 ), 110 'someobject' => array( 111 'type' => 'object', 112 'additionalProperties' => array( 113 'type' => 'string', 114 ), 115 'properties' => array( 116 'object_id' => array( 117 'type' => 'integer', 118 ), 119 ), 120 'ignored_prop' => 'ignored_prop', 121 'context' => array( 'view' ), 122 ), 96 123 ), 97 124 );
Note: See TracChangeset
for help on using the changeset viewer.