mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Props pbearne, jrf. See #39265. git-svn-id: https://develop.svn.wordpress.org/trunk@49006 602fd350-edb4-49c9-b593-d223f7449a82
71 lines
1.4 KiB
PHP
71 lines
1.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Tests for `is_serialized_string()`.
|
|
*
|
|
* @ticket 42870
|
|
*
|
|
* @group functions.php
|
|
* @covers ::is_serialized_string
|
|
*/
|
|
class Tests_Functions_IsSerializedString extends WP_UnitTestCase {
|
|
|
|
/**
|
|
* Data provider method for testing `is_serialized_string()`.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function _is_serialized_string() {
|
|
return array(
|
|
|
|
// pass array.
|
|
array( array(), false ),
|
|
|
|
// pass a class.
|
|
array( new stdClass(), false ),
|
|
|
|
// Not a string.
|
|
array( 0, false ),
|
|
|
|
// Too short when trimmed.
|
|
array( 's:3 ', false ),
|
|
|
|
// Too short.
|
|
array( 's:3', false ),
|
|
|
|
// No colon in second position.
|
|
array( 's!3:"foo";', false ),
|
|
|
|
// No trailing semicolon.
|
|
array( 's:3:"foo"', false ),
|
|
|
|
// Wrong type.
|
|
array( 'a:3:"foo";', false ),
|
|
|
|
// No closing quote.
|
|
array( 'a:3:"foo;', false ),
|
|
|
|
// have to use double Quotes.
|
|
array( "s:12:'foo';", false ),
|
|
|
|
// Wrong number of characters is close enough for is_serialized_string().
|
|
array( 's:12:"foo";', true ),
|
|
|
|
// Okay.
|
|
array( 's:3:"foo";', true ),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Run tests on `is_serialized_string()`.
|
|
*
|
|
* @dataProvider _is_serialized_string
|
|
*
|
|
* @param array|object|int|string $data Data value to test.
|
|
* @param bool $expected Expected function result.
|
|
*/
|
|
public function test_is_serialized_string( $data, $expected ) {
|
|
$this->assertSame( $expected, is_serialized_string( $data ) );
|
|
}
|
|
}
|