Make WordPress Core


Ignore:
Timestamp:
09/19/2020 10:53:15 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Give the $id variable in slashed data tests a more descriptive name.

See #50767, #51344.

File:
1 edited

Legend:

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

    r48937 r49004  
    3535     */
    3636    function test_edit_post() {
    37         $id = self::factory()->post->create();
     37        $post_id = self::factory()->post->create();
     38
    3839        if ( function_exists( 'wp_add_post_meta' ) ) {
    39             $meta_1 = wp_add_post_meta( $id, 'slash_test_1', 'foo' );
    40             $meta_2 = wp_add_post_meta( $id, 'slash_test_2', 'foo' );
    41             $meta_3 = wp_add_post_meta( $id, 'slash_test_3', 'foo' );
     40            $meta_1 = wp_add_post_meta( $post_id, 'slash_test_1', 'foo' );
     41            $meta_2 = wp_add_post_meta( $post_id, 'slash_test_2', 'foo' );
     42            $meta_3 = wp_add_post_meta( $post_id, 'slash_test_3', 'foo' );
    4243        } else {
    4344            // Expects slashed data.
    44             $meta_1 = add_post_meta( $id, 'slash_test_1', addslashes( 'foo' ) );
    45             $meta_2 = add_post_meta( $id, 'slash_test_2', addslashes( 'foo' ) );
    46             $meta_3 = add_post_meta( $id, 'slash_test_3', addslashes( 'foo' ) );
     45            $meta_1 = add_post_meta( $post_id, 'slash_test_1', addslashes( 'foo' ) );
     46            $meta_2 = add_post_meta( $post_id, 'slash_test_2', addslashes( 'foo' ) );
     47            $meta_3 = add_post_meta( $post_id, 'slash_test_3', addslashes( 'foo' ) );
    4748        }
    4849
    4950        $_POST                  = array();
    50         $_POST['post_ID']       = $id;
     51        $_POST['post_ID']       = $post_id;
    5152        $_POST['metakeyselect'] = '#NONE#';
    5253        $_POST['metakeyinput']  = 'slash_test_0';
     
    7071
    7172        edit_post();
    72         $post = get_post( $id );
    73 
    74         $this->assertSame( $this->slash_6, get_post_meta( $id, 'slash_test_0', true ) );
    75         $this->assertSame( $this->slash_1, get_post_meta( $id, 'slash_test_1', true ) );
    76         $this->assertSame( $this->slash_3, get_post_meta( $id, 'slash_test_2', true ) );
    77         $this->assertSame( $this->slash_4, get_post_meta( $id, 'slash_test_3', true ) );
     73        $post = get_post( $post_id );
     74
     75        $this->assertSame( $this->slash_6, get_post_meta( $post_id, 'slash_test_0', true ) );
     76        $this->assertSame( $this->slash_1, get_post_meta( $post_id, 'slash_test_1', true ) );
     77        $this->assertSame( $this->slash_3, get_post_meta( $post_id, 'slash_test_2', true ) );
     78        $this->assertSame( $this->slash_4, get_post_meta( $post_id, 'slash_test_3', true ) );
    7879
    7980        $_POST                  = array();
    80         $_POST['post_ID']       = $id;
     81        $_POST['post_ID']       = $post_id;
    8182        $_POST['metakeyselect'] = '#NONE#';
    8283        $_POST['metakeyinput']  = 'slash_test_0';
     
    100101
    101102        edit_post();
    102         $post = get_post( $id );
    103 
    104         $this->assertSame( $this->slash_2, get_post_meta( $id, 'slash_test_1', true ) );
    105         $this->assertSame( $this->slash_4, get_post_meta( $id, 'slash_test_2', true ) );
    106         $this->assertSame( $this->slash_5, get_post_meta( $id, 'slash_test_3', true ) );
     103        $post = get_post( $post_id );
     104
     105        $this->assertSame( $this->slash_2, get_post_meta( $post_id, 'slash_test_1', true ) );
     106        $this->assertSame( $this->slash_4, get_post_meta( $post_id, 'slash_test_2', true ) );
     107        $this->assertSame( $this->slash_5, get_post_meta( $post_id, 'slash_test_3', true ) );
    107108    }
    108109
     
    111112     */
    112113    function test_add_post_meta() {
    113         $id = self::factory()->post->create();
    114         add_post_meta( $id, 'slash_test_1', addslashes( $this->slash_1 ) );
    115         add_post_meta( $id, 'slash_test_2', addslashes( $this->slash_3 ) );
    116         add_post_meta( $id, 'slash_test_3', addslashes( $this->slash_4 ) );
    117 
    118         $this->assertSame( $this->slash_1, get_post_meta( $id, 'slash_test_1', true ) );
    119         $this->assertSame( $this->slash_3, get_post_meta( $id, 'slash_test_2', true ) );
    120         $this->assertSame( $this->slash_4, get_post_meta( $id, 'slash_test_3', true ) );
     114        $post_id = self::factory()->post->create();
     115
     116        add_post_meta( $post_id, 'slash_test_1', addslashes( $this->slash_1 ) );
     117        add_post_meta( $post_id, 'slash_test_2', addslashes( $this->slash_3 ) );
     118        add_post_meta( $post_id, 'slash_test_3', addslashes( $this->slash_4 ) );
     119
     120        $this->assertSame( $this->slash_1, get_post_meta( $post_id, 'slash_test_1', true ) );
     121        $this->assertSame( $this->slash_3, get_post_meta( $post_id, 'slash_test_2', true ) );
     122        $this->assertSame( $this->slash_4, get_post_meta( $post_id, 'slash_test_3', true ) );
    121123    }
    122124
     
    125127     */
    126128    function test_update_post_meta() {
    127         $id = self::factory()->post->create();
    128         update_post_meta( $id, 'slash_test_1', addslashes( $this->slash_1 ) );
    129         update_post_meta( $id, 'slash_test_2', addslashes( $this->slash_3 ) );
    130         update_post_meta( $id, 'slash_test_3', addslashes( $this->slash_4 ) );
    131 
    132         $this->assertSame( $this->slash_1, get_post_meta( $id, 'slash_test_1', true ) );
    133         $this->assertSame( $this->slash_3, get_post_meta( $id, 'slash_test_2', true ) );
    134         $this->assertSame( $this->slash_4, get_post_meta( $id, 'slash_test_3', true ) );
     129        $post_id = self::factory()->post->create();
     130
     131        update_post_meta( $post_id, 'slash_test_1', addslashes( $this->slash_1 ) );
     132        update_post_meta( $post_id, 'slash_test_2', addslashes( $this->slash_3 ) );
     133        update_post_meta( $post_id, 'slash_test_3', addslashes( $this->slash_4 ) );
     134
     135        $this->assertSame( $this->slash_1, get_post_meta( $post_id, 'slash_test_1', true ) );
     136        $this->assertSame( $this->slash_3, get_post_meta( $post_id, 'slash_test_2', true ) );
     137        $this->assertSame( $this->slash_4, get_post_meta( $post_id, 'slash_test_3', true ) );
    135138    }
    136139
     
    139142     */
    140143    function test_add_comment_meta() {
    141         $id = self::$comment_id;
    142 
    143         add_comment_meta( $id, 'slash_test_1', $this->slash_1 );
    144         add_comment_meta( $id, 'slash_test_2', $this->slash_3 );
    145         add_comment_meta( $id, 'slash_test_3', $this->slash_5 );
    146 
    147         $this->assertSame( wp_unslash( $this->slash_1 ), get_comment_meta( $id, 'slash_test_1', true ) );
    148         $this->assertSame( wp_unslash( $this->slash_3 ), get_comment_meta( $id, 'slash_test_2', true ) );
    149         $this->assertSame( wp_unslash( $this->slash_5 ), get_comment_meta( $id, 'slash_test_3', true ) );
    150 
    151         add_comment_meta( $id, 'slash_test_4', $this->slash_2 );
    152         add_comment_meta( $id, 'slash_test_5', $this->slash_4 );
    153         add_comment_meta( $id, 'slash_test_6', $this->slash_6 );
    154 
    155         $this->assertSame( wp_unslash( $this->slash_2 ), get_comment_meta( $id, 'slash_test_4', true ) );
    156         $this->assertSame( wp_unslash( $this->slash_4 ), get_comment_meta( $id, 'slash_test_5', true ) );
    157         $this->assertSame( wp_unslash( $this->slash_6 ), get_comment_meta( $id, 'slash_test_6', true ) );
     144        $comment_id = self::$comment_id;
     145
     146        add_comment_meta( $comment_id, 'slash_test_1', $this->slash_1 );
     147        add_comment_meta( $comment_id, 'slash_test_2', $this->slash_3 );
     148        add_comment_meta( $comment_id, 'slash_test_3', $this->slash_5 );
     149
     150        $this->assertSame( wp_unslash( $this->slash_1 ), get_comment_meta( $comment_id, 'slash_test_1', true ) );
     151        $this->assertSame( wp_unslash( $this->slash_3 ), get_comment_meta( $comment_id, 'slash_test_2', true ) );
     152        $this->assertSame( wp_unslash( $this->slash_5 ), get_comment_meta( $comment_id, 'slash_test_3', true ) );
     153
     154        add_comment_meta( $comment_id, 'slash_test_4', $this->slash_2 );
     155        add_comment_meta( $comment_id, 'slash_test_5', $this->slash_4 );
     156        add_comment_meta( $comment_id, 'slash_test_6', $this->slash_6 );
     157
     158        $this->assertSame( wp_unslash( $this->slash_2 ), get_comment_meta( $comment_id, 'slash_test_4', true ) );
     159        $this->assertSame( wp_unslash( $this->slash_4 ), get_comment_meta( $comment_id, 'slash_test_5', true ) );
     160        $this->assertSame( wp_unslash( $this->slash_6 ), get_comment_meta( $comment_id, 'slash_test_6', true ) );
    158161    }
    159162
     
    162165     */
    163166    function test_update_comment_meta() {
    164         $id = self::$comment_id;
    165 
    166         add_comment_meta( $id, 'slash_test_1', 'foo' );
    167         add_comment_meta( $id, 'slash_test_2', 'foo' );
    168         add_comment_meta( $id, 'slash_test_3', 'foo' );
    169 
    170         update_comment_meta( $id, 'slash_test_1', $this->slash_1 );
    171         update_comment_meta( $id, 'slash_test_2', $this->slash_3 );
    172         update_comment_meta( $id, 'slash_test_3', $this->slash_5 );
    173 
    174         $this->assertSame( wp_unslash( $this->slash_1 ), get_comment_meta( $id, 'slash_test_1', true ) );
    175         $this->assertSame( wp_unslash( $this->slash_3 ), get_comment_meta( $id, 'slash_test_2', true ) );
    176         $this->assertSame( wp_unslash( $this->slash_5 ), get_comment_meta( $id, 'slash_test_3', true ) );
    177 
    178         update_comment_meta( $id, 'slash_test_1', $this->slash_2 );
    179         update_comment_meta( $id, 'slash_test_2', $this->slash_4 );
    180         update_comment_meta( $id, 'slash_test_3', $this->slash_6 );
    181 
    182         $this->assertSame( wp_unslash( $this->slash_2 ), get_comment_meta( $id, 'slash_test_1', true ) );
    183         $this->assertSame( wp_unslash( $this->slash_4 ), get_comment_meta( $id, 'slash_test_2', true ) );
    184         $this->assertSame( wp_unslash( $this->slash_6 ), get_comment_meta( $id, 'slash_test_3', true ) );
     167        $comment_id = self::$comment_id;
     168
     169        add_comment_meta( $comment_id, 'slash_test_1', 'foo' );
     170        add_comment_meta( $comment_id, 'slash_test_2', 'foo' );
     171        add_comment_meta( $comment_id, 'slash_test_3', 'foo' );
     172
     173        update_comment_meta( $comment_id, 'slash_test_1', $this->slash_1 );
     174        update_comment_meta( $comment_id, 'slash_test_2', $this->slash_3 );
     175        update_comment_meta( $comment_id, 'slash_test_3', $this->slash_5 );
     176
     177        $this->assertSame( wp_unslash( $this->slash_1 ), get_comment_meta( $comment_id, 'slash_test_1', true ) );
     178        $this->assertSame( wp_unslash( $this->slash_3 ), get_comment_meta( $comment_id, 'slash_test_2', true ) );
     179        $this->assertSame( wp_unslash( $this->slash_5 ), get_comment_meta( $comment_id, 'slash_test_3', true ) );
     180
     181        update_comment_meta( $comment_id, 'slash_test_1', $this->slash_2 );
     182        update_comment_meta( $comment_id, 'slash_test_2', $this->slash_4 );
     183        update_comment_meta( $comment_id, 'slash_test_3', $this->slash_6 );
     184
     185        $this->assertSame( wp_unslash( $this->slash_2 ), get_comment_meta( $comment_id, 'slash_test_1', true ) );
     186        $this->assertSame( wp_unslash( $this->slash_4 ), get_comment_meta( $comment_id, 'slash_test_2', true ) );
     187        $this->assertSame( wp_unslash( $this->slash_6 ), get_comment_meta( $comment_id, 'slash_test_3', true ) );
    185188    }
    186189
     
    189192     */
    190193    function test_add_user_meta() {
    191         $id = self::factory()->user->create();
    192 
    193         add_user_meta( $id, 'slash_test_1', $this->slash_1 );
    194         add_user_meta( $id, 'slash_test_2', $this->slash_3 );
    195         add_user_meta( $id, 'slash_test_3', $this->slash_5 );
    196 
    197         $this->assertSame( wp_unslash( $this->slash_1 ), get_user_meta( $id, 'slash_test_1', true ) );
    198         $this->assertSame( wp_unslash( $this->slash_3 ), get_user_meta( $id, 'slash_test_2', true ) );
    199         $this->assertSame( wp_unslash( $this->slash_5 ), get_user_meta( $id, 'slash_test_3', true ) );
    200 
    201         add_user_meta( $id, 'slash_test_4', $this->slash_2 );
    202         add_user_meta( $id, 'slash_test_5', $this->slash_4 );
    203         add_user_meta( $id, 'slash_test_6', $this->slash_6 );
    204 
    205         $this->assertSame( wp_unslash( $this->slash_2 ), get_user_meta( $id, 'slash_test_4', true ) );
    206         $this->assertSame( wp_unslash( $this->slash_4 ), get_user_meta( $id, 'slash_test_5', true ) );
    207         $this->assertSame( wp_unslash( $this->slash_6 ), get_user_meta( $id, 'slash_test_6', true ) );
     194        $user_id = self::factory()->user->create();
     195
     196        add_user_meta( $user_id, 'slash_test_1', $this->slash_1 );
     197        add_user_meta( $user_id, 'slash_test_2', $this->slash_3 );
     198        add_user_meta( $user_id, 'slash_test_3', $this->slash_5 );
     199
     200        $this->assertSame( wp_unslash( $this->slash_1 ), get_user_meta( $user_id, 'slash_test_1', true ) );
     201        $this->assertSame( wp_unslash( $this->slash_3 ), get_user_meta( $user_id, 'slash_test_2', true ) );
     202        $this->assertSame( wp_unslash( $this->slash_5 ), get_user_meta( $user_id, 'slash_test_3', true ) );
     203
     204        add_user_meta( $user_id, 'slash_test_4', $this->slash_2 );
     205        add_user_meta( $user_id, 'slash_test_5', $this->slash_4 );
     206        add_user_meta( $user_id, 'slash_test_6', $this->slash_6 );
     207
     208        $this->assertSame( wp_unslash( $this->slash_2 ), get_user_meta( $user_id, 'slash_test_4', true ) );
     209        $this->assertSame( wp_unslash( $this->slash_4 ), get_user_meta( $user_id, 'slash_test_5', true ) );
     210        $this->assertSame( wp_unslash( $this->slash_6 ), get_user_meta( $user_id, 'slash_test_6', true ) );
    208211    }
    209212
     
    212215     */
    213216    function test_update_user_meta() {
    214         $id = self::factory()->user->create();
    215 
    216         add_user_meta( $id, 'slash_test_1', 'foo' );
    217         add_user_meta( $id, 'slash_test_2', 'foo' );
    218         add_user_meta( $id, 'slash_test_3', 'foo' );
    219 
    220         update_user_meta( $id, 'slash_test_1', $this->slash_1 );
    221         update_user_meta( $id, 'slash_test_2', $this->slash_3 );
    222         update_user_meta( $id, 'slash_test_3', $this->slash_5 );
    223 
    224         $this->assertSame( wp_unslash( $this->slash_1 ), get_user_meta( $id, 'slash_test_1', true ) );
    225         $this->assertSame( wp_unslash( $this->slash_3 ), get_user_meta( $id, 'slash_test_2', true ) );
    226         $this->assertSame( wp_unslash( $this->slash_5 ), get_user_meta( $id, 'slash_test_3', true ) );
    227 
    228         update_user_meta( $id, 'slash_test_1', $this->slash_2 );
    229         update_user_meta( $id, 'slash_test_2', $this->slash_4 );
    230         update_user_meta( $id, 'slash_test_3', $this->slash_6 );
    231 
    232         $this->assertSame( wp_unslash( $this->slash_2 ), get_user_meta( $id, 'slash_test_1', true ) );
    233         $this->assertSame( wp_unslash( $this->slash_4 ), get_user_meta( $id, 'slash_test_2', true ) );
    234         $this->assertSame( wp_unslash( $this->slash_6 ), get_user_meta( $id, 'slash_test_3', true ) );
     217        $user_id = self::factory()->user->create();
     218
     219        add_user_meta( $user_id, 'slash_test_1', 'foo' );
     220        add_user_meta( $user_id, 'slash_test_2', 'foo' );
     221        add_user_meta( $user_id, 'slash_test_3', 'foo' );
     222
     223        update_user_meta( $user_id, 'slash_test_1', $this->slash_1 );
     224        update_user_meta( $user_id, 'slash_test_2', $this->slash_3 );
     225        update_user_meta( $user_id, 'slash_test_3', $this->slash_5 );
     226
     227        $this->assertSame( wp_unslash( $this->slash_1 ), get_user_meta( $user_id, 'slash_test_1', true ) );
     228        $this->assertSame( wp_unslash( $this->slash_3 ), get_user_meta( $user_id, 'slash_test_2', true ) );
     229        $this->assertSame( wp_unslash( $this->slash_5 ), get_user_meta( $user_id, 'slash_test_3', true ) );
     230
     231        update_user_meta( $user_id, 'slash_test_1', $this->slash_2 );
     232        update_user_meta( $user_id, 'slash_test_2', $this->slash_4 );
     233        update_user_meta( $user_id, 'slash_test_3', $this->slash_6 );
     234
     235        $this->assertSame( wp_unslash( $this->slash_2 ), get_user_meta( $user_id, 'slash_test_1', true ) );
     236        $this->assertSame( wp_unslash( $this->slash_4 ), get_user_meta( $user_id, 'slash_test_2', true ) );
     237        $this->assertSame( wp_unslash( $this->slash_6 ), get_user_meta( $user_id, 'slash_test_3', true ) );
    235238    }
    236239}
Note: See TracChangeset for help on using the changeset viewer.