Make WordPress Core


Ignore:
Timestamp:
05/04/2016 03:29:47 AM (10 years ago)
Author:
boonebgorges
Message:

Add tests for is_serialized_string().

Props borgesbruno.
Fixes #35952.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions.php

    r37189 r37357  
    215215        function test_no_new_serializable_types() {
    216216                $this->assertFalse( is_serialized( 'C:16:"Serialized_Class":6:{a:0:{}}' ) );
     217        }
     218
     219        /**
     220         * @dataProvider data_is_serialized_string
     221         */
     222        public function test_is_serialized_string( $value, $result ) {
     223                $this->assertSame( is_serialized_string( $value ), $result );
     224        }
     225
     226        public function data_is_serialized_string() {
     227                return array(
     228                        // Not a string.
     229                        array( 0, false ),
     230
     231                        // Too short when trimmed.
     232                        array( 's:3   ', false ),
     233
     234                        // Too short.
     235                        array( 's:3', false ),
     236
     237                        // No colon in second position.
     238                        array( 's!3:"foo";', false ),
     239
     240                        // No trailing semicolon.
     241                        array( 's:3:"foo"', false ),
     242
     243                        // Wrong type.
     244                        array( 'a:3:"foo";', false ),
     245
     246                        // No closing quote.
     247                        array( 'a:3:"foo;', false ),
     248
     249                        // Wrong number of characters is close enough for is_serialized_string().
     250                        array( 's:12:"foo";', true ),
     251
     252                        // Okay.
     253                        array( 's:3:"foo";', true ),
     254
     255                );
    217256        }
    218257
Note: See TracChangeset for help on using the changeset viewer.