| 598 | * @group bp_blogs_transition_activity_status |
| 599 | * @group bp_blogs_remove_comment |
| 600 | */ |
| 601 | public function test_bp_blogs_remove_comment_should_remove_spammed_activity_comment() { |
| 602 | // save the current user and override logged-in user |
| 603 | $old_user = get_current_user_id(); |
| 604 | $u = $this->factory->user->create(); |
| 605 | $this->set_current_user( $u ); |
| 606 | $userdata = get_userdata( $u ); |
| 607 | |
| 608 | // create the blog post |
| 609 | $post_id = $this->factory->post->create( array( |
| 610 | 'post_status' => 'publish', |
| 611 | 'post_type' => 'post', |
| 612 | 'post_title' => 'First title', |
| 613 | ) ); |
| 614 | |
| 615 | // let's use activity comments instead of single "new_blog_comment" activity items |
| 616 | add_filter( 'bp_disable_blogforum_comments', '__return_false' ); |
| 617 | $c1 = wp_new_comment( array( |
| 618 | 'comment_post_ID' => $post_id, |
| 619 | 'comment_author' => $userdata->user_nicename, |
| 620 | 'comment_author_url' => 'http://buddypress.org', |
| 621 | 'comment_author_email' => $userdata->user_email, |
| 622 | 'comment_content' => 'this is a blog comment', |
| 623 | 'comment_type' => '', |
| 624 | 'comment_parent' => 0, |
| 625 | 'user_id' => $u, |
| 626 | ) ); |
| 627 | |
| 628 | // save the corresponding activity comment ID |
| 629 | $a1 = bp_activity_get_activity_id( array( |
| 630 | 'type' => 'activity_comment', |
| 631 | 'display_comments' => 'stream', |
| 632 | 'meta_query' => array( array( |
| 633 | 'key' => 'bp_blogs_post_comment_id', |
| 634 | 'value' => $c1, |
| 635 | ) ) |
| 636 | ) ); |
| 637 | |
| 638 | // trash the parent comment. |
| 639 | // corresponding activity comment should now be marked as spam |
| 640 | // @see bp_blogs_transition_activity_status() |
| 641 | wp_trash_comment( $c1 ); |
| 642 | |
| 643 | // now permanently delete the comment |
| 644 | wp_delete_comment( $c1, true ); |
| 645 | |
| 646 | // activity comment should no longer exist |
| 647 | $a = bp_activity_get( array( |
| 648 | 'in' => $a1, |
| 649 | 'display_comments' => 'stream', |
| 650 | 'spam' => 'all' |
| 651 | ) ); |
| 652 | // this is a convoluted way of testing if the activity comment still exists |
| 653 | $this->assertTrue( empty( $a['activities'][0] ) ); |
| 654 | |
| 655 | // reset |
| 656 | $this->set_current_user( $old_user ); |
| 657 | remove_filter( 'bp_disable_blogforum_comments', '__return_false' ); |
| 658 | } |
| 659 | |
| 660 | /** |