WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/30/2016 03:02:01 AM (4 years ago)
Author:
jnylen0
Message:

REST API: Add tests for empty or "no-op" updates.

The API should allow updates that don't actually change anything. This allows
clients to, for example, accidentally send the same request twice without
encountering unexpected errors. This currently works for posts, terms, and
users, so this commit adds test cases accordingly.

See #38700 for issues preventing this from working for comments.

Fixes #38975.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r39353 r39371  
    16471647        $this->assertEquals( $params['content'], $post->post_content );
    16481648        $this->assertEquals( $params['excerpt'], $post->post_excerpt );
     1649    }
     1650
     1651    public function test_update_item_no_change() {
     1652        wp_set_current_user( self::$editor_id );
     1653        $post = get_post( self::$post_id );
     1654
     1655        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     1656        $request->set_param( 'author', $post->post_author );
     1657
     1658        // Run twice to make sure that the update still succeeds even if no DB
     1659        // rows are updated.
     1660        $response = $this->server->dispatch( $request );
     1661        $this->check_update_post_response( $response );
     1662
     1663        $response = $this->server->dispatch( $request );
     1664        $this->check_update_post_response( $response );
    16491665    }
    16501666
Note: See TracChangeset for help on using the changeset viewer.