- Timestamp:
- 11/03/2016 02:17:39 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php
r39101 r39105 301 301 $this->assertEquals( 2, count( $data ) ); 302 302 $this->assertEquals( $id3, $data[0]['id'] ); 303 // Orderby=>invalid should fail. 304 $request->set_param( 'orderby', 'invalid' ); 305 $response = $this->server->dispatch( $request ); 306 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 307 // fails on invalid id. 308 $request->set_param( 'orderby', array( 'include' ) ); 309 $request->set_param( 'include', array( 'invalid' ) ); 310 $response = $this->server->dispatch( $request ); 311 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 303 312 } 304 313 … … 321 330 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 322 331 $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 332 333 // fails on invalid id. 334 $request->set_param( 'exclude', array( 'invalid' ) ); 335 $response = $this->server->dispatch( $request ); 336 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 323 337 } 324 338 … … 344 358 $response = $this->server->dispatch( $request ); 345 359 $this->assertCount( 2, $response->get_data() ); 360 // 'offset' with invalid value errors. 361 $request->set_param( 'offset', 'moreplease' ); 362 $response = $this->server->dispatch( $request ); 363 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 346 364 } 347 365 … … 365 383 $data = $response->get_data(); 366 384 $this->assertEquals( self::$approved_id, $data[0]['id'] ); 385 // order=>asc,id should fail 386 $request->set_param( 'order', 'asc,id' ); 387 $response = $this->server->dispatch( $request ); 388 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 367 389 } 368 390 … … 403 425 $comments = $response->get_data(); 404 426 $this->assertCount( 2, $comments ); 427 // Invalid author param errors 428 $request->set_param( 'author', 'skippy' ); 429 $response = $this->server->dispatch( $request ); 430 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 405 431 // Unavailable to unauthenticated; defaults to error 406 432 wp_set_current_user( 0 ); 433 $request->set_param( 'author', array( self::$author_id, self::$subscriber_id ) ); 407 434 $response = $this->server->dispatch( $request ); 408 435 $this->assertErrorResponse( 'rest_forbidden_param', $response, 401 ); … … 442 469 $comments = $response->get_data(); 443 470 $this->assertCount( 2, $comments ); 471 // 'author_exclude' for both invalid author 472 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 473 $request->set_param( 'author_exclude', 'skippy' ); 474 $response = $this->server->dispatch( $request ); 475 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 444 476 // Unavailable to unauthenticated; defaults to error 445 477 wp_set_current_user( 0 ); 478 $request->set_param( 'author_exclude', array( self::$author_id, self::$subscriber_id ) ); 446 479 $response = $this->server->dispatch( $request ); 447 480 $this->assertErrorResponse( 'rest_forbidden_param', $response, 401 ); … … 471 504 $response = $this->server->dispatch( $request ); 472 505 $this->assertCount( 2, $response->get_data() ); 506 // Invalid parent should error 507 $request->set_param( 'parent', 'invalid' ); 508 $response = $this->server->dispatch( $request ); 509 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 473 510 } 474 511 … … 496 533 $response = $this->server->dispatch( $request ); 497 534 $this->assertCount( 3, $response->get_data() ); 535 // Invalid parent id should error 536 $request->set_param( 'parent_exclude', 'invalid' ); 537 $response = $this->server->dispatch( $request ); 538 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 498 539 } 499 540 … … 958 999 } 959 1000 1001 public function test_create_comment_invalid_email() { 1002 $post_id = $this->factory->post->create(); 1003 wp_set_current_user( self::$admin_id ); 1004 1005 $params = array( 1006 'post' => $post_id, 1007 'author' => self::$admin_id, 1008 'author_name' => 'Comic Book Guy', 1009 'author_email' => 'hello:)', 1010 'author_url' => 'http://androidsdungeon.com', 1011 'content' => 'Worst Comment Ever!', 1012 'date' => '2014-11-07T10:14:25', 1013 ); 1014 1015 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1016 $request->add_header( 'content-type', 'application/json' ); 1017 $request->set_body( wp_json_encode( $params ) ); 1018 1019 $response = $this->server->dispatch( $request ); 1020 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1021 } 1022 960 1023 public function test_create_item_current_user() { 961 1024 $user_id = $this->factory->user->create( array( … … 1056 1119 1057 1120 $this->assertErrorResponse( 'rest_comment_invalid_karma', $response, 403 ); 1121 } 1122 1123 public function test_create_comment_invalid_post() { 1124 wp_set_current_user( self::$subscriber_id ); 1125 1126 $params = array( 1127 'post' => 'some-slug', 1128 'author_name' => 'Homer Jay Simpson', 1129 'author_email' => 'chunkylover53@aol.com', 1130 'author_url' => 'http://compuglobalhypermeganet.com', 1131 'content' => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.', 1132 'author' => self::$subscriber_id, 1133 ); 1134 1135 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1136 $request->add_header( 'content-type', 'application/json' ); 1137 $request->set_body( wp_json_encode( $params ) ); 1138 $response = $this->server->dispatch( $request ); 1139 1140 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1141 } 1142 1143 public function test_create_comment_karma_invalid_value() { 1144 wp_set_current_user( self::$subscriber_id ); 1145 1146 $params = array( 1147 'post' => self::$post_id, 1148 'author_name' => 'Homer Jay Simpson', 1149 'author_email' => 'chunkylover53@aol.com', 1150 'author_url' => 'http://compuglobalhypermeganet.com', 1151 'content' => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.', 1152 'author' => self::$subscriber_id, 1153 'karma' => 'themostkarmaever', 1154 ); 1155 1156 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1157 $request->add_header( 'content-type', 'application/json' ); 1158 $request->set_body( wp_json_encode( $params ) ); 1159 $response = $this->server->dispatch( $request ); 1160 1161 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1058 1162 } 1059 1163 … … 1894 1998 $this->assertArrayHasKey( 'status', $properties ); 1895 1999 $this->assertArrayHasKey( 'type', $properties ); 2000 2001 $this->assertEquals( '127.0.0.1', $properties['author_ip']['default'] ); 2002 $this->assertEquals( 0, $properties['parent']['default'] ); 2003 $this->assertEquals( 0, $properties['post']['default'] ); 1896 2004 } 1897 2005
Note: See TracChangeset
for help on using the changeset viewer.