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

    r42228 r42343  
    1111
    1212    public static function wpSetUpBeforeClass( $factory ) {
    13         self::$admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) );
     13        self::$admin_user_id  = $factory->user->create( array( 'role' => 'administrator' ) );
    1414        self::$editor_user_id = $factory->user->create( array( 'role' => 'editor' ) );
    1515        self::$author_user_id = $factory->user->create( array( 'role' => 'author' ) );
     
    2828    /**
    2929     * Note: Test needs reviewing when #16215 is fixed because I'm not sure the test current tests the "correct" behavior
     30     *
    3031     * @ticket 20982
    3132     * @ticket 16215
     
    3435        //create a post as Author
    3536        wp_set_current_user( self::$author_user_id );
    36         $post = get_default_post_to_edit( 'post', true );
     37        $post    = get_default_post_to_edit( 'post', true );
    3738        $post_id = $post->ID;
    3839
    39         wp_update_post( array( 'post_status' => 'draft', 'post_content' => 'I cant spel werds.', 'ID' => $post_id ) );
     40        wp_update_post(
     41            array(
     42                'post_status'  => 'draft',
     43                'post_content' => 'I cant spel werds.',
     44                'ID'           => $post_id,
     45            )
     46        );
    4047
    4148        //update post as Editor
    4249        wp_set_current_user( self::$editor_user_id );
    43         wp_update_post( array( 'post_content' => 'The Editor was in fixing your typos.', 'ID' => $post_id ) );
     50        wp_update_post(
     51            array(
     52                'post_content' => 'The Editor was in fixing your typos.',
     53                'ID'           => $post_id,
     54            )
     55        );
    4456
    4557        //restore back as Admin
     
    5163        $this->assertEquals( 'I cant spel werds.', $lastrevision->post_content );
    5264        // #16215
    53         $this->assertEquals( self::$author_user_id , $lastrevision->post_author);
     65        $this->assertEquals( self::$author_user_id, $lastrevision->post_author );
    5466
    5567        wp_restore_post_revision( $lastrevision->ID );
     
    6072
    6173    /**
    62     * @ticket 7392
    63     * @ticket 9843
    64     */
     74     * @ticket 7392
     75     * @ticket 9843
     76     */
    6577    function test_revision_dont_save_revision_if_unchanged() {
    66         $post = get_default_post_to_edit( 'post', true );
     78        $post    = get_default_post_to_edit( 'post', true );
    6779        $post_id = $post->ID;
    6880
    6981        $this->assertCount( 0, wp_get_post_revisions( $post_id ) ); // No revisions on auto-draft creation.
    7082
    71         wp_update_post( array( 'post_status' => 'draft', 'post_title' => 'some-post', 'post_content' => 'some_content', 'ID' => $post_id ) );
     83        wp_update_post(
     84            array(
     85                'post_status'  => 'draft',
     86                'post_title'   => 'some-post',
     87                'post_content' => 'some_content',
     88                'ID'           => $post_id,
     89            )
     90        );
    7291
    7392        $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); // Just the initial revision
    7493
    7594        // First update
    76         wp_update_post( array( 'post_content'   => 'some updated content', 'ID' => $post_id ) );
     95        wp_update_post(
     96            array(
     97                'post_content' => 'some updated content',
     98                'ID'           => $post_id,
     99            )
     100        );
    77101
    78102        $this->assertCount( 2, wp_get_post_revisions( $post_id ) ); // should be 2 revisions so far
    79103
    80104        //update the post
    81         wp_update_post( array( 'post_content'   => 'new update for some updated content', 'ID' => $post_id ) ); //2nd revision
     105        wp_update_post(
     106            array(
     107                'post_content' => 'new update for some updated content',
     108                'ID'           => $post_id,
     109            )
     110        ); //2nd revision
    82111        $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); // should be 3 revision so far
    83112
    84113        //next try to save another identical update, tests for patch that prevents storing duplicates
    85         wp_update_post( array( 'post_content'   => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save
     114        wp_update_post(
     115            array(
     116                'post_content' => 'new update for some updated content',
     117                'ID'           => $post_id,
     118            )
     119        ); //content unchanged, shouldn't save
    86120        $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); //should still be 3 revision
    87121
    88122        //next try to save another update, same content, but new ttile, should save revision
    89         wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content'  => 'new update for some updated content', 'ID' => $post_id ) );
     123        wp_update_post(
     124            array(
     125                'post_title'   => 'some-post-changed',
     126                'post_content' => 'new update for some updated content',
     127                'ID'           => $post_id,
     128            )
     129        );
    90130        $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should  be 4 revision
    91131
    92132        //next try to save another identical update
    93         wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content'  => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save
     133        wp_update_post(
     134            array(
     135                'post_title'   => 'some-post-changed',
     136                'post_content' => 'new update for some updated content',
     137                'ID'           => $post_id,
     138            )
     139        ); //content unchanged, shouldn't save
    94140        $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should still be 4 revision
    95141    }
    96142
    97143    /**
    98     * @ticket 7392
    99     * @ticket 9843
    100     */
     144     * @ticket 7392
     145     * @ticket 9843
     146     */
    101147    function test_revision_force_save_revision_even_if_unchanged() {
    102148        add_filter( 'wp_save_post_revision_check_for_changes', '__return_false' );
    103149
    104         $post = get_default_post_to_edit( 'post', true );
     150        $post    = get_default_post_to_edit( 'post', true );
    105151        $post_id = $post->ID;
    106152
    107153        $this->assertCount( 0, wp_get_post_revisions( $post_id ) ); // No revisions on auto-draft creation.
    108154
    109         wp_update_post( array( 'post_status' => 'draft', 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content', 'ID' => $post_id ) );
     155        wp_update_post(
     156            array(
     157                'post_status'  => 'draft',
     158                'post_title'   => 'some-post',
     159                'post_type'    => 'post',
     160                'post_content' => 'some_content',
     161                'ID'           => $post_id,
     162            )
     163        );
    110164
    111165        $this->assertCount( 1, wp_get_post_revisions( $post_id ) );
    112166
    113         wp_update_post( array( 'post_content'   => 'some updated content', 'ID' => $post_id ) );    //1st revision
     167        wp_update_post(
     168            array(
     169                'post_content' => 'some updated content',
     170                'ID'           => $post_id,
     171            )
     172        );    //1st revision
    114173        $this->assertCount( 2, wp_get_post_revisions( $post_id ) );
    115174
    116175        //update the post
    117         wp_update_post( array( 'post_content'   => 'new update for some updated content', 'ID' => $post_id ) ); //2nd revision
     176        wp_update_post(
     177            array(
     178                'post_content' => 'new update for some updated content',
     179                'ID'           => $post_id,
     180            )
     181        ); //2nd revision
    118182        $this->assertCount( 3, wp_get_post_revisions( $post_id ) );
    119183
    120184        //next try to save another identical update, tests for patch that prevents storing duplicates
    121         wp_update_post( array( 'post_content'   => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save
     185        wp_update_post(
     186            array(
     187                'post_content' => 'new update for some updated content',
     188                'ID'           => $post_id,
     189            )
     190        ); //content unchanged, shouldn't save
    122191        $this->assertCount( 4, wp_get_post_revisions( $post_id ) );
    123192
    124193        //next try to save another update, same content, but new ttile, should save revision
    125         wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content'  => 'new update for some updated content', 'ID' => $post_id ) );
     194        wp_update_post(
     195            array(
     196                'post_title'   => 'some-post-changed',
     197                'post_content' => 'new update for some updated content',
     198                'ID'           => $post_id,
     199            )
     200        );
    126201        $this->assertCount( 5, wp_get_post_revisions( $post_id ) );
    127202
    128203        //next try to save another identical update
    129         wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content'  => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save
     204        wp_update_post(
     205            array(
     206                'post_title'   => 'some-post-changed',
     207                'post_content' => 'new update for some updated content',
     208                'ID'           => $post_id,
     209            )
     210        ); //content unchanged, shouldn't save
    130211        $this->assertCount( 6, wp_get_post_revisions( $post_id ) );
    131212
     
    135216    /**
    136217     * Tests the Caps used in the action=view case of wp-admin/revision.php
     218     *
    137219     * @ticket 16847
    138220     */
    139221    function test_revision_view_caps_post() {
    140         $post_id = self::factory()->post->create( array( 'post_type' => 'post', 'post_author' => self::$editor_user_id ) );
    141         wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
     222        $post_id = self::factory()->post->create(
     223            array(
     224                'post_type'   => 'post',
     225                'post_author' => self::$editor_user_id,
     226            )
     227        );
     228        wp_update_post(
     229            array(
     230                'post_content' => 'This content is much better',
     231                'ID'           => $post_id,
     232            )
     233        );
    142234
    143235        $revisions = wp_get_post_revisions( $post_id );
     
    157249    /**
    158250     * Tests the Caps used in the action=restore case of wp-admin/revision.php
     251     *
    159252     * @ticket 16847
    160253     */
    161254    function test_revision_restore_caps_post() {
    162         $post_id = self::factory()->post->create( array( 'post_type' => 'post', 'post_author' => self::$editor_user_id ) );
    163         wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
     255        $post_id = self::factory()->post->create(
     256            array(
     257                'post_type'   => 'post',
     258                'post_author' => self::$editor_user_id,
     259            )
     260        );
     261        wp_update_post(
     262            array(
     263                'post_content' => 'This content is much better',
     264                'ID'           => $post_id,
     265            )
     266        );
    164267
    165268        $revisions = wp_get_post_revisions( $post_id );
     
    177280    /**
    178281     * Tests the Caps used in the action=diff case of wp-admin/revision.php
     282     *
    179283     * @ticket 16847
    180284     */
    181285    function test_revision_diff_caps_post() {
    182         $post_id = self::factory()->post->create( array( 'post_type' => 'post', 'post_author' => self::$editor_user_id ) );
    183         wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
    184         wp_update_post( array( 'post_content' => 'This content is even better', 'ID' => $post_id ) );
     286        $post_id = self::factory()->post->create(
     287            array(
     288                'post_type'   => 'post',
     289                'post_author' => self::$editor_user_id,
     290            )
     291        );
     292        wp_update_post(
     293            array(
     294                'post_content' => 'This content is much better',
     295                'ID'           => $post_id,
     296            )
     297        );
     298        wp_update_post(
     299            array(
     300                'post_content' => 'This content is even better',
     301                'ID'           => $post_id,
     302            )
     303        );
    185304
    186305        // Diff checks if you can read both left and right revisions
     
    199318    /**
    200319     * Tests the Caps used in the action=view case of wp-admin/revision.php with a CPT with Custom Capabilities
     320     *
    201321     * @ticket 16847
    202322     */
    203323    function test_revision_view_caps_cpt() {
    204         register_post_type( $this->post_type, array(
    205             'capability_type' => 'event',
    206             'map_meta_cap' => true,
    207             'supports' => array( 'revisions' ),
    208         ) );
    209 
    210         $post_id = self::factory()->post->create( array( 'post_type' => $this->post_type, 'post_author' => self::$editor_user_id ) );
    211         wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
     324        register_post_type(
     325            $this->post_type, array(
     326                'capability_type' => 'event',
     327                'map_meta_cap'    => true,
     328                'supports'        => array( 'revisions' ),
     329            )
     330        );
     331
     332        $post_id = self::factory()->post->create(
     333            array(
     334                'post_type'   => $this->post_type,
     335                'post_author' => self::$editor_user_id,
     336            )
     337        );
     338        wp_update_post(
     339            array(
     340                'post_content' => 'This content is much better',
     341                'ID'           => $post_id,
     342            )
     343        );
    212344
    213345        $revisions = wp_get_post_revisions( $post_id );
     
    227359    /**
    228360     * Tests the Caps used in the action=restore case of wp-admin/revision.php
     361     *
    229362     * @ticket 16847
    230363     */
    231364    function test_revision_restore_caps_cpt() {
    232         register_post_type( $this->post_type, array(
    233             'capability_type' => 'event',
    234             'map_meta_cap' => true,
    235             'supports' => array( 'revisions' ),
    236         ) );
     365        register_post_type(
     366            $this->post_type, array(
     367                'capability_type' => 'event',
     368                'map_meta_cap'    => true,
     369                'supports'        => array( 'revisions' ),
     370            )
     371        );
    237372
    238373        // The minimum extra caps needed for this test normally you would give the role all the relevant caps.
     
    241376
    242377        //create a post as Editor
    243         $post_id = self::factory()->post->create( array( 'post_type' => $this->post_type, 'post_author' => self::$editor_user_id ) );
    244         wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
     378        $post_id = self::factory()->post->create(
     379            array(
     380                'post_type'   => $this->post_type,
     381                'post_author' => self::$editor_user_id,
     382            )
     383        );
     384        wp_update_post(
     385            array(
     386                'post_content' => 'This content is much better',
     387                'ID'           => $post_id,
     388            )
     389        );
    245390
    246391        $revisions = wp_get_post_revisions( $post_id );
     
    259404    /**
    260405     * Tests the Caps used in the action=restore case of wp-admin/revision.php
     406     *
    261407     * @ticket 16847
    262408     */
    263409    function test_revision_restore_caps_before_publish() {
    264         register_post_type( $this->post_type, array(
    265             'capability_type' => 'post',
    266             'capabilities' => array(
    267                 // No one can edit this post type once published.
    268                 // So, revisions cannot be restored, either.
    269                 'edit_published_posts' => 'do_not_allow',
    270             ),
    271             'map_meta_cap' => true,
    272             'supports' => array( 'revisions' ),
    273         ) );
     410        register_post_type(
     411            $this->post_type, array(
     412                'capability_type' => 'post',
     413                'capabilities'    => array(
     414                    // No one can edit this post type once published.
     415                    // So, revisions cannot be restored, either.
     416                    'edit_published_posts' => 'do_not_allow',
     417                ),
     418                'map_meta_cap'    => true,
     419                'supports'        => array( 'revisions' ),
     420            )
     421        );
    274422
    275423        $old_id = get_current_user_id();
    276424        wp_set_current_user( self::$editor_user_id );
    277425
    278         $post_id = self::factory()->post->create( array( 'post_type' => $this->post_type, 'post_status' => 'draft' ) );
    279         wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
     426        $post_id = self::factory()->post->create(
     427            array(
     428                'post_type'   => $this->post_type,
     429                'post_status' => 'draft',
     430            )
     431        );
     432        wp_update_post(
     433            array(
     434                'post_content' => 'This content is much better',
     435                'ID'           => $post_id,
     436            )
     437        );
    280438
    281439        $revisions = wp_get_post_revisions( $post_id );
     
    286444        }
    287445
    288         wp_update_post( array( 'post_status' => 'publish', 'ID' => $post_id, 'post_content' => rand_str() ) );
     446        wp_update_post(
     447            array(
     448                'post_status'  => 'publish',
     449                'ID'           => $post_id,
     450                'post_content' => rand_str(),
     451            )
     452        );
    289453
    290454        $revisions = wp_get_post_revisions( $post_id );
     
    299463    /**
    300464     * Tests the Caps used in the action=diff case of wp-admin/revision.php
     465     *
    301466     * @ticket 16847
    302467     */
    303468    function test_revision_diff_caps_cpt() {
    304         register_post_type( $this->post_type, array(
    305             'capability_type' => 'event',
    306             'map_meta_cap' => true,
    307             'supports' => array( 'revisions' ),
    308         ) );
    309 
    310         $post_id = self::factory()->post->create( array( 'post_type' => $this->post_type, 'post_author' => self::$editor_user_id ) );
    311         wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
    312         wp_update_post( array( 'post_content' => 'This content is even better', 'ID' => $post_id ) );
     469        register_post_type(
     470            $this->post_type, array(
     471                'capability_type' => 'event',
     472                'map_meta_cap'    => true,
     473                'supports'        => array( 'revisions' ),
     474            )
     475        );
     476
     477        $post_id = self::factory()->post->create(
     478            array(
     479                'post_type'   => $this->post_type,
     480                'post_author' => self::$editor_user_id,
     481            )
     482        );
     483        wp_update_post(
     484            array(
     485                'post_content' => 'This content is much better',
     486                'ID'           => $post_id,
     487            )
     488        );
     489        wp_update_post(
     490            array(
     491                'post_content' => 'This content is even better',
     492                'ID'           => $post_id,
     493            )
     494        );
    313495
    314496        // Diff checks if you can read both left and right revisions
     
    331513        global $wpdb;
    332514
    333         $post = self::factory()->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) );
    334 
    335         $post = (array) $post;
     515        $post = self::factory()->post->create_and_get(
     516            array(
     517                'post_title'   => 'some-post',
     518                'post_type'    => 'post',
     519                'post_content' => 'some_content',
     520            )
     521        );
     522
     523        $post                 = (array) $post;
    336524        $post_revision_fields = _wp_post_revision_data( $post );
    337525        $post_revision_fields = wp_slash( $post_revision_fields );
    338526
    339527        $revision_ids = array();
    340         $now = time();
     528        $now          = time();
    341529        for ( $j = 1; $j < 3; $j++ ) {
    342530            // Manually modify dates to ensure they're different.
    343             $date = date( 'Y-m-d H:i:s', $now - ( $j * 10 ) );
    344             $post_revision_fields['post_date'] = $date;
     531            $date                                  = date( 'Y-m-d H:i:s', $now - ( $j * 10 ) );
     532            $post_revision_fields['post_date']     = $date;
    345533            $post_revision_fields['post_date_gmt'] = $date;
    346534
     
    359547     */
    360548    function test_wp_get_post_revisions_should_order_by_ID_when_post_date_matches() {
    361         $post = self::factory()->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) );
    362 
    363         $post = (array) $post;
     549        $post = self::factory()->post->create_and_get(
     550            array(
     551                'post_title'   => 'some-post',
     552                'post_type'    => 'post',
     553                'post_content' => 'some_content',
     554            )
     555        );
     556
     557        $post                 = (array) $post;
    364558        $post_revision_fields = _wp_post_revision_data( $post );
    365559        $post_revision_fields = wp_slash( $post_revision_fields );
    366560
    367561        $revision_ids = array();
    368         $date = date( 'Y-m-d H:i:s', time() - 10 );
     562        $date         = date( 'Y-m-d H:i:s', time() - 10 );
    369563        for ( $j = 1; $j < 3; $j++ ) {
    370564            // Manually modify dates to ensure they're the same.
    371             $post_revision_fields['post_date'] = $date;
     565            $post_revision_fields['post_date']     = $date;
    372566            $post_revision_fields['post_date_gmt'] = $date;
    373567
Note: See TracChangeset for help on using the changeset viewer.