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/post/wpUniquePostSlug.php

    r39506 r42343  
    2626            for ( $i = 0; $i < 2; $i++ ) {
    2727                $post = array(
    28                     'post_author' => $author_id,
    29                     'post_status' => 'publish',
     28                    'post_author'  => $author_id,
     29                    'post_status'  => 'publish',
    3030                    'post_content' => 'Post content',
    31                     'post_title' => $post_title,
     31                    'post_title'   => $post_title,
    3232                );
    3333
     
    3636
    3737            $post = get_post( $id );
    38             $this->assertEquals( $outputs[$k], urldecode( $post->post_name ) );
     38            $this->assertEquals( $outputs[ $k ], urldecode( $post->post_name ) );
    3939        }
    4040    }
     
    4747        register_post_type( 'post-type-2', array( 'hierarchical' => true ) );
    4848
    49         $args = array(
    50             'post_type' => 'post-type-1',
    51             'post_name' => 'some-slug',
     49        $args              = array(
     50            'post_type'   => 'post-type-1',
     51            'post_name'   => 'some-slug',
    5252            'post_status' => 'publish',
    5353        );
    54         $one = self::factory()->post->create( $args );
     54        $one               = self::factory()->post->create( $args );
    5555        $args['post_type'] = 'post-type-2';
    56         $two = self::factory()->post->create( $args );
     56        $two               = self::factory()->post->create( $args );
    5757
    5858        $this->assertEquals( 'some-slug', get_post( $one )->post_name );
     
    7272        register_post_type( 'post-type-1', array( 'hierarchical' => true ) );
    7373
    74         $args = array(
    75             'post_type' => 'post-type-1',
    76             'post_name' => 'some-slug',
     74        $args              = array(
     75            'post_type'   => 'post-type-1',
     76            'post_name'   => 'some-slug',
    7777            'post_status' => 'publish',
    7878        );
    79         $one = self::factory()->post->create( $args );
     79        $one               = self::factory()->post->create( $args );
    8080        $args['post_name'] = 'some-slug-2';
    81         $two = self::factory()->post->create( $args );
     81        $two               = self::factory()->post->create( $args );
    8282
    8383        $this->assertEquals( 'some-slug', get_post( $one )->post_name );
     
    9696
    9797        $args = array(
    98             'post_type' => 'post-type-1',
    99             'post_name' => 'some-slug',
     98            'post_type'   => 'post-type-1',
     99            'post_name'   => 'some-slug',
    100100            'post_status' => 'publish',
    101101        );
    102         $one = self::factory()->post->create( $args );
     102        $one  = self::factory()->post->create( $args );
     103
     104        $args       = array(
     105            'post_mime_type' => 'image/jpeg',
     106            'post_type'      => 'attachment',
     107            'post_name'      => 'image',
     108        );
     109        $attachment = self::factory()->attachment->create_object( 'image.jpg', $one, $args );
    103110
    104111        $args = array(
    105             'post_mime_type' => 'image/jpeg',
    106             'post_type' => 'attachment',
    107             'post_name' => 'image'
    108         );
    109         $attachment = self::factory()->attachment->create_object( 'image.jpg', $one, $args );
    110 
    111         $args = array(
    112             'post_type' => 'post-type-1',
    113             'post_name' => 'image',
     112            'post_type'   => 'post-type-1',
     113            'post_name'   => 'image',
    114114            'post_status' => 'publish',
    115             'post_parent' => $one
    116         );
    117         $two = self::factory()->post->create( $args );
     115            'post_parent' => $one,
     116        );
     117        $two  = self::factory()->post->create( $args );
    118118
    119119        $this->assertEquals( 'some-slug', get_post( $one )->post_name );
     
    131131     */
    132132    public function test_whitelisted_post_statuses_should_not_be_forced_to_be_unique( $status ) {
    133         $p1 = self::factory()->post->create( array(
    134             'post_type' => 'post',
    135             'post_name' => 'foo',
    136         ) );
    137 
    138         $p2 = self::factory()->post->create( array(
    139             'post_type' => 'post',
    140         ) );
     133        $p1 = self::factory()->post->create(
     134            array(
     135                'post_type' => 'post',
     136                'post_name' => 'foo',
     137            )
     138        );
     139
     140        $p2 = self::factory()->post->create(
     141            array(
     142                'post_type' => 'post',
     143            )
     144        );
    141145
    142146        $actual = wp_unique_post_slug( 'foo', $p2, $status, 'post', 0 );
     
    154158
    155159    public function test_revisions_should_not_be_forced_to_be_unique() {
    156         $p1 = self::factory()->post->create( array(
    157             'post_type' => 'post',
    158             'post_name' => 'foo',
    159         ) );
    160 
    161         $p2 = self::factory()->post->create( array(
    162             'post_type' => 'post',
    163         ) );
     160        $p1 = self::factory()->post->create(
     161            array(
     162                'post_type' => 'post',
     163                'post_name' => 'foo',
     164            )
     165        );
     166
     167        $p2 = self::factory()->post->create(
     168            array(
     169                'post_type' => 'post',
     170            )
     171        );
    164172
    165173        $actual = wp_unique_post_slug( 'foo', $p2, 'inherit', 'revision', 0 );
     
    174182        $this->set_permalink_structure( '/%postname%/' );
    175183
    176         $p = self::factory()->post->create( array(
    177             'post_type' => 'post',
    178             'post_name' => 'foo',
    179         ) );
     184        $p = self::factory()->post->create(
     185            array(
     186                'post_type' => 'post',
     187                'post_name' => 'foo',
     188            )
     189        );
    180190
    181191        $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 );
     
    189199        $this->set_permalink_structure( '/%postname%/' );
    190200
    191         $p = self::factory()->post->create( array(
    192             'post_type' => 'post',
    193             'post_name' => 'foo',
    194             'post_status' => 'publish',
    195         ) );
     201        $p = self::factory()->post->create(
     202            array(
     203                'post_type'   => 'post',
     204                'post_name'   => 'foo',
     205                'post_status' => 'publish',
     206            )
     207        );
    196208
    197209        $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 );
     
    205217        $this->set_permalink_structure( '/%year%/%postname%/' );
    206218
    207         $p = self::factory()->post->create( array(
    208             'post_type' => 'post',
    209             'post_name' => 'foo',
    210         ) );
     219        $p = self::factory()->post->create(
     220            array(
     221                'post_type' => 'post',
     222                'post_name' => 'foo',
     223            )
     224        );
    211225
    212226        $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 );
     
    220234        $this->set_permalink_structure( '/%year%/%postname%/' );
    221235
    222         $p = self::factory()->post->create( array(
    223             'post_type' => 'post',
    224             'post_name' => 'foo',
    225         ) );
     236        $p = self::factory()->post->create(
     237            array(
     238                'post_type' => 'post',
     239                'post_name' => 'foo',
     240            )
     241        );
    226242
    227243        $found = wp_unique_post_slug( '11', $p, 'publish', 'post', 0 );
     
    235251        $this->set_permalink_structure( '/%year%/foo/%postname%/' );
    236252
    237         $p = self::factory()->post->create( array(
    238             'post_type' => 'post',
    239             'post_name' => 'foo',
    240         ) );
     253        $p = self::factory()->post->create(
     254            array(
     255                'post_type' => 'post',
     256                'post_name' => 'foo',
     257            )
     258        );
    241259
    242260        $found = wp_unique_post_slug( '11', $p, 'publish', 'post', 0 );
     
    250268        $this->set_permalink_structure( '/%year%/%postname%/' );
    251269
    252         $p = self::factory()->post->create( array(
    253             'post_type' => 'post',
    254             'post_name' => 'foo',
    255         ) );
     270        $p = self::factory()->post->create(
     271            array(
     272                'post_type' => 'post',
     273                'post_name' => 'foo',
     274            )
     275        );
    256276
    257277        $found = wp_unique_post_slug( '13', $p, 'publish', 'post', 0 );
     
    265285        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    266286
    267         $p = self::factory()->post->create( array(
    268             'post_type' => 'post',
    269             'post_name' => 'foo',
    270         ) );
     287        $p = self::factory()->post->create(
     288            array(
     289                'post_type' => 'post',
     290                'post_name' => 'foo',
     291            )
     292        );
    271293
    272294        $found = wp_unique_post_slug( '30', $p, 'publish', 'post', 0 );
     
    280302        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    281303
    282         $p = self::factory()->post->create( array(
    283             'post_type' => 'post',
    284             'post_name' => 'foo',
    285         ) );
     304        $p = self::factory()->post->create(
     305            array(
     306                'post_type' => 'post',
     307                'post_name' => 'foo',
     308            )
     309        );
    286310
    287311        $found = wp_unique_post_slug( '30', $p, 'publish', 'post', 0 );
     
    295319        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    296320
    297         $p = self::factory()->post->create( array(
    298             'post_type' => 'post',
    299             'post_name' => 'foo',
    300         ) );
     321        $p = self::factory()->post->create(
     322            array(
     323                'post_type' => 'post',
     324                'post_name' => 'foo',
     325            )
     326        );
    301327
    302328        $found = wp_unique_post_slug( '32', $p, 'publish', 'post', 0 );
     
    310336        $this->set_permalink_structure( '/%postname%/' );
    311337
    312         $p = self::factory()->post->create( array(
    313             'post_type' => 'post',
    314             'post_name' => 'embed',
    315         ) );
     338        $p = self::factory()->post->create(
     339            array(
     340                'post_type' => 'post',
     341                'post_name' => 'embed',
     342            )
     343        );
    316344
    317345        $found = wp_unique_post_slug( 'embed', $p, 'publish', 'post', 0 );
     
    325353        $this->set_permalink_structure( '/%postname%/' );
    326354
    327         $p = self::factory()->post->create( array(
    328             'post_type' => 'page',
    329             'post_name' => 'embed',
    330         ) );
     355        $p = self::factory()->post->create(
     356            array(
     357                'post_type' => 'page',
     358                'post_name' => 'embed',
     359            )
     360        );
    331361
    332362        $found = wp_unique_post_slug( 'embed', $p, 'publish', 'paage', 0 );
     
    340370        $this->set_permalink_structure( '/%postname%/' );
    341371
    342         $p = self::factory()->post->create( array(
    343             'post_type' => 'attachment',
    344             'post_name' => 'embed',
    345         ) );
     372        $p = self::factory()->post->create(
     373            array(
     374                'post_type' => 'attachment',
     375                'post_name' => 'embed',
     376            )
     377        );
    346378
    347379        $found = wp_unique_post_slug( 'embed', $p, 'publish', 'attachment', 0 );
Note: See TracChangeset for help on using the changeset viewer.