Skip to:
Content

BuddyPress.org

Changeset 10854


Ignore:
Timestamp:
06/01/2016 05:02:06 PM (8 years ago)
Author:
r-a-y
Message:

Blogs: Do not create a post comment if the related activity comment is marked as spam.

Props hnla, r-a-y.

Fixes #7107.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-activity.php

    r10853 r10854  
    752752    }
    753753
     754    // Do not sync if the activity comment was marked as spam.
     755    $activity = new BP_Activity_Activity( $comment_id );
     756    if ( $activity->is_spam ) {
     757        return;
     758    }
     759
    754760    // Get userdata.
    755761    if ( $params['user_id'] == bp_loggedin_user_id() ) {
  • trunk/tests/phpunit/testcases/blogs/activity.php

    r10545 r10854  
    675675
    676676    /**
     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    /**
    677731     * Dopey passthrough method so we can check that the correct values
    678732     * are being passed to the filter
Note: See TracChangeset for help on using the changeset viewer.