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

Props @jnylen0.

Merges [39375] to the 4.7 branch.
Fixes #38991 for 4.7.


git-svn-id: https://develop.svn.wordpress.org/branches/4.7@39408 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Rachel Baker 2016-12-01 03:42:14 +00:00
parent 25830c6798
commit 5a55a6b747
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 );
}