Changeset 53890 for trunk/tests/phpunit/tests/functions.php
- Timestamp:
- 08/13/2022 12:09:41 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/functions.php
r53461 r53890 372 372 373 373 return $formats; 374 }375 376 /**377 * @dataProvider data_is_not_serialized378 */379 public function test_maybe_serialize( $value ) {380 if ( is_array( $value ) || is_object( $value ) ) {381 $expected = serialize( $value );382 } else {383 $expected = $value;384 }385 386 $this->assertSame( $expected, maybe_serialize( $value ) );387 }388 389 /**390 * @dataProvider data_is_serialized391 */392 public function test_maybe_serialize_with_double_serialization( $value ) {393 $expected = serialize( $value );394 395 $this->assertSame( $expected, maybe_serialize( $value ) );396 }397 398 /**399 * @dataProvider data_is_serialized400 * @dataProvider data_is_not_serialized401 */402 public function test_maybe_unserialize( $value, $is_serialized ) {403 if ( $is_serialized ) {404 $expected = unserialize( trim( $value ) );405 } else {406 $expected = $value;407 }408 409 if ( is_object( $expected ) ) {410 $this->assertEquals( $expected, maybe_unserialize( $value ) );411 } else {412 $this->assertSame( $expected, maybe_unserialize( $value ) );413 }414 }415 416 /**417 * @dataProvider data_is_serialized418 * @dataProvider data_is_not_serialized419 */420 public function test_is_serialized( $value, $expected ) {421 $this->assertSame( $expected, is_serialized( $value ) );422 }423 424 /**425 * @dataProvider data_serialize_deserialize_objects426 */427 public function test_deserialize_request_utility_filtered_iterator_objects( $value ) {428 $serialized = maybe_serialize( $value );429 if ( get_class( $value ) === 'Requests_Utility_FilteredIterator' ) {430 $new_value = unserialize( $serialized );431 $property = ( new ReflectionClass( 'Requests_Utility_FilteredIterator' ) )->getProperty( 'callback' );432 $property->setAccessible( true );433 $callback_value = $property->getValue( $new_value );434 $this->assertSame( null, $callback_value );435 } else {436 $this->assertSame( $value->count(), unserialize( $serialized )->count() );437 }438 }439 440 public function data_serialize_deserialize_objects() {441 return array(442 array( new Requests_Utility_FilteredIterator( array( 1 ), 'md5' ) ),443 array( new Requests_Utility_FilteredIterator( array( 1, 2 ), 'sha1' ) ),444 array( new ArrayIterator( array( 1, 2, 3 ) ) ),445 );446 }447 448 public function data_is_serialized() {449 return array(450 array( serialize( null ), true ),451 array( serialize( true ), true ),452 array( serialize( false ), true ),453 array( serialize( -25 ), true ),454 array( serialize( 25 ), true ),455 array( serialize( 1.1 ), true ),456 array( serialize( 'this string will be serialized' ), true ),457 array( serialize( "a\nb" ), true ),458 array( serialize( array() ), true ),459 array( serialize( array( 1, 1, 2, 3, 5, 8, 13 ) ), true ),460 array(461 serialize(462 (object) array(463 'test' => true,464 '3',465 4,466 )467 ),468 true,469 ),470 array( ' s:25:"this string is serialized"; ', true ),471 );472 }473 474 public function data_is_not_serialized() {475 return array(476 array( null, false ),477 array( true, false ),478 array( false, false ),479 array( -25, false ),480 array( 25, false ),481 array( 1.1, false ),482 array( 'this string will be serialized', false ),483 array( "a\nb", false ),484 array( array(), false ),485 array( array( 1, 1, 2, 3, 5, 8, 13 ), false ),486 array(487 (object) array(488 'test' => true,489 '3',490 4,491 ),492 false,493 ),494 array( 'a string', false ),495 array( 'garbage:a:0:garbage;', false ),496 array( 's:4:test;', false ),497 );498 }499 500 /**501 * @ticket 46570502 * @dataProvider data_is_serialized_should_return_true_for_large_floats503 */504 public function test_is_serialized_should_return_true_for_large_floats( $value ) {505 $this->assertTrue( is_serialized( $value ) );506 }507 508 public function data_is_serialized_should_return_true_for_large_floats() {509 return array(510 array( serialize( 1.7976931348623157E+308 ) ),511 array( serialize( array( 1.7976931348623157E+308, 1.23e50 ) ) ),512 );513 }514 515 /**516 * @ticket 17375517 */518 public function test_no_new_serializable_types() {519 $this->assertFalse( is_serialized( 'C:16:"Serialized_Class":6:{a:0:{}}' ) );520 374 } 521 375
Note: See TracChangeset
for help on using the changeset viewer.