Make WordPress Core


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

    r40417 r42343  
    1515        $contributor_id = $this->make_user_by_role( 'contributor' );
    1616
    17         $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
     17        $post    = array(
     18            'post_title'  => 'Post test',
     19            'post_author' => $contributor_id,
     20        );
    1821        $post_id = wp_insert_post( $post );
    1922
    2023        $new_title = 'Post test (updated)';
    21         $post2 = array( 'post_title' => $new_title );
    22         $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) );
    23         $this->assertNotIXRError( $result );
    24         $this->assertTrue($result);
     24        $post2     = array( 'post_title' => $new_title );
     25        $result    = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) );
     26        $this->assertNotIXRError( $result );
     27        $this->assertTrue( $result );
    2528
    2629        $out = get_post( $post_id );
     
    3235        $this->make_user_by_role( 'editor' );
    3336
    34         $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
     37        $post    = array(
     38            'post_title'  => 'Post test',
     39            'post_author' => $contributor_id,
     40        );
    3541        $post_id = wp_insert_post( $post );
    3642
    3743        $new_title = 'Post test (updated)';
    38         $post2 = array( 'post_title' => $new_title );
    39         $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) );
    40         $this->assertNotIXRError( $result );
    41         $this->assertTrue($result);
     44        $post2     = array( 'post_title' => $new_title );
     45        $result    = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) );
     46        $this->assertNotIXRError( $result );
     47        $this->assertTrue( $result );
    4248
    4349        $out = get_post( $post_id );
     
    5056
    5157        $original_title = 'Post test';
    52         $post = array( 'post_title' => $original_title, 'post_author' => $author_id );
    53         $post_id = wp_insert_post( $post );
     58        $post           = array(
     59            'post_title'  => $original_title,
     60            'post_author' => $author_id,
     61        );
     62        $post_id        = wp_insert_post( $post );
    5463
    5564        $new_title = 'Post test (updated)';
    56         $post2 = array( 'post_title' => $new_title );
    57         $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) );
     65        $post2     = array( 'post_title' => $new_title );
     66        $result    = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) );
    5867        $this->assertIXRError( $result );
    5968        $this->assertEquals( 401, $result->code );
     
    6574    function test_capable_reassign_author() {
    6675        $contributor_id = $this->make_user_by_role( 'contributor' );
    67         $author_id = $this->make_user_by_role( 'author' );
     76        $author_id      = $this->make_user_by_role( 'author' );
    6877        $this->make_user_by_role( 'editor' );
    6978
    70         $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
    71         $post_id = wp_insert_post( $post );
    72 
    73         $post2 = array( 'post_author' => $author_id );
     79        $post    = array(
     80            'post_title'  => 'Post test',
     81            'post_author' => $contributor_id,
     82        );
     83        $post_id = wp_insert_post( $post );
     84
     85        $post2  = array( 'post_author' => $author_id );
    7486        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) );
    7587        $this->assertNotIXRError( $result );
    76         $this->assertTrue($result);
     88        $this->assertTrue( $result );
    7789
    7890        $out = get_post( $post_id );
     
    8294    function test_incapable_reassign_author() {
    8395        $contributor_id = $this->make_user_by_role( 'contributor' );
    84         $author_id = $this->make_user_by_role( 'author' );
    85 
    86         $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
    87         $post_id = wp_insert_post( $post );
    88 
    89         $post2 = array( 'post_author' => $author_id );
     96        $author_id      = $this->make_user_by_role( 'author' );
     97
     98        $post    = array(
     99            'post_title'  => 'Post test',
     100            'post_author' => $contributor_id,
     101        );
     102        $post_id = wp_insert_post( $post );
     103
     104        $post2  = array( 'post_author' => $author_id );
    90105        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) );
    91106        $this->assertIXRError( $result );
     
    101116    function test_capable_reassign_author_to_self() {
    102117        $contributor_id = $this->make_user_by_role( 'contributor' );
    103         $editor_id = $this->make_user_by_role( 'editor' );
    104 
    105         $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
    106         $post_id = wp_insert_post( $post );
    107 
    108         $post2 = array( 'post_author' => $editor_id );
     118        $editor_id      = $this->make_user_by_role( 'editor' );
     119
     120        $post    = array(
     121            'post_title'  => 'Post test',
     122            'post_author' => $contributor_id,
     123        );
     124        $post_id = wp_insert_post( $post );
     125
     126        $post2  = array( 'post_author' => $editor_id );
    109127        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) );
    110128        $this->assertNotIXRError( $result );
    111         $this->assertTrue($result);
     129        $this->assertTrue( $result );
    112130
    113131        $out = get_post( $post_id );
     
    120138        $author_id = $this->make_user_by_role( 'author' );
    121139
    122         $post = array( 'post_title' => 'Post Thumbnail Test', 'post_author' => $author_id );
     140        $post    = array(
     141            'post_title'  => 'Post Thumbnail Test',
     142            'post_author' => $author_id,
     143        );
    123144        $post_id = wp_insert_post( $post );
    124145
     
    126147
    127148        // create attachment
    128         $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );
     149        $filename      = ( DIR_TESTDATA . '/images/a2-small.jpg' );
    129150        $attachment_id = self::factory()->attachment->create_upload_object( $filename, $post_id );
    130151
    131152        // add post thumbnail to post that does not have one
    132         $post2 = array( 'post_thumbnail' => $attachment_id );
     153        $post2  = array( 'post_thumbnail' => $attachment_id );
    133154        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post2 ) );
    134155        $this->assertNotIXRError( $result );
     
    143164
    144165        // edit the post without supplying a post_thumbnail and check that it didn't change
    145         $post3 = array( 'post_content' => 'Updated post' );
     166        $post3  = array( 'post_content' => 'Updated post' );
    146167        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post3 ) );
    147168        $this->assertNotIXRError( $result );
     
    152173
    153174        // change the post's post_thumbnail
    154         $post4 = array( 'post_thumbnail' => $attachment2_id );
     175        $post4  = array( 'post_thumbnail' => $attachment2_id );
    155176        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post4 ) );
    156177        $this->assertNotIXRError( $result );
     
    158179
    159180        // unset the post's post_thumbnail
    160         $post5 = array( 'post_thumbnail' => '' );
     181        $post5  = array( 'post_thumbnail' => '' );
    161182        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post5 ) );
    162183        $this->assertNotIXRError( $result );
     
    164185
    165186        // use invalid ID
    166         $post6 = array( 'post_thumbnail' => 398420983409 );
     187        $post6  = array( 'post_thumbnail' => 398420983409 );
    167188        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post6 ) );
    168189        $this->assertIXRError( $result );
     
    175196        $contributor_id = $this->make_user_by_role( 'contributor' );
    176197
    177         $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
    178         $post_id = wp_insert_post( $post );
     198        $post       = array(
     199            'post_title'  => 'Post test',
     200            'post_author' => $contributor_id,
     201        );
     202        $post_id    = wp_insert_post( $post );
    179203        $mid_edit   = add_post_meta( $post_id, 'custom_field_key', '12345678' );
    180204        $mid_delete = add_post_meta( $post_id, 'custom_field_to_delete', '12345678' );
    181205
    182206        $new_title = 'Post test (updated)';
    183         $post2 = array(
    184             'post_title' => $new_title,
     207        $post2     = array(
     208            'post_title'    => $new_title,
    185209            'custom_fields' =>
    186210                array(
    187211                    array( 'id' => $mid_delete ),
    188                     array( 'id' => $mid_edit, 'key' => 'custom_field_key', 'value' => '87654321' ),
    189                     array( 'key' => 'custom_field_to_create', 'value' => '12345678' )
    190                 )
     212                    array(
     213                        'id'    => $mid_edit,
     214                        'key'   => 'custom_field_key',
     215                        'value' => '87654321',
     216                    ),
     217                    array(
     218                        'key'   => 'custom_field_to_create',
     219                        'value' => '12345678',
     220                    ),
     221                ),
    191222        );
    192223
    193224        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) );
    194225        $this->assertNotIXRError( $result );
    195         $this->assertTrue($result);
     226        $this->assertTrue( $result );
    196227
    197228        $out = get_post( $post_id );
     
    212243        stick_post( $post_id );
    213244
    214         $post2 = array( 'sticky' => false );
     245        $post2  = array( 'sticky' => false );
    215246        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) );
    216247        $this->assertNotIXRError( $result );
     
    221252        // when transitioning to private status or adding a post password, post should be un-stuck
    222253        $editor_id = $this->make_user_by_role( 'editor' );
    223         $post_id = self::factory()->post->create( array( 'post_author' => $editor_id ) );
     254        $post_id   = self::factory()->post->create( array( 'post_author' => $editor_id ) );
    224255        stick_post( $post_id );
    225256
    226         $post2 = array( 'post_password' => 'foobar',  'sticky' => false );
     257        $post2  = array(
     258            'post_password' => 'foobar',
     259            'sticky'        => false,
     260        );
    227261        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) );
    228262        $this->assertNotIXRError( $result );
     
    235269        $yesterday = strtotime( '-1 day' );
    236270
    237         $post_id = self::factory()->post->create( array(
    238             'post_title'   => 'Post Revision Test',
    239             'post_content' => 'Not edited',
    240             'post_author'  => $editor_id,
    241             'post_status'  => 'publish',
    242             'post_date'    => date( 'Y-m-d H:i:s', $yesterday ),
    243         ) );
     271        $post_id = self::factory()->post->create(
     272            array(
     273                'post_title'   => 'Post Revision Test',
     274                'post_content' => 'Not edited',
     275                'post_author'  => $editor_id,
     276                'post_status'  => 'publish',
     277                'post_date'    => date( 'Y-m-d H:i:s', $yesterday ),
     278            )
     279        );
    244280
    245281        // Modify the day old post. In this case, we think it was last modified yesterday.
    246         $struct = array( 'post_content' => 'First edit', 'if_not_modified_since' => new IXR_Date( $yesterday ) );
     282        $struct = array(
     283            'post_content'          => 'First edit',
     284            'if_not_modified_since' => new IXR_Date( $yesterday ),
     285        );
    247286        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $struct ) );
    248287        $this->assertNotIXRError( $result );
     
    252291
    253292        // Modify it again. We think it was last modified yesterday, but we actually just modified it above.
    254         $struct = array( 'post_content' => 'Second edit', 'if_not_modified_since' => new IXR_Date( $yesterday ) );
     293        $struct = array(
     294            'post_content'          => 'Second edit',
     295            'if_not_modified_since' => new IXR_Date( $yesterday ),
     296        );
    255297        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $struct ) );
    256298        $this->assertIXRError( $result );
     
    264306        $editor_id = $this->make_user_by_role( 'editor' );
    265307
    266         $post_id = self::factory()->post->create( array(
    267             'post_title'   => 'Post Revision Test',
    268             'post_content' => 'Not edited',
    269             'post_status'  => 'inherit',
    270             'post_type'    => 'attachment',
    271             'post_author'  => $editor_id,
    272         ) );
     308        $post_id = self::factory()->post->create(
     309            array(
     310                'post_title'   => 'Post Revision Test',
     311                'post_content' => 'Not edited',
     312                'post_status'  => 'inherit',
     313                'post_type'    => 'attachment',
     314                'post_author'  => $editor_id,
     315            )
     316        );
    273317
    274318        $struct = array( 'post_content' => 'First edit' );
     
    283327        $editor_id = $this->make_user_by_role( 'editor' );
    284328
    285         $post_id = self::factory()->post->create( array(
    286             'post_title'   => 'Post Revision Test',
    287             'post_content' => 'Not edited',
    288             'post_author'  => $editor_id,
    289         ) );
     329        $post_id = self::factory()->post->create(
     330            array(
     331                'post_title'   => 'Post Revision Test',
     332                'post_content' => 'Not edited',
     333                'post_author'  => $editor_id,
     334            )
     335        );
    290336
    291337        $struct = array( 'post_status' => 'doesnt_exists' );
     
    303349        $editor_id = $this->make_user_by_role( 'editor' );
    304350
    305         $post_id = self::factory()->post->create( array( 'post_author'  => $editor_id ) );
     351        $post_id = self::factory()->post->create( array( 'post_author' => $editor_id ) );
    306352        $term_id = self::factory()->category->create();
    307353        self::factory()->term->add_post_terms( $post_id, $term_id, 'category', true );
     
    309355        $this->assertContains( $term_id, $term_ids );
    310356
    311         $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, array( 'ID' => $post_id, 'post_title' => 'Updated' ) ) );
     357        $result = $this->myxmlrpcserver->wp_editPost(
     358            array(
     359                1,
     360                'editor',
     361                'editor',
     362                $post_id,
     363                array(
     364                    'ID'         => $post_id,
     365                    'post_title' => 'Updated',
     366                ),
     367            )
     368        );
    312369        $this->assertNotIXRError( $result );
    313370        $this->assertEquals( 'Updated', get_post( $post_id )->post_title );
     
    323380        $editor_id = $this->make_user_by_role( 'editor' );
    324381
    325         $post_id = self::factory()->post->create( array( 'post_author'  => $editor_id ) );
     382        $post_id = self::factory()->post->create( array( 'post_author' => $editor_id ) );
    326383        $term_id = self::factory()->category->create();
    327384        self::factory()->term->add_post_terms( $post_id, $term_id, 'category', true );
     
    330387
    331388        $new_post_content = array(
    332             'ID' => $post_id,
     389            'ID'         => $post_id,
    333390            'post_title' => 'Updated',
    334             'terms' => array(
    335                 'category' => array()
    336             )
    337         );
    338         $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $new_post_content ) );
     391            'terms'      => array(
     392                'category' => array(),
     393            ),
     394        );
     395        $result           = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $new_post_content ) );
    339396        $this->assertNotIXRError( $result );
    340397        $this->assertEquals( 'Updated', get_post( $post_id )->post_title );
     
    366423
    367424        // Add a dummy post
    368         $post_id = self::factory()->post->create( array(
    369             'post_title'   => 'Post Enclosure Test',
    370             'post_content' => 'Fake content',
    371             'post_author'  => $editor_id,
    372             'post_status'  => 'publish',
    373         ) );
     425        $post_id = self::factory()->post->create(
     426            array(
     427                'post_title'   => 'Post Enclosure Test',
     428                'post_content' => 'Fake content',
     429                'post_author'  => $editor_id,
     430                'post_status'  => 'publish',
     431            )
     432        );
    374433
    375434        // Add the enclosure as it is added in "do_enclose()"
     
    414473         * the bug.
    415474         */
    416         $post = array(
     475        $post    = array(
    417476            'post_title'  => 'Test',
    418477            'post_status' => 'draft',
     
    421480
    422481        // Change the post's status to publish and date to future.
    423         $future_time = strtotime( '+1 day' );
    424         $future_date = new IXR_Date( $future_time );
     482        $future_time      = strtotime( '+1 day' );
     483        $future_date      = new IXR_Date( $future_time );
    425484        $new_post_content = array(
    426485            'ID'          => $post_id,
Note: See TracChangeset for help on using the changeset viewer.