mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-03-31 10:44:26 +00:00
REST API: Allow sending an empty or no-op comment update.
In general, updates that don't actually change anything should succeed. [39371] added tests for other object types, and this commit fixes empty updates for comments and adds the missing test. Fixes #38700. git-svn-id: https://develop.svn.wordpress.org/trunk@39597 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1961,6 +1961,22 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
|
||||
$this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 );
|
||||
}
|
||||
|
||||
public function test_update_item_no_change() {
|
||||
$comment = get_comment( self::$approved_id );
|
||||
|
||||
wp_set_current_user( self::$admin_id );
|
||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
|
||||
$request->set_param( 'post', $comment->comment_post_ID );
|
||||
|
||||
// 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_comment_status() {
|
||||
wp_set_current_user( self::$admin_id );
|
||||
|
||||
@@ -2206,6 +2222,16 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
|
||||
$this->assertErrorResponse( 'rest_comment_invalid_id', $response, 404 );
|
||||
}
|
||||
|
||||
public function test_update_comment_invalid_post_id() {
|
||||
wp_set_current_user( self::$admin_id );
|
||||
|
||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
|
||||
$request->set_param( 'post', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
|
||||
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_comment_invalid_post_id', $response, 403 );
|
||||
}
|
||||
|
||||
public function test_update_comment_invalid_permission() {
|
||||
add_filter( 'rest_allow_anonymous_comments', '__return_true' );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user