mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-04 20:54:29 +00:00
REST API: Allow updating a comment without the content present.
For all resources in the REST API, sending partial updates is supported. This fixes needing to _always_ specify comment content. Props jnylen. Fixes #38720. git-svn-id: https://develop.svn.wordpress.org/trunk@39196 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -929,7 +929,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
|
||||
$this->assertArrayHasKey( 'author_email', $data['data']['params'] );
|
||||
}
|
||||
|
||||
public function test_create_item_invalid_blank_content() {
|
||||
public function test_create_item_invalid_no_content() {
|
||||
wp_set_current_user( 0 );
|
||||
|
||||
$params = array(
|
||||
@@ -937,7 +937,6 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
|
||||
'author_name' => 'Reverend Lovejoy',
|
||||
'author_email' => 'lovejoy@example.com',
|
||||
'author_url' => 'http://timothylovejoy.jr',
|
||||
'content' => '',
|
||||
);
|
||||
|
||||
$request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
|
||||
@@ -946,6 +945,11 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
|
||||
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 );
|
||||
|
||||
$params['content'] = '';
|
||||
$request->set_body( wp_json_encode( $params ) );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 );
|
||||
}
|
||||
|
||||
public function test_create_item_invalid_date() {
|
||||
@@ -1618,6 +1622,25 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
|
||||
$this->assertEquals( '2014-11-07T10:14:25', $comment['date'] );
|
||||
}
|
||||
|
||||
public function test_update_item_no_content() {
|
||||
$post_id = $this->factory->post->create();
|
||||
|
||||
wp_set_current_user( self::$admin_id );
|
||||
|
||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
|
||||
$request->set_param( 'author_email', 'another@email.com' );
|
||||
|
||||
// Sending a request without content is fine.
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
|
||||
// Sending a request with empty comment is not fine.
|
||||
$request->set_param( 'author_email', 'yetanother@email.com' );
|
||||
$request->set_param( 'content', '' );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 );
|
||||
}
|
||||
|
||||
public function test_update_comment_status() {
|
||||
wp_set_current_user( self::$admin_id );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user