| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @group functions.php |
| 5 | */ |
| 6 | class Tests_Functions_maybe_unserialize extends WP_UnitTestCase { |
| 7 | public function data_maybe_unserialize() { |
| 8 | global $wp; |
| 9 | |
| 10 | return array( |
| 11 | array( 'a string', serialize( 'a string' ), 'pass a serialized string' ), |
| 12 | array( 'a string', 'a string', 'pass a string' ), |
| 13 | array( |
| 14 | array( |
| 15 | 'start' => 1454803200, |
| 16 | 'end' => 1455407999, |
| 17 | ), |
| 18 | serialize( array( |
| 19 | 'start' => 1454803200, |
| 20 | 'end' => 1455407999, |
| 21 | ) ), |
| 22 | 'pass serialized array', |
| 23 | ), |
| 24 | array( |
| 25 | array( |
| 26 | 'start' => 1454803200, |
| 27 | 'end' => 1455407999, |
| 28 | ), |
| 29 | array( |
| 30 | 'start' => 1454803200, |
| 31 | 'end' => 1455407999, |
| 32 | ), |
| 33 | 'pass array', |
| 34 | ), |
| 35 | array( $wp, serialize( $wp ), 'pass a serialized object' ), |
| 36 | array( $wp, $wp, 'pass a object' ), |
| 37 | array( true, serialize( true ), 'pass a serialized bool' ), |
| 38 | array( true, true, 'pass a bool' ), |
| 39 | array( 99, serialize( 99 ), 'pass a serialized int' ), |
| 40 | array( 99, 99, 'pass a int' ) |
| 41 | |
| 42 | ); |
| 43 | |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @dataProvider data_maybe_unserialize |
| 48 | * @covers ::maybe_unserialize |
| 49 | * |
| 50 | * @param $expected |
| 51 | * @param $data |
| 52 | * @param $message |
| 53 | */ |
| 54 | public function test_maybe_unserialize_pass_serialized( $expected, $data, $message ) { |
| 55 | $this->assertEquals( $expected, maybe_unserialize( $data ), $message ); |
| 56 | } |
| 57 | } |