Make WordPress Core

Changeset 53557


Ignore:
Timestamp:
06/23/2022 02:24:08 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Remove dynamic properties in Tests_*_Slashes.

Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.

In this particular case, the test classes contain a set_up() method that sets a group of properties, which are used by the tests, but the values of these properties are never changed by the tests.

In other words, setting these properties in the set_up() is an unnecessary overhead and the properties should be changed to class constants.

Follow-up to [1041/tests], [1071/tests].

Props jrf.
See #56033.

Location:
trunk/tests/phpunit/tests
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/attachment/slashes.php

    r52010 r53557  
    77 */
    88class Tests_Attachment_Slashes extends WP_UnitTestCase {
     9
     10        /*
     11         * It is important to test with both even and odd numbered slashes,
     12         * as KSES does a strip-then-add slashes in some of its function calls.
     13         */
     14
     15        const SLASH_1 = 'String with 1 slash \\';
     16        const SLASH_2 = 'String with 2 slashes \\\\';
     17        const SLASH_3 = 'String with 3 slashes \\\\\\';
     18        const SLASH_4 = 'String with 4 slashes \\\\\\\\';
     19        const SLASH_5 = 'String with 5 slashes \\\\\\\\\\';
     20        const SLASH_6 = 'String with 6 slashes \\\\\\\\\\\\';
     21        const SLASH_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
     22
    923        protected static $author_id;
    1024
     
    1731
    1832                wp_set_current_user( self::$author_id );
    19 
    20                 // It is important to test with both even and odd numbered slashes,
    21                 // as KSES does a strip-then-add slashes in some of its function calls.
    22                 $this->slash_1 = 'String with 1 slash \\';
    23                 $this->slash_2 = 'String with 2 slashes \\\\';
    24                 $this->slash_3 = 'String with 3 slashes \\\\\\';
    25                 $this->slash_4 = 'String with 4 slashes \\\\\\\\';
    26                 $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';
    27                 $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
    28                 $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    2933        }
    3034
     
    3640                        array(
    3741                                'post_status'           => 'publish',
    38                                 'post_title'            => $this->slash_1,
    39                                 'post_content_filtered' => $this->slash_3,
    40                                 'post_excerpt'          => $this->slash_5,
     42                                'post_title'            => self::SLASH_1,
     43                                'post_content_filtered' => self::SLASH_3,
     44                                'post_excerpt'          => self::SLASH_5,
    4145                                'post_type'             => 'post',
    4246                        )
     
    4448                $post    = get_post( $post_id );
    4549
    46                 $this->assertSame( wp_unslash( $this->slash_1 ), $post->post_title );
    47                 $this->assertSame( wp_unslash( $this->slash_3 ), $post->post_content_filtered );
    48                 $this->assertSame( wp_unslash( $this->slash_5 ), $post->post_excerpt );
     50                $this->assertSame( wp_unslash( self::SLASH_1 ), $post->post_title );
     51                $this->assertSame( wp_unslash( self::SLASH_3 ), $post->post_content_filtered );
     52                $this->assertSame( wp_unslash( self::SLASH_5 ), $post->post_excerpt );
    4953
    5054                $post_id = wp_insert_attachment(
    5155                        array(
    5256                                'post_status'           => 'publish',
    53                                 'post_title'            => $this->slash_2,
    54                                 'post_content_filtered' => $this->slash_4,
    55                                 'post_excerpt'          => $this->slash_6,
     57                                'post_title'            => self::SLASH_2,
     58                                'post_content_filtered' => self::SLASH_4,
     59                                'post_excerpt'          => self::SLASH_6,
    5660                                'post_type'             => 'post',
    5761                        )
     
    5963                $post    = get_post( $post_id );
    6064
    61                 $this->assertSame( wp_unslash( $this->slash_2 ), $post->post_title );
    62                 $this->assertSame( wp_unslash( $this->slash_4 ), $post->post_content_filtered );
    63                 $this->assertSame( wp_unslash( $this->slash_6 ), $post->post_excerpt );
     65                $this->assertSame( wp_unslash( self::SLASH_2 ), $post->post_title );
     66                $this->assertSame( wp_unslash( self::SLASH_4 ), $post->post_content_filtered );
     67                $this->assertSame( wp_unslash( self::SLASH_6 ), $post->post_excerpt );
    6468        }
    6569
  • trunk/tests/phpunit/tests/comment/slashes.php

    r52010 r53557  
    77 */
    88class Tests_Comment_Slashes extends WP_UnitTestCase {
     9
     10        /*
     11         * It is important to test with both even and odd numbered slashes,
     12         * as KSES does a strip-then-add slashes in some of its function calls.
     13         */
     14
     15        const SLASH_1 = 'String with 1 slash \\';
     16        const SLASH_2 = 'String with 2 slashes \\\\';
     17        const SLASH_3 = 'String with 3 slashes \\\\\\';
     18        const SLASH_4 = 'String with 4 slashes \\\\\\\\';
     19        const SLASH_5 = 'String with 5 slashes \\\\\\\\\\';
     20        const SLASH_6 = 'String with 6 slashes \\\\\\\\\\\\';
     21        const SLASH_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
     22
    923        protected static $author_id;
    1024        protected static $post_id;
     
    2034
    2135                wp_set_current_user( self::$author_id );
    22 
    23                 // It is important to test with both even and odd numbered slashes,
    24                 // as KSES does a strip-then-add slashes in some of its function calls.
    25                 $this->slash_1 = 'String with 1 slash \\';
    26                 $this->slash_2 = 'String with 2 slashes \\\\';
    27                 $this->slash_3 = 'String with 3 slashes \\\\\\';
    28                 $this->slash_4 = 'String with 4 slashes \\\\\\\\';
    29                 $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';
    30                 $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
    31                 $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    3236        }
    3337
     
    4246                $data       = array(
    4347                        'comment_post_ID'      => $post_id,
    44                         'comment_author'       => $this->slash_1,
     48                        'comment_author'       => self::SLASH_1,
    4549                        'comment_author_url'   => '',
    4650                        'comment_author_email' => '',
    4751                        'comment_type'         => '',
    48                         'comment_content'      => $this->slash_7,
     52                        'comment_content'      => self::SLASH_7,
    4953                );
    5054                $comment_id = wp_new_comment( $data );
     
    5256                $comment = get_comment( $comment_id );
    5357
    54                 $this->assertSame( wp_unslash( $this->slash_1 ), $comment->comment_author );
    55                 $this->assertSame( wp_unslash( $this->slash_7 ), $comment->comment_content );
     58                $this->assertSame( wp_unslash( self::SLASH_1 ), $comment->comment_author );
     59                $this->assertSame( wp_unslash( self::SLASH_7 ), $comment->comment_content );
    5660
    5761                $data       = array(
    5862                        'comment_post_ID'      => $post_id,
    59                         'comment_author'       => $this->slash_2,
     63                        'comment_author'       => self::SLASH_2,
    6064                        'comment_author_url'   => '',
    6165                        'comment_author_email' => '',
    6266                        'comment_type'         => '',
    63                         'comment_content'      => $this->slash_4,
     67                        'comment_content'      => self::SLASH_4,
    6468                );
    6569                $comment_id = wp_new_comment( $data );
     
    6771                $comment = get_comment( $comment_id );
    6872
    69                 $this->assertSame( wp_unslash( $this->slash_2 ), $comment->comment_author );
    70                 $this->assertSame( wp_unslash( $this->slash_4 ), $comment->comment_content );
     73                $this->assertSame( wp_unslash( self::SLASH_2 ), $comment->comment_author );
     74                $this->assertSame( wp_unslash( self::SLASH_4 ), $comment->comment_content );
    7175        }
    7276
     
    8791                $_POST['comment_ID']              = $comment_id;
    8892                $_POST['comment_status']          = '';
    89                 $_POST['newcomment_author']       = $this->slash_1;
     93                $_POST['newcomment_author']       = self::SLASH_1;
    9094                $_POST['newcomment_author_url']   = '';
    9195                $_POST['newcomment_author_email'] = '';
    92                 $_POST['content']                 = $this->slash_7;
     96                $_POST['content']                 = self::SLASH_7;
    9397
    9498                $_POST = add_magic_quotes( $_POST ); // The edit_comment() function will strip slashes.
     
    97101                $comment = get_comment( $comment_id );
    98102
    99                 $this->assertSame( $this->slash_1, $comment->comment_author );
    100                 $this->assertSame( $this->slash_7, $comment->comment_content );
     103                $this->assertSame( self::SLASH_1, $comment->comment_author );
     104                $this->assertSame( self::SLASH_7, $comment->comment_content );
    101105
    102106                $_POST                            = array();
    103107                $_POST['comment_ID']              = $comment_id;
    104108                $_POST['comment_status']          = '';
    105                 $_POST['newcomment_author']       = $this->slash_2;
     109                $_POST['newcomment_author']       = self::SLASH_2;
    106110                $_POST['newcomment_author_url']   = '';
    107111                $_POST['newcomment_author_email'] = '';
    108                 $_POST['content']                 = $this->slash_4;
     112                $_POST['content']                 = self::SLASH_4;
    109113
    110114                $_POST = add_magic_quotes( $_POST ); // The edit_comment() function will strip slashes.
     
    113117                $comment = get_comment( $comment_id );
    114118
    115                 $this->assertSame( $this->slash_2, $comment->comment_author );
    116                 $this->assertSame( $this->slash_4, $comment->comment_content );
     119                $this->assertSame( self::SLASH_2, $comment->comment_author );
     120                $this->assertSame( self::SLASH_4, $comment->comment_content );
    117121        }
    118122
     
    126130                        array(
    127131                                'comment_post_ID' => $post_id,
    128                                 'comment_author'  => $this->slash_1,
    129                                 'comment_content' => $this->slash_7,
     132                                'comment_author'  => self::SLASH_1,
     133                                'comment_content' => self::SLASH_7,
    130134                        )
    131135                );
    132136                $comment    = get_comment( $comment_id );
    133137
    134                 $this->assertSame( wp_unslash( $this->slash_1 ), $comment->comment_author );
    135                 $this->assertSame( wp_unslash( $this->slash_7 ), $comment->comment_content );
     138                $this->assertSame( wp_unslash( self::SLASH_1 ), $comment->comment_author );
     139                $this->assertSame( wp_unslash( self::SLASH_7 ), $comment->comment_content );
    136140
    137141                $comment_id = wp_insert_comment(
    138142                        array(
    139143                                'comment_post_ID' => $post_id,
    140                                 'comment_author'  => $this->slash_2,
    141                                 'comment_content' => $this->slash_4,
     144                                'comment_author'  => self::SLASH_2,
     145                                'comment_content' => self::SLASH_4,
    142146                        )
    143147                );
    144148                $comment    = get_comment( $comment_id );
    145149
    146                 $this->assertSame( wp_unslash( $this->slash_2 ), $comment->comment_author );
    147                 $this->assertSame( wp_unslash( $this->slash_4 ), $comment->comment_content );
     150                $this->assertSame( wp_unslash( self::SLASH_2 ), $comment->comment_author );
     151                $this->assertSame( wp_unslash( self::SLASH_4 ), $comment->comment_content );
    148152        }
    149153
     
    162166                        array(
    163167                                'comment_ID'      => $comment_id,
    164                                 'comment_author'  => $this->slash_1,
    165                                 'comment_content' => $this->slash_7,
     168                                'comment_author'  => self::SLASH_1,
     169                                'comment_content' => self::SLASH_7,
    166170                        )
    167171                );
    168172                $comment = get_comment( $comment_id );
    169173
    170                 $this->assertSame( wp_unslash( $this->slash_1 ), $comment->comment_author );
    171                 $this->assertSame( wp_unslash( $this->slash_7 ), $comment->comment_content );
     174                $this->assertSame( wp_unslash( self::SLASH_1 ), $comment->comment_author );
     175                $this->assertSame( wp_unslash( self::SLASH_7 ), $comment->comment_content );
    172176
    173177                wp_update_comment(
    174178                        array(
    175179                                'comment_ID'      => $comment_id,
    176                                 'comment_author'  => $this->slash_2,
    177                                 'comment_content' => $this->slash_4,
     180                                'comment_author'  => self::SLASH_2,
     181                                'comment_content' => self::SLASH_4,
    178182                        )
    179183                );
    180184                $comment = get_comment( $comment_id );
    181185
    182                 $this->assertSame( wp_unslash( $this->slash_2 ), $comment->comment_author );
    183                 $this->assertSame( wp_unslash( $this->slash_4 ), $comment->comment_content );
     186                $this->assertSame( wp_unslash( self::SLASH_2 ), $comment->comment_author );
     187                $this->assertSame( wp_unslash( self::SLASH_4 ), $comment->comment_content );
    184188        }
    185189
  • trunk/tests/phpunit/tests/meta/slashes.php

    r52010 r53557  
    77 */
    88class Tests_Meta_Slashes extends WP_UnitTestCase {
     9
     10        /*
     11         * It is important to test with both even and odd numbered slashes,
     12         * as KSES does a strip-then-add slashes in some of its function calls.
     13         */
     14
     15        const SLASH_1 = 'String with 1 slash \\';
     16        const SLASH_2 = 'String with 2 slashes \\\\';
     17        const SLASH_3 = 'String with 3 slashes \\\\\\';
     18        const SLASH_4 = 'String with 4 slashes \\\\\\\\';
     19        const SLASH_5 = 'String with 5 slashes \\\\\\\\\\';
     20        const SLASH_6 = 'String with 6 slashes \\\\\\\\\\\\';
     21        const SLASH_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
     22
    923        protected static $editor_id;
    1024        protected static $post_id;
     
    2337
    2438                wp_set_current_user( self::$editor_id );
    25 
    26                 $this->slash_1 = 'String with 1 slash \\';
    27                 $this->slash_2 = 'String with 2 slashes \\\\';
    28                 $this->slash_3 = 'String with 3 slashes \\\\\\';
    29                 $this->slash_4 = 'String with 4 slashes \\\\\\\\';
    30                 $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';
    31                 $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
    32                 $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    3339        }
    3440
     
    5460                $_POST['metakeyselect'] = '#NONE#';
    5561                $_POST['metakeyinput']  = 'slash_test_0';
    56                 $_POST['metavalue']     = $this->slash_6;
     62                $_POST['metavalue']     = self::SLASH_6;
    5763                $_POST['meta']          = array(
    5864                        $meta_1 => array(
    5965                                'key'   => 'slash_test_1',
    60                                 'value' => $this->slash_1,
     66                                'value' => self::SLASH_1,
    6167                        ),
    6268                        $meta_2 => array(
    6369                                'key'   => 'slash_test_2',
    64                                 'value' => $this->slash_3,
     70                                'value' => self::SLASH_3,
    6571                        ),
    6672                        $meta_3 => array(
    6773                                'key'   => 'slash_test_3',
    68                                 'value' => $this->slash_4,
     74                                'value' => self::SLASH_4,
    6975                        ),
    7076                );
     
    7581                $post = get_post( $post_id );
    7682
    77                 $this->assertSame( $this->slash_6, get_post_meta( $post_id, 'slash_test_0', true ) );
    78                 $this->assertSame( $this->slash_1, get_post_meta( $post_id, 'slash_test_1', true ) );
    79                 $this->assertSame( $this->slash_3, get_post_meta( $post_id, 'slash_test_2', true ) );
    80                 $this->assertSame( $this->slash_4, get_post_meta( $post_id, 'slash_test_3', true ) );
     83                $this->assertSame( self::SLASH_6, get_post_meta( $post_id, 'slash_test_0', true ) );
     84                $this->assertSame( self::SLASH_1, get_post_meta( $post_id, 'slash_test_1', true ) );
     85                $this->assertSame( self::SLASH_3, get_post_meta( $post_id, 'slash_test_2', true ) );
     86                $this->assertSame( self::SLASH_4, get_post_meta( $post_id, 'slash_test_3', true ) );
    8187
    8288                $_POST                  = array();
     
    8490                $_POST['metakeyselect'] = '#NONE#';
    8591                $_POST['metakeyinput']  = 'slash_test_0';
    86                 $_POST['metavalue']     = $this->slash_7;
     92                $_POST['metavalue']     = self::SLASH_7;
    8793                $_POST['meta']          = array(
    8894                        $meta_1 => array(
    8995                                'key'   => 'slash_test_1',
    90                                 'value' => $this->slash_2,
     96                                'value' => self::SLASH_2,
    9197                        ),
    9298                        $meta_2 => array(
    9399                                'key'   => 'slash_test_2',
    94                                 'value' => $this->slash_4,
     100                                'value' => self::SLASH_4,
    95101                        ),
    96102                        $meta_3 => array(
    97103                                'key'   => 'slash_test_3',
    98                                 'value' => $this->slash_5,
     104                                'value' => self::SLASH_5,
    99105                        ),
    100106                );
     
    105111                $post = get_post( $post_id );
    106112
    107                 $this->assertSame( $this->slash_2, get_post_meta( $post_id, 'slash_test_1', true ) );
    108                 $this->assertSame( $this->slash_4, get_post_meta( $post_id, 'slash_test_2', true ) );
    109                 $this->assertSame( $this->slash_5, get_post_meta( $post_id, 'slash_test_3', true ) );
     113                $this->assertSame( self::SLASH_2, get_post_meta( $post_id, 'slash_test_1', true ) );
     114                $this->assertSame( self::SLASH_4, get_post_meta( $post_id, 'slash_test_2', true ) );
     115                $this->assertSame( self::SLASH_5, get_post_meta( $post_id, 'slash_test_3', true ) );
    110116        }
    111117
     
    116122                $post_id = self::$post_id;
    117123
    118                 add_post_meta( $post_id, 'slash_test_1', addslashes( $this->slash_1 ) );
    119                 add_post_meta( $post_id, 'slash_test_2', addslashes( $this->slash_3 ) );
    120                 add_post_meta( $post_id, 'slash_test_3', addslashes( $this->slash_4 ) );
    121 
    122                 $this->assertSame( $this->slash_1, get_post_meta( $post_id, 'slash_test_1', true ) );
    123                 $this->assertSame( $this->slash_3, get_post_meta( $post_id, 'slash_test_2', true ) );
    124                 $this->assertSame( $this->slash_4, get_post_meta( $post_id, 'slash_test_3', true ) );
     124                add_post_meta( $post_id, 'slash_test_1', addslashes( self::SLASH_1 ) );
     125                add_post_meta( $post_id, 'slash_test_2', addslashes( self::SLASH_3 ) );
     126                add_post_meta( $post_id, 'slash_test_3', addslashes( self::SLASH_4 ) );
     127
     128                $this->assertSame( self::SLASH_1, get_post_meta( $post_id, 'slash_test_1', true ) );
     129                $this->assertSame( self::SLASH_3, get_post_meta( $post_id, 'slash_test_2', true ) );
     130                $this->assertSame( self::SLASH_4, get_post_meta( $post_id, 'slash_test_3', true ) );
    125131        }
    126132
     
    131137                $post_id = self::$post_id;
    132138
    133                 update_post_meta( $post_id, 'slash_test_1', addslashes( $this->slash_1 ) );
    134                 update_post_meta( $post_id, 'slash_test_2', addslashes( $this->slash_3 ) );
    135                 update_post_meta( $post_id, 'slash_test_3', addslashes( $this->slash_4 ) );
    136 
    137                 $this->assertSame( $this->slash_1, get_post_meta( $post_id, 'slash_test_1', true ) );
    138                 $this->assertSame( $this->slash_3, get_post_meta( $post_id, 'slash_test_2', true ) );
    139                 $this->assertSame( $this->slash_4, get_post_meta( $post_id, 'slash_test_3', true ) );
     139                update_post_meta( $post_id, 'slash_test_1', addslashes( self::SLASH_1 ) );
     140                update_post_meta( $post_id, 'slash_test_2', addslashes( self::SLASH_3 ) );
     141                update_post_meta( $post_id, 'slash_test_3', addslashes( self::SLASH_4 ) );
     142
     143                $this->assertSame( self::SLASH_1, get_post_meta( $post_id, 'slash_test_1', true ) );
     144                $this->assertSame( self::SLASH_3, get_post_meta( $post_id, 'slash_test_2', true ) );
     145                $this->assertSame( self::SLASH_4, get_post_meta( $post_id, 'slash_test_3', true ) );
    140146        }
    141147
     
    146152                $comment_id = self::$comment_id;
    147153
    148                 add_comment_meta( $comment_id, 'slash_test_1', $this->slash_1 );
    149                 add_comment_meta( $comment_id, 'slash_test_2', $this->slash_3 );
    150                 add_comment_meta( $comment_id, 'slash_test_3', $this->slash_5 );
    151 
    152                 $this->assertSame( wp_unslash( $this->slash_1 ), get_comment_meta( $comment_id, 'slash_test_1', true ) );
    153                 $this->assertSame( wp_unslash( $this->slash_3 ), get_comment_meta( $comment_id, 'slash_test_2', true ) );
    154                 $this->assertSame( wp_unslash( $this->slash_5 ), get_comment_meta( $comment_id, 'slash_test_3', true ) );
    155 
    156                 add_comment_meta( $comment_id, 'slash_test_4', $this->slash_2 );
    157                 add_comment_meta( $comment_id, 'slash_test_5', $this->slash_4 );
    158                 add_comment_meta( $comment_id, 'slash_test_6', $this->slash_6 );
    159 
    160                 $this->assertSame( wp_unslash( $this->slash_2 ), get_comment_meta( $comment_id, 'slash_test_4', true ) );
    161                 $this->assertSame( wp_unslash( $this->slash_4 ), get_comment_meta( $comment_id, 'slash_test_5', true ) );
    162                 $this->assertSame( wp_unslash( $this->slash_6 ), get_comment_meta( $comment_id, 'slash_test_6', true ) );
     154                add_comment_meta( $comment_id, 'slash_test_1', self::SLASH_1 );
     155                add_comment_meta( $comment_id, 'slash_test_2', self::SLASH_3 );
     156                add_comment_meta( $comment_id, 'slash_test_3', self::SLASH_5 );
     157
     158                $this->assertSame( wp_unslash( self::SLASH_1 ), get_comment_meta( $comment_id, 'slash_test_1', true ) );
     159                $this->assertSame( wp_unslash( self::SLASH_3 ), get_comment_meta( $comment_id, 'slash_test_2', true ) );
     160                $this->assertSame( wp_unslash( self::SLASH_5 ), get_comment_meta( $comment_id, 'slash_test_3', true ) );
     161
     162                add_comment_meta( $comment_id, 'slash_test_4', self::SLASH_2 );
     163                add_comment_meta( $comment_id, 'slash_test_5', self::SLASH_4 );
     164                add_comment_meta( $comment_id, 'slash_test_6', self::SLASH_6 );
     165
     166                $this->assertSame( wp_unslash( self::SLASH_2 ), get_comment_meta( $comment_id, 'slash_test_4', true ) );
     167                $this->assertSame( wp_unslash( self::SLASH_4 ), get_comment_meta( $comment_id, 'slash_test_5', true ) );
     168                $this->assertSame( wp_unslash( self::SLASH_6 ), get_comment_meta( $comment_id, 'slash_test_6', true ) );
    163169        }
    164170
     
    173179                add_comment_meta( $comment_id, 'slash_test_3', 'foo' );
    174180
    175                 update_comment_meta( $comment_id, 'slash_test_1', $this->slash_1 );
    176                 update_comment_meta( $comment_id, 'slash_test_2', $this->slash_3 );
    177                 update_comment_meta( $comment_id, 'slash_test_3', $this->slash_5 );
    178 
    179                 $this->assertSame( wp_unslash( $this->slash_1 ), get_comment_meta( $comment_id, 'slash_test_1', true ) );
    180                 $this->assertSame( wp_unslash( $this->slash_3 ), get_comment_meta( $comment_id, 'slash_test_2', true ) );
    181                 $this->assertSame( wp_unslash( $this->slash_5 ), get_comment_meta( $comment_id, 'slash_test_3', true ) );
    182 
    183                 update_comment_meta( $comment_id, 'slash_test_1', $this->slash_2 );
    184                 update_comment_meta( $comment_id, 'slash_test_2', $this->slash_4 );
    185                 update_comment_meta( $comment_id, 'slash_test_3', $this->slash_6 );
    186 
    187                 $this->assertSame( wp_unslash( $this->slash_2 ), get_comment_meta( $comment_id, 'slash_test_1', true ) );
    188                 $this->assertSame( wp_unslash( $this->slash_4 ), get_comment_meta( $comment_id, 'slash_test_2', true ) );
    189                 $this->assertSame( wp_unslash( $this->slash_6 ), get_comment_meta( $comment_id, 'slash_test_3', true ) );
     181                update_comment_meta( $comment_id, 'slash_test_1', self::SLASH_1 );
     182                update_comment_meta( $comment_id, 'slash_test_2', self::SLASH_3 );
     183                update_comment_meta( $comment_id, 'slash_test_3', self::SLASH_5 );
     184
     185                $this->assertSame( wp_unslash( self::SLASH_1 ), get_comment_meta( $comment_id, 'slash_test_1', true ) );
     186                $this->assertSame( wp_unslash( self::SLASH_3 ), get_comment_meta( $comment_id, 'slash_test_2', true ) );
     187                $this->assertSame( wp_unslash( self::SLASH_5 ), get_comment_meta( $comment_id, 'slash_test_3', true ) );
     188
     189                update_comment_meta( $comment_id, 'slash_test_1', self::SLASH_2 );
     190                update_comment_meta( $comment_id, 'slash_test_2', self::SLASH_4 );
     191                update_comment_meta( $comment_id, 'slash_test_3', self::SLASH_6 );
     192
     193                $this->assertSame( wp_unslash( self::SLASH_2 ), get_comment_meta( $comment_id, 'slash_test_1', true ) );
     194                $this->assertSame( wp_unslash( self::SLASH_4 ), get_comment_meta( $comment_id, 'slash_test_2', true ) );
     195                $this->assertSame( wp_unslash( self::SLASH_6 ), get_comment_meta( $comment_id, 'slash_test_3', true ) );
    190196        }
    191197
     
    196202                $user_id = self::$user_id;
    197203
    198                 add_user_meta( $user_id, 'slash_test_1', $this->slash_1 );
    199                 add_user_meta( $user_id, 'slash_test_2', $this->slash_3 );
    200                 add_user_meta( $user_id, 'slash_test_3', $this->slash_5 );
    201 
    202                 $this->assertSame( wp_unslash( $this->slash_1 ), get_user_meta( $user_id, 'slash_test_1', true ) );
    203                 $this->assertSame( wp_unslash( $this->slash_3 ), get_user_meta( $user_id, 'slash_test_2', true ) );
    204                 $this->assertSame( wp_unslash( $this->slash_5 ), get_user_meta( $user_id, 'slash_test_3', true ) );
    205 
    206                 add_user_meta( $user_id, 'slash_test_4', $this->slash_2 );
    207                 add_user_meta( $user_id, 'slash_test_5', $this->slash_4 );
    208                 add_user_meta( $user_id, 'slash_test_6', $this->slash_6 );
    209 
    210                 $this->assertSame( wp_unslash( $this->slash_2 ), get_user_meta( $user_id, 'slash_test_4', true ) );
    211                 $this->assertSame( wp_unslash( $this->slash_4 ), get_user_meta( $user_id, 'slash_test_5', true ) );
    212                 $this->assertSame( wp_unslash( $this->slash_6 ), get_user_meta( $user_id, 'slash_test_6', true ) );
     204                add_user_meta( $user_id, 'slash_test_1', self::SLASH_1 );
     205                add_user_meta( $user_id, 'slash_test_2', self::SLASH_3 );
     206                add_user_meta( $user_id, 'slash_test_3', self::SLASH_5 );
     207
     208                $this->assertSame( wp_unslash( self::SLASH_1 ), get_user_meta( $user_id, 'slash_test_1', true ) );
     209                $this->assertSame( wp_unslash( self::SLASH_3 ), get_user_meta( $user_id, 'slash_test_2', true ) );
     210                $this->assertSame( wp_unslash( self::SLASH_5 ), get_user_meta( $user_id, 'slash_test_3', true ) );
     211
     212                add_user_meta( $user_id, 'slash_test_4', self::SLASH_2 );
     213                add_user_meta( $user_id, 'slash_test_5', self::SLASH_4 );
     214                add_user_meta( $user_id, 'slash_test_6', self::SLASH_6 );
     215
     216                $this->assertSame( wp_unslash( self::SLASH_2 ), get_user_meta( $user_id, 'slash_test_4', true ) );
     217                $this->assertSame( wp_unslash( self::SLASH_4 ), get_user_meta( $user_id, 'slash_test_5', true ) );
     218                $this->assertSame( wp_unslash( self::SLASH_6 ), get_user_meta( $user_id, 'slash_test_6', true ) );
    213219        }
    214220
     
    223229                add_user_meta( $user_id, 'slash_test_3', 'foo' );
    224230
    225                 update_user_meta( $user_id, 'slash_test_1', $this->slash_1 );
    226                 update_user_meta( $user_id, 'slash_test_2', $this->slash_3 );
    227                 update_user_meta( $user_id, 'slash_test_3', $this->slash_5 );
    228 
    229                 $this->assertSame( wp_unslash( $this->slash_1 ), get_user_meta( $user_id, 'slash_test_1', true ) );
    230                 $this->assertSame( wp_unslash( $this->slash_3 ), get_user_meta( $user_id, 'slash_test_2', true ) );
    231                 $this->assertSame( wp_unslash( $this->slash_5 ), get_user_meta( $user_id, 'slash_test_3', true ) );
    232 
    233                 update_user_meta( $user_id, 'slash_test_1', $this->slash_2 );
    234                 update_user_meta( $user_id, 'slash_test_2', $this->slash_4 );
    235                 update_user_meta( $user_id, 'slash_test_3', $this->slash_6 );
    236 
    237                 $this->assertSame( wp_unslash( $this->slash_2 ), get_user_meta( $user_id, 'slash_test_1', true ) );
    238                 $this->assertSame( wp_unslash( $this->slash_4 ), get_user_meta( $user_id, 'slash_test_2', true ) );
    239                 $this->assertSame( wp_unslash( $this->slash_6 ), get_user_meta( $user_id, 'slash_test_3', true ) );
     231                update_user_meta( $user_id, 'slash_test_1', self::SLASH_1 );
     232                update_user_meta( $user_id, 'slash_test_2', self::SLASH_3 );
     233                update_user_meta( $user_id, 'slash_test_3', self::SLASH_5 );
     234
     235                $this->assertSame( wp_unslash( self::SLASH_1 ), get_user_meta( $user_id, 'slash_test_1', true ) );
     236                $this->assertSame( wp_unslash( self::SLASH_3 ), get_user_meta( $user_id, 'slash_test_2', true ) );
     237                $this->assertSame( wp_unslash( self::SLASH_5 ), get_user_meta( $user_id, 'slash_test_3', true ) );
     238
     239                update_user_meta( $user_id, 'slash_test_1', self::SLASH_2 );
     240                update_user_meta( $user_id, 'slash_test_2', self::SLASH_4 );
     241                update_user_meta( $user_id, 'slash_test_3', self::SLASH_6 );
     242
     243                $this->assertSame( wp_unslash( self::SLASH_2 ), get_user_meta( $user_id, 'slash_test_1', true ) );
     244                $this->assertSame( wp_unslash( self::SLASH_4 ), get_user_meta( $user_id, 'slash_test_2', true ) );
     245                $this->assertSame( wp_unslash( self::SLASH_6 ), get_user_meta( $user_id, 'slash_test_3', true ) );
    240246        }
    241247}
  • trunk/tests/phpunit/tests/option/slashes.php

    r52010 r53557  
    88class Tests_Option_Slashes extends WP_UnitTestCase {
    99
    10         public function set_up() {
    11                 parent::set_up();
     10        /*
     11         * It is important to test with both even and odd numbered slashes,
     12         * as KSES does a strip-then-add slashes in some of its function calls.
     13         */
    1214
    13                 // It is important to test with both even and odd numbered slashes,
    14                 // as KSES does a strip-then-add slashes in some of its function calls.
    15                 $this->slash_1 = 'String with 1 slash \\';
    16                 $this->slash_2 = 'String with 2 slashes \\\\';
    17                 $this->slash_3 = 'String with 3 slashes \\\\\\';
    18                 $this->slash_4 = 'String with 4 slashes \\\\\\\\';
    19                 $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';
    20                 $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
    21                 $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    22         }
     15        const SLASH_1 = 'String with 1 slash \\';
     16        const SLASH_2 = 'String with 2 slashes \\\\';
     17        const SLASH_3 = 'String with 3 slashes \\\\\\';
     18        const SLASH_4 = 'String with 4 slashes \\\\\\\\';
     19        const SLASH_5 = 'String with 5 slashes \\\\\\\\\\';
     20        const SLASH_6 = 'String with 6 slashes \\\\\\\\\\\\';
     21        const SLASH_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    2322
    2423        /**
     
    2625         */
    2726        public function test_add_option() {
    28                 add_option( 'slash_test_1', $this->slash_1 );
    29                 add_option( 'slash_test_2', $this->slash_2 );
    30                 add_option( 'slash_test_3', $this->slash_3 );
    31                 add_option( 'slash_test_4', $this->slash_4 );
     27                add_option( 'slash_test_1', self::SLASH_1 );
     28                add_option( 'slash_test_2', self::SLASH_2 );
     29                add_option( 'slash_test_3', self::SLASH_3 );
     30                add_option( 'slash_test_4', self::SLASH_4 );
    3231
    33                 $this->assertSame( $this->slash_1, get_option( 'slash_test_1' ) );
    34                 $this->assertSame( $this->slash_2, get_option( 'slash_test_2' ) );
    35                 $this->assertSame( $this->slash_3, get_option( 'slash_test_3' ) );
    36                 $this->assertSame( $this->slash_4, get_option( 'slash_test_4' ) );
     32                $this->assertSame( self::SLASH_1, get_option( 'slash_test_1' ) );
     33                $this->assertSame( self::SLASH_2, get_option( 'slash_test_2' ) );
     34                $this->assertSame( self::SLASH_3, get_option( 'slash_test_3' ) );
     35                $this->assertSame( self::SLASH_4, get_option( 'slash_test_4' ) );
    3736        }
    3837
     
    4342                add_option( 'slash_test_5', 'foo' );
    4443
    45                 update_option( 'slash_test_5', $this->slash_1 );
    46                 $this->assertSame( $this->slash_1, get_option( 'slash_test_5' ) );
     44                update_option( 'slash_test_5', self::SLASH_1 );
     45                $this->assertSame( self::SLASH_1, get_option( 'slash_test_5' ) );
    4746
    48                 update_option( 'slash_test_5', $this->slash_2 );
    49                 $this->assertSame( $this->slash_2, get_option( 'slash_test_5' ) );
     47                update_option( 'slash_test_5', self::SLASH_2 );
     48                $this->assertSame( self::SLASH_2, get_option( 'slash_test_5' ) );
    5049
    51                 update_option( 'slash_test_5', $this->slash_3 );
    52                 $this->assertSame( $this->slash_3, get_option( 'slash_test_5' ) );
     50                update_option( 'slash_test_5', self::SLASH_3 );
     51                $this->assertSame( self::SLASH_3, get_option( 'slash_test_5' ) );
    5352
    54                 update_option( 'slash_test_5', $this->slash_4 );
    55                 $this->assertSame( $this->slash_4, get_option( 'slash_test_5' ) );
     53                update_option( 'slash_test_5', self::SLASH_4 );
     54                $this->assertSame( self::SLASH_4, get_option( 'slash_test_5' ) );
    5655        }
    5756}
  • trunk/tests/phpunit/tests/post/slashes.php

    r52010 r53557  
    77 */
    88class Tests_Post_Slashes extends WP_UnitTestCase {
     9
     10        /*
     11         * It is important to test with both even and odd numbered slashes,
     12         * as KSES does a strip-then-add slashes in some of its function calls.
     13         */
     14
     15        const SLASH_1 = 'String with 1 slash \\';
     16        const SLASH_2 = 'String with 2 slashes \\\\';
     17        const SLASH_3 = 'String with 3 slashes \\\\\\';
     18        const SLASH_4 = 'String with 4 slashes \\\\\\\\';
     19        const SLASH_5 = 'String with 5 slashes \\\\\\\\\\';
     20        const SLASH_6 = 'String with 6 slashes \\\\\\\\\\\\';
     21        const SLASH_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
     22
    923        protected static $author_id;
    1024        protected static $post_id;
     
    1933
    2034                wp_set_current_user( self::$author_id );
    21 
    22                 // It is important to test with both even and odd numbered slashes,
    23                 // as KSES does a strip-then-add slashes in some of its function calls.
    24                 $this->slash_1 = 'String with 1 slash \\';
    25                 $this->slash_2 = 'String with 2 slashes \\\\';
    26                 $this->slash_3 = 'String with 3 slashes \\\\\\';
    27                 $this->slash_4 = 'String with 4 slashes \\\\\\\\';
    28                 $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';
    29                 $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
    30                 $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    3135        }
    3236
     
    3943                $_POST               = array();
    4044                $_POST['post_ID']    = $post_id;
    41                 $_POST['post_title'] = $this->slash_1;
    42                 $_POST['content']    = $this->slash_5;
    43                 $_POST['excerpt']    = $this->slash_7;
     45                $_POST['post_title'] = self::SLASH_1;
     46                $_POST['content']    = self::SLASH_5;
     47                $_POST['excerpt']    = self::SLASH_7;
    4448
    4549                $_POST = add_magic_quotes( $_POST ); // The edit_post() function will strip slashes.
     
    4852                $post    = get_post( $post_id );
    4953
    50                 $this->assertSame( $this->slash_1, $post->post_title );
    51                 $this->assertSame( $this->slash_5, $post->post_content );
    52                 $this->assertSame( $this->slash_7, $post->post_excerpt );
     54                $this->assertSame( self::SLASH_1, $post->post_title );
     55                $this->assertSame( self::SLASH_5, $post->post_content );
     56                $this->assertSame( self::SLASH_7, $post->post_excerpt );
    5357
    5458                $_POST               = array();
    5559                $_POST['post_ID']    = $post_id;
    56                 $_POST['post_title'] = $this->slash_2;
    57                 $_POST['content']    = $this->slash_4;
    58                 $_POST['excerpt']    = $this->slash_6;
     60                $_POST['post_title'] = self::SLASH_2;
     61                $_POST['content']    = self::SLASH_4;
     62                $_POST['excerpt']    = self::SLASH_6;
    5963
    6064                $_POST = add_magic_quotes( $_POST ); // The edit_post() function will strip slashes.
     
    6367                $post    = get_post( $post_id );
    6468
    65                 $this->assertSame( $this->slash_2, $post->post_title );
    66                 $this->assertSame( $this->slash_4, $post->post_content );
    67                 $this->assertSame( $this->slash_6, $post->post_excerpt );
     69                $this->assertSame( self::SLASH_2, $post->post_title );
     70                $this->assertSame( self::SLASH_4, $post->post_content );
     71                $this->assertSame( self::SLASH_6, $post->post_excerpt );
    6872        }
    6973
     
    7579                        array(
    7680                                'post_status'  => 'publish',
    77                                 'post_title'   => $this->slash_1,
    78                                 'post_content' => $this->slash_3,
    79                                 'post_excerpt' => $this->slash_5,
     81                                'post_title'   => self::SLASH_1,
     82                                'post_content' => self::SLASH_3,
     83                                'post_excerpt' => self::SLASH_5,
    8084                                'post_type'    => 'post',
    8185                                'slashed'      => false,
     
    8488                $post    = get_post( $post_id );
    8589
    86                 $this->assertSame( wp_unslash( $this->slash_1 ), $post->post_title );
    87                 $this->assertSame( wp_unslash( $this->slash_3 ), $post->post_content );
    88                 $this->assertSame( wp_unslash( $this->slash_5 ), $post->post_excerpt );
     90                $this->assertSame( wp_unslash( self::SLASH_1 ), $post->post_title );
     91                $this->assertSame( wp_unslash( self::SLASH_3 ), $post->post_content );
     92                $this->assertSame( wp_unslash( self::SLASH_5 ), $post->post_excerpt );
    8993
    9094                $post_id = wp_insert_post(
    9195                        array(
    9296                                'post_status'  => 'publish',
    93                                 'post_title'   => $this->slash_2,
    94                                 'post_content' => $this->slash_4,
    95                                 'post_excerpt' => $this->slash_6,
     97                                'post_title'   => self::SLASH_2,
     98                                'post_content' => self::SLASH_4,
     99                                'post_excerpt' => self::SLASH_6,
    96100                                'post_type'    => 'post',
    97101                        )
     
    99103                $post    = get_post( $post_id );
    100104
    101                 $this->assertSame( wp_unslash( $this->slash_2 ), $post->post_title );
    102                 $this->assertSame( wp_unslash( $this->slash_4 ), $post->post_content );
    103                 $this->assertSame( wp_unslash( $this->slash_6 ), $post->post_excerpt );
     105                $this->assertSame( wp_unslash( self::SLASH_2 ), $post->post_title );
     106                $this->assertSame( wp_unslash( self::SLASH_4 ), $post->post_content );
     107                $this->assertSame( wp_unslash( self::SLASH_6 ), $post->post_excerpt );
    104108        }
    105109
     
    113117                        array(
    114118                                'ID'           => $post_id,
    115                                 'post_title'   => $this->slash_1,
    116                                 'post_content' => $this->slash_3,
    117                                 'post_excerpt' => $this->slash_5,
     119                                'post_title'   => self::SLASH_1,
     120                                'post_content' => self::SLASH_3,
     121                                'post_excerpt' => self::SLASH_5,
    118122                        )
    119123                );
    120124                $post = get_post( $post_id );
    121125
    122                 $this->assertSame( wp_unslash( $this->slash_1 ), $post->post_title );
    123                 $this->assertSame( wp_unslash( $this->slash_3 ), $post->post_content );
    124                 $this->assertSame( wp_unslash( $this->slash_5 ), $post->post_excerpt );
     126                $this->assertSame( wp_unslash( self::SLASH_1 ), $post->post_title );
     127                $this->assertSame( wp_unslash( self::SLASH_3 ), $post->post_content );
     128                $this->assertSame( wp_unslash( self::SLASH_5 ), $post->post_excerpt );
    125129
    126130                wp_update_post(
    127131                        array(
    128132                                'ID'           => $post_id,
    129                                 'post_title'   => $this->slash_2,
    130                                 'post_content' => $this->slash_4,
    131                                 'post_excerpt' => $this->slash_6,
     133                                'post_title'   => self::SLASH_2,
     134                                'post_content' => self::SLASH_4,
     135                                'post_excerpt' => self::SLASH_6,
    132136                        )
    133137                );
    134138                $post = get_post( $post_id );
    135139
    136                 $this->assertSame( wp_unslash( $this->slash_2 ), $post->post_title );
    137                 $this->assertSame( wp_unslash( $this->slash_4 ), $post->post_content );
    138                 $this->assertSame( wp_unslash( $this->slash_6 ), $post->post_excerpt );
     140                $this->assertSame( wp_unslash( self::SLASH_2 ), $post->post_title );
     141                $this->assertSame( wp_unslash( self::SLASH_4 ), $post->post_content );
     142                $this->assertSame( wp_unslash( self::SLASH_6 ), $post->post_excerpt );
    139143        }
    140144
     
    144148        public function test_wp_trash_untrash() {
    145149                $post    = array(
    146                         'post_title'   => $this->slash_1,
    147                         'post_content' => $this->slash_3,
    148                         'post_excerpt' => $this->slash_5,
     150                        'post_title'   => self::SLASH_1,
     151                        'post_content' => self::SLASH_3,
     152                        'post_excerpt' => self::SLASH_5,
    149153                );
    150154                $post_id = wp_insert_post( wp_slash( $post ) );
     
    155159                $post = get_post( $post_id );
    156160
    157                 $this->assertSame( $this->slash_1, $post->post_title );
    158                 $this->assertSame( $this->slash_3, $post->post_content );
    159                 $this->assertSame( $this->slash_5, $post->post_excerpt );
     161                $this->assertSame( self::SLASH_1, $post->post_title );
     162                $this->assertSame( self::SLASH_3, $post->post_content );
     163                $this->assertSame( self::SLASH_5, $post->post_excerpt );
    160164
    161165                $untrashed = wp_untrash_post( $post_id );
     
    164168                $post = get_post( $post_id );
    165169
    166                 $this->assertSame( $this->slash_1, $post->post_title );
    167                 $this->assertSame( $this->slash_3, $post->post_content );
    168                 $this->assertSame( $this->slash_5, $post->post_excerpt );
     170                $this->assertSame( self::SLASH_1, $post->post_title );
     171                $this->assertSame( self::SLASH_3, $post->post_content );
     172                $this->assertSame( self::SLASH_5, $post->post_excerpt );
    169173        }
    170174}
  • trunk/tests/phpunit/tests/term/slashes.php

    r52010 r53557  
    77 */
    88class Tests_Term_Slashes extends WP_Ajax_UnitTestCase {
     9
     10        /*
     11         * It is important to test with both even and odd numbered slashes,
     12         * as KSES does a strip-then-add slashes in some of its function calls.
     13         */
     14
     15        const SLASH_1 = 'String with 1 slash \\';
     16        const SLASH_2 = 'String with 2 slashes \\\\';
     17        const SLASH_3 = 'String with 3 slashes \\\\\\';
     18        const SLASH_4 = 'String with 4 slashes \\\\\\\\';
     19        const SLASH_5 = 'String with 5 slashes \\\\\\\\\\';
     20        const SLASH_6 = 'String with 6 slashes \\\\\\\\\\\\';
     21        const SLASH_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
     22
    923        protected static $author_id;
    1024
     
    1731
    1832                wp_set_current_user( self::$author_id );
    19 
    20                 $this->slash_1 = 'String with 1 slash \\';
    21                 $this->slash_2 = 'String with 2 slashes \\\\';
    22                 $this->slash_3 = 'String with 3 slashes \\\\\\';
    23                 $this->slash_4 = 'String with 4 slashes \\\\\\\\';
    24                 $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';
    25                 $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
    26                 $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    2733        }
    2834
     
    3743                foreach ( $taxonomies as $taxonomy ) {
    3844                        $insert = wp_insert_term(
    39                                 $this->slash_1,
     45                                self::SLASH_1,
    4046                                $taxonomy,
    4147                                array(
    4248                                        'slug'        => 'slash_test_1_' . $taxonomy,
    43                                         'description' => $this->slash_3,
     49                                        'description' => self::SLASH_3,
    4450                                )
    4551                        );
    4652                        $term   = get_term( $insert['term_id'], $taxonomy );
    47                         $this->assertSame( wp_unslash( $this->slash_1 ), $term->name );
    48                         $this->assertSame( wp_unslash( $this->slash_3 ), $term->description );
     53                        $this->assertSame( wp_unslash( self::SLASH_1 ), $term->name );
     54                        $this->assertSame( wp_unslash( self::SLASH_3 ), $term->description );
    4955
    5056                        $insert = wp_insert_term(
    51                                 $this->slash_3,
     57                                self::SLASH_3,
    5258                                $taxonomy,
    5359                                array(
    5460                                        'slug'        => 'slash_test_2_' . $taxonomy,
    55                                         'description' => $this->slash_5,
     61                                        'description' => self::SLASH_5,
    5662                                )
    5763                        );
    5864                        $term   = get_term( $insert['term_id'], $taxonomy );
    59                         $this->assertSame( wp_unslash( $this->slash_3 ), $term->name );
    60                         $this->assertSame( wp_unslash( $this->slash_5 ), $term->description );
     65                        $this->assertSame( wp_unslash( self::SLASH_3 ), $term->name );
     66                        $this->assertSame( wp_unslash( self::SLASH_5 ), $term->description );
    6167
    6268                        $insert = wp_insert_term(
    63                                 $this->slash_2,
     69                                self::SLASH_2,
    6470                                $taxonomy,
    6571                                array(
    6672                                        'slug'        => 'slash_test_3_' . $taxonomy,
    67                                         'description' => $this->slash_4,
     73                                        'description' => self::SLASH_4,
    6874                                )
    6975                        );
    7076                        $term   = get_term( $insert['term_id'], $taxonomy );
    71                         $this->assertSame( wp_unslash( $this->slash_2 ), $term->name );
    72                         $this->assertSame( wp_unslash( $this->slash_4 ), $term->description );
     77                        $this->assertSame( wp_unslash( self::SLASH_2 ), $term->name );
     78                        $this->assertSame( wp_unslash( self::SLASH_4 ), $term->description );
    7379                }
    7480        }
     
    9399                                $taxonomy,
    94100                                array(
    95                                         'name'        => $this->slash_1,
    96                                         'description' => $this->slash_3,
     101                                        'name'        => self::SLASH_1,
     102                                        'description' => self::SLASH_3,
    97103                                )
    98104                        );
    99105
    100106                        $term = get_term( $term_id, $taxonomy );
    101                         $this->assertSame( wp_unslash( $this->slash_1 ), $term->name );
    102                         $this->assertSame( wp_unslash( $this->slash_3 ), $term->description );
     107                        $this->assertSame( wp_unslash( self::SLASH_1 ), $term->name );
     108                        $this->assertSame( wp_unslash( self::SLASH_3 ), $term->description );
    103109
    104110                        $update = wp_update_term(
     
    106112                                $taxonomy,
    107113                                array(
    108                                         'name'        => $this->slash_3,
    109                                         'description' => $this->slash_5,
     114                                        'name'        => self::SLASH_3,
     115                                        'description' => self::SLASH_5,
    110116                                )
    111117                        );
    112118                        $term   = get_term( $term_id, $taxonomy );
    113                         $this->assertSame( wp_unslash( $this->slash_3 ), $term->name );
    114                         $this->assertSame( wp_unslash( $this->slash_5 ), $term->description );
     119                        $this->assertSame( wp_unslash( self::SLASH_3 ), $term->name );
     120                        $this->assertSame( wp_unslash( self::SLASH_5 ), $term->description );
    115121
    116122                        $update = wp_update_term(
     
    118124                                $taxonomy,
    119125                                array(
    120                                         'name'        => $this->slash_2,
    121                                         'description' => $this->slash_4,
     126                                        'name'        => self::SLASH_2,
     127                                        'description' => self::SLASH_4,
    122128                                )
    123129                        );
    124130                        $term   = get_term( $term_id, $taxonomy );
    125                         $this->assertSame( wp_unslash( $this->slash_2 ), $term->name );
    126                         $this->assertSame( wp_unslash( $this->slash_4 ), $term->description );
     131                        $this->assertSame( wp_unslash( self::SLASH_2 ), $term->name );
     132                        $this->assertSame( wp_unslash( self::SLASH_4 ), $term->description );
    127133                }
    128134        }
  • trunk/tests/phpunit/tests/user/slashes.php

    r52010 r53557  
    77 */
    88class Tests_User_Slashes extends WP_UnitTestCase {
     9
     10        /*
     11         * It is important to test with both even and odd numbered slashes,
     12         * as KSES does a strip-then-add slashes in some of its function calls.
     13         */
     14
     15        const SLASH_1 = 'String with 1 slash \\';
     16        const SLASH_2 = 'String with 2 slashes \\\\';
     17        const SLASH_3 = 'String with 3 slashes \\\\\\';
     18        const SLASH_4 = 'String with 4 slashes \\\\\\\\';
     19        const SLASH_5 = 'String with 5 slashes \\\\\\\\\\';
     20        const SLASH_6 = 'String with 6 slashes \\\\\\\\\\\\';
     21        const SLASH_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
     22
    923        protected static $author_id;
    1024        protected static $user_id;
     
    1933
    2034                wp_set_current_user( self::$author_id );
    21 
    22                 // It is important to test with both even and odd numbered slashes,
    23                 // as KSES does a strip-then-add slashes in some of its function calls.
    24                 $this->slash_1 = 'String with 1 slash \\';
    25                 $this->slash_2 = 'String with 2 slashes \\\\';
    26                 $this->slash_3 = 'String with 3 slashes \\\\\\';
    27                 $this->slash_4 = 'String with 4 slashes \\\\\\\\';
    28                 $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';
    29                 $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
    30                 $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    3135        }
    3236
     
    4347                $_POST['role']         = 'subscriber';
    4448                $_POST['email']        = 'user1@example.com';
    45                 $_POST['first_name']   = $this->slash_1;
    46                 $_POST['last_name']    = $this->slash_3;
    47                 $_POST['nickname']     = $this->slash_5;
    48                 $_POST['display_name'] = $this->slash_7;
    49                 $_POST['description']  = $this->slash_3;
     49                $_POST['first_name']   = self::SLASH_1;
     50                $_POST['last_name']    = self::SLASH_3;
     51                $_POST['nickname']     = self::SLASH_5;
     52                $_POST['display_name'] = self::SLASH_7;
     53                $_POST['description']  = self::SLASH_3;
    5054
    5155                $_POST = add_magic_quotes( $_POST ); // The add_user() function will strip slashes.
     
    5458                $user    = get_user_to_edit( $user_id );
    5559
    56                 $this->assertSame( $this->slash_1, $user->first_name );
    57                 $this->assertSame( $this->slash_3, $user->last_name );
    58                 $this->assertSame( $this->slash_5, $user->nickname );
    59                 $this->assertSame( $this->slash_7, $user->display_name );
    60                 $this->assertSame( $this->slash_3, $user->description );
     60                $this->assertSame( self::SLASH_1, $user->first_name );
     61                $this->assertSame( self::SLASH_3, $user->last_name );
     62                $this->assertSame( self::SLASH_5, $user->nickname );
     63                $this->assertSame( self::SLASH_7, $user->display_name );
     64                $this->assertSame( self::SLASH_3, $user->description );
    6165
    6266                $_POST                 = array();
     
    6872                $_POST['role']         = 'subscriber';
    6973                $_POST['email']        = 'user2@example.com';
    70                 $_POST['first_name']   = $this->slash_2;
    71                 $_POST['last_name']    = $this->slash_4;
    72                 $_POST['nickname']     = $this->slash_6;
    73                 $_POST['display_name'] = $this->slash_2;
    74                 $_POST['description']  = $this->slash_4;
     74                $_POST['first_name']   = self::SLASH_2;
     75                $_POST['last_name']    = self::SLASH_4;
     76                $_POST['nickname']     = self::SLASH_6;
     77                $_POST['display_name'] = self::SLASH_2;
     78                $_POST['description']  = self::SLASH_4;
    7579
    7680                $_POST = add_magic_quotes( $_POST ); // The add_user() function will strip slashes.
     
    7983                $user    = get_user_to_edit( $user_id );
    8084
    81                 $this->assertSame( $this->slash_2, $user->first_name );
    82                 $this->assertSame( $this->slash_4, $user->last_name );
    83                 $this->assertSame( $this->slash_6, $user->nickname );
    84                 $this->assertSame( $this->slash_2, $user->display_name );
    85                 $this->assertSame( $this->slash_4, $user->description );
     85                $this->assertSame( self::SLASH_2, $user->first_name );
     86                $this->assertSame( self::SLASH_4, $user->last_name );
     87                $this->assertSame( self::SLASH_6, $user->nickname );
     88                $this->assertSame( self::SLASH_2, $user->display_name );
     89                $this->assertSame( self::SLASH_4, $user->description );
    8690        }
    8791
     
    97101                $_POST['role']         = 'subscriber';
    98102                $_POST['email']        = 'user1@example.com';
    99                 $_POST['first_name']   = $this->slash_1;
    100                 $_POST['last_name']    = $this->slash_3;
    101                 $_POST['nickname']     = $this->slash_5;
    102                 $_POST['display_name'] = $this->slash_7;
    103                 $_POST['description']  = $this->slash_3;
     103                $_POST['first_name']   = self::SLASH_1;
     104                $_POST['last_name']    = self::SLASH_3;
     105                $_POST['nickname']     = self::SLASH_5;
     106                $_POST['display_name'] = self::SLASH_7;
     107                $_POST['description']  = self::SLASH_3;
    104108
    105109                $_POST = add_magic_quotes( $_POST ); // The edit_user() function will strip slashes.
     
    108112                $user    = get_user_to_edit( $user_id );
    109113
    110                 $this->assertSame( $this->slash_1, $user->first_name );
    111                 $this->assertSame( $this->slash_3, $user->last_name );
    112                 $this->assertSame( $this->slash_5, $user->nickname );
    113                 $this->assertSame( $this->slash_7, $user->display_name );
    114                 $this->assertSame( $this->slash_3, $user->description );
     114                $this->assertSame( self::SLASH_1, $user->first_name );
     115                $this->assertSame( self::SLASH_3, $user->last_name );
     116                $this->assertSame( self::SLASH_5, $user->nickname );
     117                $this->assertSame( self::SLASH_7, $user->display_name );
     118                $this->assertSame( self::SLASH_3, $user->description );
    115119
    116120                $_POST                 = array();
     
    119123                $_POST['role']         = 'subscriber';
    120124                $_POST['email']        = 'user2@example.com';
    121                 $_POST['first_name']   = $this->slash_2;
    122                 $_POST['last_name']    = $this->slash_4;
    123                 $_POST['nickname']     = $this->slash_6;
    124                 $_POST['display_name'] = $this->slash_2;
    125                 $_POST['description']  = $this->slash_4;
     125                $_POST['first_name']   = self::SLASH_2;
     126                $_POST['last_name']    = self::SLASH_4;
     127                $_POST['nickname']     = self::SLASH_6;
     128                $_POST['display_name'] = self::SLASH_2;
     129                $_POST['description']  = self::SLASH_4;
    126130
    127131                $_POST = add_magic_quotes( $_POST ); // The edit_user() function will strip slashes.
     
    130134                $user    = get_user_to_edit( $user_id );
    131135
    132                 $this->assertSame( $this->slash_2, $user->first_name );
    133                 $this->assertSame( $this->slash_4, $user->last_name );
    134                 $this->assertSame( $this->slash_6, $user->nickname );
    135                 $this->assertSame( $this->slash_2, $user->display_name );
    136                 $this->assertSame( $this->slash_4, $user->description );
     136                $this->assertSame( self::SLASH_2, $user->first_name );
     137                $this->assertSame( self::SLASH_4, $user->last_name );
     138                $this->assertSame( self::SLASH_6, $user->nickname );
     139                $this->assertSame( self::SLASH_2, $user->display_name );
     140                $this->assertSame( self::SLASH_4, $user->description );
    137141        }
    138142
     
    146150                                'role'         => 'subscriber',
    147151                                'email'        => 'user3@example.com',
    148                                 'first_name'   => $this->slash_1,
    149                                 'last_name'    => $this->slash_3,
    150                                 'nickname'     => $this->slash_5,
    151                                 'display_name' => $this->slash_7,
    152                                 'description'  => $this->slash_3,
     152                                'first_name'   => self::SLASH_1,
     153                                'last_name'    => self::SLASH_3,
     154                                'nickname'     => self::SLASH_5,
     155                                'display_name' => self::SLASH_7,
     156                                'description'  => self::SLASH_3,
    153157                                'user_pass'    => '',
    154158                        )
     
    156160                $user    = get_user_to_edit( $user_id );
    157161
    158                 $this->assertSame( wp_unslash( $this->slash_1 ), $user->first_name );
    159                 $this->assertSame( wp_unslash( $this->slash_3 ), $user->last_name );
    160                 $this->assertSame( wp_unslash( $this->slash_5 ), $user->nickname );
    161                 $this->assertSame( wp_unslash( $this->slash_7 ), $user->display_name );
    162                 $this->assertSame( wp_unslash( $this->slash_3 ), $user->description );
     162                $this->assertSame( wp_unslash( self::SLASH_1 ), $user->first_name );
     163                $this->assertSame( wp_unslash( self::SLASH_3 ), $user->last_name );
     164                $this->assertSame( wp_unslash( self::SLASH_5 ), $user->nickname );
     165                $this->assertSame( wp_unslash( self::SLASH_7 ), $user->display_name );
     166                $this->assertSame( wp_unslash( self::SLASH_3 ), $user->description );
    163167
    164168                $user_id = wp_insert_user(
     
    167171                                'role'         => 'subscriber',
    168172                                'email'        => 'user3@example.com',
    169                                 'first_name'   => $this->slash_2,
    170                                 'last_name'    => $this->slash_4,
    171                                 'nickname'     => $this->slash_6,
    172                                 'display_name' => $this->slash_2,
    173                                 'description'  => $this->slash_4,
     173                                'first_name'   => self::SLASH_2,
     174                                'last_name'    => self::SLASH_4,
     175                                'nickname'     => self::SLASH_6,
     176                                'display_name' => self::SLASH_2,
     177                                'description'  => self::SLASH_4,
    174178                                'user_pass'    => '',
    175179                        )
     
    177181                $user    = get_user_to_edit( $user_id );
    178182
    179                 $this->assertSame( wp_unslash( $this->slash_2 ), $user->first_name );
    180                 $this->assertSame( wp_unslash( $this->slash_4 ), $user->last_name );
    181                 $this->assertSame( wp_unslash( $this->slash_6 ), $user->nickname );
    182                 $this->assertSame( wp_unslash( $this->slash_2 ), $user->display_name );
    183                 $this->assertSame( wp_unslash( $this->slash_4 ), $user->description );
     183                $this->assertSame( wp_unslash( self::SLASH_2 ), $user->first_name );
     184                $this->assertSame( wp_unslash( self::SLASH_4 ), $user->last_name );
     185                $this->assertSame( wp_unslash( self::SLASH_6 ), $user->nickname );
     186                $this->assertSame( wp_unslash( self::SLASH_2 ), $user->display_name );
     187                $this->assertSame( wp_unslash( self::SLASH_4 ), $user->description );
    184188        }
    185189
     
    193197                                'ID'           => $user_id,
    194198                                'role'         => 'subscriber',
    195                                 'first_name'   => $this->slash_1,
    196                                 'last_name'    => $this->slash_3,
    197                                 'nickname'     => $this->slash_5,
    198                                 'display_name' => $this->slash_7,
    199                                 'description'  => $this->slash_3,
    200                         )
    201                 );
    202                 $user    = get_user_to_edit( $user_id );
    203 
    204                 $this->assertSame( wp_unslash( $this->slash_1 ), $user->first_name );
    205                 $this->assertSame( wp_unslash( $this->slash_3 ), $user->last_name );
    206                 $this->assertSame( wp_unslash( $this->slash_5 ), $user->nickname );
    207                 $this->assertSame( wp_unslash( $this->slash_7 ), $user->display_name );
    208                 $this->assertSame( wp_unslash( $this->slash_3 ), $user->description );
     199                                'first_name'   => self::SLASH_1,
     200                                'last_name'    => self::SLASH_3,
     201                                'nickname'     => self::SLASH_5,
     202                                'display_name' => self::SLASH_7,
     203                                'description'  => self::SLASH_3,
     204                        )
     205                );
     206                $user    = get_user_to_edit( $user_id );
     207
     208                $this->assertSame( wp_unslash( self::SLASH_1 ), $user->first_name );
     209                $this->assertSame( wp_unslash( self::SLASH_3 ), $user->last_name );
     210                $this->assertSame( wp_unslash( self::SLASH_5 ), $user->nickname );
     211                $this->assertSame( wp_unslash( self::SLASH_7 ), $user->display_name );
     212                $this->assertSame( wp_unslash( self::SLASH_3 ), $user->description );
    209213
    210214                $user_id = wp_update_user(
     
    212216                                'ID'           => $user_id,
    213217                                'role'         => 'subscriber',
    214                                 'first_name'   => $this->slash_2,
    215                                 'last_name'    => $this->slash_4,
    216                                 'nickname'     => $this->slash_6,
    217                                 'display_name' => $this->slash_2,
    218                                 'description'  => $this->slash_4,
    219                         )
    220                 );
    221                 $user    = get_user_to_edit( $user_id );
    222 
    223                 $this->assertSame( wp_unslash( $this->slash_2 ), $user->first_name );
    224                 $this->assertSame( wp_unslash( $this->slash_4 ), $user->last_name );
    225                 $this->assertSame( wp_unslash( $this->slash_6 ), $user->nickname );
    226                 $this->assertSame( wp_unslash( $this->slash_2 ), $user->display_name );
    227                 $this->assertSame( wp_unslash( $this->slash_4 ), $user->description );
     218                                'first_name'   => self::SLASH_2,
     219                                'last_name'    => self::SLASH_4,
     220                                'nickname'     => self::SLASH_6,
     221                                'display_name' => self::SLASH_2,
     222                                'description'  => self::SLASH_4,
     223                        )
     224                );
     225                $user    = get_user_to_edit( $user_id );
     226
     227                $this->assertSame( wp_unslash( self::SLASH_2 ), $user->first_name );
     228                $this->assertSame( wp_unslash( self::SLASH_4 ), $user->last_name );
     229                $this->assertSame( wp_unslash( self::SLASH_6 ), $user->nickname );
     230                $this->assertSame( wp_unslash( self::SLASH_2 ), $user->display_name );
     231                $this->assertSame( wp_unslash( self::SLASH_4 ), $user->description );
    228232        }
    229233
Note: See TracChangeset for help on using the changeset viewer.