Make WordPress Core

Changeset 1049 in tests


Ignore:
Timestamp:
09/27/2012 03:28:03 AM (12 years ago)
Author:
nacin
Message:

Tests for wp.editPost's if_not_modified_since. props koke, markoheijnen. see #WP21397.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/xmlrpc/wp/editPost.php

    r1040 r1049  
    222222    }
    223223
     224    function test_if_not_modified_since() {
     225        $editor_id = $this->make_user_by_role( 'editor' );
     226
     227        $yesterday = strtotime( '-1 day' );
     228
     229        $post_id = $this->factory->post->create( array(
     230            'post_title'   => 'Post Revision Test',
     231            'post_content' => 'Not edited',
     232            'post_author'  => $editor_id,
     233            'post_status'  => 'publish',
     234            'post_date'    => date( 'Y-m-d H:i:s', $yesterday ),
     235        ) );
     236
     237        // Modify the day old post. In this case, we think it was last modified yesterday.
     238        $struct = array( 'post_content' => 'First edit', 'if_not_modified_since' => new IXR_Date( $yesterday ) );
     239        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $struct ) );
     240        $this->assertNotInstanceOf( 'IXR_Error', $result );
     241
     242        // Make sure the edit went through.
     243        $this->assertEquals( 'First edit', get_post( $post_id )->post_content );
     244
     245        // Modify it again. We think it was last modified yesterday, but we actually just modified it above.
     246        $struct = array( 'post_content' => 'Second edit', 'if_not_modified_since' => new IXR_Date( $yesterday ) );
     247        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $struct ) );
     248        $this->assertInstanceOf( 'IXR_Error', $result );
     249        $this->assertEquals( 409, $result->code );
     250
     251        // Make sure the edit did not go through.
     252        $this->assertEquals( 'First edit', get_post( $post_id )->post_content );
     253    }
    224254}
Note: See TracChangeset for help on using the changeset viewer.