diff --git a/tests/phpunit/tests/functions/isSerializedString.php b/tests/phpunit/tests/functions/isSerializedString.php index 677bf6d591..78f6860864 100644 --- a/tests/phpunit/tests/functions/isSerializedString.php +++ b/tests/phpunit/tests/functions/isSerializedString.php @@ -11,55 +11,7 @@ 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 + * @dataProvider data_is_serialized_string * * @param array|object|int|string $data Data value to test. * @param bool $expected Expected function result. @@ -67,4 +19,62 @@ class Tests_Functions_IsSerializedString extends WP_UnitTestCase { public function test_is_serialized_string( $data, $expected ) { $this->assertSame( $expected, is_serialized_string( $data ) ); } + + /** + * Data provider for `test_is_serialized_string()`. + * + * @return array + */ + public function data_is_serialized_string() { + return array( + 'an array' => array( + 'data' => array(), + 'expected' => false, + ), + 'a class' => array( + 'data' => new stdClass(), + 'expected' => false, + ), + 'an integer 0' => array( + 'data' => 0, + 'expected' => false, + ), + 'a string that is too short when trimmed' => array( + 'data' => 's:3 ', + 'expected' => false, + ), + 'a string that is too short' => array( + 'data' => 's:3', + 'expected' => false, + ), + 'not a colon in second position' => array( + 'data' => 's!3:"foo";', + 'expected' => false, + ), + 'no trailing semicolon' => array( + 'data' => 's:3:"foo"', + 'expected' => false, + ), + 'wrong type of serialized data' => array( + 'data' => 'a:3:"foo";', + 'expected' => false, + ), + 'no closing quote' => array( + 'data' => 'a:3:"foo;', + 'expected' => false, + ), + 'single quotes instead of double' => array( + 'data' => "s:12:'foo';", + 'expected' => false, + ), + 'wrong number of characters (should not matter)' => array( + 'data' => 's:12:"foo";', + 'expected' => true, + ), + 'valid serialized string' => array( + 'data' => 's:3:"foo";', + 'expected' => true, + ), + ); + } }