Make WordPress Core

Ticket #39080: 39080.diff

File 39080.diff, 3.3 KB (added by whyisjake, 5 years ago)
  • tests/phpunit/tests/functions.php

     
    222222        }
    223223
    224224        /**
    225          * @dataProvider data_is_not_serialized
    226          */
    227         function test_maybe_serialize( $value ) {
    228                 if ( is_array( $value ) || is_object( $value ) ) {
    229                         $expected = serialize( $value );
    230                 } else {
    231                         $expected = $value;
    232                 }
    233 
    234                 $this->assertSame( $expected, maybe_serialize( $value ) );
    235         }
    236 
    237         /**
    238          * @dataProvider data_is_serialized
    239          */
    240         function test_maybe_serialize_with_double_serialization( $value ) {
    241                 $expected = serialize( $value );
    242 
    243                 $this->assertSame( $expected, maybe_serialize( $value ) );
    244         }
    245 
    246         /**
    247          * @dataProvider data_is_serialized
    248          * @dataProvider data_is_not_serialized
    249          */
    250         function test_maybe_unserialize( $value, $is_serialized ) {
    251                 if ( $is_serialized ) {
    252                         $expected = unserialize( trim( $value ) );
    253                 } else {
    254                         $expected = $value;
    255                 }
    256 
    257                 if ( is_object( $expected ) ) {
    258                         $this->assertEquals( $expected, maybe_unserialize( $value ) );
    259                 } else {
    260                         $this->assertSame( $expected, maybe_unserialize( $value ) );
    261                 }
    262         }
    263 
    264         /**
    265          * @dataProvider data_is_serialized
    266          * @dataProvider data_is_not_serialized
    267          */
    268         function test_is_serialized( $value, $expected ) {
    269                 $this->assertSame( $expected, is_serialized( $value ) );
    270         }
    271 
    272         function data_is_serialized() {
    273                 return array(
    274                         array( serialize( null ), true ),
    275                         array( serialize( true ), true ),
    276                         array( serialize( false ), true ),
    277                         array( serialize( -25 ), true ),
    278                         array( serialize( 25 ), true ),
    279                         array( serialize( 1.1 ), true ),
    280                         array( serialize( 'this string will be serialized' ), true ),
    281                         array( serialize( "a\nb" ), true ),
    282                         array( serialize( array() ), true ),
    283                         array( serialize( array( 1, 1, 2, 3, 5, 8, 13 ) ), true ),
    284                         array(
    285                                 serialize(
    286                                         (object) array(
    287                                                 'test' => true,
    288                                                 '3',
    289                                                 4,
    290                                         )
    291                                 ),
    292                                 true,
    293                         ),
    294                         array( '   s:25:"this string is serialized";   ', true ),
    295                 );
    296         }
    297 
    298         function data_is_not_serialized() {
    299                 return array(
    300                         array( null, false ),
    301                         array( true, false ),
    302                         array( false, false ),
    303                         array( -25, false ),
    304                         array( 25, false ),
    305                         array( 1.1, false ),
    306                         array( 'this string will be serialized', false ),
    307                         array( "a\nb", false ),
    308                         array( array(), false ),
    309                         array( array( 1, 1, 2, 3, 5, 8, 13 ), false ),
    310                         array(
    311                                 (object) array(
    312                                         'test' => true,
    313                                         '3',
    314                                         4,
    315                                 ),
    316                                 false,
    317                         ),
    318                         array( 'a string', false ),
    319                         array( 'garbage:a:0:garbage;', false ),
    320                         array( 's:4:test;', false ),
    321                 );
    322         }
    323 
    324         /**
    325          * @ticket 46570
    326          * @dataProvider data_is_serialized_should_return_true_for_large_floats
    327          */
    328         function test_is_serialized_should_return_true_for_large_floats( $value ) {
    329                 $this->assertTrue( is_serialized( $value ) );
    330         }
    331 
    332         function data_is_serialized_should_return_true_for_large_floats() {
    333                 return array(
    334                         array( serialize( 1.7976931348623157E+308 ) ),
    335                         array( serialize( array( 1.7976931348623157E+308, 1.23e50 ) ) ),
    336                 );
    337         }
    338 
    339         /**
    340          * @ticket 17375
    341          */
    342         function test_no_new_serializable_types() {
    343                 $this->assertFalse( is_serialized( 'C:16:"Serialized_Class":6:{a:0:{}}' ) );
    344         }
    345 
    346         /**
    347225         * @group add_query_arg
    348226         */
    349227        function test_add_query_arg() {