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/countUsers.php

    r41653 r42343  
    1414        public function test_count_users_is_accurate( $strategy ) {
    1515                // Setup users
    16                 $admin = self::factory()->user->create( array(
    17                         'role' => 'administrator',
    18                 ) );
    19                 $editor = self::factory()->user->create( array(
    20                         'role' => 'editor',
    21                 ) );
    22                 $author = self::factory()->user->create( array(
    23                         'role' => 'author',
    24                 ) );
    25                 $contributor = self::factory()->user->create( array(
    26                         'role' => 'contributor',
    27                 ) );
    28                 $subscriber = self::factory()->user->create( array(
    29                         'role' => 'subscriber',
    30                 ) );
    31                 $none = self::factory()->user->create( array(
    32                         'role' => '',
    33                 ) );
    34                 $nobody = self::factory()->user->create( array(
    35                         'role' => '',
    36                 ) );
     16                $admin       = self::factory()->user->create(
     17                        array(
     18                                'role' => 'administrator',
     19                        )
     20                );
     21                $editor      = self::factory()->user->create(
     22                        array(
     23                                'role' => 'editor',
     24                        )
     25                );
     26                $author      = self::factory()->user->create(
     27                        array(
     28                                'role' => 'author',
     29                        )
     30                );
     31                $contributor = self::factory()->user->create(
     32                        array(
     33                                'role' => 'contributor',
     34                        )
     35                );
     36                $subscriber  = self::factory()->user->create(
     37                        array(
     38                                'role' => 'subscriber',
     39                        )
     40                );
     41                $none        = self::factory()->user->create(
     42                        array(
     43                                'role' => '',
     44                        )
     45                );
     46                $nobody      = self::factory()->user->create(
     47                        array(
     48                                'role' => '',
     49                        )
     50                );
    3751
    3852                // Test user counts
     
    4054
    4155                $this->assertEquals( 8, $count['total_users'] );
    42                 $this->assertEquals( array(
    43                         'administrator' => 2,
    44                         'editor'        => 1,
    45                         'author'        => 1,
    46                         'contributor'   => 1,
    47                         'subscriber'    => 1,
    48                         'none'          => 2,
    49                 ), $count['avail_roles'] );
     56                $this->assertEquals(
     57                        array(
     58                                'administrator' => 2,
     59                                'editor'        => 1,
     60                                'author'        => 1,
     61                                'contributor'   => 1,
     62                                'subscriber'    => 1,
     63                                'none'          => 2,
     64                        ), $count['avail_roles']
     65                );
    5066
    5167        }
     
    6177        public function test_count_users_multisite_is_accurate( $strategy ) {
    6278                // Setup users
    63                 $admin = self::factory()->user->create( array(
    64                         'role' => 'administrator',
    65                 ) );
    66                 $editor = self::factory()->user->create( array(
    67                         'role' => 'editor',
    68                 ) );
    69                 $author = self::factory()->user->create( array(
    70                         'role' => 'author',
    71                 ) );
    72                 $contributor = self::factory()->user->create( array(
    73                         'role' => 'contributor',
    74                 ) );
    75                 $subscriber = self::factory()->user->create( array(
    76                         'role' => 'subscriber',
    77                 ) );
    78                 $none = self::factory()->user->create( array(
    79                         'role' => '',
    80                 ) );
    81                 $nobody = self::factory()->user->create( array(
    82                         'role' => '',
    83                 ) );
     79                $admin       = self::factory()->user->create(
     80                        array(
     81                                'role' => 'administrator',
     82                        )
     83                );
     84                $editor      = self::factory()->user->create(
     85                        array(
     86                                'role' => 'editor',
     87                        )
     88                );
     89                $author      = self::factory()->user->create(
     90                        array(
     91                                'role' => 'author',
     92                        )
     93                );
     94                $contributor = self::factory()->user->create(
     95                        array(
     96                                'role' => 'contributor',
     97                        )
     98                );
     99                $subscriber  = self::factory()->user->create(
     100                        array(
     101                                'role' => 'subscriber',
     102                        )
     103                );
     104                $none        = self::factory()->user->create(
     105                        array(
     106                                'role' => '',
     107                        )
     108                );
     109                $nobody      = self::factory()->user->create(
     110                        array(
     111                                'role' => '',
     112                        )
     113                );
    84114
    85115                // Setup blogs
    86                 $blog_1 = (int) self::factory()->blog->create( array(
    87                         'user_id' => $editor,
    88                 ) );
    89                 $blog_2 = (int) self::factory()->blog->create( array(
    90                         'user_id' => $author,
    91                 ) );
     116                $blog_1 = (int) self::factory()->blog->create(
     117                        array(
     118                                'user_id' => $editor,
     119                        )
     120                );
     121                $blog_2 = (int) self::factory()->blog->create(
     122                        array(
     123                                'user_id' => $author,
     124                        )
     125                );
    92126
    93127                // Add users to blogs
     
    99133
    100134                $this->assertEquals( 8, $count['total_users'] );
    101                 $this->assertEquals( array(
    102                         'administrator' => 2,
    103                         'editor'        => 1,
    104                         'author'        => 1,
    105                         'contributor'   => 1,
    106                         'subscriber'    => 1,
    107                         'none'          => 2,
    108                 ), $count['avail_roles'] );
     135                $this->assertEquals(
     136                        array(
     137                                'administrator' => 2,
     138                                'editor'        => 1,
     139                                'author'        => 1,
     140                                'contributor'   => 1,
     141                                'subscriber'    => 1,
     142                                'none'          => 2,
     143                        ), $count['avail_roles']
     144                );
    109145
    110146                // Test users counts on blog 1
     
    114150
    115151                $this->assertEquals( 2, $count['total_users'] );
    116                 $this->assertEquals( array(
    117                         'administrator' => 1,
    118                         'editor'        => 1,
    119                         'none'          => 0,
    120                 ), $count['avail_roles'] );
     152                $this->assertEquals(
     153                        array(
     154                                'administrator' => 1,
     155                                'editor'        => 1,
     156                                'none'          => 0,
     157                        ), $count['avail_roles']
     158                );
    121159
    122160                // Test users counts on blog 2
     
    126164
    127165                $this->assertEquals( 2, $count['total_users'] );
    128                 $this->assertEquals( array(
    129                         'administrator' => 1,
    130                         'contributor'   => 1,
    131                         'none'          => 0,
    132                 ), $count['avail_roles'] );
     166                $this->assertEquals(
     167                        array(
     168                                'administrator' => 1,
     169                                'contributor'   => 1,
     170                                'none'          => 0,
     171                        ), $count['avail_roles']
     172                );
    133173
    134174        }
     
    146186                switch_to_blog( $site_id );
    147187                wp_roles()->add_role( 'tester', 'Tester', array( 'test' => true ) );
    148                 $user_id = self::factory()->user->create( array(
    149                         'role' => 'tester',
    150                 ) );
     188                $user_id = self::factory()->user->create(
     189                        array(
     190                                'role' => 'tester',
     191                        )
     192                );
    151193                restore_current_blog();
    152194
    153195                $count = count_users( $strategy, $site_id );
    154                 $this->assertEqualSetsWithIndex( array(
    155                         'tester' => 1,
    156                         'none'   => 0,
    157                 ), $count['avail_roles'] );
     196                $this->assertEqualSetsWithIndex(
     197                        array(
     198                                'tester' => 1,
     199                                'none'   => 0,
     200                        ), $count['avail_roles']
     201                );
    158202        }
    159203
     
    166210
    167211                // Setup users
    168                 $admin = self::factory()->user->create( array(
    169                         'role' => 'administrator',
    170                 ) );
    171                 $editor = self::factory()->user->create( array(
    172                         'role' => 'editor',
    173                 ) );
     212                $admin  = self::factory()->user->create(
     213                        array(
     214                                'role' => 'administrator',
     215                        )
     216                );
     217                $editor = self::factory()->user->create(
     218                        array(
     219                                'role' => 'editor',
     220                        )
     221                );
    174222
    175223                get_userdata( $editor )->add_role( 'author' );
    176224
    177                 $this->assertEquals( array(
    178                         'editor',
    179                         'author'
    180                 ), get_userdata( $editor )->roles );
     225                $this->assertEquals(
     226                        array(
     227                                'editor',
     228                                'author',
     229                        ), get_userdata( $editor )->roles
     230                );
    181231
    182232                // Test user counts
     
    184234
    185235                $this->assertEquals( 3, $count['total_users'] );
    186                 $this->assertEquals( array(
    187                         'administrator' => 2,
    188                         'editor'        => 1,
    189                         'author'        => 1,
    190                         'none'          => 0,
    191                 ), $count['avail_roles'] );
     236                $this->assertEquals(
     237                        array(
     238                                'administrator' => 2,
     239                                'editor'        => 1,
     240                                'author'        => 1,
     241                                'none'          => 0,
     242                        ), $count['avail_roles']
     243                );
    192244
    193245        }
     
    204256                $count = count_users( $strategy );
    205257
    206                 $u = self::factory()->user->create( array(
    207                         'role' => 'editor',
    208                 ) );
     258                $u = self::factory()->user->create(
     259                        array(
     260                                'role' => 'editor',
     261                        )
     262                );
    209263
    210264                // Manually delete the user, but leave the capabilities usermeta.
    211                 $wpdb->delete( $wpdb->users, array(
    212                         'ID' => $u,
    213                 ) );
     265                $wpdb->delete(
     266                        $wpdb->users, array(
     267                                'ID' => $u,
     268                        )
     269                );
    214270
    215271                $count2 = count_users( $strategy );
Note: See TracChangeset for help on using the changeset viewer.