mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
REST API: Support the (min|max)Length JSON Schema keywords.
Props sorenbronsted. Fixes #48820. git-svn-id: https://develop.svn.wordpress.org/trunk@47627 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -348,4 +348,52 @@ class WP_Test_REST_Schema_Validation extends WP_UnitTestCase {
|
||||
$this->assertTrue( rest_validate_value_from_schema( array( 'raw' => 'My Value' ), $schema ) );
|
||||
$this->assertWPError( rest_validate_value_from_schema( array( 'raw' => array( 'a list' ) ), $schema ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 48820
|
||||
*/
|
||||
public function test_string_min_length() {
|
||||
$schema = array(
|
||||
'type' => 'string',
|
||||
'minLength' => 2,
|
||||
);
|
||||
|
||||
// longer
|
||||
$this->assertTrue( rest_validate_value_from_schema( 'foo', $schema ) );
|
||||
// exact
|
||||
$this->assertTrue( rest_validate_value_from_schema( 'fo', $schema ) );
|
||||
// non-strings does not validate
|
||||
$this->assertWPError( rest_validate_value_from_schema( 1, $schema ) );
|
||||
// to short
|
||||
$this->assertWPError( rest_validate_value_from_schema( 'f', $schema ) );
|
||||
// one supplementary Unicode code point is not long enough
|
||||
$mb_char = mb_convert_encoding( 'က', 'UTF-8', 'HTML-ENTITIES' );
|
||||
$this->assertWPError( rest_validate_value_from_schema( $mb_char, $schema ) );
|
||||
// two supplementary Unicode code point is long enough
|
||||
$this->assertTrue( rest_validate_value_from_schema( $mb_char . $mb_char, $schema ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 48820
|
||||
*/
|
||||
public function test_string_max_length() {
|
||||
$schema = array(
|
||||
'type' => 'string',
|
||||
'maxLength' => 2,
|
||||
);
|
||||
|
||||
// shorter
|
||||
$this->assertTrue( rest_validate_value_from_schema( 'f', $schema ) );
|
||||
// exact
|
||||
$this->assertTrue( rest_validate_value_from_schema( 'fo', $schema ) );
|
||||
// to long
|
||||
$this->assertWPError( rest_validate_value_from_schema( 'foo', $schema ) );
|
||||
// non string
|
||||
$this->assertWPError( rest_validate_value_from_schema( 100, $schema ) );
|
||||
// two supplementary Unicode code point is long enough
|
||||
$mb_char = mb_convert_encoding( 'က', 'UTF-8', 'HTML-ENTITIES' );
|
||||
$this->assertTrue( rest_validate_value_from_schema( $mb_char, $schema ) );
|
||||
// three supplementary Unicode code point is to long
|
||||
$this->assertWPError( rest_validate_value_from_schema( $mb_char . $mb_char . $mb_char, $schema ) );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user