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.


git-svn-id: https://develop.svn.wordpress.org/trunk@39371 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
jnylen0
2016-11-30 03:02:01 +00:00
parent 2d854ef714
commit c716e604c5
3 changed files with 52 additions and 0 deletions

View File

@@ -1087,6 +1087,23 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
$this->assertEquals( $pw_before, $user->user_pass );
}
public function test_update_item_no_change() {
$this->allow_user_to_manage_multisite();
wp_set_current_user( self::$user );
$user = get_userdata( self::$editor );
$request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', self::$editor ) );
$request->set_param( 'slug', $user->user_nicename );
// Run twice to make sure that the update still succeeds even if no DB
// rows are updated.
$response = $this->server->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
$response = $this->server->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
}
public function test_update_item_existing_email() {
$user1 = $this->factory->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com' ) );
$user2 = $this->factory->user->create( array( 'user_login' => 'test_json_user2', 'user_email' => 'testjson2@example.com' ) );