Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 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/query/postStatus.php

    r38398 r42343  
    1616        self::$author_user_id = $factory->user->create( array( 'role' => 'author' ) );
    1717
    18         self::$editor_private_post = $factory->post->create( array( 'post_author' => self::$editor_user_id, 'post_status' => 'private' ) );
    19         self::$author_private_post = $factory->post->create( array( 'post_author' => self::$author_user_id, 'post_status' => 'private' ) );
     18        self::$editor_private_post = $factory->post->create(
     19            array(
     20                'post_author' => self::$editor_user_id,
     21                'post_status' => 'private',
     22            )
     23        );
     24        self::$author_private_post = $factory->post->create(
     25            array(
     26                'post_author' => self::$author_user_id,
     27                'post_status' => 'private',
     28            )
     29        );
    2030
    2131        // Custom status with private=true.
    2232        register_post_status( 'privatefoo', array( 'private' => true ) );
    23         self::$editor_privatefoo_post = $factory->post->create( array( 'post_author' => self::$editor_user_id, 'post_status' => 'privatefoo' ) );
    24         self::$author_privatefoo_post = $factory->post->create( array( 'post_author' => self::$author_user_id, 'post_status' => 'privatefoo' ) );
     33        self::$editor_privatefoo_post = $factory->post->create(
     34            array(
     35                'post_author' => self::$editor_user_id,
     36                'post_status' => 'privatefoo',
     37            )
     38        );
     39        self::$author_privatefoo_post = $factory->post->create(
     40            array(
     41                'post_author' => self::$author_user_id,
     42                'post_status' => 'privatefoo',
     43            )
     44        );
    2545        _unregister_post_status( 'privatefoo' );
    2646    }
     
    2949        register_post_status( 'foo', array( 'exclude_from_search' => true ) );
    3050
    31         $q = new WP_Query( array(
    32             'post_status' => array( 'any' ),
    33         ) );
     51        $q = new WP_Query(
     52            array(
     53                'post_status' => array( 'any' ),
     54            )
     55        );
    3456
    3557        $this->assertContains( "post_status <> 'foo'", $q->request );
     
    3961        register_post_status( 'foo', array( 'exclude_from_search' => false ) );
    4062
    41         $q = new WP_Query( array(
    42             'post_status' => array( 'any' ),
    43         ) );
     63        $q = new WP_Query(
     64            array(
     65                'post_status' => array( 'any' ),
     66            )
     67        );
    4468
    4569        $this->assertNotContains( "post_status <> 'foo'", $q->request );
     
    4771
    4872    public function test_private_should_be_included_if_perm_is_false() {
    49         $q = new WP_Query( array(
    50             'post_status' => array( 'private' ),
    51             'perm' => false,
    52         ) );
     73        $q = new WP_Query(
     74            array(
     75                'post_status' => array( 'private' ),
     76                'perm'        => false,
     77            )
     78        );
    5379
    5480        $expected = array(
     
    6389        // Current user is 0.
    6490
    65         $q = new WP_Query( array(
    66             'post_status' => array( 'private' ),
    67             'perm' => 'editable',
    68         ) );
     91        $q = new WP_Query(
     92            array(
     93                'post_status' => array( 'private' ),
     94                'perm'        => 'editable',
     95            )
     96        );
    6997
    7098        $this->assertEmpty( $q->posts );
     
    74102        wp_set_current_user( self::$author_user_id );
    75103
    76         $q = new WP_Query( array(
    77             'post_status' => array( 'private' ),
    78             'perm' => 'readable',
    79         ) );
     104        $q = new WP_Query(
     105            array(
     106                'post_status' => array( 'private' ),
     107                'perm'        => 'readable',
     108            )
     109        );
    80110
    81111        $expected = array(
     
    89119        wp_set_current_user( self::$editor_user_id );
    90120
    91         $q = new WP_Query( array(
    92             'post_status' => array( 'private' ),
    93             'perm' => 'readable',
    94         ) );
     121        $q = new WP_Query(
     122            array(
     123                'post_status' => array( 'private' ),
     124                'perm'        => 'readable',
     125            )
     126        );
    95127
    96128        $expected = array(
     
    105137        wp_set_current_user( self::$author_user_id );
    106138
    107         $q = new WP_Query( array(
    108             'post_status' => array( 'private' ),
    109             'perm' => 'editable',
    110         ) );
     139        $q = new WP_Query(
     140            array(
     141                'post_status' => array( 'private' ),
     142                'perm'        => 'editable',
     143            )
     144        );
    111145
    112146        $expected = array(
     
    120154        wp_set_current_user( self::$editor_user_id );
    121155
    122         $q = new WP_Query( array(
    123             'post_status' => array( 'private' ),
    124             'perm' => 'editable',
    125         ) );
     156        $q = new WP_Query(
     157            array(
     158                'post_status' => array( 'private' ),
     159                'perm'        => 'editable',
     160            )
     161        );
    126162
    127163        $expected = array(
     
    136172        register_post_status( 'foo', array( 'public' => true ) );
    137173
    138         $q = new WP_Query( array(
    139             'posts_per_page' => 1, // Or the query will short-circuit.
    140         ) );
     174        $q = new WP_Query(
     175            array(
     176                'posts_per_page' => 1, // Or the query will short-circuit.
     177            )
     178        );
    141179
    142180        foreach ( get_post_stati( array( 'public' => true ) ) as $status ) {
     
    148186        register_post_status( 'foo', array( 'protected' => true ) );
    149187
    150         $q = new WP_Query( array(
    151             'posts_per_page' => 1, // Or the query will short-circuit.
    152         ) );
     188        $q = new WP_Query(
     189            array(
     190                'posts_per_page' => 1, // Or the query will short-circuit.
     191            )
     192        );
    153193
    154194        $this->assertNotContains( "post_status = 'foo", $q->request );
     
    157197    public function test_protected_should_be_included_when_in_the_admin() {
    158198        set_current_screen( 'dashboard' );
    159         register_post_status( 'foo', array( 'protected' => true, 'show_in_admin_all_list' => true ) );
    160 
    161         $q = new WP_Query( array(
    162             'posts_per_page' => -1, // Or the query will short-circuit.
    163         ) );
     199        register_post_status(
     200            'foo', array(
     201                'protected'              => true,
     202                'show_in_admin_all_list' => true,
     203            )
     204        );
     205
     206        $q = new WP_Query(
     207            array(
     208                'posts_per_page' => -1, // Or the query will short-circuit.
     209            )
     210        );
    164211
    165212        $this->assertContains( "post_status = 'foo", $q->request );
     
    172219        register_post_status( 'privatefoo', array( 'private' => true ) );
    173220
    174         $q = new WP_Query( array(
    175             'posts_per_page' => -1,
    176         ) );
     221        $q = new WP_Query(
     222            array(
     223                'posts_per_page' => -1,
     224            )
     225        );
    177226
    178227        $this->assertContains( self::$author_privatefoo_post, wp_list_pluck( $q->posts, 'ID' ) );
     
    185234        register_post_status( 'privatefoo', array( 'private' => true ) );
    186235
    187         $q = new WP_Query( array(
    188             'posts_per_page' => 2, // Or the query will short-circuit.
    189         ) );
     236        $q = new WP_Query(
     237            array(
     238                'posts_per_page' => 2, // Or the query will short-circuit.
     239            )
     240        );
    190241
    191242        $expected = array(
     
    202253        $p = self::factory()->post->create( array( 'post_status' => 'foo_ps' ) );
    203254
    204         $q = new WP_Query( array(
    205             'p' => $p,
    206         ) );
     255        $q = new WP_Query(
     256            array(
     257                'p' => $p,
     258            )
     259        );
    207260
    208261        $this->assertEmpty( $q->posts );
     
    211264    public function test_single_post_with_nonpublic_and_protected_status_should_not_be_shown_for_user_who_cannot_edit_others_posts() {
    212265        register_post_type( 'foo_pt' );
    213         register_post_status( 'foo_ps', array( 'public' => false, 'protected' => true ) );
    214         $p = self::factory()->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$editor_user_id ) );
     266        register_post_status(
     267            'foo_ps', array(
     268                'public'    => false,
     269                'protected' => true,
     270            )
     271        );
     272        $p = self::factory()->post->create(
     273            array(
     274                'post_status' => 'foo_ps',
     275                'post_author' => self::$editor_user_id,
     276            )
     277        );
    215278
    216279        wp_set_current_user( self::$author_user_id );
    217280
    218         $q = new WP_Query( array(
    219             'p' => $p,
    220         ) );
     281        $q = new WP_Query(
     282            array(
     283                'p' => $p,
     284            )
     285        );
    221286
    222287        $this->assertEmpty( $q->posts );
     
    225290    public function test_single_post_with_nonpublic_and_protected_status_should_be_shown_for_user_who_can_edit_others_posts() {
    226291        register_post_type( 'foo_pt' );
    227         register_post_status( 'foo_ps', array( 'public' => false, 'protected' => true ) );
    228         $p = self::factory()->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user_id ) );
    229 
    230         wp_set_current_user( self::$editor_user_id );
    231 
    232         $q = new WP_Query( array(
    233             'p' => $p,
    234         ) );
     292        register_post_status(
     293            'foo_ps', array(
     294                'public'    => false,
     295                'protected' => true,
     296            )
     297        );
     298        $p = self::factory()->post->create(
     299            array(
     300                'post_status' => 'foo_ps',
     301                'post_author' => self::$author_user_id,
     302            )
     303        );
     304
     305        wp_set_current_user( self::$editor_user_id );
     306
     307        $q = new WP_Query(
     308            array(
     309                'p' => $p,
     310            )
     311        );
    235312
    236313        $this->assertEquals( array( $p ), wp_list_pluck( $q->posts, 'ID' ) );
     
    239316    public function test_single_post_with_nonpublic_and_private_status_should_not_be_shown_for_user_who_cannot_edit_others_posts() {
    240317        register_post_type( 'foo_pt' );
    241         register_post_status( 'foo_ps', array( 'public' => false, 'private' => true ) );
    242         $p = self::factory()->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$editor_user_id ) );
     318        register_post_status(
     319            'foo_ps', array(
     320                'public'  => false,
     321                'private' => true,
     322            )
     323        );
     324        $p = self::factory()->post->create(
     325            array(
     326                'post_status' => 'foo_ps',
     327                'post_author' => self::$editor_user_id,
     328            )
     329        );
    243330
    244331        wp_set_current_user( self::$author_user_id );
    245332
    246         $q = new WP_Query( array(
    247             'p' => $p,
    248         ) );
     333        $q = new WP_Query(
     334            array(
     335                'p' => $p,
     336            )
     337        );
    249338
    250339        $this->assertEmpty( $q->posts );
     
    253342    public function test_single_post_with_nonpublic_and_private_status_should_be_shown_for_user_who_can_edit_others_posts() {
    254343        register_post_type( 'foo_pt' );
    255         register_post_status( 'foo_ps', array( 'public' => false, 'private' => true ) );
    256         $p = self::factory()->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user_id ) );
    257 
    258         wp_set_current_user( self::$editor_user_id );
    259 
    260         $q = new WP_Query( array(
    261             'p' => $p,
    262         ) );
     344        register_post_status(
     345            'foo_ps', array(
     346                'public'  => false,
     347                'private' => true,
     348            )
     349        );
     350        $p = self::factory()->post->create(
     351            array(
     352                'post_status' => 'foo_ps',
     353                'post_author' => self::$author_user_id,
     354            )
     355        );
     356
     357        wp_set_current_user( self::$editor_user_id );
     358
     359        $q = new WP_Query(
     360            array(
     361                'p' => $p,
     362            )
     363        );
    263364
    264365        $this->assertEquals( array( $p ), wp_list_pluck( $q->posts, 'ID' ) );
     
    268369        register_post_type( 'foo_pt' );
    269370        register_post_status( 'foo_ps', array( 'public' => false ) );
    270         $p = self::factory()->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user_id ) );
    271 
    272         wp_set_current_user( self::$editor_user_id );
    273 
    274         $q = new WP_Query( array(
    275             'p' => $p,
    276         ) );
     371        $p = self::factory()->post->create(
     372            array(
     373                'post_status' => 'foo_ps',
     374                'post_author' => self::$author_user_id,
     375            )
     376        );
     377
     378        wp_set_current_user( self::$editor_user_id );
     379
     380        $q = new WP_Query(
     381            array(
     382                'p' => $p,
     383            )
     384        );
    277385
    278386        $this->assertEmpty( $q->posts );
     
    286394        $p2 = self::factory()->post->create( array( 'post_status' => 'publish' ) );
    287395
    288         $q = new WP_Query( array(
    289             'p' => $p1,
    290             'post_status' => array( 'trash', 'publish' ),
    291         ) );
     396        $q = new WP_Query(
     397            array(
     398                'p'           => $p1,
     399                'post_status' => array( 'trash', 'publish' ),
     400            )
     401        );
    292402
    293403        $this->assertContains( $p1, wp_list_pluck( $q->posts, 'ID' ) );
Note: See TracChangeset for help on using the changeset viewer.