- Timestamp:
- 10/27/2016 02:56:28 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php
r38864 r38975 12 12 class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase { 13 13 14 protected $admin_id;15 protected $subscriber_id;16 17 protected $post_id; 18 protected $private_id;19 protected $draft_id;20 protected $trash_id;21 22 protected $approved_id;23 protected $hold_id;14 protected static $admin_id; 15 protected static $subscriber_id; 16 protected static $author_id; 17 18 protected static $post_id; 19 protected static $private_id; 20 protected static $draft_id; 21 protected static $trash_id; 22 protected static $approved_id; 23 protected static $hold_id; 24 24 25 25 protected $endpoint; 26 26 27 public function setUp() { 28 parent::setUp(); 29 30 $this->admin_id = $this->factory->user->create( array( 27 public static function wpSetUpBeforeClass( $factory ) { 28 self::$admin_id = $factory->user->create( array( 31 29 'role' => 'administrator', 32 ) );33 $this->subscriber_id = $this->factory->user->create( array(30 ) ); 31 self::$subscriber_id = $factory->user->create( array( 34 32 'role' => 'subscriber', 35 ) );36 $this->author_id = $this->factory->user->create( array(33 ) ); 34 self::$author_id = $factory->user->create( array( 37 35 'role' => 'author', 38 36 'display_name' => 'Sea Captain', … … 41 39 'user_email' => 'captain@thefryingdutchman.com', 42 40 'user_url' => 'http://thefryingdutchman.com', 43 ) );44 45 $this->post_id = $this->factory->post->create();46 $this->private_id = $this->factory->post->create( array(41 ) ); 42 43 self::$post_id = $factory->post->create(); 44 self::$private_id = $factory->post->create( array( 47 45 'post_status' => 'private', 48 ) );49 $this->draft_id = $this->factory->post->create( array(46 ) ); 47 self::$draft_id = $factory->post->create( array( 50 48 'post_status' => 'draft', 51 ) );52 $this->trash_id = $this->factory->post->create( array(49 ) ); 50 self::$trash_id = $factory->post->create( array( 53 51 'post_status' => 'trash', 54 ) );55 56 $this->approved_id = $this->factory->comment->create( array(57 'comment_approved' => 1, 58 'comment_post_ID' => $this->post_id,52 ) ); 53 54 self::$approved_id = $factory->comment->create( array( 55 'comment_approved' => 1, 56 'comment_post_ID' => self::$post_id, 59 57 'user_id' => 0, 60 ) );61 $this->hold_id = $this->factory->comment->create( array(58 ) ); 59 self::$hold_id = $factory->comment->create( array( 62 60 'comment_approved' => 0, 63 'comment_post_ID' => $this->post_id, 64 'user_id' => $this->subscriber_id, 65 )); 66 61 'comment_post_ID' => self::$post_id, 62 'user_id' => self::$subscriber_id, 63 ) ); 64 } 65 66 public static function wpTearDownAfterClass() { 67 self::delete_user( self::$admin_id ); 68 self::delete_user( self::$subscriber_id ); 69 self::delete_user( self::$author_id ); 70 71 wp_delete_post( self::$post_id, true ); 72 wp_delete_post( self::$private_id, true ); 73 wp_delete_post( self::$draft_id, true ); 74 wp_delete_post( self::$trash_id, true ); 75 wp_delete_post( self::$approved_id, true ); 76 wp_delete_post( self::$hold_id, true ); 77 } 78 79 public function setUp() { 80 parent::setUp(); 67 81 $this->endpoint = new WP_REST_Comments_Controller; 68 82 } … … 89 103 $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); 90 104 // Single 91 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments/' . $this->approved_id );105 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments/' . self::$approved_id ); 92 106 $response = $this->server->dispatch( $request ); 93 107 $data = $response->get_data(); … … 127 141 128 142 public function test_get_items() { 129 $this->factory->comment->create_post_comments( $this->post_id, 6 );143 $this->factory->comment->create_post_comments( self::$post_id, 6 ); 130 144 131 145 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); … … 135 149 136 150 $comments = $response->get_data(); 137 // We created 6 comments in this method, plus $this->approved_id.151 // We created 6 comments in this method, plus self::$approved_id. 138 152 $this->assertCount( 7, $comments ); 139 153 } … … 144 158 $args = array( 145 159 'comment_approved' => 1, 146 'comment_post_ID' => $this->private_id,160 'comment_post_ID' => self::$private_id, 147 161 ); 148 162 $private_comment = $this->factory->comment->create( $args ); … … 158 172 159 173 public function test_get_items_with_private_post_permission() { 160 wp_set_current_user( $this->admin_id );174 wp_set_current_user( self::$admin_id ); 161 175 162 176 $args = array( 163 177 'comment_approved' => 1, 164 'comment_post_ID' => $this->private_id,178 'comment_post_ID' => self::$private_id, 165 179 ); 166 180 $private_comment = $this->factory->comment->create( $args ); … … 195 209 196 210 public function test_get_items_with_invalid_post_permission() { 197 wp_set_current_user( $this->admin_id );211 wp_set_current_user( self::$admin_id ); 198 212 199 213 $comment_id = $this->factory->comment->create( array( … … 223 237 public function test_get_items_no_post() { 224 238 $this->factory->comment->create_post_comments( 0, 2 ); 225 wp_set_current_user( $this->admin_id );239 wp_set_current_user( self::$admin_id ); 226 240 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 227 241 $request->set_param( 'post', 0 ); … … 241 255 242 256 public function test_get_items_edit_context() { 243 wp_set_current_user( $this->admin_id );257 wp_set_current_user( self::$admin_id ); 244 258 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 245 259 $request->set_param( 'context', 'edit' ); … … 265 279 266 280 public function test_get_items_include_query() { 267 wp_set_current_user( $this->admin_id );281 wp_set_current_user( self::$admin_id ); 268 282 $args = array( 269 283 'comment_approved' => 1, 270 'comment_post_ID' => $this->post_id,284 'comment_post_ID' => self::$post_id, 271 285 ); 272 286 $id1 = $this->factory->comment->create( $args ); … … 290 304 291 305 public function test_get_items_exclude_query() { 292 wp_set_current_user( $this->admin_id );306 wp_set_current_user( self::$admin_id ); 293 307 $args = array( 294 308 'comment_approved' => 1, 295 'comment_post_ID' => $this->post_id,309 'comment_post_ID' => self::$post_id, 296 310 ); 297 311 $id1 = $this->factory->comment->create( $args ); … … 310 324 311 325 public function test_get_items_offset_query() { 312 wp_set_current_user( $this->admin_id );326 wp_set_current_user( self::$admin_id ); 313 327 $args = array( 314 328 'comment_approved' => 1, 315 'comment_post_ID' => $this->post_id,329 'comment_post_ID' => self::$post_id, 316 330 ); 317 331 $this->factory->comment->create( $args ); … … 333 347 334 348 public function test_get_items_order_query() { 335 wp_set_current_user( $this->admin_id );349 wp_set_current_user( self::$admin_id ); 336 350 $args = array( 337 351 'comment_approved' => 1, 338 'comment_post_ID' => $this->post_id,352 'comment_post_ID' => self::$post_id, 339 353 ); 340 354 $this->factory->comment->create( $args ); … … 350 364 $response = $this->server->dispatch( $request ); 351 365 $data = $response->get_data(); 352 $this->assertEquals( $this->approved_id, $data[0]['id'] );366 $this->assertEquals( self::$approved_id, $data[0]['id'] ); 353 367 } 354 368 … … 364 378 public function test_get_items_author_arg() { 365 379 // Authorized 366 wp_set_current_user( $this->admin_id );380 wp_set_current_user( self::$admin_id ); 367 381 $args = array( 368 382 'comment_approved' => 1, 369 'comment_post_ID' => $this->post_id,370 'user_id' => $this->author_id,383 'comment_post_ID' => self::$post_id, 384 'user_id' => self::$author_id, 371 385 ); 372 386 $this->factory->comment->create( $args ); 373 $args['user_id'] = $this->subscriber_id;387 $args['user_id'] = self::$subscriber_id; 374 388 $this->factory->comment->create( $args ); 375 389 unset( $args['user_id'] ); … … 378 392 // 'author' limits result to 1 of 3 379 393 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 380 $request->set_param( 'author', $this->author_id );394 $request->set_param( 'author', self::$author_id ); 381 395 $response = $this->server->dispatch( $request ); 382 396 $this->assertEquals( 200, $response->get_status() ); … … 384 398 $this->assertCount( 1, $comments ); 385 399 // Multiple authors are supported 386 $request->set_param( 'author', array( $this->author_id, $this->subscriber_id ) );400 $request->set_param( 'author', array( self::$author_id, self::$subscriber_id ) ); 387 401 $response = $this->server->dispatch( $request ); 388 402 $this->assertEquals( 200, $response->get_status() ); … … 397 411 public function test_get_items_author_exclude_arg() { 398 412 // Authorized 399 wp_set_current_user( $this->admin_id );413 wp_set_current_user( self::$admin_id ); 400 414 $args = array( 401 415 'comment_approved' => 1, 402 'comment_post_ID' => $this->post_id,403 'user_id' => $this->author_id,416 'comment_post_ID' => self::$post_id, 417 'user_id' => self::$author_id, 404 418 ); 405 419 $this->factory->comment->create( $args ); 406 $args['user_id'] = $this->subscriber_id;420 $args['user_id'] = self::$subscriber_id; 407 421 $this->factory->comment->create( $args ); 408 422 unset( $args['user_id'] ); … … 416 430 // 'author_exclude' limits result to 3 of 4 417 431 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 418 $request->set_param( 'author_exclude', $this->author_id );432 $request->set_param( 'author_exclude', self::$author_id ); 419 433 $response = $this->server->dispatch( $request ); 420 434 $this->assertEquals( 200, $response->get_status() ); … … 423 437 // 'author_exclude' for both comment authors (2 of 4) 424 438 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 425 $request->set_param( 'author_exclude', array( $this->author_id, $this->subscriber_id ) );439 $request->set_param( 'author_exclude', array( self::$author_id, self::$subscriber_id ) ); 426 440 $response = $this->server->dispatch( $request ); 427 441 $this->assertEquals( 200, $response->get_status() ); … … 437 451 $args = array( 438 452 'comment_approved' => 1, 439 'comment_post_ID' => $this->post_id,453 'comment_post_ID' => self::$post_id, 440 454 ); 441 455 $parent_id = $this->factory->comment->create( $args ); … … 462 476 $args = array( 463 477 'comment_approved' => 1, 464 'comment_post_ID' => $this->post_id,478 'comment_post_ID' => self::$post_id, 465 479 ); 466 480 $parent_id = $this->factory->comment->create( $args ); … … 485 499 486 500 public function test_get_items_search_query() { 487 wp_set_current_user( $this->admin_id );501 wp_set_current_user( self::$admin_id ); 488 502 $args = array( 489 503 'comment_approved' => 1, 490 'comment_post_ID' => $this->post_id,504 'comment_post_ID' => self::$post_id, 491 505 'comment_content' => 'foo', 492 506 'comment_author' => 'Homer J Simpson', … … 510 524 511 525 public function test_get_comments_pagination_headers() { 512 wp_set_current_user( $this->admin_id );526 wp_set_current_user( self::$admin_id ); 513 527 // Start of the index 514 528 for ( $i = 0; $i < 49; $i++ ) { 515 529 $this->factory->comment->create( array( 516 530 'comment_content' => "Comment {$i}", 517 'comment_post_ID' => $this->post_id,531 'comment_post_ID' => self::$post_id, 518 532 ) ); 519 533 } … … 531 545 $this->factory->comment->create( array( 532 546 'comment_content' => 'Comment 51', 533 'comment_post_ID' => $this->post_id,547 'comment_post_ID' => self::$post_id, 534 548 ) ); 535 549 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); … … 584 598 $comment1 = $this->factory->comment->create( array( 585 599 'comment_date' => '2016-01-15T00:00:00Z', 586 'comment_post_ID' => $this->post_id,600 'comment_post_ID' => self::$post_id, 587 601 ) ); 588 602 $comment2 = $this->factory->comment->create( array( 589 603 'comment_date' => '2016-01-16T00:00:00Z', 590 'comment_post_ID' => $this->post_id,604 'comment_post_ID' => self::$post_id, 591 605 ) ); 592 606 $comment3 = $this->factory->comment->create( array( 593 607 'comment_date' => '2016-01-17T00:00:00Z', 594 'comment_post_ID' => $this->post_id,608 'comment_post_ID' => self::$post_id, 595 609 ) ); 596 610 … … 605 619 606 620 public function test_get_item() { 607 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );621 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 608 622 609 623 $response = $this->server->dispatch( $request ); … … 615 629 616 630 public function test_prepare_item() { 617 wp_set_current_user( $this->admin_id );618 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );631 wp_set_current_user( self::$admin_id ); 632 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 619 633 $request->set_query_params( array( 620 634 'context' => 'edit', … … 629 643 630 644 public function test_get_comment_author_avatar_urls() { 631 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );645 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 632 646 633 647 $response = $this->server->dispatch( $request ); … … 638 652 $this->assertArrayHasKey( 96, $data['author_avatar_urls'] ); 639 653 640 $comment = get_comment( $this->approved_id );654 $comment = get_comment( self::$approved_id ); 641 655 /** 642 656 * Ignore the subdomain, since 'get_avatar_url randomly sets the Gravatar … … 655 669 public function test_get_comment_invalid_context() { 656 670 wp_set_current_user( 0 ); 657 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $this->approved_id ) );671 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', self::$approved_id ) ); 658 672 $request->set_param( 'context', 'edit' ); 659 673 $response = $this->server->dispatch( $request ); … … 674 688 675 689 public function test_get_comment_invalid_post_id_as_admin() { 676 wp_set_current_user( $this->admin_id );690 wp_set_current_user( self::$admin_id ); 677 691 $comment_id = $this->factory->comment->create( array( 678 692 'comment_approved' => 1, … … 688 702 wp_set_current_user( 0 ); 689 703 690 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $this->hold_id ) );704 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) ); 691 705 692 706 $response = $this->server->dispatch( $request ); … … 695 709 696 710 public function test_get_comment_not_approved_same_user() { 697 wp_set_current_user( $this->subscriber_id );698 699 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $this->hold_id ) );711 wp_set_current_user( self::$subscriber_id ); 712 713 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) ); 700 714 701 715 $response = $this->server->dispatch( $request ); … … 706 720 $comment_id_1 = $this->factory->comment->create( array( 707 721 'comment_approved' => 1, 708 'comment_post_ID' => $this->post_id,709 'user_id' => $this->subscriber_id,722 'comment_post_ID' => self::$post_id, 723 'user_id' => self::$subscriber_id, 710 724 ) ); 711 725 … … 713 727 'comment_approved' => 1, 714 728 'comment_parent' => $comment_id_1, 715 'comment_post_ID' => $this->post_id,716 'user_id' => $this->subscriber_id,729 'comment_post_ID' => self::$post_id, 730 'user_id' => self::$subscriber_id, 717 731 ) ); 718 732 … … 726 740 $comment_id_1 = $this->factory->comment->create( array( 727 741 'comment_approved' => 1, 728 'comment_post_ID' => $this->post_id,729 'user_id' => $this->subscriber_id,742 'comment_post_ID' => self::$post_id, 743 'user_id' => self::$subscriber_id, 730 744 ) ); 731 745 … … 740 754 741 755 $params = array( 742 'post' => $this->post_id,756 'post' => self::$post_id, 743 757 'author_name' => 'Comic Book Guy', 744 758 'author_email' => 'cbg@androidsdungeon.com', … … 759 773 $this->assertEquals( 'hold', $data['status'] ); 760 774 $this->assertEquals( '2014-11-07T10:14:25', $data['date'] ); 761 $this->assertEquals( $this->post_id, $data['post'] );775 $this->assertEquals( self::$post_id, $data['post'] ); 762 776 } 763 777 … … 766 780 767 781 $params = array( 768 'post' => $this->post_id,782 'post' => self::$post_id, 769 783 'author_name' => 'Reverend Lovejoy', 770 784 'author_email' => 'lovejoy@example.com', … … 791 805 792 806 $params = array( 793 'post' => $this->post_id,807 'post' => self::$post_id, 794 808 'content' => 'Now, I don\'t want you to worry class. These tests will have no affect on your grades. They merely determine your future social status and financial success. If any.', 795 809 ); … … 809 823 810 824 $params = array( 811 'post' => $this->post_id,825 'post' => self::$post_id, 812 826 'author_email' => 'ekrabappel@springfield-elementary.edu', 813 827 'content' => 'Now, I don\'t want you to worry class. These tests will have no affect on your grades. They merely determine your future social status and financial success. If any.', … … 828 842 829 843 $params = array( 830 'post' => $this->post_id,844 'post' => self::$post_id, 831 845 'author_name' => 'Edna Krabappel', 832 846 'content' => 'Now, I don\'t want you to worry class. These tests will have no affect on your grades. They merely determine your future social status and financial success. If any.', … … 847 861 848 862 $params = array( 849 'post' => $this->post_id,863 'post' => self::$post_id, 850 864 'author_name' => 'Reverend Lovejoy', 851 865 'author_email' => 'lovejoy@example.com', … … 866 880 867 881 $params = array( 868 'post' => $this->post_id,882 'post' => self::$post_id, 869 883 'author_name' => 'Reverend Lovejoy', 870 884 'author_email' => 'lovejoy@example.com', … … 889 903 )); 890 904 891 wp_set_current_user( $this->admin_id );892 $params = array( 893 'post' => $this->post_id,905 wp_set_current_user( self::$admin_id ); 906 $params = array( 907 'post' => self::$post_id, 894 908 'author_name' => 'Comic Book Guy', 895 909 'author_email' => 'cbg@androidsdungeon.com', … … 912 926 public function test_create_comment_without_type() { 913 927 $post_id = $this->factory->post->create(); 914 wp_set_current_user( $this->admin_id );928 wp_set_current_user( self::$admin_id ); 915 929 916 930 $params = array( 917 931 'post' => $post_id, 918 'author' => $this->admin_id,932 'author' => self::$admin_id, 919 933 'author_name' => 'Comic Book Guy', 920 934 'author_email' => 'cbg@androidsdungeon.com', … … 957 971 958 972 $params = array( 959 'post' => $this->post_id,973 'post' => self::$post_id, 960 974 'content' => "Well sir, there's nothing on earth like a genuine, bona fide, electrified, six-car Monorail!", 961 975 ); … … 979 993 980 994 public function test_create_comment_other_user() { 981 wp_set_current_user( $this->admin_id );982 983 $params = array( 984 'post' => $this->post_id,995 wp_set_current_user( self::$admin_id ); 996 997 $params = array( 998 'post' => self::$post_id, 985 999 'author_name' => 'Homer Jay Simpson', 986 1000 'author_email' => 'chunkylover53@aol.com', 987 1001 'author_url' => 'http://compuglobalhypermeganet.com', 988 1002 'content' => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.', 989 'author' => $this->subscriber_id,1003 'author' => self::$subscriber_id, 990 1004 ); 991 1005 … … 997 1011 $this->assertEquals( 201, $response->get_status() ); 998 1012 $data = $response->get_data(); 999 $this->assertEquals( $this->subscriber_id, $data['author'] );1013 $this->assertEquals( self::$subscriber_id, $data['author'] ); 1000 1014 $this->assertEquals( 'Homer Jay Simpson', $data['author_name'] ); 1001 1015 $this->assertEquals( 'chunkylover53@aol.com', $data['author_email'] ); … … 1004 1018 1005 1019 public function test_create_comment_other_user_without_permission() { 1006 wp_set_current_user( $this->subscriber_id );1007 1008 $params = array( 1009 'post' => $this->post_id,1020 wp_set_current_user( self::$subscriber_id ); 1021 1022 $params = array( 1023 'post' => self::$post_id, 1010 1024 'author_name' => 'Homer Jay Simpson', 1011 1025 'author_email' => 'chunkylover53@aol.com', 1012 1026 'author_url' => 'http://compuglobalhypermeganet.com', 1013 1027 'content' => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.', 1014 'author' => $this->admin_id,1028 'author' => self::$admin_id, 1015 1029 ); 1016 1030 … … 1024 1038 1025 1039 public function test_create_comment_karma_without_permission() { 1026 wp_set_current_user( $this->subscriber_id );1027 1028 $params = array( 1029 'post' => $this->post_id,1040 wp_set_current_user( self::$subscriber_id ); 1041 1042 $params = array( 1043 'post' => self::$post_id, 1030 1044 'author_name' => 'Homer Jay Simpson', 1031 1045 'author_email' => 'chunkylover53@aol.com', 1032 1046 'author_url' => 'http://compuglobalhypermeganet.com', 1033 1047 'content' => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.', 1034 'author' => $this->subscriber_id,1048 'author' => self::$subscriber_id, 1035 1049 'karma' => 100, 1036 1050 ); … … 1045 1059 1046 1060 public function test_create_comment_status_without_permission() { 1047 wp_set_current_user( $this->subscriber_id );1048 1049 $params = array( 1050 'post' => $this->post_id,1061 wp_set_current_user( self::$subscriber_id ); 1062 1063 $params = array( 1064 'post' => self::$post_id, 1051 1065 'author_name' => 'Homer Jay Simpson', 1052 1066 'author_email' => 'chunkylover53@aol.com', 1053 1067 'author_url' => 'http://compuglobalhypermeganet.com', 1054 1068 'content' => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.', 1055 'author' => $this->subscriber_id,1069 'author' => self::$subscriber_id, 1056 1070 'status' => 'approved', 1057 1071 ); … … 1067 1081 public function test_create_comment_with_status_IP_and_user_agent() { 1068 1082 $post_id = $this->factory->post->create(); 1069 wp_set_current_user( $this->admin_id );1083 wp_set_current_user( self::$admin_id ); 1070 1084 1071 1085 $params = array( … … 1094 1108 1095 1109 public function test_create_comment_invalid_author_IP() { 1096 wp_set_current_user( $this->admin_id );1110 wp_set_current_user( self::$admin_id ); 1097 1111 1098 1112 $params = array( … … 1114 1128 1115 1129 public function test_create_comment_no_post_id() { 1116 wp_set_current_user( $this->admin_id );1130 wp_set_current_user( self::$admin_id ); 1117 1131 1118 1132 $params = array( … … 1132 1146 1133 1147 public function test_create_comment_no_post_id_no_permission() { 1134 wp_set_current_user( $this->subscriber_id );1148 wp_set_current_user( self::$subscriber_id ); 1135 1149 1136 1150 $params = array( … … 1139 1153 'author_url' => 'http://compuglobalhypermeganet.com', 1140 1154 'content' => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.', 1141 'author' => $this->subscriber_id,1155 'author' => self::$subscriber_id, 1142 1156 ); 1143 1157 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); … … 1151 1165 1152 1166 public function test_create_comment_draft_post() { 1153 wp_set_current_user( $this->subscriber_id );1154 1155 $params = array( 1156 'post' => $this->draft_id,1167 wp_set_current_user( self::$subscriber_id ); 1168 1169 $params = array( 1170 'post' => self::$draft_id, 1157 1171 'author_name' => 'Ishmael', 1158 1172 'author_email' => 'herman-melville@earthlink.net', 1159 1173 'author_url' => 'https://en.wikipedia.org/wiki/Herman_Melville', 1160 1174 'content' => 'Call me Ishmael.', 1161 'author' => $this->subscriber_id,1175 'author' => self::$subscriber_id, 1162 1176 ); 1163 1177 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); … … 1171 1185 1172 1186 public function test_create_comment_trash_post() { 1173 wp_set_current_user( $this->subscriber_id );1174 1175 $params = array( 1176 'post' => $this->trash_id,1187 wp_set_current_user( self::$subscriber_id ); 1188 1189 $params = array( 1190 'post' => self::$trash_id, 1177 1191 'author_name' => 'Ishmael', 1178 1192 'author_email' => 'herman-melville@earthlink.net', 1179 1193 'author_url' => 'https://en.wikipedia.org/wiki/Herman_Melville', 1180 1194 'content' => 'Call me Ishmael.', 1181 'author' => $this->subscriber_id,1195 'author' => self::$subscriber_id, 1182 1196 ); 1183 1197 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); … … 1191 1205 1192 1206 public function test_create_comment_private_post_invalid_permission() { 1193 wp_set_current_user( $this->subscriber_id );1194 1195 $params = array( 1196 'post' => $this->private_id,1207 wp_set_current_user( self::$subscriber_id ); 1208 1209 $params = array( 1210 'post' => self::$private_id, 1197 1211 'author_name' => 'Homer Jay Simpson', 1198 1212 'author_email' => 'chunkylover53@aol.com', 1199 1213 'author_url' => 'http://compuglobalhypermeganet.com', 1200 1214 'content' => 'I\’d be a vegetarian if bacon grew on trees.', 1201 'author' => $this->subscriber_id,1215 'author' => self::$subscriber_id, 1202 1216 ); 1203 1217 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); … … 1213 1227 $this->factory->comment->create( 1214 1228 array( 1215 'comment_post_ID' => $this->post_id,1229 'comment_post_ID' => self::$post_id, 1216 1230 'comment_author' => 'Guy N. Cognito', 1217 1231 'comment_author_email' => 'chunkylover53@aol.co.uk', … … 1222 1236 1223 1237 $params = array( 1224 'post' => $this->post_id,1238 'post' => self::$post_id, 1225 1239 'author_name' => 'Guy N. Cognito', 1226 1240 'author_email' => 'chunkylover53@aol.co.uk', … … 1258 1272 update_option( 'comment_registration', 1 ); 1259 1273 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1260 $request->set_param( 'post', $this->post_id );1274 $request->set_param( 'post', self::$post_id ); 1261 1275 $response = $this->server->dispatch( $request ); 1262 1276 $this->assertEquals( 401, $response->get_status() ); … … 1266 1280 1267 1281 public function test_create_item_invalid_author() { 1268 wp_set_current_user( $this->admin_id );1269 1270 $params = array( 1271 'post' => $this->post_id,1282 wp_set_current_user( self::$admin_id ); 1283 1284 $params = array( 1285 'post' => self::$post_id, 1272 1286 'author' => REST_TESTS_IMPOSSIBLY_HIGH_NUMBER, 1273 1287 'content' => 'It\'s all over\, people! We don\'t have a prayer!', … … 1283 1297 1284 1298 public function test_create_item_pull_author_info() { 1285 wp_set_current_user( $this->admin_id );1286 1287 $author = new WP_User( $this->author_id );1288 $params = array( 1289 'post' => $this->post_id,1290 'author' => $this->author_id,1299 wp_set_current_user( self::$admin_id ); 1300 1301 $author = new WP_User( self::$author_id ); 1302 $params = array( 1303 'post' => self::$post_id, 1304 'author' => self::$author_id, 1291 1305 'content' => 'It\'s all over\, people! We don\'t have a prayer!', 1292 1306 ); … … 1299 1313 1300 1314 $result = $response->get_data(); 1301 $this->assertSame( $this->author_id, $result['author'] );1315 $this->assertSame( self::$author_id, $result['author'] ); 1302 1316 $this->assertSame( 'Sea Captain', $result['author_name'] ); 1303 1317 $this->assertSame( 'captain@thefryingdutchman.com', $result['author_email'] ); … … 1309 1323 1310 1324 $params = array( 1311 'post' => $this->post_id,1325 'post' => self::$post_id, 1312 1326 'author_name' => 'Comic Book Guy', 1313 1327 'author_email' => 'cbg@androidsdungeon.com', … … 1324 1338 1325 1339 $params = array( 1326 'post' => $this->post_id,1340 'post' => self::$post_id, 1327 1341 'author_name' => 'Comic Book Guy', 1328 1342 'author_email' => 'cbg@androidsdungeon.com', … … 1342 1356 $post_id = $this->factory->post->create(); 1343 1357 1344 wp_set_current_user( $this->admin_id );1345 1346 $params = array( 1347 'author' => $this->subscriber_id,1358 wp_set_current_user( self::$admin_id ); 1359 1360 $params = array( 1361 'author' => self::$subscriber_id, 1348 1362 'author_name' => 'Disco Stu', 1349 1363 'author_url' => 'http://stusdisco.com', … … 1355 1369 'post' => $post_id, 1356 1370 ); 1357 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );1371 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 1358 1372 $request->add_header( 'content-type', 'application/json' ); 1359 1373 $request->set_body( wp_json_encode( $params ) ); … … 1363 1377 1364 1378 $comment = $response->get_data(); 1365 $updated = get_comment( $this->approved_id );1379 $updated = get_comment( self::$approved_id ); 1366 1380 $this->assertEquals( $params['content'], $comment['content']['raw'] ); 1367 1381 $this->assertEquals( $params['author'], $comment['author'] ); … … 1378 1392 1379 1393 public function test_update_comment_status() { 1380 wp_set_current_user( $this->admin_id );1394 wp_set_current_user( self::$admin_id ); 1381 1395 1382 1396 $comment_id = $this->factory->comment->create( array( 1383 1397 'comment_approved' => 0, 1384 'comment_post_ID' => $this->post_id,1398 'comment_post_ID' => self::$post_id, 1385 1399 )); 1386 1400 … … 1402 1416 1403 1417 public function test_update_comment_field_does_not_use_default_values() { 1404 wp_set_current_user( $this->admin_id );1418 wp_set_current_user( self::$admin_id ); 1405 1419 1406 1420 $comment_id = $this->factory->comment->create( array( 1407 1421 'comment_approved' => 0, 1408 'comment_post_ID' => $this->post_id,1422 'comment_post_ID' => self::$post_id, 1409 1423 'comment_content' => 'some content', 1410 1424 )); … … 1428 1442 1429 1443 public function test_update_comment_date_gmt() { 1430 wp_set_current_user( $this->admin_id );1444 wp_set_current_user( self::$admin_id ); 1431 1445 1432 1446 $params = array( … … 1434 1448 'content' => 'I\'ll be deep in the cold, cold ground before I recognize Missouri.', 1435 1449 ); 1436 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );1450 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 1437 1451 $request->add_header( 'content-type', 'application/json' ); 1438 1452 $request->set_body( wp_json_encode( $params ) ); … … 1442 1456 1443 1457 $comment = $response->get_data(); 1444 $updated = get_comment( $this->approved_id );1458 $updated = get_comment( self::$approved_id ); 1445 1459 $this->assertEquals( $params['date_gmt'], $comment['date_gmt'] ); 1446 1460 $this->assertEquals( $params['date_gmt'], mysql_to_rfc3339( $updated->comment_date_gmt ) ); … … 1448 1462 1449 1463 public function test_update_comment_invalid_type() { 1450 wp_set_current_user( $this->admin_id );1464 wp_set_current_user( self::$admin_id ); 1451 1465 1452 1466 $params = array( 1453 1467 'type' => 'trackback', 1454 1468 ); 1455 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );1469 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 1456 1470 $request->add_header( 'content-type', 'application/json' ); 1457 1471 $request->set_body( wp_json_encode( $params ) ); … … 1462 1476 1463 1477 public function test_update_comment_with_raw_property() { 1464 wp_set_current_user( $this->admin_id );1478 wp_set_current_user( self::$admin_id ); 1465 1479 1466 1480 $params = array( … … 1469 1483 ), 1470 1484 ); 1471 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );1485 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 1472 1486 $request->add_header( 'content-type', 'application/json' ); 1473 1487 $request->set_body( wp_json_encode( $params ) ); … … 1478 1492 1479 1493 $comment = $response->get_data(); 1480 $updated = get_comment( $this->approved_id );1494 $updated = get_comment( self::$approved_id ); 1481 1495 $this->assertEquals( $params['content']['raw'], $updated->comment_content ); 1482 1496 } 1483 1497 1484 1498 public function test_update_item_invalid_date() { 1485 wp_set_current_user( $this->admin_id );1499 wp_set_current_user( self::$admin_id ); 1486 1500 1487 1501 $params = array( … … 1490 1504 ); 1491 1505 1492 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );1506 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 1493 1507 $request->add_header( 'content-type', 'application/json' ); 1494 1508 $request->set_body( wp_json_encode( $params ) ); … … 1499 1513 1500 1514 public function test_update_item_invalid_date_gmt() { 1501 wp_set_current_user( $this->admin_id );1515 wp_set_current_user( self::$admin_id ); 1502 1516 1503 1517 $params = array( … … 1506 1520 ); 1507 1521 1508 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );1522 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 1509 1523 $request->add_header( 'content-type', 'application/json' ); 1510 1524 $request->set_body( wp_json_encode( $params ) ); … … 1534 1548 'content' => 'Disco Stu likes disco music.', 1535 1549 ); 1536 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $this->hold_id ) );1550 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$hold_id ) ); 1537 1551 $request->add_header( 'content-type', 'application/json' ); 1538 1552 $request->set_body( wp_json_encode( $params ) ); … … 1545 1559 $private_comment_id = $this->factory->comment->create( array( 1546 1560 'comment_approved' => 1, 1547 'comment_post_ID' => $this->private_id,1561 'comment_post_ID' => self::$private_id, 1548 1562 'user_id' => 0, 1549 1563 )); 1550 1564 1551 wp_set_current_user( $this->subscriber_id );1565 wp_set_current_user( self::$subscriber_id ); 1552 1566 1553 1567 $params = array( … … 1563 1577 1564 1578 public function test_update_comment_with_children_link() { 1565 wp_set_current_user( $this->admin_id );1579 wp_set_current_user( self::$admin_id ); 1566 1580 $comment_id_1 = $this->factory->comment->create( array( 1567 1581 'comment_approved' => 1, 1568 'comment_post_ID' => $this->post_id,1569 'user_id' => $this->subscriber_id,1582 'comment_post_ID' => self::$post_id, 1583 'user_id' => self::$subscriber_id, 1570 1584 ) ); 1571 1585 1572 1586 $child_comment = $this->factory->comment->create( array( 1573 1587 'comment_approved' => 1, 1574 'comment_post_ID' => $this->post_id,1575 'user_id' => $this->subscriber_id,1588 'comment_post_ID' => self::$post_id, 1589 'user_id' => self::$subscriber_id, 1576 1590 ) ); 1577 1591 … … 1597 1611 1598 1612 public function test_delete_item() { 1599 wp_set_current_user( $this->admin_id );1613 wp_set_current_user( self::$admin_id ); 1600 1614 1601 1615 $comment_id = $this->factory->comment->create( array( 1602 1616 'comment_approved' => 1, 1603 'comment_post_ID' => $this->post_id,1604 'user_id' => $this->subscriber_id,1617 'comment_post_ID' => self::$post_id, 1618 'user_id' => self::$subscriber_id, 1605 1619 )); 1606 1620 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) ); … … 1609 1623 $this->assertEquals( 200, $response->get_status() ); 1610 1624 $data = $response->get_data(); 1611 $this->assertEquals( $this->post_id, $data['post'] );1625 $this->assertEquals( self::$post_id, $data['post'] ); 1612 1626 } 1613 1627 1614 1628 public function test_delete_item_skip_trash() { 1615 wp_set_current_user( $this->admin_id );1629 wp_set_current_user( self::$admin_id ); 1616 1630 1617 1631 $comment_id = $this->factory->comment->create( array( 1618 1632 'comment_approved' => 1, 1619 'comment_post_ID' => $this->post_id,1620 'user_id' => $this->subscriber_id,1633 'comment_post_ID' => self::$post_id, 1634 'user_id' => self::$subscriber_id, 1621 1635 )); 1622 1636 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) ); … … 1626 1640 $this->assertEquals( 200, $response->get_status() ); 1627 1641 $data = $response->get_data(); 1628 $this->assertEquals( $this->post_id, $data['post'] );1642 $this->assertEquals( self::$post_id, $data['post'] ); 1629 1643 } 1630 1644 1631 1645 public function test_delete_item_already_trashed() { 1632 wp_set_current_user( $this->admin_id );1646 wp_set_current_user( self::$admin_id ); 1633 1647 1634 1648 $comment_id = $this->factory->comment->create( array( 1635 1649 'comment_approved' => 1, 1636 'comment_post_ID' => $this->post_id,1637 'user_id' => $this->subscriber_id,1650 'comment_post_ID' => self::$post_id, 1651 'user_id' => self::$subscriber_id, 1638 1652 )); 1639 1653 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) ); … … 1646 1660 1647 1661 public function test_delete_comment_invalid_id() { 1648 wp_set_current_user( $this->admin_id );1662 wp_set_current_user( self::$admin_id ); 1649 1663 1650 1664 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) ); … … 1655 1669 1656 1670 public function test_delete_comment_without_permission() { 1657 wp_set_current_user( $this->subscriber_id );1658 1659 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );1671 wp_set_current_user( self::$subscriber_id ); 1672 1673 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 1660 1674 1661 1675 $response = $this->server->dispatch( $request ); … … 1664 1678 1665 1679 public function test_delete_child_comment_link() { 1666 wp_set_current_user( $this->admin_id );1680 wp_set_current_user( self::$admin_id ); 1667 1681 $comment_id_1 = $this->factory->comment->create( array( 1668 1682 'comment_approved' => 1, 1669 'comment_post_ID' => $this->post_id,1670 'user_id' => $this->subscriber_id,1683 'comment_post_ID' => self::$post_id, 1684 'user_id' => self::$subscriber_id, 1671 1685 ) ); 1672 1686 … … 1674 1688 'comment_approved' => 1, 1675 1689 'comment_parent' => $comment_id_1, 1676 'comment_post_ID' => $this->post_id,1677 'user_id' => $this->subscriber_id,1690 'comment_post_ID' => self::$post_id, 1691 'user_id' => self::$subscriber_id, 1678 1692 ) ); 1679 1693 … … 1748 1762 $this->assertEquals( $schema, $data['schema']['properties']['my_custom_int'] ); 1749 1763 1750 $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $this->approved_id );1764 $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . self::$approved_id ); 1751 1765 1752 1766 $response = $this->server->dispatch( $request ); 1753 1767 $this->assertArrayHasKey( 'my_custom_int', $response->data ); 1754 1768 1755 $request = new WP_REST_Request( 'POST', '/wp/v2/comments/' . $this->approved_id );1769 $request = new WP_REST_Request( 'POST', '/wp/v2/comments/' . self::$approved_id ); 1756 1770 $request->set_body_params(array( 1757 1771 'my_custom_int' => 123, … … 1761 1775 wp_set_current_user( 1 ); 1762 1776 $this->server->dispatch( $request ); 1763 $this->assertEquals( 123, get_comment_meta( $this->approved_id, 'my_custom_int', true ) );1777 $this->assertEquals( 123, get_comment_meta( self::$approved_id, 'my_custom_int', true ) ); 1764 1778 1765 1779 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); … … 1768 1782 'title' => 'hello', 1769 1783 'content' => 'goodbye', 1770 'post' => $this->post_id,1784 'post' => self::$post_id, 1771 1785 )); 1772 1786 … … 1793 1807 ) ); 1794 1808 1795 wp_set_current_user( $this->admin_id );1809 wp_set_current_user( self::$admin_id ); 1796 1810 1797 1811 // Check for error on update. 1798 $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );1812 $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 1799 1813 $request->set_body_params(array( 1800 1814 'my_custom_int' => 'returnError',
Note: See TracChangeset
for help on using the changeset viewer.