REST API: Add test for creating a comment with an invalid post ID.

#38816 fixed creating a comment with an invalid post ID (this should not be
allowed), but we need a test for this.

Fixes #38991.


git-svn-id: https://develop.svn.wordpress.org/trunk@39375 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
James Nylen 2016-11-30 16:21:38 +00:00
parent 60cc79e40b
commit 74efb754fd
1 changed files with 19 additions and 0 deletions

View File

@ -1505,7 +1505,26 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
$request->set_body( wp_json_encode( $params ) );
$response = $this->server->dispatch( $request );
$this->assertErrorResponse( 'rest_comment_invalid_post_id', $response, 403 );
}
public function test_create_comment_invalid_post_id() {
wp_set_current_user( self::$admin_id );
$params = array(
'author_name' => 'Homer Jay Simpson',
'author_email' => 'chunkylover53@aol.com',
'author_url' => 'http://compuglobalhypermeganet.com',
'content' => 'Here\s to alcohol: the cause of, and solution to, all of life\s problems.',
'status' => 'approved',
'post' => REST_TESTS_IMPOSSIBLY_HIGH_NUMBER,
);
$request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
$request->add_header( 'content-type', 'application/json' );
$request->set_body( wp_json_encode( $params ) );
$response = $this->server->dispatch( $request );
$this->assertErrorResponse( 'rest_comment_invalid_post_id', $response, 403 );
}