diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 70db2e2bd3..8f8bc73476 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -1648,6 +1648,22 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $this->assertEquals( $params['excerpt'], $post->post_excerpt ); } + public function test_update_item_no_change() { + wp_set_current_user( self::$editor_id ); + $post = get_post( self::$post_id ); + + $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); + $request->set_param( 'author', $post->post_author ); + + // Run twice to make sure that the update still succeeds even if no DB + // rows are updated. + $response = $this->server->dispatch( $request ); + $this->check_update_post_response( $response ); + + $response = $this->server->dispatch( $request ); + $this->check_update_post_response( $response ); + } + public function test_rest_update_post() { wp_set_current_user( self::$editor_id ); diff --git a/tests/phpunit/tests/rest-api/rest-tags-controller.php b/tests/phpunit/tests/rest-api/rest-tags-controller.php index 4c461d347d..bdca9cb852 100644 --- a/tests/phpunit/tests/rest-api/rest-tags-controller.php +++ b/tests/phpunit/tests/rest-api/rest-tags-controller.php @@ -554,6 +554,25 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { $this->assertEquals( 'new-slug', $data['slug'] ); } + public function test_update_item_no_change() { + wp_set_current_user( self::$administrator ); + $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); + + $request = new WP_REST_Request( 'PUT', '/wp/v2/tags/' . $term->term_id ); + + $response = $this->server->dispatch( $request ); + $this->assertEquals( 200, $response->get_status() ); + $request->set_param( 'slug', $term->slug ); + + // 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_invalid_term() { wp_set_current_user( self::$administrator ); $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php index 8da864f3a8..62da9228fe 100644 --- a/tests/phpunit/tests/rest-api/rest-users-controller.php +++ b/tests/phpunit/tests/rest-api/rest-users-controller.php @@ -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' ) );