Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r35244 r42343  
    2626        /**
    2727         * Tests the controller function that expects slashed data
    28          *
    2928         */
    3029        function test_add_user() {
    31                 $_POST = $_GET = $_REQUEST = array();
    32                 $_POST['user_login'] = 'slash_example_user_1';
    33                 $_POST['pass1'] = 'password';
    34                 $_POST['pass2'] = 'password';
    35                 $_POST['role'] = 'subscriber';
    36                 $_POST['email'] = 'user1@example.com';
    37                 $_POST['first_name'] = $this->slash_1;
    38                 $_POST['last_name'] = $this->slash_3;
    39                 $_POST['nickname'] = $this->slash_5;
     30                $_POST                 = $_GET = $_REQUEST = array();
     31                $_POST['user_login']   = 'slash_example_user_1';
     32                $_POST['pass1']        = 'password';
     33                $_POST['pass2']        = 'password';
     34                $_POST['role']         = 'subscriber';
     35                $_POST['email']        = 'user1@example.com';
     36                $_POST['first_name']   = $this->slash_1;
     37                $_POST['last_name']    = $this->slash_3;
     38                $_POST['nickname']     = $this->slash_5;
    4039                $_POST['display_name'] = $this->slash_7;
    41                 $_POST['description'] = $this->slash_3;
    42                 $_POST = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes
    43 
    44                 $id = add_user();
     40                $_POST['description']  = $this->slash_3;
     41                $_POST                 = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes
     42
     43                $id   = add_user();
    4544                $user = get_user_to_edit( $id );
    4645
     
    5150                $this->assertEquals( $this->slash_3, $user->description );
    5251
    53                 $_POST = $_GET = $_REQUEST = array();
    54                 $_POST['user_login'] = 'slash_example_user_2';
    55                 $_POST['pass1'] = 'password';
    56                 $_POST['pass2'] = 'password';
    57                 $_POST['role'] = 'subscriber';
    58                 $_POST['email'] = 'user2@example.com';
    59                 $_POST['first_name'] = $this->slash_2;
    60                 $_POST['last_name'] = $this->slash_4;
    61                 $_POST['nickname'] = $this->slash_6;
     52                $_POST                 = $_GET = $_REQUEST = array();
     53                $_POST['user_login']   = 'slash_example_user_2';
     54                $_POST['pass1']        = 'password';
     55                $_POST['pass2']        = 'password';
     56                $_POST['role']         = 'subscriber';
     57                $_POST['email']        = 'user2@example.com';
     58                $_POST['first_name']   = $this->slash_2;
     59                $_POST['last_name']    = $this->slash_4;
     60                $_POST['nickname']     = $this->slash_6;
    6261                $_POST['display_name'] = $this->slash_2;
    63                 $_POST['description'] = $this->slash_4;
    64                 $_POST = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes
    65 
    66                 $id = add_user();
     62                $_POST['description']  = $this->slash_4;
     63                $_POST                 = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes
     64
     65                $id   = add_user();
    6766                $user = get_user_to_edit( $id );
    6867
     
    7675        /**
    7776         * Tests the controller function that expects slashed data
    78          *
    7977         */
    8078        function test_edit_user() {
    8179                $id = self::factory()->user->create();
    8280
    83                 $_POST = $_GET = $_REQUEST = array();
    84                 $_POST['role'] = 'subscriber';
    85                 $_POST['email'] = 'user1@example.com';
    86                 $_POST['first_name'] = $this->slash_1;
    87                 $_POST['last_name'] = $this->slash_3;
    88                 $_POST['nickname'] = $this->slash_5;
     81                $_POST                 = $_GET = $_REQUEST = array();
     82                $_POST['role']         = 'subscriber';
     83                $_POST['email']        = 'user1@example.com';
     84                $_POST['first_name']   = $this->slash_1;
     85                $_POST['last_name']    = $this->slash_3;
     86                $_POST['nickname']     = $this->slash_5;
    8987                $_POST['display_name'] = $this->slash_7;
    90                 $_POST['description'] = $this->slash_3;
    91                 $_POST = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes
    92 
    93                 $id = edit_user( $id );
     88                $_POST['description']  = $this->slash_3;
     89                $_POST                 = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes
     90
     91                $id   = edit_user( $id );
    9492                $user = get_user_to_edit( $id );
    9593
     
    10098                $this->assertEquals( $this->slash_3, $user->description );
    10199
    102                 $_POST = $_GET = $_REQUEST = array();
    103                 $_POST['role'] = 'subscriber';
    104                 $_POST['email'] = 'user2@example.com';
    105                 $_POST['first_name'] = $this->slash_2;
    106                 $_POST['last_name'] = $this->slash_4;
    107                 $_POST['nickname'] = $this->slash_6;
     100                $_POST                 = $_GET = $_REQUEST = array();
     101                $_POST['role']         = 'subscriber';
     102                $_POST['email']        = 'user2@example.com';
     103                $_POST['first_name']   = $this->slash_2;
     104                $_POST['last_name']    = $this->slash_4;
     105                $_POST['nickname']     = $this->slash_6;
    108106                $_POST['display_name'] = $this->slash_2;
    109                 $_POST['description'] = $this->slash_4;
    110                 $_POST = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes
    111 
    112                 $id = edit_user( $id );
     107                $_POST['description']  = $this->slash_4;
     108                $_POST                 = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes
     109
     110                $id   = edit_user( $id );
    113111                $user = get_user_to_edit( $id );
    114112
     
    122120        /**
    123121         * Tests the model function that expects slashed data
    124          *
    125122         */
    126123        function test_wp_insert_user() {
    127                 $id = wp_insert_user( array(
    128                         'user_login' => 'slash_example_user_3',
    129                         'role' => 'subscriber',
    130                         'email' => 'user3@example.com',
    131                         'first_name' => $this->slash_1,
    132                         'last_name' => $this->slash_3,
    133                         'nickname' => $this->slash_5,
    134                         'display_name' => $this->slash_7,
    135                         'description' => $this->slash_3,
    136                         'user_pass' => ''
    137                 ) );
     124                $id   = wp_insert_user(
     125                        array(
     126                                'user_login'   => 'slash_example_user_3',
     127                                'role'         => 'subscriber',
     128                                'email'        => 'user3@example.com',
     129                                'first_name'   => $this->slash_1,
     130                                'last_name'    => $this->slash_3,
     131                                'nickname'     => $this->slash_5,
     132                                'display_name' => $this->slash_7,
     133                                'description'  => $this->slash_3,
     134                                'user_pass'    => '',
     135                        )
     136                );
    138137                $user = get_user_to_edit( $id );
    139138
     
    144143                $this->assertEquals( wp_unslash( $this->slash_3 ), $user->description );
    145144
    146                 $id = wp_insert_user( array(
    147                         'user_login' => 'slash_example_user_4',
    148                         'role' => 'subscriber',
    149                         'email' => 'user3@example.com',
    150                         'first_name' => $this->slash_2,
    151                         'last_name' => $this->slash_4,
    152                         'nickname' => $this->slash_6,
    153                         'display_name' => $this->slash_2,
    154                         'description' => $this->slash_4,
    155                         'user_pass' => ''
    156                 ) );
     145                $id   = wp_insert_user(
     146                        array(
     147                                'user_login'   => 'slash_example_user_4',
     148                                'role'         => 'subscriber',
     149                                'email'        => 'user3@example.com',
     150                                'first_name'   => $this->slash_2,
     151                                'last_name'    => $this->slash_4,
     152                                'nickname'     => $this->slash_6,
     153                                'display_name' => $this->slash_2,
     154                                'description'  => $this->slash_4,
     155                                'user_pass'    => '',
     156                        )
     157                );
    157158                $user = get_user_to_edit( $id );
    158159
     
    166167        /**
    167168         * Tests the model function that expects slashed data
    168          *
    169169         */
    170170        function test_wp_update_user() {
    171                 $id = self::factory()->user->create();
    172                 $id = wp_update_user(array(
    173                         'ID' => $id,
    174                         'role' => 'subscriber',
    175                         'first_name' => $this->slash_1,
    176                         'last_name' => $this->slash_3,
    177                         'nickname' => $this->slash_5,
    178                         'display_name' => $this->slash_7,
    179                         'description' => $this->slash_3,
    180                 ));
     171                $id   = self::factory()->user->create();
     172                $id   = wp_update_user(
     173                        array(
     174                                'ID'           => $id,
     175                                'role'         => 'subscriber',
     176                                'first_name'   => $this->slash_1,
     177                                'last_name'    => $this->slash_3,
     178                                'nickname'     => $this->slash_5,
     179                                'display_name' => $this->slash_7,
     180                                'description'  => $this->slash_3,
     181                        )
     182                );
    181183                $user = get_user_to_edit( $id );
    182184
     
    187189                $this->assertEquals( wp_unslash( $this->slash_3 ), $user->description );
    188190
    189                 $id = wp_update_user(array(
    190                         'ID' => $id,
    191                         'role' => 'subscriber',
    192                         'first_name' => $this->slash_2,
    193                         'last_name' => $this->slash_4,
    194                         'nickname' => $this->slash_6,
    195                         'display_name' => $this->slash_2,
    196                         'description' => $this->slash_4,
    197                 ));
     191                $id   = wp_update_user(
     192                        array(
     193                                'ID'           => $id,
     194                                'role'         => 'subscriber',
     195                                'first_name'   => $this->slash_2,
     196                                'last_name'    => $this->slash_4,
     197                                'nickname'     => $this->slash_6,
     198                                'display_name' => $this->slash_2,
     199                                'description'  => $this->slash_4,
     200                        )
     201                );
    198202                $user = get_user_to_edit( $id );
    199203
Note: See TracChangeset for help on using the changeset viewer.