Skip to:
Content

BuddyPress.org

Ticket #6793: spam-synced.unittests.patch

File spam-synced.unittests.patch, 2.5 KB (added by imath, 9 years ago)
  • tests/phpunit/testcases/activity/actions.php

    diff --git tests/phpunit/testcases/activity/actions.php tests/phpunit/testcases/activity/actions.php
    index d1ae6df..6c4a6b8 100644
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    147147                $bp->activity->track = array();
    148148        }
    149149
     150        /**
     151         * @ticket BP6482
     152         */
     153        public function test_spam_unspam_post_comment_on_activity_comment_spamed_unspamed() {
     154                $old_user = get_current_user_id();
     155                $u = $this->factory->user->create();
     156                $this->set_current_user( $u );
     157                $userdata = get_userdata( $u );
     158
     159                // let's use activity comments instead of single "new_blog_comment" activity items
     160                add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     161
     162                // create the blog post
     163                $post_id = $this->factory->post->create( array(
     164                        'post_status' => 'publish',
     165                        'post_type'   => 'post',
     166                        'post_title'  => 'Test activity comment to post comment',
     167                ) );
     168
     169                // grab the activity ID for the activity comment
     170                $a1 = bp_activity_get_activity_id( array(
     171                        'type'      => 'new_blog_post',
     172                        'component' => buddypress()->blogs->id,
     173                        'filter'    => array(
     174                                'item_id' => get_current_blog_id(),
     175                                'secondary_item_id' => $post_id
     176                        ),
     177                ) );
     178
     179                $a2 = bp_activity_new_comment( array(
     180                        'content'     => 'the generated comment should be spammed/unspammed once the activity comment is spammed/unspammed',
     181                        'user_id'     => $u,
     182                        'activity_id' => $a1,
     183                ) );
     184
     185                $activity = new BP_Activity_Activity( $a2 );
     186
     187                bp_activity_mark_as_spam( $activity );
     188
     189                $post_comments = get_comments( array( 'post_id' => $post_id, 'status' => 'approve' ) );
     190
     191                $this->assertEmpty( $post_comments, 'A post comment should be spammed when the corresponding activity is spammed' );
     192
     193                bp_activity_mark_as_ham( $activity );
     194
     195                $post_comments = get_comments( array( 'post_id' => $post_id, 'status' => 'approve' ) );
     196                $comment = reset( $post_comments );
     197
     198                $this->assertTrue( (int) $comment->comment_ID === (int) bp_activity_get_meta( $a2, 'bp_blogs_post_comment_id' ), 'The comment ID should be in the activity meta' );
     199                $this->assertTrue( (int) $a2 === (int) get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true ), 'The activity ID should be in the comment meta' );
     200
     201                // reset
     202                remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     203
     204                $this->set_current_user( $old_user );
     205        }
     206
    150207        protected function activity_exists_for_post( $post_id, $action ) {
    151208                $a = bp_activity_get( array(
    152209                        'action'            => $action,