mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
REST API: Support the minProperties and maxProperties JSON Schema keywords.
Props yakimun. Fixes #51023. git-svn-id: https://develop.svn.wordpress.org/trunk@49053 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -291,7 +291,7 @@ class WP_Test_REST_Controller extends WP_Test_REST_TestCase {
|
||||
$this->assertArrayHasKey( $property, $args['somearray'] );
|
||||
}
|
||||
|
||||
foreach ( array( 'properties', 'additionalProperties' ) as $property ) {
|
||||
foreach ( array( 'properties', 'additionalProperties', 'minProperties', 'maxProperties' ) as $property ) {
|
||||
$this->assertArrayHasKey( $property, $args['someobject'] );
|
||||
}
|
||||
|
||||
|
||||
@@ -836,6 +836,61 @@ class WP_Test_REST_Schema_Validation extends WP_UnitTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 51023
|
||||
*/
|
||||
public function test_object_min_properties() {
|
||||
$schema = array(
|
||||
'type' => 'object',
|
||||
'minProperties' => 1,
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
rest_validate_value_from_schema(
|
||||
array(
|
||||
'propA' => 'a',
|
||||
'propB' => 'b',
|
||||
),
|
||||
$schema
|
||||
)
|
||||
);
|
||||
$this->assertTrue( rest_validate_value_from_schema( array( 'propA' => 'a' ), $schema ) );
|
||||
$this->assertWPError( rest_validate_value_from_schema( array(), $schema ) );
|
||||
$this->assertWPError( rest_validate_value_from_schema( '', $schema ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 51023
|
||||
*/
|
||||
public function test_object_max_properties() {
|
||||
$schema = array(
|
||||
'type' => 'object',
|
||||
'maxProperties' => 2,
|
||||
);
|
||||
|
||||
$this->assertTrue( rest_validate_value_from_schema( array( 'propA' => 'a' ), $schema ) );
|
||||
$this->assertTrue(
|
||||
rest_validate_value_from_schema(
|
||||
array(
|
||||
'propA' => 'a',
|
||||
'propB' => 'b',
|
||||
),
|
||||
$schema
|
||||
)
|
||||
);
|
||||
$this->assertWPError(
|
||||
rest_validate_value_from_schema(
|
||||
array(
|
||||
'propA' => 'a',
|
||||
'propB' => 'b',
|
||||
'propC' => 'c',
|
||||
),
|
||||
$schema
|
||||
)
|
||||
);
|
||||
$this->assertWPError( rest_validate_value_from_schema( 'foobar', $schema ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44949
|
||||
*/
|
||||
|
||||
@@ -120,6 +120,8 @@ class WP_REST_Test_Controller extends WP_REST_Controller {
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
'minProperties' => 1,
|
||||
'maxProperties' => 10,
|
||||
'ignored_prop' => 'ignored_prop',
|
||||
'context' => array( 'view' ),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user