Ticket #39010: 39010.diff
File 39010.diff, 2.3 KB (added by , 8 years ago) |
---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index b07ced4..45e00c0 100644
a b class WP_REST_Comments_Controller extends WP_REST_Controller { 392 392 * response. 393 393 */ 394 394 $allow_anonymous = apply_filters( 'rest_allow_anonymous_comments', false, $request ); 395 if ( false ===$allow_anonymous ) {395 if ( ! $allow_anonymous ) { 396 396 return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) ); 397 397 } 398 398 } -
tests/phpunit/tests/rest-api/rest-comments-controller.php
diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index 1daa35e..6705970 100644
a b class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 1737 1737 $this->assertEquals( 400, $response->get_status() ); 1738 1738 } 1739 1739 1740 public function anonymous_comments_callback_null() { 1741 // I'm a plugin developer who forgot to include a return value for some 1742 // code path in my 'rest_allow_anonymous_comments' filter. 1743 } 1744 1745 public function test_allow_anonymous_comments_null() { 1746 add_filter( 'rest_allow_anonymous_comments', array( $this, 'anonymous_comments_callback_null' ), 10, 2 ); 1747 1748 $params = array( 1749 'post' => self::$post_id, 1750 'author_name' => 'Comic Book Guy', 1751 'author_email' => 'cbg@androidsdungeon.com', 1752 'author_url' => 'http://androidsdungeon.com', 1753 'content' => 'Worst Comment Ever!', 1754 ); 1755 1756 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1757 $request->add_header( 'content-type', 'application/json' ); 1758 $request->set_body( wp_json_encode( $params ) ); 1759 1760 $response = $this->server->dispatch( $request ); 1761 1762 remove_filter( 'rest_allow_anonymous_comments', array( $this, 'anonymous_comments_callback_null' ), 10, 2 ); 1763 1764 $this->assertErrorResponse( 'rest_comment_login_required', $response, 401 ); 1765 } 1766 1740 1767 /** 1741 1768 * @ticket 38477 1742 1769 */