Make WordPress Core

Ticket #30854: 30854.diff

File 30854.diff, 5.9 KB (added by adamsilverstein, 7 years ago)
  • src/wp-includes/default-filters.php

     
    306306add_action( 'shutdown',                   'wp_ob_end_flush_all',                      1    );
    307307// Create a revision whenever a post is updated.
    308308add_action( 'post_updated',               'wp_save_post_revision',                   10, 1 );
     309add_action( 'new_to_publish',             'wp_save_post_revision',                   10, 1 );
    309310add_action( 'publish_post',               '_publish_post_hook',                       5, 1 );
    310311add_action( 'transition_post_status',     '_transition_post_status',                  5, 3 );
    311312add_action( 'transition_post_status',     '_update_term_count_on_transition_post_status', 10, 3 );
  • tests/phpunit/tests/post/revisions.php

     
    141141                wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
    142142
    143143                $revisions = wp_get_post_revisions( $post_id );
    144                 $this->assertCount( 1, $revisions );
     144                $this->assertCount( 2, $revisions );
    145145                $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $post_id ) );
    146146
    147147                foreach ( $revisions as $revision ) {
     
    163163                wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
    164164
    165165                $revisions = wp_get_post_revisions( $post_id );
    166                 $this->assertCount( 1, $revisions );
     166                $this->assertCount( 2, $revisions );
    167167                foreach ( $revisions as $revision ) {
    168168                         $this->assertTrue( user_can( self::$editor_user_id, 'edit_post', $revision->post_parent ) );
    169169                }
     
    185185
    186186                // Diff checks if you can read both left and right revisions
    187187                $revisions = wp_get_post_revisions( $post_id );
    188                 $this->assertCount( 2, $revisions );
     188                $this->assertCount( 3, $revisions );
    189189                foreach ( $revisions as $revision ) {
    190190                        $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $revision->ID ) );
    191191                }
     
    211211                wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
    212212
    213213                $revisions = wp_get_post_revisions( $post_id );
    214                 $this->assertCount( 1, $revisions );
     214                $this->assertCount( 2, $revisions );
    215215                $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $post_id ) );
    216216
    217217                foreach ( $revisions as $revision ) {
     
    244244                wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
    245245
    246246                $revisions = wp_get_post_revisions( $post_id );
    247                 $this->assertCount( 1, $revisions );
     247                $this->assertCount( 2, $revisions );
    248248                foreach ( $revisions as $revision ) {
    249249                        $this->assertTrue( user_can( self::$editor_user_id, 'edit_post', $revision->post_parent ) );
    250250                }
     
    313313
    314314                // Diff checks if you can read both left and right revisions
    315315                $revisions = wp_get_post_revisions( $post_id );
    316                 $this->assertCount( 2, $revisions );
     316                $this->assertCount( 3, $revisions );
    317317                foreach ( $revisions as $revision ) {
    318318                        $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $revision->ID ) );
    319319                }
     
    329329         */
    330330        function test_wp_get_post_revisions_should_order_by_post_date() {
    331331                global $wpdb;
     332                $now = time();
     333                $date = date( 'Y-m-d H:i:s', $now );
    332334
    333                 $post = self::factory()->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) );
     335                $post = self::factory()->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content', 'post_date' => $date, 'post_date_gmt' => $date ) );
    334336
    335337                $post = (array) $post;
     338                $revision_ids = array();
     339
     340                $revisions = wp_get_post_revisions( $post['ID'] );
     341                $revision_ids[] = current( $revisions )->ID;
     342
    336343                $post_revision_fields = _wp_post_revision_data( $post );
    337344                $post_revision_fields = wp_slash( $post_revision_fields );
    338345
    339                 $revision_ids = array();
    340                 $now = time();
    341346                for ( $j = 1; $j < 3; $j++ ) {
    342347                        // Manually modify dates to ensure they're different.
    343348                        $date = date( 'Y-m-d H:i:s', $now - ( $j * 10 ) );
     
    358363         * @ticket 26042
    359364         */
    360365        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 
     366                $revision_ids = array();
     367                $date = date( 'Y-m-d H:i:s', time() - 10 );
     368                $post = self::factory()->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content', 'post_date' => $date, 'post_date_gmt' => $date ) );
    363369                $post = (array) $post;
    364370                $post_revision_fields = _wp_post_revision_data( $post );
    365371                $post_revision_fields = wp_slash( $post_revision_fields );
     372                $revisions = wp_get_post_revisions( $post['ID'] );
     373                $revision_ids[] = current( $revisions )->ID;
    366374
    367                 $revision_ids = array();
    368                 $date = date( 'Y-m-d H:i:s', time() - 10 );
    369375                for ( $j = 1; $j < 3; $j++ ) {
    370376                        // Manually modify dates to ensure they're the same.
    371377                        $post_revision_fields['post_date'] = $date;
     
    382388
    383389                $this->assertEquals( $revision_ids, array_values( wp_list_pluck( $revisions, 'ID' ) ) );
    384390        }
     391
     392        /**
     393         * @ticket 39011
     394         */
     395        function test_wp_first_revision_is_not_lost() {
     396                $post = self::factory()->post->create_and_get( array(
     397                        'post_title' => 'some-post',
     398                        'post_type' => 'post',
     399                        'post_content' => 'Initial Content',
     400                ) );
     401
     402                wp_update_post( array(
     403                        'ID' => $post->ID,
     404                        'post_content' => 'Update #1',
     405                ) );
     406
     407                wp_update_post( array(
     408                        'ID' => $post->ID,
     409                        'post_content' => 'Update #2',
     410                ) );
     411
     412                $revisions = wp_get_post_revisions( $post->ID );
     413                $earliest_revision = end( $revisions );
     414
     415                $this->assertEquals( 'Initial Content', $earliest_revision->post_content );
     416        }
    385417}