- Timestamp:
- 07/04/2020 07:51:10 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-schema-sanitization.php
r47753 r48300 313 313 314 314 public function test_type_unknown() { 315 $this->setExpectedIncorrectUsage( 'rest_sanitize_value_from_schema' ); 316 315 317 $schema = array( 316 318 'type' => 'lalala', … … 322 324 323 325 public function test_no_type() { 326 $this->setExpectedIncorrectUsage( 'rest_sanitize_value_from_schema' ); 327 324 328 $schema = array( 325 329 'type' => null, … … 339 343 $this->assertEquals( '2019-09-19T18:00:00', rest_sanitize_value_from_schema( '2019-09-19T18:00:00', $schema ) ); 340 344 $this->assertNull( rest_sanitize_value_from_schema( 'lalala', $schema ) ); 345 } 346 347 /** 348 * @ticket 50189 349 */ 350 public function test_format_validation_is_skipped_if_non_string_type() { 351 $schema = array( 352 'type' => 'array', 353 'format' => 'hex-color', 354 ); 355 $this->assertEquals( array( '#fff' ), rest_sanitize_value_from_schema( '#fff', $schema ) ); 356 $this->assertEquals( array( '#qrst' ), rest_sanitize_value_from_schema( '#qrst', $schema ) ); 357 } 358 359 /** 360 * @ticket 50189 361 */ 362 public function test_format_validation_is_applied_if_missing_type() { 363 $this->expectException( 'PHPUnit_Framework_Error_Notice' ); // For the undefined index. 364 $this->setExpectedIncorrectUsage( 'rest_sanitize_value_from_schema' ); 365 366 $schema = array( 'format' => 'hex-color' ); 367 $this->assertEquals( '#abc', rest_sanitize_value_from_schema( '#abc', $schema ) ); 368 $this->assertEquals( '', rest_sanitize_value_from_schema( '#jkl', $schema ) ); 369 } 370 371 /** 372 * @ticket 50189 373 */ 374 public function test_format_validation_is_applied_if_unknown_type() { 375 $this->setExpectedIncorrectUsage( 'rest_sanitize_value_from_schema' ); 376 377 $schema = array( 378 'format' => 'hex-color', 379 'type' => 'str', 380 ); 381 $this->assertEquals( '#abc', rest_sanitize_value_from_schema( '#abc', $schema ) ); 382 $this->assertEquals( '', rest_sanitize_value_from_schema( '#jkl', $schema ) ); 341 383 } 342 384
Note: See TracChangeset
for help on using the changeset viewer.