Changeset 53890
- Timestamp:
- 08/13/2022 12:09:41 PM (2 years ago)
- Location:
- trunk/tests/phpunit/tests
- Files:
-
- 1 added
- 3 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 -
trunk/tests/phpunit/tests/functions/isSerialized.php
r53886 r53890 12 12 13 13 /** 14 * Run tests on `is_serialized()`.15 *16 14 * @dataProvider data_is_serialized 15 * @dataProvider data_is_not_serialized 17 16 * 18 17 * @param mixed $data Data value to test. 19 18 * @param bool $expected Expected function result. 20 19 */ 21 public function test_is_serialized _string( $data, $expected ) {20 public function test_is_serialized( $data, $expected ) { 22 21 $this->assertSame( $expected, is_serialized( $data ) ); 23 22 } 24 23 25 24 /** 26 * Data provider method for testing `is_serialized()`.25 * Data provider for `test_is_serialized()`. 27 26 * 28 27 * @return array … … 30 29 public function data_is_serialized() { 31 30 return array( 32 'an array' => array( 31 'serialized empty array' => array( 32 'data' => serialize( array() ), 33 'expected' => true, 34 ), 35 'serialized non-empty array' => array( 36 'data' => serialize( array( 1, 1, 2, 3, 5, 8, 13 ) ), 37 'expected' => true, 38 ), 39 'serialized empty object' => array( 40 'data' => serialize( new stdClass() ), 41 'expected' => true, 42 ), 43 'serialized non-empty object' => array( 44 'data' => serialize( 45 (object) array( 46 'test' => true, 47 '1', 48 2, 49 ) 50 ), 51 'expected' => true, 52 ), 53 'serialized null' => array( 54 'data' => serialize( null ), 55 'expected' => true, 56 ), 57 'serialized boolean true' => array( 58 'data' => serialize( true ), 59 'expected' => true, 60 ), 61 'serialized boolean false' => array( 62 'data' => serialize( false ), 63 'expected' => true, 64 ), 65 'serialized integer -1' => array( 66 'data' => serialize( -1 ), 67 'expected' => true, 68 ), 69 'serialized integer 1' => array( 70 'data' => serialize( -1 ), 71 'expected' => true, 72 ), 73 'serialized float 1.1' => array( 74 'data' => serialize( 1.1 ), 75 'expected' => true, 76 ), 77 'serialized string' => array( 78 'data' => serialize( 'this string will be serialized' ), 79 'expected' => true, 80 ), 81 'serialized string with line break' => array( 82 'data' => serialize( "a\nb" ), 83 'expected' => true, 84 ), 85 'serialized string with leading and trailing spaces' => array( 86 'data' => ' s:25:"this string is serialized"; ', 87 'expected' => true, 88 ), 89 'serialized enum' => array( 90 'data' => 'E:7:"Foo:bar";', 91 'expected' => true, 92 ), 93 ); 94 } 95 96 /** 97 * Data provider for `test_is_serialized()`. 98 * 99 * @return array 100 */ 101 public function data_is_not_serialized() { 102 return array( 103 'an empty array' => array( 33 104 'data' => array(), 34 105 'expected' => false, 35 106 ), 36 'an object' => array( 107 'a non-empty array' => array( 108 'data' => array( 1, 1, 2, 3, 5, 8, 13 ), 109 'expected' => false, 110 ), 111 'an empty object' => array( 37 112 'data' => new stdClass(), 38 113 'expected' => false, 39 114 ), 40 'a boolean false' => array( 115 'a non-empty object' => array( 116 'data' => (object) array( 117 'test' => true, 118 '1', 119 2, 120 ), 121 'expected' => false, 122 ), 123 'null' => array( 124 'data' => null, 125 'expected' => false, 126 ), 127 'a boolean true' => array( 128 'data' => true, 129 'expected' => false, 130 ), 131 'a boolean false' => array( 41 132 'data' => false, 42 133 'expected' => false, 43 134 ), 44 'a boolean true'=> array(45 'data' => true,46 'expected' => false, 47 ), 48 'an integer 0' => array(135 'an integer -1' => array( 136 'data' => -1, 137 'expected' => false, 138 ), 139 'an integer 0' => array( 49 140 'data' => 0, 50 141 'expected' => false, 51 142 ), 52 'an integer 1' => array(143 'an integer 1' => array( 53 144 'data' => 1, 54 145 'expected' => false, 55 146 ), 56 'a float 0.0' => array(147 'a float 0.0' => array( 57 148 'data' => 0.0, 58 149 'expected' => false, 59 150 ), 60 'a float 1.0' => array( 61 'data' => 1.0, 62 'expected' => false, 63 ), 64 'string that is too short' => array( 151 'a float 1.1' => array( 152 'data' => 1.1, 153 'expected' => false, 154 ), 155 'a string' => array( 156 'data' => 'a string', 157 'expected' => false, 158 ), 159 'a string with line break' => array( 160 'data' => "a\nb", 161 'expected' => false, 162 ), 163 'a string with leading and trailing garbage' => array( 164 'data' => 'garbage:a:0:garbage;', 165 'expected' => false, 166 ), 167 'a string with missing double quotes' => array( 168 'data' => 's:4:test;', 169 'expected' => false, 170 ), 171 'a string that is too short' => array( 65 172 'data' => 's:3', 66 173 'expected' => false, 67 174 ), 68 'not a colon in second position' => array(175 'not a colon in second position' => array( 69 176 'data' => 's!3:"foo";', 70 177 'expected' => false, 71 178 ), 72 'no trailing semicolon (strict check)' => array(179 'no trailing semicolon (strict check)' => array( 73 180 'data' => 's:3:"foo"', 74 181 'expected' => false, 75 182 ), 76 'valid serialized null' => array(77 'data' => 'N;',78 'expected' => true,79 ),80 'valid serialized Enum' => array(81 'data' => 'E:7:"Foo:bar";',82 'expected' => true,83 ),84 183 ); 85 184 } 185 186 /** 187 * @ticket 46570 188 * @dataProvider data_is_serialized_should_return_true_for_large_floats 189 */ 190 public function test_is_serialized_should_return_true_for_large_floats( $value ) { 191 $this->assertTrue( is_serialized( $value ) ); 192 } 193 194 public function data_is_serialized_should_return_true_for_large_floats() { 195 return array( 196 array( serialize( 1.7976931348623157E+308 ) ), 197 array( serialize( array( 1.7976931348623157E+308, 1.23e50 ) ) ), 198 ); 199 } 200 201 /** 202 * @ticket 17375 203 */ 204 public function test_no_new_serializable_types() { 205 $this->assertFalse( is_serialized( 'C:16:"Serialized_Class":6:{a:0:{}}' ) ); 206 } 86 207 } -
trunk/tests/phpunit/tests/functions/isSerializedString.php
r53889 r53890 32 32 'expected' => false, 33 33 ), 34 'a class'=> array(34 'an object' => array( 35 35 'data' => new stdClass(), 36 36 'expected' => false,
Note: See TracChangeset
for help on using the changeset viewer.