Changeset 47452 for trunk/tests/phpunit/tests/functions.php
- Timestamp:
- 03/13/2020 08:39:02 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/functions.php
r47122 r47452 139 139 $this->assertEquals( $expected, wp_normalize_path( $path ) ); 140 140 } 141 141 142 function data_wp_normalize_path() { 142 143 return array( … … 221 222 } 222 223 223 function test_is_serialized() { 224 $cases = array( 225 serialize( null ), 226 serialize( true ), 227 serialize( false ), 228 serialize( -25 ), 229 serialize( 25 ), 230 serialize( 1.1 ), 231 serialize( 'this string will be serialized' ), 232 serialize( "a\nb" ), 233 serialize( array() ), 234 serialize( array( 1, 1, 2, 3, 5, 8, 13 ) ), 235 serialize( 224 /** 225 * @dataProvider data_is_not_serialized 226 */ 227 function test_maybe_serialize( $value ) { 228 if ( is_array( $value ) || is_object( $value ) ) { 229 $expected = serialize( $value ); 230 } else { 231 $expected = $value; 232 } 233 234 $this->assertSame( $expected, maybe_serialize( $value ) ); 235 } 236 237 /** 238 * @dataProvider data_is_serialized 239 */ 240 function test_maybe_serialize_with_double_serialization( $value ) { 241 $expected = serialize( $value ); 242 243 $this->assertSame( $expected, maybe_serialize( $value ) ); 244 } 245 246 /** 247 * @dataProvider data_is_serialized 248 * @dataProvider data_is_not_serialized 249 */ 250 function test_maybe_unserialize( $value, $is_serialized ) { 251 if ( $is_serialized ) { 252 $expected = unserialize( trim( $value ) ); 253 } else { 254 $expected = $value; 255 } 256 257 if ( is_object( $expected ) ) { 258 $this->assertEquals( $expected, maybe_unserialize( $value ) ); 259 } else { 260 $this->assertSame( $expected, maybe_unserialize( $value ) ); 261 } 262 } 263 264 /** 265 * @dataProvider data_is_serialized 266 * @dataProvider data_is_not_serialized 267 */ 268 function test_is_serialized( $value, $expected ) { 269 $this->assertSame( $expected, is_serialized( $value ) ); 270 } 271 272 function data_is_serialized() { 273 return array( 274 array( serialize( null ), true ), 275 array( serialize( true ), true ), 276 array( serialize( false ), true ), 277 array( serialize( -25 ), true ), 278 array( serialize( 25 ), true ), 279 array( serialize( 1.1 ), true ), 280 array( serialize( 'this string will be serialized' ), true ), 281 array( serialize( "a\nb" ), true ), 282 array( serialize( array() ), true ), 283 array( serialize( array( 1, 1, 2, 3, 5, 8, 13 ) ), true ), 284 array( 285 serialize( 286 (object) array( 287 'test' => true, 288 '3', 289 4, 290 ) 291 ), 292 true, 293 ), 294 ); 295 } 296 297 function data_is_not_serialized() { 298 return array( 299 array( null, false ), 300 array( true, false ), 301 array( false, false ), 302 array( -25, false ), 303 array( 25, false ), 304 array( 1.1, false ), 305 array( 'this string will be serialized', false ), 306 array( "a\nb", false ), 307 array( array(), false ), 308 array( array( 1, 1, 2, 3, 5, 8, 13 ), false ), 309 array( 236 310 (object) array( 237 311 'test' => true, 238 312 '3', 239 313 4, 240 ) 241 ), 242 ); 243 244 foreach ( $cases as $case ) { 245 $this->assertTrue( is_serialized( $case ), "Serialized data: $case" ); 246 } 247 248 $not_serialized = array( 249 'a string', 250 'garbage:a:0:garbage;', 251 's:4:test;', 252 ); 253 254 foreach ( $not_serialized as $case ) { 255 $this->assertFalse( is_serialized( $case ), "Test data: $case" ); 256 } 314 ), 315 false, 316 ), 317 array( 'a string', false ), 318 array( 'garbage:a:0:garbage;', false ), 319 array( 's:4:test;', false ), 320 ); 257 321 } 258 322 259 323 /** 260 324 * @ticket 46570 261 */ 262 function test_is_serialized_should_return_true_for_large_floats() { 263 $cases = array( 264 serialize( 1.7976931348623157E+308 ), 265 serialize( array( 1.7976931348623157E+308, 1.23e50 ) ), 266 ); 267 268 foreach ( $cases as $case ) { 269 $this->assertTrue( is_serialized( $case ), "Serialized data: $case" ); 270 } 325 * @dataProvider data_is_serialized_should_return_true_for_large_floats 326 */ 327 function test_is_serialized_should_return_true_for_large_floats( $value ) { 328 $this->assertTrue( is_serialized( $value ) ); 329 } 330 331 function data_is_serialized_should_return_true_for_large_floats() { 332 return array( 333 array( serialize( 1.7976931348623157E+308 ) ), 334 array( serialize( array( 1.7976931348623157E+308, 1.23e50 ) ) ), 335 ); 271 336 } 272 337 … … 277 342 $this->assertFalse( is_serialized( 'C:16:"Serialized_Class":6:{a:0:{}}' ) ); 278 343 } 279 280 344 281 345 /**
Note: See TracChangeset
for help on using the changeset viewer.