Changeset 49063
- Timestamp:
- 09/27/2020 07:01:18 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r49054 r49063 1553 1553 * Validate required properties. 1554 1554 * @since 5.6.0 Support the "minProperties" and "maxProperties" keywords for objects. 1555 * Support the "multipleOf" keyword for numbers and integers. 1555 1556 * 1556 1557 * @param mixed $value The value to validate. … … 1692 1693 } 1693 1694 1694 if ( in_array( $args['type'], array( 'integer', 'number' ), true ) && ! is_numeric( $value ) ) { 1695 /* translators: 1: Parameter, 2: Type name. */ 1696 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, $args['type'] ) ); 1695 if ( in_array( $args['type'], array( 'integer', 'number' ), true ) ) { 1696 if ( ! is_numeric( $value ) ) { 1697 /* translators: 1: Parameter, 2: Type name. */ 1698 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, $args['type'] ) ); 1699 } 1700 1701 if ( isset( $args['multipleOf'] ) && fmod( $value, $args['multipleOf'] ) !== 0.0 ) { 1702 /* translators: 1: Parameter, 2: Multiplier. */ 1703 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be a multiple of %2$s.' ), $param, $args['multipleOf'] ) ); 1704 } 1697 1705 } 1698 1706 … … 2299 2307 'exclusiveMinimum', 2300 2308 'exclusiveMaximum', 2309 'multipleOf', 2301 2310 'minLength', 2302 2311 'maxLength', -
trunk/tests/phpunit/tests/rest-api/rest-controller.php
r49053 r49063 282 282 } 283 283 284 foreach ( array( 'm inimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum' ) as $property ) {284 foreach ( array( 'multipleOf', 'minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum' ) as $property ) { 285 285 $this->assertArrayHasKey( $property, $args['someinteger'] ); 286 286 } -
trunk/tests/phpunit/tests/rest-api/rest-schema-validation.php
r49053 r49063 434 434 $this->assertWPError( $error ); 435 435 $this->assertSame( 'param must be between 10 (inclusive) and 20 (inclusive)', $error->get_error_message() ); 436 } 437 438 /** 439 * @ticket 51022 440 * 441 * @dataProvider data_multiply_of 442 * 443 * @param int|float $value 444 * @param int|float $divisor 445 * @param bool $expected 446 */ 447 public function test_numeric_multiple_of( $value, $divisor, $expected ) { 448 $schema = array( 449 'type' => 'number', 450 'multipleOf' => $divisor, 451 ); 452 453 $result = rest_validate_value_from_schema( $value, $schema ); 454 455 if ( $expected ) { 456 $this->assertTrue( $result ); 457 } else { 458 $this->assertWPError( $result ); 459 } 460 } 461 462 public function data_multiply_of() { 463 return array( 464 array( 0, 2, true ), 465 array( 4, 2, true ), 466 array( 3, 1.5, true ), 467 array( 2.4, 1.2, true ), 468 array( 1, 2, false ), 469 array( 2, 1.5, false ), 470 array( 2.1, 1.5, false ), 471 ); 436 472 } 437 473 -
trunk/tests/phpunit/tests/rest-api/rest-test-controller.php
r49053 r49063 47 47 'someinteger' => array( 48 48 'type' => 'integer', 49 'multipleOf' => 10, 49 50 'minimum' => 100, 50 51 'maximum' => 200,
Note: See TracChangeset
for help on using the changeset viewer.