From 23b3f3e2eefa62a0f34b941e433125a0d47a37bb Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Wed, 4 May 2016 03:29:47 +0000 Subject: [PATCH] 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 --- tests/phpunit/tests/functions.php | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 7d3beb3d3c..2a7f5c5bef 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -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 */