mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
REST API: Support the multipleOf JSON Schema keyword.
Props yakimun. Fixes #51022. git-svn-id: https://develop.svn.wordpress.org/trunk@49063 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -281,7 +281,7 @@ class WP_Test_REST_Controller extends WP_Test_REST_TestCase {
|
||||
$this->assertArrayHasKey( $property, $args['somestring'] );
|
||||
}
|
||||
|
||||
foreach ( array( 'minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum' ) as $property ) {
|
||||
foreach ( array( 'multipleOf', 'minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum' ) as $property ) {
|
||||
$this->assertArrayHasKey( $property, $args['someinteger'] );
|
||||
}
|
||||
|
||||
|
||||
@@ -435,6 +435,42 @@ class WP_Test_REST_Schema_Validation extends WP_UnitTestCase {
|
||||
$this->assertSame( 'param must be between 10 (inclusive) and 20 (inclusive)', $error->get_error_message() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 51022
|
||||
*
|
||||
* @dataProvider data_multiply_of
|
||||
*
|
||||
* @param int|float $value
|
||||
* @param int|float $divisor
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function test_numeric_multiple_of( $value, $divisor, $expected ) {
|
||||
$schema = array(
|
||||
'type' => 'number',
|
||||
'multipleOf' => $divisor,
|
||||
);
|
||||
|
||||
$result = rest_validate_value_from_schema( $value, $schema );
|
||||
|
||||
if ( $expected ) {
|
||||
$this->assertTrue( $result );
|
||||
} else {
|
||||
$this->assertWPError( $result );
|
||||
}
|
||||
}
|
||||
|
||||
public function data_multiply_of() {
|
||||
return array(
|
||||
array( 0, 2, true ),
|
||||
array( 4, 2, true ),
|
||||
array( 3, 1.5, true ),
|
||||
array( 2.4, 1.2, true ),
|
||||
array( 1, 2, false ),
|
||||
array( 2, 1.5, false ),
|
||||
array( 2.1, 1.5, false ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 50300
|
||||
*/
|
||||
|
||||
@@ -46,6 +46,7 @@ class WP_REST_Test_Controller extends WP_REST_Controller {
|
||||
),
|
||||
'someinteger' => array(
|
||||
'type' => 'integer',
|
||||
'multipleOf' => 10,
|
||||
'minimum' => 100,
|
||||
'maximum' => 200,
|
||||
'exclusiveMinimum' => true,
|
||||
|
||||
Reference in New Issue
Block a user