| | 677 | * @group bp_blogs_sync_activity_edit_to_post_comment |
| | 678 | * @group post_type_comment_activities |
| | 679 | */ |
| | 680 | public function test_spammed_activity_comment_should_not_create_post_comment() { |
| | 681 | $old_user = get_current_user_id(); |
| | 682 | $u = $this->factory->user->create(); |
| | 683 | $this->set_current_user( $u ); |
| | 684 | $userdata = get_userdata( $u ); |
| | 685 | |
| | 686 | // let's use activity comments instead of single "new_blog_comment" activity items. |
| | 687 | add_filter( 'bp_disable_blogforum_comments', '__return_false' ); |
| | 688 | |
| | 689 | // create the blog post. |
| | 690 | $post_id = $this->factory->post->create( array( |
| | 691 | 'post_status' => 'publish', |
| | 692 | 'post_type' => 'post', |
| | 693 | 'post_title' => 'Test activity comment to post comment', |
| | 694 | ) ); |
| | 695 | |
| | 696 | // Grab the activity ID for the activity comment. |
| | 697 | $a1 = bp_activity_get_activity_id( array( |
| | 698 | 'type' => 'new_blog_post', |
| | 699 | 'component' => buddypress()->blogs->id, |
| | 700 | 'filter' => array( |
| | 701 | 'item_id' => get_current_blog_id(), |
| | 702 | 'secondary_item_id' => $post_id |
| | 703 | ), |
| | 704 | ) ); |
| | 705 | |
| | 706 | // Update 'Comment blacklist' section to include some words we want to block. |
| | 707 | update_option( 'blacklist_keys', 'yolo' ); |
| | 708 | |
| | 709 | // Create spammed activity comment. |
| | 710 | $a2 = bp_activity_new_comment( array( |
| | 711 | 'content' => 'this activity comment shoud not be created as a new post comment. yolo.', |
| | 712 | 'user_id' => $u, |
| | 713 | 'activity_id' => $a1, |
| | 714 | ) ); |
| | 715 | |
| | 716 | // Grab post comments. |
| | 717 | $approved_comments = get_approved_comments( $post_id ); |
| | 718 | $comment = reset( $approved_comments ); |
| | 719 | |
| | 720 | // Assert that post comment wasn't created. |
| | 721 | $this->assertEmpty( $comment ); |
| | 722 | |
| | 723 | // Reset. |
| | 724 | remove_filter( 'bp_disable_blogforum_comments', '__return_false' ); |
| | 725 | update_option( 'blacklist_keys', '' ); |
| | 726 | |
| | 727 | $this->set_current_user( $old_user ); |
| | 728 | } |
| | 729 | |
| | 730 | /** |