Add tests for `is_serialized_string()`.

Props borgesbruno.
Fixes #35952.

git-svn-id: https://develop.svn.wordpress.org/trunk@37357 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2016-05-04 03:29:47 +00:00
parent 9e504d6476
commit 23b3f3e2ee
1 changed files with 39 additions and 0 deletions

View File

@ -216,6 +216,45 @@ class Tests_Functions extends WP_UnitTestCase {
$this->assertFalse( is_serialized( 'C:16:"Serialized_Class":6:{a:0:{}}' ) );
}
/**
* @dataProvider data_is_serialized_string
*/
public function test_is_serialized_string( $value, $result ) {
$this->assertSame( is_serialized_string( $value ), $result );
}
public function data_is_serialized_string() {
return array(
// 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 ),
// Wrong number of characters is close enough for is_serialized_string().
array( 's:12:"foo";', true ),
// Okay.
array( 's:3:"foo";', true ),
);
}
/**
* @group add_query_arg
*/