- Timestamp:
- 09/02/2020 12:35:36 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-schema-sanitization.php
r48357 r48937 17 17 ); 18 18 $this->assertEquals( 1, rest_sanitize_value_from_schema( 1, $schema ) ); 19 $this->assert Equals( 1.10, rest_sanitize_value_from_schema( '1.10', $schema ) );19 $this->assertSame( 1.10, rest_sanitize_value_from_schema( '1.10', $schema ) ); 20 20 $this->assertEquals( 1, rest_sanitize_value_from_schema( '1abc', $schema ) ); 21 21 $this->assertEquals( 0, rest_sanitize_value_from_schema( 'abc', $schema ) ); … … 27 27 'type' => 'integer', 28 28 ); 29 $this->assert Equals( 1, rest_sanitize_value_from_schema( 1, $schema ) );30 $this->assert Equals( 1, rest_sanitize_value_from_schema( '1.10', $schema ) );31 $this->assert Equals( 1, rest_sanitize_value_from_schema( '1abc', $schema ) );32 $this->assert Equals( 0, rest_sanitize_value_from_schema( 'abc', $schema ) );33 $this->assert Equals( 0, rest_sanitize_value_from_schema( array(), $schema ) );29 $this->assertSame( 1, rest_sanitize_value_from_schema( 1, $schema ) ); 30 $this->assertSame( 1, rest_sanitize_value_from_schema( '1.10', $schema ) ); 31 $this->assertSame( 1, rest_sanitize_value_from_schema( '1abc', $schema ) ); 32 $this->assertSame( 0, rest_sanitize_value_from_schema( 'abc', $schema ) ); 33 $this->assertSame( 0, rest_sanitize_value_from_schema( array(), $schema ) ); 34 34 } 35 35 … … 38 38 'type' => 'string', 39 39 ); 40 $this->assert Equals( 'Hello', rest_sanitize_value_from_schema( 'Hello', $schema ) );41 $this->assert Equals( '1.10', rest_sanitize_value_from_schema( '1.10', $schema ) );42 $this->assert Equals( '1.1', rest_sanitize_value_from_schema( 1.1, $schema ) );43 $this->assert Equals( '1', rest_sanitize_value_from_schema( 1, $schema ) );40 $this->assertSame( 'Hello', rest_sanitize_value_from_schema( 'Hello', $schema ) ); 41 $this->assertSame( '1.10', rest_sanitize_value_from_schema( '1.10', $schema ) ); 42 $this->assertSame( '1.1', rest_sanitize_value_from_schema( 1.1, $schema ) ); 43 $this->assertSame( '1', rest_sanitize_value_from_schema( 1, $schema ) ); 44 44 } 45 45 … … 48 48 'type' => 'boolean', 49 49 ); 50 $this->assert Equals( true,rest_sanitize_value_from_schema( '1', $schema ) );51 $this->assert Equals( true,rest_sanitize_value_from_schema( 'true', $schema ) );52 $this->assert Equals( true,rest_sanitize_value_from_schema( '100', $schema ) );53 $this->assert Equals( true,rest_sanitize_value_from_schema( 1, $schema ) );54 $this->assert Equals( false,rest_sanitize_value_from_schema( '0', $schema ) );55 $this->assert Equals( false,rest_sanitize_value_from_schema( 'false', $schema ) );56 $this->assert Equals( false,rest_sanitize_value_from_schema( 0, $schema ) );50 $this->assertTrue( rest_sanitize_value_from_schema( '1', $schema ) ); 51 $this->assertTrue( rest_sanitize_value_from_schema( 'true', $schema ) ); 52 $this->assertTrue( rest_sanitize_value_from_schema( '100', $schema ) ); 53 $this->assertTrue( rest_sanitize_value_from_schema( 1, $schema ) ); 54 $this->assertFalse( rest_sanitize_value_from_schema( '0', $schema ) ); 55 $this->assertFalse( rest_sanitize_value_from_schema( 'false', $schema ) ); 56 $this->assertFalse( rest_sanitize_value_from_schema( 0, $schema ) ); 57 57 } 58 58 … … 62 62 'format' => 'email', 63 63 ); 64 $this->assert Equals( 'email@example.com', rest_sanitize_value_from_schema( 'email@example.com', $schema ) );65 $this->assert Equals( 'a@b.c', rest_sanitize_value_from_schema( 'a@b.c', $schema ) );66 $this->assert Equals( 'invalid', rest_sanitize_value_from_schema( 'invalid', $schema ) );64 $this->assertSame( 'email@example.com', rest_sanitize_value_from_schema( 'email@example.com', $schema ) ); 65 $this->assertSame( 'a@b.c', rest_sanitize_value_from_schema( 'a@b.c', $schema ) ); 66 $this->assertSame( 'invalid', rest_sanitize_value_from_schema( 'invalid', $schema ) ); 67 67 } 68 68 … … 73 73 ); 74 74 75 $this->assert Equals( '127.0.0.1', rest_sanitize_value_from_schema( '127.0.0.1', $schema ) );76 $this->assert Equals( 'hello', rest_sanitize_value_from_schema( 'hello', $schema ) );77 $this->assert Equals( '2001:DB8:0:0:8:800:200C:417A', rest_sanitize_value_from_schema( '2001:DB8:0:0:8:800:200C:417A', $schema ) );75 $this->assertSame( '127.0.0.1', rest_sanitize_value_from_schema( '127.0.0.1', $schema ) ); 76 $this->assertSame( 'hello', rest_sanitize_value_from_schema( 'hello', $schema ) ); 77 $this->assertSame( '2001:DB8:0:0:8:800:200C:417A', rest_sanitize_value_from_schema( '2001:DB8:0:0:8:800:200C:417A', $schema ) ); 78 78 } 79 79 … … 86 86 'format' => 'hex-color', 87 87 ); 88 $this->assert Equals( '#000000', rest_sanitize_value_from_schema( '#000000', $schema ) );89 $this->assert Equals( '#FFF', rest_sanitize_value_from_schema( '#FFF', $schema ) );90 $this->assert Equals( '', rest_sanitize_value_from_schema( 'WordPress', $schema ) );88 $this->assertSame( '#000000', rest_sanitize_value_from_schema( '#000000', $schema ) ); 89 $this->assertSame( '#FFF', rest_sanitize_value_from_schema( '#FFF', $schema ) ); 90 $this->assertSame( '', rest_sanitize_value_from_schema( 'WordPress', $schema ) ); 91 91 } 92 92 … … 99 99 'format' => 'uuid', 100 100 ); 101 $this->assert Equals( '44', rest_sanitize_value_from_schema( 44, $schema ) );102 $this->assert Equals( 'hello', rest_sanitize_value_from_schema( 'hello', $schema ) );103 $this->assert Equals(101 $this->assertSame( '44', rest_sanitize_value_from_schema( 44, $schema ) ); 102 $this->assertSame( 'hello', rest_sanitize_value_from_schema( 'hello', $schema ) ); 103 $this->assertSame( 104 104 '123e4567-e89b-12d3-a456-426655440000', 105 105 rest_sanitize_value_from_schema( '123e4567-e89b-12d3-a456-426655440000', $schema ) … … 152 152 ), 153 153 ); 154 $this->assert Equals( array( 'ribs', 'brisket' ), rest_sanitize_value_from_schema( array( 'ribs', 'brisket' ), $schema ) );155 $this->assert Equals( array( 'coleslaw' ), rest_sanitize_value_from_schema( array( 'coleslaw' ), $schema ) );154 $this->assertSame( array( 'ribs', 'brisket' ), rest_sanitize_value_from_schema( array( 'ribs', 'brisket' ), $schema ) ); 155 $this->assertSame( array( 'coleslaw' ), rest_sanitize_value_from_schema( array( 'coleslaw' ), $schema ) ); 156 156 } 157 157 … … 164 164 ), 165 165 ); 166 $this->assert Equals( array( 'ribs', 'chicken' ), rest_sanitize_value_from_schema( 'ribs,chicken', $schema ) );167 $this->assert Equals( array( 'chicken', 'coleslaw' ), rest_sanitize_value_from_schema( 'chicken,coleslaw', $schema ) );168 $this->assert Equals( array( 'chicken', 'coleslaw' ), rest_sanitize_value_from_schema( 'chicken,coleslaw,', $schema ) );166 $this->assertSame( array( 'ribs', 'chicken' ), rest_sanitize_value_from_schema( 'ribs,chicken', $schema ) ); 167 $this->assertSame( array( 'chicken', 'coleslaw' ), rest_sanitize_value_from_schema( 'chicken,coleslaw', $schema ) ); 168 $this->assertSame( array( 'chicken', 'coleslaw' ), rest_sanitize_value_from_schema( 'chicken,coleslaw,', $schema ) ); 169 169 } 170 170 … … 176 176 ), 177 177 ); 178 $this->assert Equals(178 $this->assertSame( 179 179 array( '1', '2' ), 180 180 rest_sanitize_value_from_schema( … … 290 290 ) 291 291 ); 292 $this->assert Equals( array( 'a' => array() ), rest_sanitize_value_from_schema( array( 'a' => null ), $schema ) );292 $this->assertSame( array( 'a' => array() ), rest_sanitize_value_from_schema( array( 'a' => null ), $schema ) ); 293 293 } 294 294 … … 309 309 */ 310 310 public function test_type_object_accepts_empty_string() { 311 $this->assert Equals( array(), rest_sanitize_value_from_schema( '', array( 'type' => 'object' ) ) );311 $this->assertSame( array(), rest_sanitize_value_from_schema( '', array( 'type' => 'object' ) ) ); 312 312 } 313 313 … … 318 318 'type' => 'lalala', 319 319 ); 320 $this->assert Equals( 'Best lyrics', rest_sanitize_value_from_schema( 'Best lyrics', $schema ) );321 $this->assert Equals( 1.10, rest_sanitize_value_from_schema( 1.10, $schema ) );322 $this->assert Equals( 1, rest_sanitize_value_from_schema( 1, $schema ) );320 $this->assertSame( 'Best lyrics', rest_sanitize_value_from_schema( 'Best lyrics', $schema ) ); 321 $this->assertSame( 1.10, rest_sanitize_value_from_schema( 1.10, $schema ) ); 322 $this->assertSame( 1, rest_sanitize_value_from_schema( 1, $schema ) ); 323 323 } 324 324 … … 329 329 'type' => null, 330 330 ); 331 $this->assert Equals( 'Nothing', rest_sanitize_value_from_schema( 'Nothing', $schema ) );332 $this->assert Equals( 1.10, rest_sanitize_value_from_schema( 1.10, $schema ) );333 $this->assert Equals( 1, rest_sanitize_value_from_schema( 1, $schema ) );331 $this->assertSame( 'Nothing', rest_sanitize_value_from_schema( 'Nothing', $schema ) ); 332 $this->assertSame( 1.10, rest_sanitize_value_from_schema( 1.10, $schema ) ); 333 $this->assertSame( 1, rest_sanitize_value_from_schema( 1, $schema ) ); 334 334 } 335 335 … … 341 341 342 342 $this->assertNull( rest_sanitize_value_from_schema( null, $schema ) ); 343 $this->assert Equals( '2019-09-19T18:00:00', rest_sanitize_value_from_schema( '2019-09-19T18:00:00', $schema ) );344 $this->assert Equals( 'lalala', rest_sanitize_value_from_schema( 'lalala', $schema ) );343 $this->assertSame( '2019-09-19T18:00:00', rest_sanitize_value_from_schema( '2019-09-19T18:00:00', $schema ) ); 344 $this->assertSame( 'lalala', rest_sanitize_value_from_schema( 'lalala', $schema ) ); 345 345 } 346 346 … … 353 353 'format' => 'hex-color', 354 354 ); 355 $this->assert Equals( array( '#fff' ), rest_sanitize_value_from_schema( '#fff', $schema ) );356 $this->assert Equals( array( '#qrst' ), rest_sanitize_value_from_schema( '#qrst', $schema ) );355 $this->assertSame( array( '#fff' ), rest_sanitize_value_from_schema( '#fff', $schema ) ); 356 $this->assertSame( array( '#qrst' ), rest_sanitize_value_from_schema( '#qrst', $schema ) ); 357 357 } 358 358 … … 365 365 366 366 $schema = array( 'format' => 'hex-color' ); 367 $this->assert Equals( '#abc', rest_sanitize_value_from_schema( '#abc', $schema ) );368 $this->assert Equals( '', rest_sanitize_value_from_schema( '#jkl', $schema ) );367 $this->assertSame( '#abc', rest_sanitize_value_from_schema( '#abc', $schema ) ); 368 $this->assertSame( '', rest_sanitize_value_from_schema( '#jkl', $schema ) ); 369 369 } 370 370 … … 379 379 'type' => 'str', 380 380 ); 381 $this->assert Equals( '#abc', rest_sanitize_value_from_schema( '#abc', $schema ) );382 $this->assert Equals( '', rest_sanitize_value_from_schema( '#jkl', $schema ) );381 $this->assertSame( '#abc', rest_sanitize_value_from_schema( '#abc', $schema ) ); 382 $this->assertSame( '', rest_sanitize_value_from_schema( '#jkl', $schema ) ); 383 383 } 384 384 … … 393 393 ); 394 394 395 $this->assert Equals( 'My Value', rest_sanitize_value_from_schema( 'My Value', $schema ) );396 $this->assert Equals( array( 'raw' => 'My Value' ), rest_sanitize_value_from_schema( array( 'raw' => 'My Value' ), $schema ) );397 $this->assert Equals( array( 'raw' => '1' ), rest_sanitize_value_from_schema( array( 'raw' => 1 ), $schema ) );395 $this->assertSame( 'My Value', rest_sanitize_value_from_schema( 'My Value', $schema ) ); 396 $this->assertSame( array( 'raw' => 'My Value' ), rest_sanitize_value_from_schema( array( 'raw' => 'My Value' ), $schema ) ); 397 $this->assertSame( array( 'raw' => '1' ), rest_sanitize_value_from_schema( array( 'raw' => 1 ), $schema ) ); 398 398 } 399 399 … … 416 416 $this->assertFalse( rest_sanitize_value_from_schema( 0, $schema ) ); 417 417 418 $this->assert Equals( array( 'raw' => true ), rest_sanitize_value_from_schema( array( 'raw' => true ), $schema ) );419 $this->assert Equals( array( 'raw' => true ), rest_sanitize_value_from_schema( array( 'raw' => '1' ), $schema ) );420 $this->assert Equals( array( 'raw' => true ), rest_sanitize_value_from_schema( array( 'raw' => 1 ), $schema ) );421 422 $this->assert Equals( array( 'raw' => false ), rest_sanitize_value_from_schema( array( 'raw' => false ), $schema ) );423 $this->assert Equals( array( 'raw' => false ), rest_sanitize_value_from_schema( array( 'raw' => '0' ), $schema ) );424 $this->assert Equals( array( 'raw' => false ), rest_sanitize_value_from_schema( array( 'raw' => 0 ), $schema ) );425 426 $this->assert Equals( array( 'raw' => true ), rest_sanitize_value_from_schema( array( 'raw' => 'something non boolean' ), $schema ) );418 $this->assertSame( array( 'raw' => true ), rest_sanitize_value_from_schema( array( 'raw' => true ), $schema ) ); 419 $this->assertSame( array( 'raw' => true ), rest_sanitize_value_from_schema( array( 'raw' => '1' ), $schema ) ); 420 $this->assertSame( array( 'raw' => true ), rest_sanitize_value_from_schema( array( 'raw' => 1 ), $schema ) ); 421 422 $this->assertSame( array( 'raw' => false ), rest_sanitize_value_from_schema( array( 'raw' => false ), $schema ) ); 423 $this->assertSame( array( 'raw' => false ), rest_sanitize_value_from_schema( array( 'raw' => '0' ), $schema ) ); 424 $this->assertSame( array( 'raw' => false ), rest_sanitize_value_from_schema( array( 'raw' => 0 ), $schema ) ); 425 426 $this->assertSame( array( 'raw' => true ), rest_sanitize_value_from_schema( array( 'raw' => 'something non boolean' ), $schema ) ); 427 427 } 428 428 … … 438 438 ); 439 439 440 $this->assert Equals( 'My Value', rest_sanitize_value_from_schema( 'My Value', $schema ) );440 $this->assertSame( 'My Value', rest_sanitize_value_from_schema( 'My Value', $schema ) ); 441 441 } 442 442 … … 452 452 ); 453 453 454 $this->assert Equals( 'My Value', rest_sanitize_value_from_schema( 'My Value', $schema ) );454 $this->assertSame( 'My Value', rest_sanitize_value_from_schema( 'My Value', $schema ) ); 455 455 } 456 456
Note: See TracChangeset
for help on using the changeset viewer.