Skip to:
Content

BuddyPress.org

Changeset 10034


Ignore:
Timestamp:
08/06/2015 02:43:32 PM (10 years ago)
Author:
imath
Message:

Activity comments/Post comments sync: Make sure the activity comment is permanently deleted when the corresponding post comment has been permanently deleted.

Props r-a-y

Fixes #6484

Location:
trunk
Files:
2 edited

Legend:

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

    r10011 r10034  
    10181018                'in'               => $activity_id,
    10191019                'display_comments' => 'stream',
     1020                'spam'             => 'all',
    10201021            ) );
    10211022
  • trunk/tests/phpunit/testcases/blogs/functions.php

    r9819 r10034  
    596596
    597597    /**
     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    /**
    598661     * @group bp_blogs_catch_transition_post_status
    599662     */
Note: See TracChangeset for help on using the changeset viewer.