Make WordPress Core

Changeset 1211 in tests


Ignore:
Timestamp:
02/14/2013 11:17:34 AM (12 years ago)
Author:
westi
Message:

Revisions: When we are trying to save a new revision we shouldn't save one if the previous version was the same.

See #7392 and #9843 props adamsilverstein

File:
1 edited

Legend:

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

    r1210 r1211  
    3939         $this->assertEquals( get_post_meta( $post_id, '_edit_last', true ), $author_user_id ); //after restoring user
    4040    }
     41
     42    /**
     43    * @ticket 7392
     44    * @ticket 9843
     45    */
     46    function test_revision_dont_save_revision_if_unchanged() {
     47        $post_id = $this->factory->post->create( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) );
     48
     49        wp_update_post( array( 'post_content'   => 'some updated content', 'ID' => $post_id ) );    //1st revision
     50        $this->assertEquals( 1, count( wp_get_post_revisions( $post_id ) ) ); //should be 1 revision so far
     51
     52        //update the post
     53        wp_update_post( array( 'post_content'   => 'new update for some updated content', 'ID' => $post_id ) ); //2nd revision
     54        $this->assertEquals( 2, count( wp_get_post_revisions( $post_id ) ) ); //should be 2 revision so far
     55
     56        //next try to save another identical update, tests for patch that prevents storing duplicates
     57        wp_update_post( array( 'post_content'   => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save
     58        $this->assertEquals( 2, count( wp_get_post_revisions( $post_id ) ) ); //should still be 2 revision
     59
     60        //next try to save another update, same content, but new ttile, should save revision
     61        wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content'  => 'new update for some updated content', 'ID' => $post_id ) );
     62        $this->assertEquals( 3, count( wp_get_post_revisions( $post_id ) ) ); //should  be 3 revision
     63
     64        //next try to save another identical update
     65        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
     66        $this->assertEquals( 3, count( wp_get_post_revisions( $post_id ) ) ); //should still be 3 revision
     67    }
    4168}
Note: See TracChangeset for help on using the changeset viewer.