- Timestamp:
- 11/05/2019 08:41:12 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php
r46586 r46657 26 26 protected static $hold_id; 27 27 28 protected static $comment_ids = array(); 29 protected static $total_comments = 30; 30 protected static $per_page = 50; 31 28 32 protected $endpoint; 29 33 … … 111 115 ) 112 116 ); 117 118 // Set up comments for pagination tests. 119 for ( $i = 0; $i < self::$total_comments - 1; $i++ ) { 120 $comment_ids[] = $factory->comment->create( 121 array( 122 'comment_content' => "Comment {$i}", 123 'comment_post_ID' => self::$post_id, 124 ) 125 ); 126 } 113 127 } 114 128 … … 130 144 wp_delete_post( self::$approved_id, true ); 131 145 wp_delete_post( self::$hold_id, true ); 146 147 // Remove comments for pagination tests. 148 foreach ( self::$comment_ids as $comment_id ) { 149 wp_delete_comment( $comment_id, true ); 150 } 132 151 } 133 152 … … 198 217 199 218 public function test_get_items() { 200 $this->factory->comment->create_post_comments( self::$post_id, 6 );201 202 219 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 220 $request->set_param( 'per_page', self::$per_page ); 203 221 204 222 $response = rest_get_server()->dispatch( $request ); … … 206 224 207 225 $comments = $response->get_data(); 208 // We created 6 comments in this method, plus self::$approved_id. 209 $this->assertCount( 7, $comments ); 226 $this->assertCount( self::$total_comments, $comments ); 210 227 } 211 228 … … 216 233 wp_set_current_user( 0 ); 217 234 218 $args 235 $args = array( 219 236 'comment_approved' => 1, 220 237 'comment_post_ID' => self::$password_id, 221 238 ); 239 222 240 $password_comment = $this->factory->comment->create( $args ); 223 241 … … 238 256 public function test_get_items_with_password_without_post() { 239 257 wp_set_current_user( 0 ); 240 $args = array( 258 259 $args = array( 241 260 'comment_approved' => 1, 242 261 'comment_post_ID' => self::$password_id, 243 262 ); 263 244 264 $password_comment = $this->factory->comment->create( $args ); 245 265 … … 259 279 public function test_get_items_with_password_with_multiple_post() { 260 280 wp_set_current_user( 0 ); 261 $args = array( 281 282 $args = array( 262 283 'comment_approved' => 1, 263 284 'comment_post_ID' => self::$password_id, 264 285 ); 286 265 287 $password_comment = $this->factory->comment->create( $args ); 266 288 … … 276 298 wp_set_current_user( 0 ); 277 299 278 $args 300 $args = array( 279 301 'comment_approved' => 1, 280 302 'comment_post_ID' => self::$password_id, 281 303 ); 304 282 305 $password_comment = $this->factory->comment->create( $args ); 283 306 … … 294 317 wp_set_current_user( self::$admin_id ); 295 318 296 $args 319 $args = array( 297 320 'comment_approved' => 1, 298 321 'comment_post_ID' => self::$password_id, 299 322 ); 323 300 324 $password_comment = $this->factory->comment->create( $args ); 301 325 … … 312 336 wp_set_current_user( 0 ); 313 337 314 $args 338 $args = array( 315 339 'comment_approved' => 1, 316 340 'comment_post_ID' => self::$private_id, 317 341 ); 342 318 343 $private_comment = $this->factory->comment->create( $args ); 319 344 … … 330 355 wp_set_current_user( self::$admin_id ); 331 356 332 $args 357 $args = array( 333 358 'comment_approved' => 1, 334 359 'comment_post_ID' => self::$private_id, 335 360 ); 361 336 362 $private_comment = $this->factory->comment->create( $args ); 337 363 … … 389 415 public function test_get_items_no_permission_for_context() { 390 416 wp_set_current_user( 0 ); 417 391 418 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 392 419 $request->set_param( 'context', 'edit' ); … … 396 423 397 424 public function test_get_items_no_post() { 425 wp_set_current_user( self::$admin_id ); 426 398 427 $this->factory->comment->create_post_comments( 0, 2 ); 399 wp_set_current_user( self::$admin_id ); 428 400 429 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 401 430 $request->set_param( 'post', 0 ); … … 408 437 public function test_get_items_no_permission_for_no_post() { 409 438 wp_set_current_user( 0 ); 439 410 440 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 411 441 $request->set_param( 'post', 0 ); … … 416 446 public function test_get_items_edit_context() { 417 447 wp_set_current_user( self::$admin_id ); 448 418 449 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 419 450 $request->set_param( 'context', 'edit' ); … … 442 473 public function test_get_items_include_query() { 443 474 wp_set_current_user( self::$admin_id ); 475 444 476 $args = array( 445 477 'comment_approved' => 1, 446 478 'comment_post_ID' => self::$post_id, 447 479 ); 448 $id1 = $this->factory->comment->create( $args ); 449 $this->factory->comment->create( $args ); 450 $id3 = $this->factory->comment->create( $args ); 480 481 $id1 = $this->factory->comment->create( $args ); 482 $id2 = $this->factory->comment->create( $args ); 483 451 484 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 452 // Order=>asc 485 486 // 'order' => 'asc'. 453 487 $request->set_param( 'order', 'asc' ); 454 $request->set_param( 'include', array( $id 3, $id1 ) );488 $request->set_param( 'include', array( $id2, $id1 ) ); 455 489 $response = rest_get_server()->dispatch( $request ); 456 490 $data = $response->get_data(); 457 491 $this->assertEquals( 2, count( $data ) ); 458 492 $this->assertEquals( $id1, $data[0]['id'] ); 459 // Orderby=>include 493 494 // 'orderby' => 'include'. 460 495 $request->set_param( 'orderby', 'include' ); 461 496 $response = rest_get_server()->dispatch( $request ); 462 497 $data = $response->get_data(); 463 498 $this->assertEquals( 2, count( $data ) ); 464 $this->assertEquals( $id3, $data[0]['id'] ); 465 // Orderby=>invalid should fail. 499 $this->assertEquals( $id2, $data[0]['id'] ); 500 501 // Invalid 'orderby' should error. 466 502 $request->set_param( 'orderby', 'invalid' ); 467 503 $response = rest_get_server()->dispatch( $request ); 468 504 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 469 // fails on invalid id. 505 506 // Invalid 'include' should error. 470 507 $request->set_param( 'orderby', array( 'include' ) ); 471 508 $request->set_param( 'include', array( 'invalid' ) ); … … 476 513 public function test_get_items_exclude_query() { 477 514 wp_set_current_user( self::$admin_id ); 478 $args = array( 479 'comment_approved' => 1, 480 'comment_post_ID' => self::$post_id, 481 ); 482 $id1 = $this->factory->comment->create( $args ); 483 $id2 = $this->factory->comment->create( $args ); 484 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 485 $response = rest_get_server()->dispatch( $request ); 486 $data = $response->get_data(); 487 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 488 $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 489 $request->set_param( 'exclude', array( $id2 ) ); 490 $response = rest_get_server()->dispatch( $request ); 491 $data = $response->get_data(); 492 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 493 $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 494 495 // fails on invalid id. 496 $request->set_param( 'exclude', array( 'invalid' ) ); 497 $response = rest_get_server()->dispatch( $request ); 498 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 499 } 500 501 public function test_get_items_offset_query() { 502 wp_set_current_user( self::$admin_id ); 515 503 516 $args = array( 504 517 'comment_approved' => 1, 505 518 'comment_post_ID' => self::$post_id, 506 519 ); 507 $this->factory->comment->create( $args ); 508 $this->factory->comment->create( $args ); 509 $this->factory->comment->create( $args ); 520 521 $id1 = $this->factory->comment->create( $args ); 522 $id2 = $this->factory->comment->create( $args ); 523 524 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 525 $response = rest_get_server()->dispatch( $request ); 526 $data = $response->get_data(); 527 $ids = wp_list_pluck( $data, 'id' ); 528 $this->assertTrue( in_array( $id1, $ids, true ) ); 529 $this->assertTrue( in_array( $id2, $ids, true ) ); 530 531 $request->set_param( 'exclude', array( $id2 ) ); 532 $response = rest_get_server()->dispatch( $request ); 533 $data = $response->get_data(); 534 $ids = wp_list_pluck( $data, 'id' ); 535 $this->assertTrue( in_array( $id1, $ids, true ) ); 536 $this->assertFalse( in_array( $id2, $ids, true ) ); 537 538 // Invalid 'exclude' should error. 539 $request->set_param( 'exclude', array( 'invalid' ) ); 540 $response = rest_get_server()->dispatch( $request ); 541 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 542 } 543 544 public function test_get_items_offset_query() { 545 wp_set_current_user( self::$admin_id ); 546 510 547 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 548 $request->set_param( 'per_page', self::$per_page ); 511 549 $request->set_param( 'offset', 1 ); 512 550 $response = rest_get_server()->dispatch( $request ); 513 $this->assertCount( 3, $response->get_data() ); 514 // 'offset' works with 'per_page' 551 $this->assertCount( self::$total_comments - 1, $response->get_data() ); 552 553 // 'offset' works with 'per_page'. 515 554 $request->set_param( 'per_page', 2 ); 516 555 $response = rest_get_server()->dispatch( $request ); 517 556 $this->assertCount( 2, $response->get_data() ); 518 // 'offset' takes priority over 'page' 557 558 // 'offset' takes priority over 'page'. 519 559 $request->set_param( 'page', 3 ); 520 560 $response = rest_get_server()->dispatch( $request ); 521 561 $this->assertCount( 2, $response->get_data() ); 522 // 'offset' with invalid value errors. 562 563 // Invalid 'offset' should error. 523 564 $request->set_param( 'offset', 'moreplease' ); 524 565 $response = rest_get_server()->dispatch( $request ); … … 528 569 public function test_get_items_order_query() { 529 570 wp_set_current_user( self::$admin_id ); 571 530 572 $args = array( 531 573 'comment_approved' => 1, 532 574 'comment_post_ID' => self::$post_id, 533 575 ); 534 $this->factory->comment->create( $args ); 535 $ this->factory->comment->create( $args );536 $id3 = $this->factory->comment->create( $args ); 576 577 $id = $this->factory->comment->create( $args ); 578 537 579 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 538 // order defaults to 'desc' 580 581 // Order defaults to 'desc'. 539 582 $response = rest_get_server()->dispatch( $request ); 540 583 $data = $response->get_data(); 541 $this->assertEquals( $id3, $data[0]['id'] ); 542 // order=>asc 584 $this->assertEquals( $id, $data[0]['id'] ); 585 586 // 'order' => 'asc'. 543 587 $request->set_param( 'order', 'asc' ); 544 588 $response = rest_get_server()->dispatch( $request ); 545 589 $data = $response->get_data(); 546 590 $this->assertEquals( self::$approved_id, $data[0]['id'] ); 547 // order=>asc,id should fail 591 592 // 'order' => 'asc,id' should error. 548 593 $request->set_param( 'order', 'asc,id' ); 549 594 $response = rest_get_server()->dispatch( $request ); … … 553 598 public function test_get_items_private_post_no_permissions() { 554 599 wp_set_current_user( 0 ); 600 555 601 $post_id = $this->factory->post->create( array( 'post_status' => 'private' ) ); 602 556 603 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 557 604 $request->set_param( 'post', $post_id ); … … 561 608 562 609 public function test_get_items_author_arg() { 563 // Authorized 564 wp_set_current_user( self::$admin_id ); 610 // Authorized. 611 wp_set_current_user( self::$admin_id ); 612 565 613 $args = array( 566 614 'comment_approved' => 1, … … 568 616 'user_id' => self::$author_id, 569 617 ); 618 570 619 $this->factory->comment->create( $args ); 571 620 $args['user_id'] = self::$subscriber_id; … … 574 623 $this->factory->comment->create( $args ); 575 624 576 // 'author' limits result to 1 of 3625 // Limit to comment author. 577 626 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 578 627 $request->set_param( 'author', self::$author_id ); … … 581 630 $comments = $response->get_data(); 582 631 $this->assertCount( 1, $comments ); 583 // Multiple authors are supported 632 633 // Multiple authors are supported. 584 634 $request->set_param( 'author', array( self::$author_id, self::$subscriber_id ) ); 585 635 $response = rest_get_server()->dispatch( $request ); … … 587 637 $comments = $response->get_data(); 588 638 $this->assertCount( 2, $comments ); 589 // Invalid author param errors 639 640 // Invalid 'author' should error. 590 641 $request->set_param( 'author', 'skippy' ); 591 642 $response = rest_get_server()->dispatch( $request ); 592 643 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 593 // Unavailable to unauthenticated; defaults to error 644 645 // Unavailable to unauthenticated; defaults to error. 594 646 wp_set_current_user( 0 ); 595 647 $request->set_param( 'author', array( self::$author_id, self::$subscriber_id ) ); … … 599 651 600 652 public function test_get_items_author_exclude_arg() { 601 // Authorized 602 wp_set_current_user( self::$admin_id ); 653 // Authorized. 654 wp_set_current_user( self::$admin_id ); 655 603 656 $args = array( 604 657 'comment_approved' => 1, … … 606 659 'user_id' => self::$author_id, 607 660 ); 661 608 662 $this->factory->comment->create( $args ); 609 663 $args['user_id'] = self::$subscriber_id; … … 612 666 $this->factory->comment->create( $args ); 613 667 614 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 668 $total_comments = self::$total_comments + 3; 669 670 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 671 $request->set_param( 'per_page', self::$per_page ); 615 672 $response = rest_get_server()->dispatch( $request ); 616 673 $comments = $response->get_data(); 617 $this->assertCount( 4, $comments );618 619 // 'author_exclude' limits result to 3 of 4674 $this->assertCount( $total_comments, $comments ); 675 676 // Exclude comment author. 620 677 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 678 $request->set_param( 'per_page', self::$per_page ); 621 679 $request->set_param( 'author_exclude', self::$author_id ); 622 680 $response = rest_get_server()->dispatch( $request ); 623 681 $this->assertEquals( 200, $response->get_status() ); 624 682 $comments = $response->get_data(); 625 $this->assertCount( 3, $comments ); 626 // 'author_exclude' for both comment authors (2 of 4) 683 $this->assertCount( $total_comments - 1, $comments ); 684 685 // Exclude both comment authors. 627 686 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 687 $request->set_param( 'per_page', self::$per_page ); 628 688 $request->set_param( 'author_exclude', array( self::$author_id, self::$subscriber_id ) ); 629 689 $response = rest_get_server()->dispatch( $request ); 630 690 $this->assertEquals( 200, $response->get_status() ); 631 691 $comments = $response->get_data(); 632 $this->assertCount( 2, $comments ); 633 // 'author_exclude' for both invalid author 692 $this->assertCount( $total_comments - 2, $comments ); 693 694 // 'author_exclude' for invalid author. 634 695 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 635 696 $request->set_param( 'author_exclude', 'skippy' ); 636 697 $response = rest_get_server()->dispatch( $request ); 637 698 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 638 // Unavailable to unauthenticated; defaults to error 699 700 // Unavailable to unauthenticated; defaults to error. 639 701 wp_set_current_user( 0 ); 640 702 $request->set_param( 'author_exclude', array( self::$author_id, self::$subscriber_id ) ); … … 654 716 $args['comment_parent'] = $parent_id2; 655 717 $this->factory->comment->create( $args ); 656 // All comments in the database 657 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 658 $response = rest_get_server()->dispatch( $request ); 659 $this->assertCount( 5, $response->get_data() ); 660 // Limit to the parent 718 719 $total_comments = self::$total_comments + 4; 720 721 // All comments in the database. 722 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 723 $request->set_param( 'per_page', self::$per_page ); 724 $response = rest_get_server()->dispatch( $request ); 725 $this->assertCount( $total_comments, $response->get_data() ); 726 727 // Limit to the parent. 661 728 $request->set_param( 'parent', $parent_id ); 662 729 $response = rest_get_server()->dispatch( $request ); 663 730 $this->assertCount( 1, $response->get_data() ); 664 // Limit to two parents 731 732 // Limit to two parents. 665 733 $request->set_param( 'parent', array( $parent_id, $parent_id2 ) ); 666 734 $response = rest_get_server()->dispatch( $request ); 667 735 $this->assertCount( 2, $response->get_data() ); 668 // Invalid parent should error 736 737 // Invalid 'parent' should error. 669 738 $request->set_param( 'parent', 'invalid' ); 670 739 $response = rest_get_server()->dispatch( $request ); … … 683 752 $args['comment_parent'] = $parent_id2; 684 753 $this->factory->comment->create( $args ); 685 // All comments in the database 686 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 687 $response = rest_get_server()->dispatch( $request ); 688 $this->assertCount( 5, $response->get_data() ); 689 // Exclude this particular parent 754 755 $total_comments = self::$total_comments + 4; 756 757 // All comments in the database. 758 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 759 $request->set_param( 'per_page', self::$per_page ); 760 $response = rest_get_server()->dispatch( $request ); 761 $this->assertCount( $total_comments, $response->get_data() ); 762 763 // Exclude this particular parent. 690 764 $request->set_param( 'parent_exclude', $parent_id ); 691 765 $response = rest_get_server()->dispatch( $request ); 692 $this->assertCount( 4, $response->get_data() ); 693 // Exclude both comment parents 766 $this->assertCount( $total_comments - 1, $response->get_data() ); 767 768 // Exclude both comment parents. 694 769 $request->set_param( 'parent_exclude', array( $parent_id, $parent_id2 ) ); 695 770 $response = rest_get_server()->dispatch( $request ); 696 $this->assertCount( 3, $response->get_data() ); 697 // Invalid parent id should error 771 $this->assertCount( $total_comments - 2, $response->get_data() ); 772 773 // Invalid 'parent_exclude' should error. 698 774 $request->set_param( 'parent_exclude', 'invalid' ); 699 775 $response = rest_get_server()->dispatch( $request ); … … 703 779 public function test_get_items_search_query() { 704 780 wp_set_current_user( self::$admin_id ); 705 $args = array( 781 782 $args = array( 706 783 'comment_approved' => 1, 707 784 'comment_post_ID' => self::$post_id, … … 709 786 'comment_author' => 'Homer J Simpson', 710 787 ); 711 $id1 = $this->factory->comment->create( $args ); 712 $args['comment_content'] = 'bar'; 713 $this->factory->comment->create( $args ); 714 $args['comment_content'] = 'burrito'; 715 $this->factory->comment->create( $args ); 716 // 3 comments, plus 1 created in construct 717 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 718 $response = rest_get_server()->dispatch( $request ); 719 $this->assertCount( 4, $response->get_data() ); 720 // One matching comments 788 789 $id = $this->factory->comment->create( $args ); 790 791 $total_comments = self::$total_comments + 1; 792 793 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 794 $request->set_param( 'per_page', self::$per_page ); 795 $response = rest_get_server()->dispatch( $request ); 796 $this->assertCount( $total_comments, $response->get_data() ); 797 798 // One matching comment. 721 799 $request->set_param( 'search', 'foo' ); 722 800 $response = rest_get_server()->dispatch( $request ); 723 801 $data = $response->get_data(); 724 802 $this->assertCount( 1, $data ); 725 $this->assertEquals( $id 1, $data[0]['id'] );803 $this->assertEquals( $id, $data[0]['id'] ); 726 804 } 727 805 728 806 public function test_get_comments_pagination_headers() { 729 wp_set_current_user( self::$admin_id ); 730 // Start of the index 731 for ( $i = 0; $i < 49; $i++ ) { 732 $this->factory->comment->create( 733 array( 734 'comment_content' => "Comment {$i}", 735 'comment_post_ID' => self::$post_id, 736 ) 737 ); 738 } 807 $total_comments = self::$total_comments; 808 $total_pages = (int) ceil( $total_comments / 10 ); 809 810 wp_set_current_user( self::$admin_id ); 811 812 // Start of the index. 739 813 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 740 814 $response = rest_get_server()->dispatch( $request ); 741 815 $headers = $response->get_headers(); 742 $this->assertEquals( 50, $headers['X-WP-Total'] );743 $this->assertEquals( 5, $headers['X-WP-TotalPages'] );816 $this->assertEquals( $total_comments, $headers['X-WP-Total'] ); 817 $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] ); 744 818 $next_link = add_query_arg( 745 819 array( … … 750 824 $this->assertFalse( stripos( $headers['Link'], 'rel="prev"' ) ); 751 825 $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] ); 752 // 3rd page 826 827 // 3rd page. 753 828 $this->factory->comment->create( 754 829 array( 755 'comment_content' => 'Comment 51',756 830 'comment_post_ID' => self::$post_id, 757 831 ) 758 832 ); 833 $total_comments++; 834 $total_pages++; 759 835 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 760 836 $request->set_param( 'page', 3 ); 761 837 $response = rest_get_server()->dispatch( $request ); 762 838 $headers = $response->get_headers(); 763 $this->assertEquals( 51, $headers['X-WP-Total'] );764 $this->assertEquals( 6, $headers['X-WP-TotalPages'] );839 $this->assertEquals( $total_comments, $headers['X-WP-Total'] ); 840 $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] ); 765 841 $prev_link = add_query_arg( 766 842 array( … … 777 853 ); 778 854 $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] ); 779 // Last page 855 856 // Last page. 780 857 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 781 $request->set_param( 'page', 6);858 $request->set_param( 'page', $total_pages ); 782 859 $response = rest_get_server()->dispatch( $request ); 783 860 $headers = $response->get_headers(); 784 $this->assertEquals( 51, $headers['X-WP-Total'] );785 $this->assertEquals( 6, $headers['X-WP-TotalPages'] );861 $this->assertEquals( $total_comments, $headers['X-WP-Total'] ); 862 $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] ); 786 863 $prev_link = add_query_arg( 787 864 array( 788 'page' => 5,865 'page' => $total_pages - 1, 789 866 ), 790 867 rest_url( '/wp/v2/comments' ) … … 792 869 $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] ); 793 870 $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) ); 794 // Out of bounds 871 872 // Out of bounds. 795 873 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 796 $request->set_param( 'page', 8);874 $request->set_param( 'page', 100 ); 797 875 $response = rest_get_server()->dispatch( $request ); 798 876 $headers = $response->get_headers(); 799 $this->assertEquals( 51, $headers['X-WP-Total'] );800 $this->assertEquals( 6, $headers['X-WP-TotalPages'] );877 $this->assertEquals( $total_comments, $headers['X-WP-Total'] ); 878 $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] ); 801 879 $prev_link = add_query_arg( 802 880 array( 803 'page' => 6,881 'page' => $total_pages, 804 882 ), 805 883 rest_url( '/wp/v2/comments' ) … … 858 936 public function test_prepare_item() { 859 937 wp_set_current_user( self::$admin_id ); 938 860 939 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 861 940 $request->set_query_params( … … 874 953 public function test_prepare_item_limit_fields() { 875 954 wp_set_current_user( self::$admin_id ); 955 876 956 $endpoint = new WP_REST_Comments_Controller; 877 957 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); … … 916 996 public function test_get_comment_invalid_context() { 917 997 wp_set_current_user( 0 ); 998 918 999 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', self::$approved_id ) ); 919 1000 $request->set_param( 'context', 'edit' ); … … 924 1005 public function test_get_comment_invalid_post_id() { 925 1006 wp_set_current_user( 0 ); 1007 926 1008 $comment_id = $this->factory->comment->create( 927 1009 array( … … 930 1012 ) 931 1013 ); 932 $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $comment_id ); 933 1014 1015 $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $comment_id ); 934 1016 $response = rest_get_server()->dispatch( $request ); 935 1017 $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 ); … … 938 1020 public function test_get_comment_invalid_post_id_as_admin() { 939 1021 wp_set_current_user( self::$admin_id ); 1022 940 1023 $comment_id = $this->factory->comment->create( 941 1024 array( … … 944 1027 ) 945 1028 ); 946 $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $comment_id ); 947 1029 1030 $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $comment_id ); 948 1031 $response = rest_get_server()->dispatch( $request ); 949 1032 $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 ); … … 953 1036 wp_set_current_user( 0 ); 954 1037 955 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) ); 956 1038 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) ); 957 1039 $response = rest_get_server()->dispatch( $request ); 958 1040 $this->assertErrorResponse( 'rest_cannot_read', $response, 401 ); … … 962 1044 wp_set_current_user( self::$admin_id ); 963 1045 964 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) ); 965 1046 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) ); 966 1047 $response = rest_get_server()->dispatch( $request ); 967 1048 $this->assertEquals( 200, $response->get_status() ); … … 1009 1090 public function test_get_comment_with_password_without_edit_post_permission() { 1010 1091 wp_set_current_user( self::$subscriber_id ); 1011 $args = array( 1092 1093 $args = array( 1012 1094 'comment_approved' => 1, 1013 1095 'comment_post_ID' => self::$password_id, 1014 1096 ); 1097 1015 1098 $password_comment = $this->factory->comment->create( $args ); 1016 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $password_comment ) ); 1017 $response = rest_get_server()->dispatch( $request ); 1099 1100 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $password_comment ) ); 1101 $response = rest_get_server()->dispatch( $request ); 1018 1102 $this->assertErrorResponse( 'rest_cannot_read', $response, 403 ); 1019 1103 } … … 1025 1109 wp_set_current_user( self::$subscriber_id ); 1026 1110 1027 $args 1111 $args = array( 1028 1112 'comment_approved' => 1, 1029 1113 'comment_post_ID' => self::$password_id, 1030 1114 ); 1115 1031 1116 $password_comment = $this->factory->comment->create( $args ); 1032 1117 … … 1114 1199 public function test_create_comment_date( $params, $results ) { 1115 1200 wp_set_current_user( self::$admin_id ); 1201 1116 1202 update_option( 'timezone_string', $params['timezone_string'] ); 1117 1203 … … 1234 1320 public function test_create_comment_missing_required_author_email() { 1235 1321 wp_set_current_user( self::$admin_id ); 1322 1236 1323 update_option( 'require_name_email', 1 ); 1237 1324 … … 1252 1339 public function test_create_comment_empty_required_author_email() { 1253 1340 wp_set_current_user( self::$admin_id ); 1341 1254 1342 update_option( 'require_name_email', 1 ); 1255 1343 … … 1343 1431 1344 1432 wp_set_current_user( self::$admin_id ); 1345 $params = array( 1433 1434 $params = array( 1346 1435 'post' => self::$post_id, 1347 1436 'author_name' => 'Comic Book Guy', … … 1352 1441 'date' => '2014-11-07T10:14:25', 1353 1442 ); 1443 1354 1444 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1355 1445 $request->add_header( 'content-type', 'application/json' ); … … 1365 1455 public function test_create_comment_without_type() { 1366 1456 $post_id = $this->factory->post->create(); 1457 1367 1458 wp_set_current_user( self::$admin_id ); 1368 1459 … … 1402 1493 public function test_create_comment_with_invalid_type() { 1403 1494 $post_id = $this->factory->post->create(); 1495 1404 1496 wp_set_current_user( self::$admin_id ); 1405 1497 … … 1425 1517 public function test_create_comment_invalid_email() { 1426 1518 $post_id = $this->factory->post->create(); 1519 1427 1520 wp_set_current_user( self::$admin_id ); 1428 1521 … … 1569 1662 public function test_create_comment_with_status_IP_and_user_agent() { 1570 1663 $post_id = $this->factory->post->create(); 1664 1571 1665 wp_set_current_user( self::$admin_id ); 1572 1666 … … 1663 1757 public function test_create_comment_author_ip_no_permission() { 1664 1758 wp_set_current_user( self::$subscriber_id ); 1665 $params = array( 1759 1760 $params = array( 1666 1761 'author_name' => 'Comic Book Guy', 1667 1762 'author_email' => 'cbg@androidsdungeon.com', … … 1671 1766 'status' => 'approved', 1672 1767 ); 1768 1673 1769 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1674 1770 $request->add_header( 'content-type', 'application/json' ); … … 1680 1776 public function test_create_comment_author_ip_defaults_to_remote_addr() { 1681 1777 wp_set_current_user( self::$admin_id ); 1778 1682 1779 $_SERVER['REMOTE_ADDR'] = '127.0.0.2'; 1683 $params = array( 1780 1781 $params = array( 1684 1782 'post' => self::$post_id, 1685 1783 'author_name' => 'Comic Book Guy', … … 1688 1786 'content' => 'Worst Comment Ever!', 1689 1787 ); 1690 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1788 1789 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1691 1790 $request->add_header( 'content-type', 'application/json' ); 1692 1791 $request->set_body( wp_json_encode( $params ) ); … … 1700 1799 wp_set_current_user( self::$admin_id ); 1701 1800 1702 $params 1801 $params = array( 1703 1802 'author_name' => 'Comic Book Guy', 1704 1803 'author_email' => 'cbg@androidsdungeon.com', … … 1707 1806 'status' => 'approved', 1708 1807 ); 1808 1709 1809 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1710 1810 $request->add_header( 'content-type', 'application/json' ); … … 1719 1819 wp_set_current_user( self::$subscriber_id ); 1720 1820 1721 $params 1821 $params = array( 1722 1822 'author_name' => 'Homer Jay Simpson', 1723 1823 'author_email' => 'chunkylover53@aol.com', … … 1726 1826 'author' => self::$subscriber_id, 1727 1827 ); 1828 1728 1829 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1729 1830 $request->add_header( 'content-type', 'application/json' ); … … 1757 1858 wp_set_current_user( self::$subscriber_id ); 1758 1859 1759 $params 1860 $params = array( 1760 1861 'post' => self::$draft_id, 1761 1862 'author_name' => 'Ishmael', … … 1765 1866 'author' => self::$subscriber_id, 1766 1867 ); 1767 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1768 $request ->add_header( 'content-type', 'application/json' );1769 $request-> set_body( wp_json_encode( $params ));1770 1771 $response = rest_get_server()->dispatch( $request ); 1772 1868 1869 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1870 $request->add_header( 'content-type', 'application/json' ); 1871 $request->set_body( wp_json_encode( $params ) ); 1872 1873 $response = rest_get_server()->dispatch( $request ); 1773 1874 $this->assertErrorResponse( 'rest_comment_draft_post', $response, 403 ); 1774 1875 } … … 1777 1878 wp_set_current_user( self::$subscriber_id ); 1778 1879 1779 $params 1880 $params = array( 1780 1881 'post' => self::$trash_id, 1781 1882 'author_name' => 'Ishmael', … … 1785 1886 'author' => self::$subscriber_id, 1786 1887 ); 1888 1787 1889 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1788 1890 $request->add_header( 'content-type', 'application/json' ); … … 1797 1899 wp_set_current_user( self::$subscriber_id ); 1798 1900 1799 $params 1901 $params = array( 1800 1902 'post' => self::$private_id, 1801 1903 'author_name' => 'Homer Jay Simpson', … … 1805 1907 'author' => self::$subscriber_id, 1806 1908 ); 1807 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1808 $request ->add_header( 'content-type', 'application/json' );1809 $request-> set_body( wp_json_encode( $params ));1810 1811 $response = rest_get_server()->dispatch( $request ); 1812 1909 1910 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1911 $request->add_header( 'content-type', 'application/json' ); 1912 $request->set_body( wp_json_encode( $params ) ); 1913 1914 $response = rest_get_server()->dispatch( $request ); 1813 1915 $this->assertErrorResponse( 'rest_cannot_read_post', $response, 403 ); 1814 1916 } … … 1817 1919 wp_set_current_user( self::$subscriber_id ); 1818 1920 1819 $params 1921 $params = array( 1820 1922 'post' => self::$password_id, 1821 1923 'author_name' => 'Homer Jay Simpson', … … 1825 1927 'author' => self::$subscriber_id, 1826 1928 ); 1929 1827 1930 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1828 1931 $request->add_header( 'content-type', 'application/json' ); … … 1835 1938 public function test_create_item_duplicate() { 1836 1939 wp_set_current_user( self::$subscriber_id ); 1940 1837 1941 $this->factory->comment->create( 1838 1942 array( … … 1865 1969 ) 1866 1970 ); 1971 1867 1972 wp_set_current_user( self::$subscriber_id ); 1868 1973 … … 1881 1986 public function test_create_comment_require_login() { 1882 1987 wp_set_current_user( 0 ); 1988 1883 1989 update_option( 'comment_registration', 1 ); 1884 1990 add_filter( 'rest_allow_anonymous_comments', '__return_true' ); 1991 1885 1992 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1886 1993 $request->set_param( 'post', self::$post_id ); … … 1998 2105 wp_set_current_user( self::$subscriber_id ); 1999 2106 2000 $params 2107 $params = array( 2001 2108 'post' => self::$post_id, 2002 2109 'author_name' => rand_long_str( 246 ), … … 2006 2113 'date' => '1995-04-30T10:22:00', 2007 2114 ); 2115 2008 2116 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 2009 2117 … … 2021 2129 wp_set_current_user( self::$subscriber_id ); 2022 2130 2023 $params 2131 $params = array( 2024 2132 'post' => self::$post_id, 2025 2133 'author_name' => 'Bleeding Gums Murphy', … … 2029 2137 'date' => '1995-04-30T10:22:00', 2030 2138 ); 2139 2031 2140 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 2032 2141 … … 2044 2153 wp_set_current_user( self::$subscriber_id ); 2045 2154 2046 $params 2155 $params = array( 2047 2156 'post' => self::$post_id, 2048 2157 'author_name' => 'Bleeding Gums Murphy', … … 2052 2161 'date' => '1995-04-30T10:22:00', 2053 2162 ); 2163 2054 2164 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 2055 2165 … … 2067 2177 wp_set_current_user( self::$subscriber_id ); 2068 2178 2069 $params 2179 $params = array( 2070 2180 'post' => self::$post_id, 2071 2181 'author_name' => 'Bleeding Gums Murphy', … … 2075 2185 'date' => '1995-04-30T10:22:00', 2076 2186 ); 2187 2077 2188 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 2078 2189 … … 2087 2198 wp_set_current_user( self::$subscriber_id ); 2088 2199 2089 $params 2200 $params = array( 2090 2201 'post' => self::$password_id, 2091 2202 'author_name' => 'Bleeding Gums Murphy', … … 2094 2205 'content' => 'This isn\'t a saxophone. It\'s an umbrella.', 2095 2206 ); 2207 2096 2208 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 2097 2209 … … 2106 2218 add_filter( 'rest_allow_anonymous_comments', '__return_true' ); 2107 2219 2108 $params 2220 $params = array( 2109 2221 'post' => self::$password_id, 2110 2222 'author_name' => 'Bleeding Gums Murphy', … … 2114 2226 'password' => 'toomanysecrets', 2115 2227 ); 2228 2116 2229 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 2117 2230 … … 2127 2240 wp_set_current_user( self::$admin_id ); 2128 2241 2129 $params 2242 $params = array( 2130 2243 'author' => self::$subscriber_id, 2131 2244 'author_name' => 'Disco Stu', … … 2137 2250 'post' => $post_id, 2138 2251 ); 2252 2139 2253 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 2140 2254 $request->add_header( 'content-type', 'application/json' ); … … 2163 2277 public function test_update_comment_date( $params, $results ) { 2164 2278 wp_set_current_user( self::$editor_id ); 2279 2165 2280 update_option( 'timezone_string', $params['timezone_string'] ); 2166 2281 … … 2214 2329 2215 2330 wp_set_current_user( self::$admin_id ); 2331 2216 2332 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 2217 2333 $request->set_param( 'post', $comment->comment_post_ID ); … … 2236 2352 ); 2237 2353 2238 $params 2354 $params = array( 2239 2355 'status' => 'approve', 2240 2356 ); 2357 2241 2358 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $comment_id ) ); 2242 2359 $request->add_header( 'content-type', 'application/json' ); … … 2263 2380 ); 2264 2381 2265 $params 2382 $params = array( 2266 2383 'status' => 'approve', 2267 2384 ); 2385 2268 2386 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $comment_id ) ); 2269 2387 $request->add_header( 'content-type', 'application/json' ); … … 2283 2401 wp_set_current_user( self::$admin_id ); 2284 2402 2285 $params 2403 $params = array( 2286 2404 'date_gmt' => '2015-05-07T10:14:25', 2287 2405 'content' => 'I\'ll be deep in the cold, cold ground before I recognize Missouri.', 2288 2406 ); 2407 2289 2408 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 2290 2409 $request->add_header( 'content-type', 'application/json' ); … … 2302 2421 public function test_update_comment_author_email_only() { 2303 2422 wp_set_current_user( self::$editor_id ); 2423 2304 2424 update_option( 'require_name_email', 1 ); 2305 2425 … … 2320 2440 public function test_update_comment_empty_author_name() { 2321 2441 wp_set_current_user( self::$editor_id ); 2442 2322 2443 update_option( 'require_name_email', 1 ); 2323 2444 … … 2339 2460 public function test_update_comment_author_name_only() { 2340 2461 wp_set_current_user( self::$admin_id ); 2462 2341 2463 update_option( 'require_name_email', 1 ); 2342 2464 … … 2357 2479 public function test_update_comment_empty_author_email() { 2358 2480 wp_set_current_user( self::$admin_id ); 2481 2359 2482 update_option( 'require_name_email', 1 ); 2360 2483 … … 2397 2520 wp_set_current_user( self::$admin_id ); 2398 2521 2399 $params 2522 $params = array( 2400 2523 'type' => 'trackback', 2401 2524 ); 2525 2402 2526 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 2403 2527 $request->add_header( 'content-type', 'application/json' ); … … 2411 2535 wp_set_current_user( self::$admin_id ); 2412 2536 2413 $params 2537 $params = array( 2414 2538 'content' => array( 2415 2539 'raw' => 'What the heck kind of name is Persephone?', 2416 2540 ), 2417 2541 ); 2542 2418 2543 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 2419 2544 $request->add_header( 'content-type', 'application/json' ); … … 2464 2589 wp_set_current_user( self::$subscriber_id ); 2465 2590 2466 $params 2591 $params = array( 2467 2592 'content' => 'Oh, they have the internet on computers now!', 2468 2593 ); 2594 2469 2595 $request = new WP_REST_Request( 'PUT', '/wp/v2/comments/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 2470 2596 $request->add_header( 'content-type', 'application/json' ); … … 2488 2614 add_filter( 'rest_allow_anonymous_comments', '__return_true' ); 2489 2615 2490 $params 2616 $params = array( 2491 2617 'content' => 'Disco Stu likes disco music.', 2492 2618 ); 2619 2493 2620 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$hold_id ) ); 2494 2621 $request->add_header( 'content-type', 'application/json' ); … … 2505 2632 wp_set_current_user( self::$moderator_id ); 2506 2633 2507 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 2508 $params = array( 2634 $params = array( 2509 2635 'content' => 'Updated comment.', 2510 2636 'date' => '2019-10-07T23:14:25', 2511 2637 ); 2638 2639 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 2512 2640 $request->add_header( 'content-type', 'application/json' ); 2513 2641 $request->set_body( wp_json_encode( $params ) ); … … 2535 2663 wp_set_current_user( self::$subscriber_id ); 2536 2664 2537 $params 2665 $params = array( 2538 2666 'content' => 'Disco Stu likes disco music.', 2539 2667 ); 2668 2540 2669 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $private_comment_id ) ); 2541 2670 $request->add_header( 'content-type', 'application/json' ); … … 2548 2677 public function test_update_comment_with_children_link() { 2549 2678 wp_set_current_user( self::$admin_id ); 2679 2550 2680 $comment_id_1 = $this->factory->comment->create( 2551 2681 array( … … 2590 2720 wp_set_current_user( self::$admin_id ); 2591 2721 2592 $params 2722 $params = array( 2593 2723 'author_name' => rand_long_str( 246 ), 2594 2724 'content' => 'This isn\'t a saxophone. It\'s an umbrella.', 2595 2725 ); 2726 2596 2727 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 2597 2728 … … 2609 2740 wp_set_current_user( self::$admin_id ); 2610 2741 2611 $params 2742 $params = array( 2612 2743 'author_email' => 'murphy@' . rand_long_str( 190 ) . '.com', 2613 2744 'content' => 'This isn\'t a saxophone. It\'s an umbrella.', 2614 2745 ); 2746 2615 2747 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 2616 2748 … … 2628 2760 wp_set_current_user( self::$admin_id ); 2629 2761 2630 $params 2762 $params = array( 2631 2763 'author_url' => 'http://jazz.' . rand_long_str( 185 ) . '.com', 2632 2764 'content' => 'This isn\'t a saxophone. It\'s an umbrella.', 2633 2765 ); 2766 2634 2767 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 2635 2768 … … 2647 2780 wp_set_current_user( self::$admin_id ); 2648 2781 2649 $params 2782 $params = array( 2650 2783 'content' => rand_long_str( 66525 ), 2651 2784 ); 2785 2652 2786 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 2653 2787 … … 2712 2846 public function test_comment_roundtrip_as_editor() { 2713 2847 wp_set_current_user( self::$editor_id ); 2848 2714 2849 $this->assertEquals( ! is_multisite(), current_user_can( 'unfiltered_html' ) ); 2715 2850 $this->verify_comment_roundtrip( … … 2732 2867 public function test_comment_roundtrip_as_editor_unfiltered_html() { 2733 2868 wp_set_current_user( self::$editor_id ); 2869 2734 2870 if ( is_multisite() ) { 2735 2871 $this->assertFalse( current_user_can( 'unfiltered_html' ) ); … … 2771 2907 public function test_comment_roundtrip_as_superadmin() { 2772 2908 wp_set_current_user( self::$superadmin_id ); 2909 2773 2910 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 2774 2911 $this->verify_comment_roundtrip( … … 2791 2928 public function test_comment_roundtrip_as_superadmin_unfiltered_html() { 2792 2929 wp_set_current_user( self::$superadmin_id ); 2930 2793 2931 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 2794 2932 $this->verify_comment_roundtrip( … … 2832 2970 wp_set_current_user( self::$admin_id ); 2833 2971 2834 $comment_id 2972 $comment_id = $this->factory->comment->create( 2835 2973 array( 2836 2974 'comment_approved' => 1, … … 2839 2977 ) 2840 2978 ); 2979 2841 2980 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) ); 2842 2981 $request['force'] = true; … … 2859 2998 ) 2860 2999 ); 2861 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) ); 2862 $response = rest_get_server()->dispatch( $request ); 3000 3001 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) ); 3002 $response = rest_get_server()->dispatch( $request ); 2863 3003 $this->assertEquals( 200, $response->get_status() ); 2864 3004 $data = $response->get_data(); … … 2870 3010 wp_set_current_user( self::$admin_id ); 2871 3011 2872 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) ); 2873 3012 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) ); 2874 3013 $response = rest_get_server()->dispatch( $request ); 2875 3014 $this->assertErrorResponse( 'rest_comment_invalid_id', $response, 404 ); … … 2879 3018 wp_set_current_user( self::$subscriber_id ); 2880 3019 2881 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 2882 3020 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 2883 3021 $response = rest_get_server()->dispatch( $request ); 2884 3022 $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 ); … … 2887 3025 public function test_delete_child_comment_link() { 2888 3026 wp_set_current_user( self::$admin_id ); 3027 2889 3028 $comment_id_1 = $this->factory->comment->create( 2890 3029 array( … … 2948 3087 public function test_get_item_schema_show_avatar() { 2949 3088 update_option( 'show_avatars', false ); 3089 2950 3090 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' ); 2951 3091 $response = rest_get_server()->dispatch( $request ); … … 2975 3115 ); 2976 3116 2977 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments' ); 2978 3117 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments' ); 2979 3118 $response = rest_get_server()->dispatch( $request ); 2980 3119 $data = $response->get_data(); … … 2983 3122 $this->assertEquals( $schema, $data['schema']['properties']['my_custom_int'] ); 2984 3123 2985 $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . self::$approved_id ); 2986 3124 $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . self::$approved_id ); 2987 3125 $response = rest_get_server()->dispatch( $request ); 2988 3126 $this->assertArrayHasKey( 'my_custom_int', $response->data );
Note: See TracChangeset
for help on using the changeset viewer.