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
This commit is contained in:
parent
49509a1c6a
commit
c7e92e437c
@ -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
|
||||
|
68
tests/phpunit/tests/functions/isSerializedString.php
Normal file
68
tests/phpunit/tests/functions/isSerializedString.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tests for `is_serialized_string()`.
|
||||
*
|
||||
* @group functions.php
|
||||
* @ticket 42870
|
||||
*/
|
||||
class Tests_Functions_Is_Serialized_String 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 ) );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user