From 74efb754fd93ff2008f9c10ab2ca512572d4c160 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Wed, 30 Nov 2016 16:21:38 +0000 Subject: [PATCH] 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 --- .../rest-api/rest-comments-controller.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index 112a26c525..1daa35ea38 100644 --- a/tests/phpunit/tests/rest-api/rest-comments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php @@ -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 ); }