- Timestamp:
- 11/23/2016 04:14:08 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php
r39337 r39349 147 147 'parent', 148 148 'parent_exclude', 149 'password', 149 150 'per_page', 150 151 'post', … … 166 167 // We created 6 comments in this method, plus self::$approved_id. 167 168 $this->assertCount( 7, $comments ); 169 } 170 171 /** 172 * @ticket 38692 173 */ 174 public function test_get_items_with_password() { 175 wp_set_current_user( 0 ); 176 177 $args = array( 178 'comment_approved' => 1, 179 'comment_post_ID' => self::$password_id, 180 ); 181 $password_comment = $this->factory->comment->create( $args ); 182 183 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 184 $request->set_param( 'password', 'toomanysecrets' ); 185 $request->set_param( 'post', self::$password_id ); 186 187 $response = $this->server->dispatch( $request ); 188 $this->assertEquals( 200, $response->get_status() ); 189 190 $collection_data = $response->get_data(); 191 $this->assertTrue( in_array( $password_comment, wp_list_pluck( $collection_data, 'id' ), true ) ); 192 } 193 194 /** 195 * @ticket 38692 196 */ 197 public function test_get_items_with_password_without_post() { 198 wp_set_current_user( 0 ); 199 $args = array( 200 'comment_approved' => 1, 201 'comment_post_ID' => self::$password_id, 202 ); 203 $password_comment = $this->factory->comment->create( $args ); 204 205 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 206 $request->set_param( 'password', 'toomanysecrets' ); 207 208 $response = $this->server->dispatch( $request ); 209 $this->assertEquals( 200, $response->get_status() ); 210 211 $collection_data = $response->get_data(); 212 $this->assertFalse( in_array( $password_comment, wp_list_pluck( $collection_data, 'id' ), true ) ); 213 } 214 215 /** 216 * @ticket 38692 217 */ 218 public function test_get_items_with_password_with_multiple_post() { 219 wp_set_current_user( 0 ); 220 $args = array( 221 'comment_approved' => 1, 222 'comment_post_ID' => self::$password_id, 223 ); 224 $password_comment = $this->factory->comment->create( $args ); 225 226 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 227 $request->set_param( 'password', 'toomanysecrets' ); 228 $request->set_param( 'post', array( self::$password_id, self::$post_id ) ); 229 230 $response = $this->server->dispatch( $request ); 231 $this->assertErrorResponse( 'rest_cannot_read_post', $response, 401 ); 168 232 } 169 233 … … 854 918 } 855 919 920 /** 921 * @ticket 38692 922 */ 923 public function test_get_comment_with_password_with_valid_password() { 924 wp_set_current_user( self::$subscriber_id ); 925 926 $args = array( 927 'comment_approved' => 1, 928 'comment_post_ID' => self::$password_id, 929 ); 930 $password_comment = $this->factory->comment->create( $args ); 931 932 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $password_comment ) ); 933 $request->set_param( 'password', 'toomanysecrets' ); 934 935 $response = $this->server->dispatch( $request ); 936 $this->assertEquals( 200, $response->get_status() ); 937 } 938 856 939 public function test_create_item() { 857 940 wp_set_current_user( self::$admin_id ); … … 1726 1809 1727 1810 $this->assertErrorResponse( 'comment_content_column_length', $response, 400 ); 1811 } 1812 1813 public function test_create_comment_without_password() { 1814 wp_set_current_user( self::$subscriber_id ); 1815 1816 $params = array( 1817 'post' => self::$password_id, 1818 'author_name' => 'Bleeding Gums Murphy', 1819 'author_email' => 'murphy@gingivitis.com', 1820 'author_url' => 'http://jazz.gingivitis.com', 1821 'content' => 'This isn\'t a saxophone. It\'s an umbrella.', 1822 ); 1823 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1824 1825 $request->add_header( 'content-type', 'application/json' ); 1826 $request->set_body( wp_json_encode( $params ) ); 1827 $response = $this->server->dispatch( $request ); 1828 1829 $this->assertErrorResponse( 'rest_cannot_read_post', $response, 403 ); 1830 } 1831 1832 public function test_create_comment_with_password() { 1833 add_filter( 'rest_allow_anonymous_comments', '__return_true' ); 1834 1835 $params = array( 1836 'post' => self::$password_id, 1837 'author_name' => 'Bleeding Gums Murphy', 1838 'author_email' => 'murphy@gingivitis.com', 1839 'author_url' => 'http://jazz.gingivitis.com', 1840 'content' => 'This isn\'t a saxophone. It\'s an umbrella.', 1841 'password' => 'toomanysecrets', 1842 ); 1843 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1844 1845 $request->add_header( 'content-type', 'application/json' ); 1846 $request->set_body( wp_json_encode( $params ) ); 1847 $response = $this->server->dispatch( $request ); 1848 $this->assertEquals( 201, $response->get_status() ); 1728 1849 } 1729 1850
Note: See TracChangeset
for help on using the changeset viewer.