Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (6 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/xmlrpc/wp/newPost.php

    r40417 r42343  
    3232        $this->make_user_by_role( 'author' );
    3333
    34         $post = array( 'post_title' => 'Test' );
     34        $post   = array( 'post_title' => 'Test' );
    3535        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
    3636        $this->assertNotIXRError( $result );
     
    4141        $this->make_user_by_role( 'author' );
    4242
    43         $post = array( 'post_title' => 'Test', 'ID' => 103948 );
     43        $post   = array(
     44            'post_title' => 'Test',
     45            'ID'         => 103948,
     46        );
    4447        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
    4548        $this->assertNotIXRError( $result );
     
    5053        $this->make_user_by_role( 'author' );
    5154
    52         $post = array( 'post_title' => 'Test', 'post_status' => 'publish' );
     55        $post   = array(
     56            'post_title'  => 'Test',
     57            'post_status' => 'publish',
     58        );
    5359        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
    5460        $this->assertNotIXRError( $result );
     
    5864        $this->make_user_by_role( 'contributor' );
    5965
    60         $post = array( 'post_title' => 'Test', 'post_status' => 'publish' );
     66        $post   = array(
     67            'post_title'  => 'Test',
     68            'post_status' => 'publish',
     69        );
    6170        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) );
    6271        $this->assertIXRError( $result );
     
    6776        $this->make_user_by_role( 'editor' );
    6877
    69         $post = array( 'post_title' => 'Test', 'post_status' => 'private' );
     78        $post   = array(
     79            'post_title'  => 'Test',
     80            'post_status' => 'private',
     81        );
    7082        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
    7183        $this->assertNotIXRError( $result );
     
    7587        $this->make_user_by_role( 'contributor' );
    7688
    77         $post = array( 'post_title' => 'Test', 'post_status' => 'private' );
     89        $post   = array(
     90            'post_title'  => 'Test',
     91            'post_status' => 'private',
     92        );
    7893        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) );
    7994        $this->assertIXRError( $result );
     
    85100        $this->make_user_by_role( 'editor' );
    86101
    87         $post = array( 'post_title' => 'Test', 'post_author' => $other_author_id );
     102        $post   = array(
     103            'post_title'  => 'Test',
     104            'post_author' => $other_author_id,
     105        );
    88106        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
    89107        $this->assertNotIXRError( $result );
     
    94112        $this->make_user_by_role( 'contributor' );
    95113
    96         $post = array( 'post_title' => 'Test', 'post_author' => $other_author_id );
     114        $post   = array(
     115            'post_title'  => 'Test',
     116            'post_author' => $other_author_id,
     117        );
    97118        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) );
    98119        $this->assertIXRError( $result );
     
    103124        $this->make_user_by_role( 'editor' );
    104125
    105         $post = array( 'post_title' => 'Test', 'post_author' => 99999999 );
     126        $post   = array(
     127            'post_title'  => 'Test',
     128            'post_author' => 99999999,
     129        );
    106130        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
    107131        $this->assertIXRError( $result );
     
    112136        $my_author_id = $this->make_user_by_role( 'author' );
    113137
    114         $post = array( 'post_title' => 'Test' );
     138        $post   = array( 'post_title' => 'Test' );
    115139        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
    116140        $this->assertNotIXRError( $result );
     
    128152
    129153        // create attachment
    130         $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );
     154        $filename      = ( DIR_TESTDATA . '/images/a2-small.jpg' );
    131155        $attachment_id = self::factory()->attachment->create_upload_object( $filename );
    132156
    133         $post = array( 'post_title' => 'Post Thumbnail Test', 'post_thumbnail' => $attachment_id );
     157        $post   = array(
     158            'post_title'     => 'Post Thumbnail Test',
     159            'post_thumbnail' => $attachment_id,
     160        );
    134161        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
    135162        $this->assertNotIXRError( $result );
     
    142169        $this->make_user_by_role( 'author' );
    143170
    144         $post = array( 'post_title' => 'Test', 'post_status' => 'foobar_status' );
     171        $post   = array(
     172            'post_title'  => 'Test',
     173            'post_status' => 'foobar_status',
     174        );
    145175        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
    146176        $this->assertNotIXRError( $result );
     
    151181        $this->make_user_by_role( 'contributor' );
    152182
    153         $post = array( 'post_title' => 'Test', 'sticky' => true );
     183        $post   = array(
     184            'post_title' => 'Test',
     185            'sticky'     => true,
     186        );
    154187        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) );
    155188        $this->assertIXRError( $result );
     
    160193        $this->make_user_by_role( 'editor' );
    161194
    162         $post = array( 'post_title' => 'Test', 'sticky' => true );
     195        $post   = array(
     196            'post_title' => 'Test',
     197            'sticky'     => true,
     198        );
    163199        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
    164200        $this->assertNotIXRError( $result );
     
    169205        $this->make_user_by_role( 'editor' );
    170206
    171         $post = array( 'post_title' => 'Test', 'post_status' => 'private', 'sticky' => true );
     207        $post   = array(
     208            'post_title'  => 'Test',
     209            'post_status' => 'private',
     210            'sticky'      => true,
     211        );
    172212        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
    173213        $this->assertIXRError( $result );
     
    178218        $this->make_user_by_role( 'editor' );
    179219
    180         $post = array( 'post_title' => 'Test', 'post_format' => 'quote' );
     220        $post   = array(
     221            'post_title'  => 'Test',
     222            'post_format' => 'quote',
     223        );
    181224        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
    182225        $this->assertNotIXRError( $result );
     
    187230        $this->make_user_by_role( 'editor' );
    188231
    189         $post = array( 'post_title' => 'Test', 'post_format' => 'tumblr' );
     232        $post   = array(
     233            'post_title'  => 'Test',
     234            'post_format' => 'tumblr',
     235        );
    190236        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
    191237        $this->assertNotIXRError( $result );
     
    196242        $this->make_user_by_role( 'editor' );
    197243
    198         $post = array(
    199             'post_title' => 'Test',
    200             'terms' => array(
    201                 'foobar_nonexistant' => array( 1 )
    202             )
    203         );
    204         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
    205         $this->assertIXRError( $result );
    206         $this->assertEquals( 401, $result->code );
    207 
    208         $post2 = array(
    209             'post_title' => 'Test',
     244        $post   = array(
     245            'post_title' => 'Test',
     246            'terms'      => array(
     247                'foobar_nonexistant' => array( 1 ),
     248            ),
     249        );
     250        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
     251        $this->assertIXRError( $result );
     252        $this->assertEquals( 401, $result->code );
     253
     254        $post2   = array(
     255            'post_title'  => 'Test',
    210256            'terms_names' => array(
    211                 'foobar_nonexistant' => array( 1 )
    212             )
     257                'foobar_nonexistant' => array( 1 ),
     258            ),
    213259        );
    214260        $result2 = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post2 ) );
     
    220266        $this->make_user_by_role( 'editor' );
    221267
    222         $post = array(
    223             'post_title' => 'Test',
    224             'terms' => array(
    225                 'post_tag' => array( 1390490823409 )
    226             )
     268        $post   = array(
     269            'post_title' => 'Test',
     270            'terms'      => array(
     271                'post_tag' => array( 1390490823409 ),
     272            ),
    227273        );
    228274        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
     
    241287        $this->assertInternalType( 'array', $tag3 );
    242288
    243         $post = array(
    244             'post_title' => 'Test',
    245             'terms' => array(
    246                 'post_tag' => array( $tag2['term_id'], $tag3['term_id'] )
    247             )
     289        $post   = array(
     290            'post_title' => 'Test',
     291            'terms'      => array(
     292                'post_tag' => array( $tag2['term_id'], $tag3['term_id'] ),
     293            ),
    248294        );
    249295        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
     
    260306
    261307        $ambiguous_name = 'foo';
    262         $parent_cat = wp_create_category( $ambiguous_name );
    263         $child_cat = wp_create_category( $ambiguous_name, $parent_cat );
     308        $parent_cat     = wp_create_category( $ambiguous_name );
     309        $child_cat      = wp_create_category( $ambiguous_name, $parent_cat );
    264310
    265311        $cat1_name = 'cat1';
    266         $cat1 = wp_create_category( $cat1_name, $parent_cat );
     312        $cat1      = wp_create_category( $cat1_name, $parent_cat );
    267313        $cat2_name = 'cat2';
    268314
    269315        // first a post with valid categories; one that already exists and one to be created
    270         $post = array(
    271             'post_title' => 'Test',
     316        $post   = array(
     317            'post_title'  => 'Test',
    272318            'terms_names' => array(
    273                 'category' => array( $cat1_name, $cat2_name )
    274             )
     319                'category' => array( $cat1_name, $cat2_name ),
     320            ),
    275321        );
    276322        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
     
    285331
    286332        // create a second post attempting to use the ambiguous name
    287         $post2 = array(
    288             'post_title' => 'Test',
     333        $post2   = array(
     334            'post_title'  => 'Test',
    289335            'terms_names' => array(
    290                 'category' => array( $cat1_name, $ambiguous_name )
    291             )
     336                'category' => array( $cat1_name, $ambiguous_name ),
     337            ),
    292338        );
    293339        $result2 = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post2 ) );
     
    301347    function test_invalid_post_date_does_not_fatal() {
    302348        $this->make_user_by_role( 'author' );
    303         $date_string = 'invalid_date';
    304         $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date' => $date_string );
    305         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
     349        $date_string  = 'invalid_date';
     350        $post         = array(
     351            'post_title'   => 'test',
     352            'post_content' => 'test',
     353            'post_date'    => $date_string,
     354        );
     355        $result       = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
    306356        $fetched_post = get_post( $result );
    307357        $this->assertStringMatchesFormat( '%d', $result );
     
    314364    function test_invalid_post_date_gmt_does_not_fatal() {
    315365        $this->make_user_by_role( 'author' );
    316         $date_string = 'invalid date';
    317         $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date_gmt' => $date_string );
    318         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
     366        $date_string  = 'invalid date';
     367        $post         = array(
     368            'post_title'    => 'test',
     369            'post_content'  => 'test',
     370            'post_date_gmt' => $date_string,
     371        );
     372        $result       = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
    319373        $fetched_post = get_post( $result );
    320374        $this->assertStringMatchesFormat( '%d', $result );
     
    327381    function test_valid_string_post_date() {
    328382        $this->make_user_by_role( 'author' );
    329         $date_string = '1984-01-11 05:00:00';
    330         $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date' => $date_string );
    331         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
    332         $fetched_post = get_post( $result );
    333         $this->assertStringMatchesFormat( '%d', $result );
    334         $this->assertEquals( $date_string , $fetched_post->post_date );
     383        $date_string  = '1984-01-11 05:00:00';
     384        $post         = array(
     385            'post_title'   => 'test',
     386            'post_content' => 'test',
     387            'post_date'    => $date_string,
     388        );
     389        $result       = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
     390        $fetched_post = get_post( $result );
     391        $this->assertStringMatchesFormat( '%d', $result );
     392        $this->assertEquals( $date_string, $fetched_post->post_date );
    335393    }
    336394
     
    340398    function test_valid_string_post_date_gmt() {
    341399        $this->make_user_by_role( 'author' );
    342         $date_string = '1984-01-11 05:00:00';
    343         $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date_gmt' => $date_string );
    344         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
    345         $fetched_post = get_post( $result );
    346         $this->assertStringMatchesFormat( '%d', $result );
    347         $this->assertEquals( $date_string , $fetched_post->post_date_gmt );
     400        $date_string  = '1984-01-11 05:00:00';
     401        $post         = array(
     402            'post_title'    => 'test',
     403            'post_content'  => 'test',
     404            'post_date_gmt' => $date_string,
     405        );
     406        $result       = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
     407        $fetched_post = get_post( $result );
     408        $this->assertStringMatchesFormat( '%d', $result );
     409        $this->assertEquals( $date_string, $fetched_post->post_date_gmt );
    348410    }
    349411
     
    353415    function test_valid_IXR_post_date() {
    354416        $this->make_user_by_role( 'author' );
    355         $date_string = '1984-01-11 05:00:00';
    356         $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) ) );
    357         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
    358         $fetched_post = get_post( $result );
    359         $this->assertStringMatchesFormat( '%d', $result );
    360         $this->assertEquals( $date_string , $fetched_post->post_date );
     417        $date_string  = '1984-01-11 05:00:00';
     418        $post         = array(
     419            'post_title'   => 'test',
     420            'post_content' => 'test',
     421            'post_date'    => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) ),
     422        );
     423        $result       = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
     424        $fetched_post = get_post( $result );
     425        $this->assertStringMatchesFormat( '%d', $result );
     426        $this->assertEquals( $date_string, $fetched_post->post_date );
    361427    }
    362428
     
    366432    function test_valid_IXR_post_date_gmt() {
    367433        $this->make_user_by_role( 'author' );
    368         $date_string = '1984-01-11 05:00:00';
    369         $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) ) );
    370         $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
    371         $fetched_post = get_post( $result );
    372         $this->assertStringMatchesFormat( '%d', $result );
    373         $this->assertEquals( $date_string , $fetched_post->post_date_gmt );
     434        $date_string  = '1984-01-11 05:00:00';
     435        $post         = array(
     436            'post_title'    => 'test',
     437            'post_content'  => 'test',
     438            'post_date_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) ),
     439        );
     440        $result       = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
     441        $fetched_post = get_post( $result );
     442        $this->assertStringMatchesFormat( '%d', $result );
     443        $this->assertEquals( $date_string, $fetched_post->post_date_gmt );
    374444    }
    375445
Note: See TracChangeset for help on using the changeset viewer.