Changeset 42343 for trunk/tests/phpunit/tests/comment-submission.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/comment-submission.php
r41644 r42343 18 18 $this->assertSame( 0, did_action( $error ) ); 19 19 20 $data = array(20 $data = array( 21 21 'comment_post_ID' => 0, 22 22 ); … … 35 35 $this->assertSame( 0, did_action( $error ) ); 36 36 37 $post = self::factory()->post->create_and_get( array( 38 'comment_status' => 'closed', 39 ) ); 40 $data = array( 37 $post = self::factory()->post->create_and_get( 38 array( 39 'comment_status' => 'closed', 40 ) 41 ); 42 $data = array( 41 43 'comment_post_ID' => $post->ID, 42 44 ); … … 57 59 $post = self::factory()->post->create_and_get(); 58 60 wp_trash_post( $post->ID ); 59 $data = array(61 $data = array( 60 62 'comment_post_ID' => $post->ID, 61 63 ); … … 73 75 $this->assertSame( 0, did_action( $error ) ); 74 76 75 $post = self::factory()->post->create_and_get( array( 76 'post_status' => 'draft', 77 ) ); 78 $data = array( 77 $post = self::factory()->post->create_and_get( 78 array( 79 'post_status' => 'draft', 80 ) 81 ); 82 $data = array( 79 83 'comment_post_ID' => $post->ID, 80 84 ); … … 94 98 $error = 'comment_on_draft'; 95 99 96 $user = self::factory()->user->create_and_get( array( 97 'role' => 'author', 98 ) ); 100 $user = self::factory()->user->create_and_get( 101 array( 102 'role' => 'author', 103 ) 104 ); 99 105 100 106 wp_set_current_user( $user->ID ); … … 102 108 $this->assertSame( 0, did_action( $error ) ); 103 109 104 $post = self::factory()->post->create_and_get( array( 105 'post_status' => 'draft', 106 'post_author' => $user->ID, 107 ) ); 108 $data = array( 110 $post = self::factory()->post->create_and_get( 111 array( 112 'post_status' => 'draft', 113 'post_author' => $user->ID, 114 ) 115 ); 116 $data = array( 109 117 'comment_post_ID' => $post->ID, 110 118 ); … … 124 132 $this->assertSame( 0, did_action( $error ) ); 125 133 126 $post = self::factory()->post->create_and_get( array( 127 'post_date' => date( 'Y-m-d H:i:s', strtotime( '+1 day' ) ), 128 ) ); 134 $post = self::factory()->post->create_and_get( 135 array( 136 'post_date' => date( 'Y-m-d H:i:s', strtotime( '+1 day' ) ), 137 ) 138 ); 129 139 130 140 $this->assertSame( 'future', $post->post_status ); 131 141 132 $data = array(142 $data = array( 133 143 'comment_post_ID' => $post->ID, 134 144 ); … … 147 157 $this->assertSame( 0, did_action( $error ) ); 148 158 149 $post = self::factory()->post->create_and_get( array( 150 'post_password' => 'password', 151 ) ); 152 $data = array( 159 $post = self::factory()->post->create_and_get( 160 array( 161 'post_password' => 'password', 162 ) 163 ); 164 $data = array( 153 165 'comment_post_ID' => $post->ID, 154 166 ); … … 166 178 $hasher = new PasswordHash( 8, true ); 167 179 168 $_COOKIE['wp-postpass_' . COOKIEHASH] = $hasher->HashPassword( $password ); 169 170 $post = self::factory()->post->create_and_get( array( 171 'post_password' => $password, 172 ) ); 173 $data = array( 180 $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] = $hasher->HashPassword( $password ); 181 182 $post = self::factory()->post->create_and_get( 183 array( 184 'post_password' => $password, 185 ) 186 ); 187 $data = array( 174 188 'comment_post_ID' => $post->ID, 175 189 'comment' => 'Comment', … … 179 193 $comment = wp_handle_comment_submission( $data ); 180 194 181 unset( $_COOKIE[ 'wp-postpass_' . COOKIEHASH] );195 unset( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ); 182 196 183 197 $this->assertNotWPError( $comment ); … … 188 202 public function test_submitting_valid_comment_as_logged_in_user_succeeds() { 189 203 190 $user = self::factory()->user->create_and_get( array( 191 'user_url' => 'http://user.example.org' 192 ) ); 193 194 wp_set_current_user( $user->ID ); 195 196 $post = self::factory()->post->create_and_get(); 197 $data = array( 198 'comment_post_ID' => $post->ID, 199 'comment' => 'Comment', 200 ); 201 $comment = wp_handle_comment_submission( $data ); 202 203 $this->assertNotWPError( $comment ); 204 $this->assertInstanceOf( 'WP_Comment', $comment ); 205 206 $this->assertSame( 'Comment', $comment->comment_content); 204 $user = self::factory()->user->create_and_get( 205 array( 206 'user_url' => 'http://user.example.org', 207 ) 208 ); 209 210 wp_set_current_user( $user->ID ); 211 212 $post = self::factory()->post->create_and_get(); 213 $data = array( 214 'comment_post_ID' => $post->ID, 215 'comment' => 'Comment', 216 ); 217 $comment = wp_handle_comment_submission( $data ); 218 219 $this->assertNotWPError( $comment ); 220 $this->assertInstanceOf( 'WP_Comment', $comment ); 221 222 $this->assertSame( 'Comment', $comment->comment_content ); 207 223 $this->assertSame( $user->display_name, $comment->comment_author ); 208 224 $this->assertSame( $user->user_email, $comment->comment_author_email ); … … 214 230 public function test_submitting_valid_comment_anonymously_succeeds() { 215 231 216 $post = self::factory()->post->create_and_get();217 $data = array(232 $post = self::factory()->post->create_and_get(); 233 $data = array( 218 234 'comment_post_ID' => $post->ID, 219 235 'comment' => 'Comment', 220 236 'author' => 'Comment Author', 221 237 'email' => 'comment@example.org', 222 'url' => 'user.example.org' 223 ); 224 $comment = wp_handle_comment_submission( $data ); 225 226 $this->assertNotWPError( $comment ); 227 $this->assertInstanceOf( 'WP_Comment', $comment ); 228 229 $this->assertSame( 'Comment', $comment->comment_content );238 'url' => 'user.example.org', 239 ); 240 $comment = wp_handle_comment_submission( $data ); 241 242 $this->assertNotWPError( $comment ); 243 $this->assertInstanceOf( 'WP_Comment', $comment ); 244 245 $this->assertSame( 'Comment', $comment->comment_content ); 230 246 $this->assertSame( 'Comment Author', $comment->comment_author ); 231 247 $this->assertSame( 'comment@example.org', $comment->comment_author_email ); … … 242 258 public function test_submitting_comment_handles_slashes_correctly_handles_slashes() { 243 259 244 $post = self::factory()->post->create_and_get();245 $data = array(260 $post = self::factory()->post->create_and_get(); 261 $data = array( 246 262 'comment_post_ID' => $post->ID, 247 263 'comment' => 'Comment with 1 slash: \\', … … 254 270 $this->assertInstanceOf( 'WP_Comment', $comment ); 255 271 256 $this->assertSame( 'Comment with 1 slash: \\', $comment->comment_content );272 $this->assertSame( 'Comment with 1 slash: \\', $comment->comment_content ); 257 273 $this->assertSame( 'Comment Author with 1 slash: \\', $comment->comment_author ); 258 274 $this->assertSame( 'comment@example.org', $comment->comment_author_email ); … … 264 280 $error = 'comment_id_not_found'; 265 281 266 $post = self::factory()->post->create_and_get( array( 267 'post_status' => 'private', 268 ) ); 269 $data = array( 282 $post = self::factory()->post->create_and_get( 283 array( 284 'post_status' => 'private', 285 ) 286 ); 287 $data = array( 270 288 'comment_post_ID' => $post->ID, 271 289 ); … … 280 298 public function test_submitting_comment_as_logged_in_user_to_inaccessible_private_post_returns_error() { 281 299 282 $error = 'comment_id_not_found'; 283 284 $author = self::factory()->user->create_and_get( array( 285 'role' => 'author', 286 ) ); 287 $user = self::factory()->user->create_and_get( array( 288 'role' => 'author', 289 ) ); 290 291 wp_set_current_user( $user->ID ); 292 293 $post = self::factory()->post->create_and_get( array( 294 'post_status' => 'private', 295 'post_author' => $author->ID, 296 ) ); 297 $data = array( 300 $error = 'comment_id_not_found'; 301 302 $author = self::factory()->user->create_and_get( 303 array( 304 'role' => 'author', 305 ) 306 ); 307 $user = self::factory()->user->create_and_get( 308 array( 309 'role' => 'author', 310 ) 311 ); 312 313 wp_set_current_user( $user->ID ); 314 315 $post = self::factory()->post->create_and_get( 316 array( 317 'post_status' => 'private', 318 'post_author' => $author->ID, 319 ) 320 ); 321 $data = array( 298 322 'comment_post_ID' => $post->ID, 299 323 ); … … 308 332 public function test_submitting_comment_to_private_post_with_closed_comments_returns_correct_error() { 309 333 310 $error = 'comment_id_not_found'; 311 312 $author = self::factory()->user->create_and_get( array( 313 'role' => 'author', 314 ) ); 315 $user = self::factory()->user->create_and_get( array( 316 'role' => 'author', 317 ) ); 318 319 wp_set_current_user( $user->ID ); 320 321 $post = self::factory()->post->create_and_get( array( 322 'post_status' => 'private', 323 'post_author' => $author->ID, 324 'comment_status' => 'closed', 325 ) ); 326 $data = array( 334 $error = 'comment_id_not_found'; 335 336 $author = self::factory()->user->create_and_get( 337 array( 338 'role' => 'author', 339 ) 340 ); 341 $user = self::factory()->user->create_and_get( 342 array( 343 'role' => 'author', 344 ) 345 ); 346 347 wp_set_current_user( $user->ID ); 348 349 $post = self::factory()->post->create_and_get( 350 array( 351 'post_status' => 'private', 352 'post_author' => $author->ID, 353 'comment_status' => 'closed', 354 ) 355 ); 356 $data = array( 327 357 'comment_post_ID' => $post->ID, 328 358 ); … … 341 371 wp_set_current_user( $user->ID ); 342 372 343 $post = self::factory()->post->create_and_get( array( 344 'post_status' => 'private', 345 'post_author' => $user->ID, 346 ) ); 347 $data = array( 373 $post = self::factory()->post->create_and_get( 374 array( 375 'post_status' => 'private', 376 'post_author' => $user->ID, 377 ) 378 ); 379 $data = array( 348 380 'comment_post_ID' => $post->ID, 349 381 'comment' => 'Comment', … … 359 391 public function test_submitting_comment_to_accessible_private_post_succeeds() { 360 392 361 $author = self::factory()->user->create_and_get( array( 362 'role' => 'author', 363 ) ); 364 $user = self::factory()->user->create_and_get( array( 365 'role' => 'editor', 366 ) ); 367 368 wp_set_current_user( $user->ID ); 369 370 $post = self::factory()->post->create_and_get( array( 371 'post_status' => 'private', 372 'post_author' => $author->ID, 373 ) ); 374 $data = array( 393 $author = self::factory()->user->create_and_get( 394 array( 395 'role' => 'author', 396 ) 397 ); 398 $user = self::factory()->user->create_and_get( 399 array( 400 'role' => 'editor', 401 ) 402 ); 403 404 wp_set_current_user( $user->ID ); 405 406 $post = self::factory()->post->create_and_get( 407 array( 408 'post_status' => 'private', 409 'post_author' => $author->ID, 410 ) 411 ); 412 $data = array( 375 413 'comment_post_ID' => $post->ID, 376 414 'comment' => 'Comment', … … 386 424 public function test_anonymous_user_cannot_comment_unfiltered_html() { 387 425 388 $post = self::factory()->post->create_and_get();389 $data = array(426 $post = self::factory()->post->create_and_get(); 427 $data = array( 390 428 'comment_post_ID' => $post->ID, 391 429 'comment' => 'Comment <script>alert(document.cookie);</script>', … … 403 441 public function test_unprivileged_user_cannot_comment_unfiltered_html() { 404 442 405 $user = self::factory()->user->create_and_get( array( 406 'role' => 'author', 407 ) ); 443 $user = self::factory()->user->create_and_get( 444 array( 445 'role' => 'author', 446 ) 447 ); 408 448 wp_set_current_user( $user->ID ); 409 449 410 450 $this->assertFalse( current_user_can( 'unfiltered_html' ) ); 411 451 412 $post = self::factory()->post->create_and_get();413 $data = array(452 $post = self::factory()->post->create_and_get(); 453 $data = array( 414 454 'comment_post_ID' => $post->ID, 415 455 'comment' => 'Comment <script>alert(document.cookie);</script>', … … 425 465 public function test_unprivileged_user_cannot_comment_unfiltered_html_even_with_valid_nonce() { 426 466 427 $user = self::factory()->user->create_and_get( array( 428 'role' => 'author', 429 ) ); 467 $user = self::factory()->user->create_and_get( 468 array( 469 'role' => 'author', 470 ) 471 ); 430 472 wp_set_current_user( $user->ID ); 431 473 … … 438 480 $this->assertNotEmpty( wp_verify_nonce( $nonce, $action ) ); 439 481 440 $data = array(482 $data = array( 441 483 'comment_post_ID' => $post->ID, 442 484 'comment' => 'Comment <script>alert(document.cookie);</script>', … … 455 497 $this->assertFalse( defined( 'DISALLOW_UNFILTERED_HTML' ) ); 456 498 457 $user = self::factory()->user->create_and_get( array( 458 'role' => 'editor', 459 ) ); 499 $user = self::factory()->user->create_and_get( 500 array( 501 'role' => 'editor', 502 ) 503 ); 460 504 461 505 if ( is_multisite() ) { … … 475 519 $this->assertNotEmpty( wp_verify_nonce( $nonce, $action ) ); 476 520 477 $data = array(521 $data = array( 478 522 'comment_post_ID' => $post->ID, 479 523 'comment' => 'Comment <script>alert(document.cookie);</script>', … … 490 534 public function test_privileged_user_cannot_comment_unfiltered_html_without_valid_nonce() { 491 535 492 $user = self::factory()->user->create_and_get( array( 493 'role' => 'editor', 494 ) ); 536 $user = self::factory()->user->create_and_get( 537 array( 538 'role' => 'editor', 539 ) 540 ); 495 541 496 542 if ( is_multisite() ) { … … 504 550 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 505 551 506 $post = self::factory()->post->create_and_get();507 $data = array(552 $post = self::factory()->post->create_and_get(); 553 $data = array( 508 554 'comment_post_ID' => $post->ID, 509 555 'comment' => 'Comment <script>alert(document.cookie);</script>', … … 524 570 update_option( 'comment_registration', '1' ); 525 571 526 $post = self::factory()->post->create_and_get();527 $data = array(572 $post = self::factory()->post->create_and_get(); 573 $data = array( 528 574 'comment_post_ID' => $post->ID, 529 575 ); … … 544 590 update_option( 'require_name_email', '1' ); 545 591 546 $post = self::factory()->post->create_and_get();547 $data = array(592 $post = self::factory()->post->create_and_get(); 593 $data = array( 548 594 'comment_post_ID' => $post->ID, 549 595 'comment' => 'Comment', … … 566 612 update_option( 'require_name_email', '1' ); 567 613 568 $post = self::factory()->post->create_and_get();569 $data = array(614 $post = self::factory()->post->create_and_get(); 615 $data = array( 570 616 'comment_post_ID' => $post->ID, 571 617 'comment' => 'Comment', … … 588 634 update_option( 'require_name_email', '1' ); 589 635 590 $post = self::factory()->post->create_and_get();591 $data = array(636 $post = self::factory()->post->create_and_get(); 637 $data = array( 592 638 'comment_post_ID' => $post->ID, 593 639 'comment' => 'Comment', … … 608 654 $error = 'require_valid_comment'; 609 655 610 $post = self::factory()->post->create_and_get();611 $data = array(656 $post = self::factory()->post->create_and_get(); 657 $data = array( 612 658 'comment_post_ID' => $post->ID, 613 659 'comment' => '', … … 630 676 $post = self::factory()->post->create_and_get(); 631 677 632 $data = array(678 $data = array( 633 679 'comment_post_ID' => $post->ID, 634 680 'comment' => rand_long_str( 65536 ), … … 650 696 $post = self::factory()->post->create_and_get(); 651 697 652 $data = array(698 $data = array( 653 699 'comment_post_ID' => $post->ID, 654 700 'comment' => 'Comment', … … 670 716 $post = self::factory()->post->create_and_get(); 671 717 672 $data = array(718 $data = array( 673 719 'comment_post_ID' => $post->ID, 674 720 'comment' => 'Comment', … … 688 734 $error = 'comment_author_url_column_length'; 689 735 690 $post = self::factory()->post->create_and_get();691 $data = array(736 $post = self::factory()->post->create_and_get(); 737 $data = array( 692 738 'comment_post_ID' => $post->ID, 693 739 'comment' => 'Comment', … … 707 753 public function test_comment_submission_sends_all_expected_parameters_to_preprocess_comment_filter() { 708 754 709 $user = self::factory()->user->create_and_get( array( 710 'role' => 'author', 711 ) ); 755 $user = self::factory()->user->create_and_get( 756 array( 757 'role' => 'author', 758 ) 759 ); 712 760 wp_set_current_user( $user->ID ); 713 761 … … 725 773 726 774 $this->assertNotWPError( $comment ); 727 $this->assertEquals( array( 728 'comment_post_ID' => $post->ID, 729 'comment_author' => $user->display_name, 730 'comment_author_email' => $user->user_email, 731 'comment_author_url' => $user->user_url, 732 'comment_content' => $data['comment'], 733 'comment_type' => '', 734 'comment_parent' => '0', 735 'user_ID' => $user->ID, 736 'user_id' => $user->ID, 737 ), $this->preprocess_comment_data ); 775 $this->assertEquals( 776 array( 777 'comment_post_ID' => $post->ID, 778 'comment_author' => $user->display_name, 779 'comment_author_email' => $user->user_email, 780 'comment_author_url' => $user->user_url, 781 'comment_content' => $data['comment'], 782 'comment_type' => '', 783 'comment_parent' => '0', 784 'user_ID' => $user->ID, 785 'user_id' => $user->ID, 786 ), $this->preprocess_comment_data 787 ); 738 788 739 789 } … … 748 798 */ 749 799 public function test_submitting_duplicate_comments() { 750 $post = self::factory()->post->create_and_get( array( 751 'post_status' => 'publish', 752 ) ); 753 $data = array( 800 $post = self::factory()->post->create_and_get( 801 array( 802 'post_status' => 'publish', 803 ) 804 ); 805 $data = array( 754 806 'comment_post_ID' => $post->ID, 755 807 'comment' => 'Did I say that?', … … 757 809 'email' => 'mail@example.com', 758 810 ); 759 $first_comment = wp_handle_comment_submission( $data );811 $first_comment = wp_handle_comment_submission( $data ); 760 812 $second_comment = wp_handle_comment_submission( $data ); 761 813 $this->assertWPError( $second_comment ); … … 767 819 */ 768 820 public function test_comments_flood() { 769 $post = self::factory()->post->create_and_get( array( 770 'post_status' => 'publish', 771 ) ); 772 $data = array( 821 $post = self::factory()->post->create_and_get( 822 array( 823 'post_status' => 'publish', 824 ) 825 ); 826 $data = array( 773 827 'comment_post_ID' => $post->ID, 774 828 'comment' => 'Did I say that?', … … 779 833 780 834 $data['comment'] = 'Wow! I am quick!'; 781 $second_comment = wp_handle_comment_submission( $data );835 $second_comment = wp_handle_comment_submission( $data ); 782 836 783 837 $this->assertWPError( $second_comment ); … … 789 843 */ 790 844 public function test_comments_flood_user_is_admin() { 791 $user = self::factory()->user->create_and_get( array( 792 'role' => 'administrator', 793 ) ); 794 wp_set_current_user( $user->ID ); 795 796 $post = self::factory()->post->create_and_get( array( 797 'post_status' => 'publish', 798 ) ); 799 $data = array( 845 $user = self::factory()->user->create_and_get( 846 array( 847 'role' => 'administrator', 848 ) 849 ); 850 wp_set_current_user( $user->ID ); 851 852 $post = self::factory()->post->create_and_get( 853 array( 854 'post_status' => 'publish', 855 ) 856 ); 857 $data = array( 800 858 'comment_post_ID' => $post->ID, 801 859 'comment' => 'Did I say that?', … … 806 864 807 865 $data['comment'] = 'Wow! I am quick!'; 808 $second_comment = wp_handle_comment_submission( $data );866 $second_comment = wp_handle_comment_submission( $data ); 809 867 810 868 $this->assertNotWPError( $second_comment );
Note: See TracChangeset
for help on using the changeset viewer.