Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/07/2016 04:55:04 PM (9 years ago)
Author:
imath
Message:

Post Type Activities: add unit tests and improve existing ones.

See #6482
Fixes #6128

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/blogs/activity.php

    r9819 r10545  
    157157     * @group activity_action
    158158     * @group bp_blogs_format_activity_action_new_blog_comment
     159     * @group post_type_comment_activities
    159160     */
    160161    public function test_bp_blogs_format_activity_action_new_blog_comment_ms_nonrootblog() {
     
    319320        }
    320321
    321         $bp = buddypress();
    322         $activity_actions = $bp->activity->actions;
    323         $bp->activity->actions = new stdClass();
     322        buddypress()->activity->actions = new stdClass();
    324323
    325324        $u = $this->factory->user->create();
     
    347346
    348347        $this->assertSame( $expected, $a_obj['activities'][0]->action );
    349 
    350         // Reset activity actions
    351         $bp->activity->actions = $activity_actions;
    352         $bp->activity->track = array();
    353348    }
    354349
     
    362357        }
    363358
    364         $bp = buddypress();
    365         $activity_actions = $bp->activity->actions;
    366         $bp->activity->actions = new stdClass();
     359        buddypress()->activity->actions = new stdClass();
    367360
    368361        $u = $this->factory->user->create();
     
    408401
    409402        $this->assertSame( $expected, $a_obj['activities'][0]->action );
    410 
    411         // Reset activity actions
    412         $bp->activity->actions = $activity_actions;
    413         $bp->activity->track = array();
     403    }
     404
     405    /**
     406     * @group bp_blogs_sync_add_from_activity_comment
     407     * @group post_type_comment_activities
     408     */
     409    public function test_bp_blogs_sync_add_from_activity_comment() {
     410        $old_user = get_current_user_id();
     411        $u = $this->factory->user->create();
     412        $this->set_current_user( $u );
     413        $userdata = get_userdata( $u );
     414
     415        // let's use activity comments instead of single "new_blog_comment" activity items
     416        add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     417
     418        // create the blog post
     419        $post_id = $this->factory->post->create( array(
     420            'post_status' => 'publish',
     421            'post_type'   => 'post',
     422            'post_title'  => 'Test activity comment to post comment',
     423        ) );
     424
     425        // grab the activity ID for the activity comment
     426        $a1 = bp_activity_get_activity_id( array(
     427            'type'      => 'new_blog_post',
     428            'component' => buddypress()->blogs->id,
     429            'filter'    => array(
     430                'item_id' => get_current_blog_id(),
     431                'secondary_item_id' => $post_id
     432            ),
     433        ) );
     434
     435        $a2 = bp_activity_new_comment( array(
     436            'content'     => 'this content shoud be in a new post comment',
     437            'user_id'     => $u,
     438            'activity_id' => $a1,
     439        ) );
     440
     441        $approved_comments = get_approved_comments( $post_id );
     442        $comment = reset( $approved_comments );
     443
     444        $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' );
     445        $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' );
     446
     447        // reset
     448        remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     449
     450        $this->set_current_user( $old_user );
     451    }
     452
     453    /**
     454     * @group bp_blogs_sync_delete_from_activity_comment
     455     * @group post_type_comment_activities
     456     */
     457    public function test_bp_blogs_sync_delete_from_activity_comment() {
     458        $old_user = get_current_user_id();
     459        $u = $this->factory->user->create();
     460        $this->set_current_user( $u );
     461        $userdata = get_userdata( $u );
     462
     463        // let's use activity comments instead of single "new_blog_comment" activity items
     464        add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     465
     466        // create the blog post
     467        $post_id = $this->factory->post->create( array(
     468            'post_status' => 'publish',
     469            'post_type'   => 'post',
     470            'post_title'  => 'Test activity comment to post comment',
     471        ) );
     472
     473        // grab the activity ID for the activity comment
     474        $a1 = bp_activity_get_activity_id( array(
     475            'type'      => 'new_blog_post',
     476            'component' => buddypress()->blogs->id,
     477            'filter'    => array(
     478                'item_id' => get_current_blog_id(),
     479                'secondary_item_id' => $post_id
     480            ),
     481        ) );
     482
     483        $a2 = bp_activity_new_comment( array(
     484            'content'     => 'the generated comment should be deleted once the activity comment is removed',
     485            'user_id'     => $u,
     486            'activity_id' => $a1,
     487        ) );
     488
     489        bp_activity_delete_comment( $a1, $a2 );
     490
     491        $post_comments = get_comments( array( 'post_id' => $post_id ) );
     492
     493        $this->assertEmpty( $post_comments, 'A post comment should be deleted when the corresponding activity is' );
     494
     495        // reset
     496        remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     497
     498        $this->set_current_user( $old_user );
     499    }
     500
     501    /**
     502     * @group bp_blogs_sync_activity_edit_to_post_comment
     503     * @group post_type_comment_activities
     504     */
     505    public function test_bp_blogs_sync_activity_edit_to_post_comment_spam_unspam_activity_comment() {
     506        $old_user = get_current_user_id();
     507        $u = $this->factory->user->create();
     508        $this->set_current_user( $u );
     509        $userdata = get_userdata( $u );
     510
     511        // let's use activity comments instead of single "new_blog_comment" activity items
     512        add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     513
     514        // create the blog post
     515        $post_id = $this->factory->post->create( array(
     516            'post_status' => 'publish',
     517            'post_type'   => 'post',
     518            'post_title'  => 'Test activity comment to post comment',
     519        ) );
     520
     521        // grab the activity ID for the activity comment
     522        $a1 = bp_activity_get_activity_id( array(
     523            'type'      => 'new_blog_post',
     524            'component' => buddypress()->blogs->id,
     525            'filter'    => array(
     526                'item_id' => get_current_blog_id(),
     527                'secondary_item_id' => $post_id
     528            ),
     529        ) );
     530
     531        $a2 = bp_activity_new_comment( array(
     532            'content'     => 'the generated comment should be spamed/unspamed once the activity comment is spamed/unspamed',
     533            'user_id'     => $u,
     534            'activity_id' => $a1,
     535        ) );
     536
     537        $activity = new BP_Activity_Activity( $a2 );
     538
     539        bp_activity_mark_as_spam( $activity );
     540        $activity->save();
     541
     542        $post_comments = get_comments( array( 'post_id' => $post_id, 'status' => 'approve' ) );
     543
     544        $this->assertEmpty( $post_comments, 'A post comment should be spammed when the corresponding activity is spammed' );
     545
     546        bp_activity_mark_as_ham( $activity );
     547        $activity->save();
     548
     549        $post_comments = get_comments( array( 'post_id' => $post_id, 'status' => 'approve' ) );
     550        $comment = reset( $post_comments );
     551
     552        $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' );
     553        $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' );
     554
     555        // reset
     556        remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     557
     558        $this->set_current_user( $old_user );
     559    }
     560
     561    /**
     562     * @group bp_blogs_sync_activity_edit_to_post_comment
     563     * @group post_type_comment_activities
     564     */
     565    public function test_bp_blogs_sync_activity_edit_to_post_comment_spam_activity_comment_unspam_post_comment() {
     566        $old_user = get_current_user_id();
     567        $u = $this->factory->user->create();
     568        $this->set_current_user( $u );
     569        $userdata = get_userdata( $u );
     570
     571        // let's use activity comments instead of single "new_blog_comment" activity items
     572        add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     573
     574        // create the blog post
     575        $post_id = $this->factory->post->create( array(
     576            'post_status' => 'publish',
     577            'post_type'   => 'post',
     578            'post_title'  => 'Test activity comment to post comment',
     579        ) );
     580
     581        // grab the activity ID for the activity comment
     582        $a1 = bp_activity_get_activity_id( array(
     583            'type'      => 'new_blog_post',
     584            'component' => buddypress()->blogs->id,
     585            'filter'    => array(
     586                'item_id' => get_current_blog_id(),
     587                'secondary_item_id' => $post_id
     588            ),
     589        ) );
     590
     591        $a2 = bp_activity_new_comment( array(
     592            'content'     => 'the generated comment should be spamed/unspamed once the activity comment is spamed/unspamed',
     593            'user_id'     => $u,
     594            'activity_id' => $a1,
     595        ) );
     596
     597        $c = bp_activity_get_meta( $a2, 'bp_blogs_post_comment_id' );
     598
     599        $activity = new BP_Activity_Activity( $a2 );
     600
     601        bp_activity_mark_as_spam( $activity );
     602        $activity->save();
     603
     604        wp_unspam_comment( $c );
     605
     606        $post_comments = get_comments( array( 'post_id' => $post_id, 'status' => 'approve' ) );
     607        $comment = reset( $post_comments );
     608
     609        $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' );
     610        $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' );
     611
     612        // reset
     613        remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     614
     615        $this->set_current_user( $old_user );
     616    }
     617
     618    /**
     619     * @group bp_blogs_sync_activity_edit_to_post_comment
     620     * @group post_type_comment_activities
     621     * @group imath
     622     */
     623    public function test_bp_blogs_sync_activity_edit_to_post_comment_trash_comment_ham_activity() {
     624        $old_user = get_current_user_id();
     625        $u = $this->factory->user->create();
     626        $this->set_current_user( $u );
     627        $userdata = get_userdata( $u );
     628
     629        // let's use activity comments instead of single "new_blog_comment" activity items
     630        add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     631
     632        // create the blog post
     633        $post_id = $this->factory->post->create( array(
     634            'post_status' => 'publish',
     635            'post_type'   => 'post',
     636            'post_title'  => 'Test activity comment to post comment',
     637        ) );
     638
     639        // grab the activity ID for the activity comment
     640        $a1 = bp_activity_get_activity_id( array(
     641            'type'      => 'new_blog_post',
     642            'component' => buddypress()->blogs->id,
     643            'filter'    => array(
     644                'item_id' => get_current_blog_id(),
     645                'secondary_item_id' => $post_id
     646            ),
     647        ) );
     648
     649        $a2 = bp_activity_new_comment( array(
     650            'content'     => 'the generated comment should be spamed/unspamed once the activity comment is spamed/unspamed',
     651            'user_id'     => $u,
     652            'activity_id' => $a1,
     653        ) );
     654
     655        $c = bp_activity_get_meta( $a2, 'bp_blogs_post_comment_id' );
     656
     657        wp_trash_comment( $c );
     658
     659        $activity = new BP_Activity_Activity( $a2 );
     660
     661        bp_activity_mark_as_ham( $activity );
     662        $activity->save();
     663
     664        $post_comments = get_comments( array( 'post_id' => $post_id, 'status' => 'approve' ) );
     665        $comment = reset( $post_comments );
     666
     667        $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' );
     668        $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' );
     669
     670        // reset
     671        remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     672
     673        $this->set_current_user( $old_user );
    414674    }
    415675
Note: See TracChangeset for help on using the changeset viewer.