Changeset 49053
- Timestamp:
- 09/26/2020 06:18:53 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r48951 r49053 1552 1552 * Support the "minItems", "maxItems" and "uniqueItems" keywords for arrays. 1553 1553 * Validate required properties. 1554 * @since 5.7.0 Support the "minProperties" and "maxProperties" keywords for objects. 1554 1555 * 1555 1556 * @param mixed $value The value to validate. … … 1662 1663 } 1663 1664 } 1665 } 1666 1667 if ( isset( $args['minProperties'] ) && count( $value ) < $args['minProperties'] ) { 1668 /* translators: 1: Parameter, 2: Number. */ 1669 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must contain at least %2$s properties.' ), $param, number_format_i18n( $args['minProperties'] ) ) ); 1670 } 1671 1672 if ( isset( $args['maxProperties'] ) && count( $value ) > $args['maxProperties'] ) { 1673 /* translators: 1: Parameter, 2: Number. */ 1674 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must contain at most %2$s properties.' ), $param, number_format_i18n( $args['maxProperties'] ) ) ); 1664 1675 } 1665 1676 } … … 2282 2293 'properties', 2283 2294 'additionalProperties', 2295 'minProperties', 2296 'maxProperties', 2284 2297 'minimum', 2285 2298 'maximum', -
trunk/tests/phpunit/tests/rest-api/rest-controller.php
r48951 r49053 292 292 } 293 293 294 foreach ( array( 'properties', 'additionalProperties' ) as $property ) {294 foreach ( array( 'properties', 'additionalProperties', 'minProperties', 'maxProperties' ) as $property ) { 295 295 $this->assertArrayHasKey( $property, $args['someobject'] ); 296 296 } -
trunk/tests/phpunit/tests/rest-api/rest-schema-validation.php
r49008 r49053 838 838 839 839 /** 840 * @ticket 51023 841 */ 842 public function test_object_min_properties() { 843 $schema = array( 844 'type' => 'object', 845 'minProperties' => 1, 846 ); 847 848 $this->assertTrue( 849 rest_validate_value_from_schema( 850 array( 851 'propA' => 'a', 852 'propB' => 'b', 853 ), 854 $schema 855 ) 856 ); 857 $this->assertTrue( rest_validate_value_from_schema( array( 'propA' => 'a' ), $schema ) ); 858 $this->assertWPError( rest_validate_value_from_schema( array(), $schema ) ); 859 $this->assertWPError( rest_validate_value_from_schema( '', $schema ) ); 860 } 861 862 /** 863 * @ticket 51023 864 */ 865 public function test_object_max_properties() { 866 $schema = array( 867 'type' => 'object', 868 'maxProperties' => 2, 869 ); 870 871 $this->assertTrue( rest_validate_value_from_schema( array( 'propA' => 'a' ), $schema ) ); 872 $this->assertTrue( 873 rest_validate_value_from_schema( 874 array( 875 'propA' => 'a', 876 'propB' => 'b', 877 ), 878 $schema 879 ) 880 ); 881 $this->assertWPError( 882 rest_validate_value_from_schema( 883 array( 884 'propA' => 'a', 885 'propB' => 'b', 886 'propC' => 'c', 887 ), 888 $schema 889 ) 890 ); 891 $this->assertWPError( rest_validate_value_from_schema( 'foobar', $schema ) ); 892 } 893 894 /** 840 895 * @ticket 44949 841 896 */ -
trunk/tests/phpunit/tests/rest-api/rest-test-controller.php
r48796 r49053 121 121 ), 122 122 ), 123 'minProperties' => 1, 124 'maxProperties' => 10, 123 125 'ignored_prop' => 'ignored_prop', 124 126 'context' => array( 'view' ),
Note: See TracChangeset
for help on using the changeset viewer.