Changeset 39196
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
r39179 r39196 432 432 433 433 /* 434 * Do not allow a comment to be created with an empty string for434 * Do not allow a comment to be created with missing or empty 435 435 * comment_content. See wp_handle_comment_submission(). 436 436 */ 437 if ( '' === $prepared_comment['comment_content']) {437 if ( empty( $prepared_comment['comment_content'] ) ) { 438 438 return new WP_Error( 'rest_comment_content_invalid', __( 'Comment content is invalid.' ), array( 'status' => 400 ) ); 439 439 } … … 635 635 if ( is_wp_error( $prepared_args ) ) { 636 636 return $prepared_args; 637 } 638 639 if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) { 640 return new WP_Error( 'rest_comment_content_invalid', __( 'Comment content is invalid.' ), array( 'status' => 400 ) ); 637 641 } 638 642 … … 1063 1067 list( $prepared_comment['comment_date'], $prepared_comment['comment_date_gmt'] ) = $date_data; 1064 1068 } 1065 }1066 1067 // Require 'comment_content' unless only the 'comment_status' is being updated.1068 if ( ! empty( $prepared_comment ) && ! isset( $prepared_comment['comment_content'] ) ) {1069 return new WP_Error( 'rest_comment_content_required', __( 'Missing comment content.' ), array( 'status' => 400 ) );1070 1069 } 1071 1070 -
trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php
r39158 r39196 930 930 } 931 931 932 public function test_create_item_invalid_ blank_content() {932 public function test_create_item_invalid_no_content() { 933 933 wp_set_current_user( 0 ); 934 934 … … 938 938 'author_email' => 'lovejoy@example.com', 939 939 'author_url' => 'http://timothylovejoy.jr', 940 'content' => '', 941 ); 942 943 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 944 $request->add_header( 'content-type', 'application/json' ); 945 $request->set_body( wp_json_encode( $params ) ); 946 940 ); 941 942 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 943 $request->add_header( 'content-type', 'application/json' ); 944 $request->set_body( wp_json_encode( $params ) ); 945 946 $response = $this->server->dispatch( $request ); 947 $this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 ); 948 949 $params['content'] = ''; 950 $request->set_body( wp_json_encode( $params ) ); 947 951 $response = $this->server->dispatch( $request ); 948 952 $this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 ); … … 1617 1621 $this->assertEquals( mysql_to_rfc3339( $updated->comment_date ), $comment['date'] ); 1618 1622 $this->assertEquals( '2014-11-07T10:14:25', $comment['date'] ); 1623 } 1624 1625 public function test_update_item_no_content() { 1626 $post_id = $this->factory->post->create(); 1627 1628 wp_set_current_user( self::$admin_id ); 1629 1630 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 1631 $request->set_param( 'author_email', 'another@email.com' ); 1632 1633 // Sending a request without content is fine. 1634 $response = $this->server->dispatch( $request ); 1635 $this->assertEquals( 200, $response->get_status() ); 1636 1637 // Sending a request with empty comment is not fine. 1638 $request->set_param( 'author_email', 'yetanother@email.com' ); 1639 $request->set_param( 'content', '' ); 1640 $response = $this->server->dispatch( $request ); 1641 $this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 ); 1619 1642 } 1620 1643
Note: See TracChangeset
for help on using the changeset viewer.