From c7e92e437cace2ff498f14746172bf4a657c7cb5 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Tue, 8 Jan 2019 19:04:51 +0000 Subject: [PATCH] Tests: Add missing test cases for `is_serialized_string()`. Also, reorganize these tests into their own class. Props pbearne. Fixes #42870. git-svn-id: https://develop.svn.wordpress.org/trunk@44478 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/functions.php | 38 ----------- .../tests/functions/isSerializedString.php | 68 +++++++++++++++++++ 2 files changed, 68 insertions(+), 38 deletions(-) create mode 100644 tests/phpunit/tests/functions/isSerializedString.php diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index dd908dfcf7..84d032dd95 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -236,44 +236,6 @@ 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 diff --git a/tests/phpunit/tests/functions/isSerializedString.php b/tests/phpunit/tests/functions/isSerializedString.php new file mode 100644 index 0000000000..292765aab4 --- /dev/null +++ b/tests/phpunit/tests/functions/isSerializedString.php @@ -0,0 +1,68 @@ +assertSame( $expected, is_serialized_string( $data ) ); + } +}