Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/10/2023 02:09:10 AM (10 months ago)
Author:
imath
Message:

Make Activity loop reliable when post & activity comments are synced

As the $action key of the bp_has_activities() function arguments array accepts a string, a boolean as well as an array, we need to make sure the bp_blogs_new_blog_comment_query_backpat() function doesn't trigger an error when an array of activity type is passed.

Props btwebdesign, magland, teeboy4real

Fixes #9010
Closes https://github.com/buddypress/buddypress/pull/190

File:
1 edited

Legend:

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

    r13342 r13642  
    618618
    619619    /**
     620     * @ticket BP9010
     621     * @group post_type_comment_activities
     622     */
     623    public function test_bp_blogs_new_blog_comment_query_backpat() {
     624        $old_user = get_current_user_id();
     625        $u        = self::factory()->user->create();
     626        $reset_at = isset( $GLOBALS['activities_template'] ) ? $GLOBALS['activities_template'] : null;
     627
     628        $this->set_current_user( $u );
     629
     630        // let's use activity comments instead of single "new_blog_comment" activity items
     631        add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     632
     633        // create the blog post
     634        $post_id = self::factory()->post->create(
     635            array(
     636                'post_status' => 'publish',
     637                'post_type'   => 'post',
     638                'post_title'  => 'Test new_blog_comment_query_backpat',
     639            )
     640        );
     641
     642        // Grab the activity ID for the activity comment.
     643        $a = bp_activity_get_activity_id(
     644            array(
     645                'type'      => 'new_blog_post',
     646                'component' => buddypress()->blogs->id,
     647                'filter'    => array(
     648                    'item_id'           => get_current_blog_id(),
     649                    'secondary_item_id' => $post_id
     650                ),
     651            )
     652        );
     653
     654        $c = bp_activity_new_comment(
     655            array(
     656                'content'     => 'this activity should have the `new_blog_comment` type',
     657                'user_id'     => $u,
     658                'activity_id' => $a,
     659            )
     660        );
     661
     662        // Check activity is fetch.
     663        bp_has_activities(
     664            array(
     665                'action' => 'new_blog_comment',
     666            )
     667        );
     668
     669        $ids = wp_list_pluck( $GLOBALS['activities_template']->activities, 'id' );
     670        $this->assertEquals( array( $c ), $ids );
     671
     672        // Reset.
     673        remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     674        $GLOBALS['activities_template'] = $reset_at;
     675        $this->set_current_user( $old_user );
     676    }
     677
     678    /**
     679     * @ticket BP9010
     680     * @group post_type_comment_activities
     681     */
     682    public function test_bp_blogs_new_blog_comment_query_backpat_with_array_of_actions() {
     683        $old_user = get_current_user_id();
     684        $u        = self::factory()->user->create();
     685        $reset_at = isset( $GLOBALS['activities_template'] ) ? $GLOBALS['activities_template'] : null;
     686
     687        $this->set_current_user( $u );
     688
     689        // let's use activity comments instead of single "new_blog_comment" activity items
     690        add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     691
     692        // create the blog post
     693        $post_id = self::factory()->post->create(
     694            array(
     695                'post_status' => 'publish',
     696                'post_type'   => 'post',
     697                'post_title'  => 'Test new_blog_comment_query_backpat with an array',
     698            )
     699        );
     700
     701        // Grab the activity ID for the activity comment.
     702        $a = bp_activity_get_activity_id(
     703            array(
     704                'type'      => 'new_blog_post',
     705                'component' => buddypress()->blogs->id,
     706                'filter'    => array(
     707                    'item_id'           => get_current_blog_id(),
     708                    'secondary_item_id' => $post_id
     709                ),
     710            )
     711        );
     712
     713        $c = bp_activity_new_comment(
     714            array(
     715                'content'     => 'Check no fatal error is triggered!',
     716                'user_id'     => $u,
     717                'activity_id' => $a,
     718            )
     719        );
     720
     721        // Check no fatal error is triggered.
     722        bp_has_activities(
     723            array(
     724                'action' => array( 'new_blog_comment', 'new_blog_comment' ),
     725            )
     726        );
     727
     728        $this->assertEmpty( $GLOBALS['activities_template']->activities );
     729
     730        // Reset.
     731        remove_filter( 'bp_disable_blogforum_comments', '__return_false' );
     732        $GLOBALS['activities_template'] = $reset_at;
     733        $this->set_current_user( $old_user );
     734    }
     735
     736    /**
    620737     * Dopey passthrough method so we can check that the correct values
    621738     * are being passed to the filter
Note: See TracChangeset for help on using the changeset viewer.