Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/revisions.php

    r46586 r47122  
    3333     */
    3434    function test_revision_restore_updates_edit_last_post_meta() {
    35         //create a post as Author
     35        // Create a post as Author.
    3636        wp_set_current_user( self::$author_user_id );
    3737        $post    = get_default_post_to_edit( 'post', true );
     
    4646        );
    4747
    48         //update post as Editor
     48        // Update post as Editor.
    4949        wp_set_current_user( self::$editor_user_id );
    5050        wp_update_post(
     
    5555        );
    5656
    57         //restore back as Admin
     57        // Restore back as Admin.
    5858        wp_set_current_user( self::$admin_user_id );
    5959        $revisions = wp_get_post_revisions( $post->ID );
     
    6767        wp_restore_post_revision( $lastrevision->ID );
    6868
    69         //is post_meta correctly set to revision author
    70         $this->assertEquals( self::$admin_user_id, get_post_meta( $post_id, '_edit_last', true ) ); //after restoring user
     69        // Is post_meta correctly set to revision author after restoring user?
     70        $this->assertEquals( self::$admin_user_id, get_post_meta( $post_id, '_edit_last', true ) );
    7171    }
    7272
     
    9090        );
    9191
    92         $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); // Just the initial revision
    93 
    94         // First update
     92        $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); // Just the initial revision.
     93
     94        // First update.
    9595        wp_update_post(
    9696            array(
     
    9898                'ID'           => $post_id,
    9999            )
    100         );
    101 
    102         $this->assertCount( 2, wp_get_post_revisions( $post_id ) ); // should be 2 revisions so far
    103 
    104         //update the post
    105         wp_update_post(
    106             array(
    107                 'post_content' => 'new update for some updated content',
    108                 'ID'           => $post_id,
    109             )
    110         ); //2nd revision
    111         $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); // should be 3 revision so far
    112 
    113         //next try to save another identical update, tests for patch that prevents storing duplicates
    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
    120         $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); //should still be 3 revision
    121 
    122         //next try to save another update, same content, but new ttile, should save revision
     100        ); // First revision.
     101
     102        $this->assertCount( 2, wp_get_post_revisions( $post_id ) ); // Should be 2 revisions so far.
     103
     104        // Update the post.
     105        wp_update_post(
     106            array(
     107                'post_content' => 'new update for some updated content',
     108                'ID'           => $post_id,
     109            )
     110        ); // Second revision.
     111        $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); // Should be 3 revisions so far.
     112
     113        // Next, try to save another identical update, tests for patch that prevents storing duplicates.
     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.
     120        $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); // Should still be 3 revisions.
     121
     122        // Next, try to save another update, same content, but new title, should save revision.
    123123        wp_update_post(
    124124            array(
     
    128128            )
    129129        );
    130         $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should  be 4 revision
    131 
    132         //next try to save another identical update
     130        $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); // Should be 4 revisions.
     131
     132        // Next, try to save another identical update.
    133133        wp_update_post(
    134134            array(
     
    137137                'ID'           => $post_id,
    138138            )
    139         ); //content unchanged, shouldn't save
    140         $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should still be 4 revision
     139        ); // Content unchanged, shouldn't save.
     140        $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); // Should still be 4 revisions.
    141141    }
    142142
     
    165165        $this->assertCount( 1, wp_get_post_revisions( $post_id ) );
    166166
     167        // First update.
    167168        wp_update_post(
    168169            array(
     
    170171                'ID'           => $post_id,
    171172            )
    172         );    //1st revision
     173        ); // First revision.
    173174        $this->assertCount( 2, wp_get_post_revisions( $post_id ) );
    174175
    175         //update the post
    176         wp_update_post(
    177             array(
    178                 'post_content' => 'new update for some updated content',
    179                 'ID'           => $post_id,
    180             )
    181         ); //2nd revision
     176        // Update the post.
     177        wp_update_post(
     178            array(
     179                'post_content' => 'new update for some updated content',
     180                'ID'           => $post_id,
     181            )
     182        ); // Second revision.
    182183        $this->assertCount( 3, wp_get_post_revisions( $post_id ) );
    183184
    184         //next try to save another identical update, tests for patch that prevents storing duplicates
    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
     185        // Next, try to save another identical update, tests for patch that prevents storing duplicates.
     186        wp_update_post(
     187            array(
     188                'post_content' => 'new update for some updated content',
     189                'ID'           => $post_id,
     190            )
     191        ); // Content unchanged, shouldn't save.
    191192        $this->assertCount( 4, wp_get_post_revisions( $post_id ) );
    192193
    193         //next try to save another update, same content, but new ttile, should save revision
     194        // Next, try to save another update, same content, but new title, should save revision.
    194195        wp_update_post(
    195196            array(
     
    201202        $this->assertCount( 5, wp_get_post_revisions( $post_id ) );
    202203
    203         //next try to save another identical update
     204        // Next, try to save another identical update.
    204205        wp_update_post(
    205206            array(
     
    208209                'ID'           => $post_id,
    209210            )
    210         ); //content unchanged, shouldn't save
     211        ); // Content unchanged, shouldn't save.
    211212        $this->assertCount( 6, wp_get_post_revisions( $post_id ) );
    212213
     
    241242        }
    242243
    243         // Author should be able to view the revisions fine
     244        // Author should be able to view the revisions fine.
    244245        foreach ( $revisions as $revision ) {
    245246            $this->assertTrue( user_can( self::$author_user_id, 'read_post', $revision->ID ) );
     
    272273        }
    273274
    274         // Author shouldn't be able to restore the revisions
     275        // Author shouldn't be able to restore the revisions.
    275276        foreach ( $revisions as $revision ) {
    276277            $this->assertFalse( user_can( self::$author_user_id, 'edit_post', $revision->post_parent ) );
     
    303304        );
    304305
    305         // Diff checks if you can read both left and right revisions
     306        // Diff checks if you can read both left and right revisions.
    306307        $revisions = wp_get_post_revisions( $post_id );
    307308        $this->assertCount( 2, $revisions );
     
    310311        }
    311312
    312         // Author should be able to diff the revisions fine
     313        // Author should be able to diff the revisions fine.
    313314        foreach ( $revisions as $revision ) {
    314315            $this->assertTrue( user_can( self::$author_user_id, 'read_post', $revision->ID ) );
     
    352353        }
    353354
    354         // Author should be able to view the revisions fine
     355        // Author should be able to view the revisions fine.
    355356        foreach ( $revisions as $revision ) {
    356357            $this->assertTrue( user_can( self::$author_user_id, 'read_post', $revision->ID ) );
     
    377378        $editor_user->add_cap( 'edit_published_events' );
    378379
    379         //create a post as Editor
     380        // Create a post as Editor.
    380381        $post_id = self::factory()->post->create(
    381382            array(
     
    397398        }
    398399
    399         // Author shouldn't be able to restore the revisions
     400        // Author shouldn't be able to restore the revisions.
    400401        wp_set_current_user( self::$author_user_id );
    401402        foreach ( $revisions as $revision ) {
     
    498499        );
    499500
    500         // Diff checks if you can read both left and right revisions
     501        // Diff checks if you can read both left and right revisions.
    501502        $revisions = wp_get_post_revisions( $post_id );
    502503        $this->assertCount( 2, $revisions );
     
    505506        }
    506507
    507         // Author should be able to diff the revisions fine
     508        // Author should be able to diff the revisions fine.
    508509        foreach ( $revisions as $revision ) {
    509510            $this->assertTrue( user_can( self::$author_user_id, 'read_post', $revision->ID ) );
Note: See TracChangeset for help on using the changeset viewer.