mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Tests: Use named data provider for is_serialized_string() tests.
This makes the output when using the `--testdox` option more descriptive and is helpful when trying to debug which data set from a data provider failed the test. Follow-up to [37357], [44478]. See #55652. git-svn-id: https://develop.svn.wordpress.org/trunk@53889 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
902530bba9
commit
c45ea397da
@ -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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user