- Timestamp:
- 09/23/2019 05:24:58 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-schema-validation.php
r44546 r46249 297 297 $this->assertTrue( rest_validate_value_from_schema( array(), $schema ) ); 298 298 } 299 300 public function test_type_null() { 301 $this->assertTrue( rest_validate_value_from_schema( null, array( 'type' => 'null' ) ) ); 302 $this->assertWPError( rest_validate_value_from_schema( '', array( 'type' => 'null' ) ) ); 303 $this->assertWPError( rest_validate_value_from_schema( 'null', array( 'type' => 'null' ) ) ); 304 } 305 306 public function test_nullable_date() { 307 $schema = array( 308 'type' => array( 'string', 'null' ), 309 'format' => 'date-time', 310 ); 311 312 $this->assertTrue( rest_validate_value_from_schema( null, $schema ) ); 313 $this->assertTrue( rest_validate_value_from_schema( '2019-09-19T18:00:00', $schema ) ); 314 $this->assertWPError( rest_validate_value_from_schema( 'some random string', $schema ) ); 315 } 316 317 public function test_object_or_string() { 318 $schema = array( 319 'type' => array( 'object', 'string' ), 320 'properties' => array( 321 'raw' => array( 322 'type' => 'string', 323 ), 324 ), 325 ); 326 327 $this->assertTrue( rest_validate_value_from_schema( 'My Value', $schema ) ); 328 $this->assertTrue( rest_validate_value_from_schema( array( 'raw' => 'My Value' ), $schema ) ); 329 $this->assertWPError( rest_validate_value_from_schema( array( 'raw' => array( 'a list' ) ), $schema ) ); 330 } 299 331 }
Note: See TracChangeset
for help on using the changeset viewer.