mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
There were two sets of tests for `is_serialized()`: * One in the `functions.php` file, based on the same file name in core. * One in a separate class in the `functions` directory. To avoid confusion and make it easier to decide where new tests should go in the future, the existing tests are now combined in the latter location. Includes: * Moving `is_serialized()` and `maybe_serialize()` tests into their own classes. * Using named data providers to make test output more descriptive. * Combining test cases and removing duplicates. Follow-up to [278/tests], [279/tests], [328/tests], [32631], [45754], [47452], [49382], [53886], [53889]. See #55652. git-svn-id: https://develop.svn.wordpress.org/trunk@53890 602fd350-edb4-49c9-b593-d223f7449a82
81 lines
2.0 KiB
PHP
81 lines
2.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Tests for `is_serialized_string()`.
|
|
*
|
|
* @ticket 42870
|
|
*
|
|
* @group functions.php
|
|
* @covers ::is_serialized_string
|
|
*/
|
|
class Tests_Functions_IsSerializedString extends WP_UnitTestCase {
|
|
|
|
/**
|
|
* @dataProvider data_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 ) );
|
|
}
|
|
|
|
/**
|
|
* Data provider for `test_is_serialized_string()`.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function data_is_serialized_string() {
|
|
return array(
|
|
'an array' => array(
|
|
'data' => array(),
|
|
'expected' => false,
|
|
),
|
|
'an object' => 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,
|
|
),
|
|
);
|
|
}
|
|
}
|