Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/06/2022 10:31:49 PM (17 months ago)
Author:
imath
Message:

Activity introduce 2 new parameters to BP_Activity_Activity::get()`

  • The user_id__in parameter makes it possible to retrieve activities for

a list of user IDs.

  • The user_id__not_in parameter makes it possible to exclude activity

posted by a list of user IDs from retrieved activities.

Props username_, slaFFik, boonebgorges

Fixes #4184

File:
1 edited

Legend:

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

    r13150 r13337  
    413413    /**
    414414     * @group get
     415     */
     416    public function test_get_with_user_id__in() {
     417        $u1 = self::factory()->user->create();
     418        $u2 = self::factory()->user->create();
     419        $u3 = self::factory()->user->create();
     420        $a1 = self::factory()->activity->create( array( 'user_id' => $u1 ) );
     421        $a2 = self::factory()->activity->create( array( 'user_id' => $u2 ) );
     422        $a3 = self::factory()->activity->create( array( 'user_id' => $u3 ) );
     423
     424        $activities = BP_Activity_Activity::get( array(
     425            'user_id__in' => array( $u1, $u2 ),
     426        ) );
     427
     428        $ids = wp_list_pluck( $activities['activities'], 'id' );
     429        sort( $ids );
     430        $this->assertEquals( array( $a1, $a2 ), $ids );
     431    }
     432
     433    /**
     434     * @group get
     435     */
     436    public function test_get_with_user_id__not_in() {
     437        $u1 = self::factory()->user->create();
     438        $u2 = self::factory()->user->create();
     439        $u3 = self::factory()->user->create();
     440        $a1 = self::factory()->activity->create( array( 'user_id' => $u1 ) );
     441        $a2 = self::factory()->activity->create( array( 'user_id' => $u2 ) );
     442        $a3 = self::factory()->activity->create( array( 'user_id' => $u3 ) );
     443
     444        $activities = BP_Activity_Activity::get( array(
     445            'user_id__not_in' => array( $u2, $u3 ),
     446        ) );
     447
     448        $ids = wp_list_pluck( $activities['activities'], 'id' );
     449        $this->assertEquals( array( $a1 ), $ids );
     450    }
     451
     452    /**
     453     * @group get
     454     */
     455    public function test_get_with_user_id__in_andnot_in() {
     456        $u1 = self::factory()->user->create();
     457        $u2 = self::factory()->user->create();
     458        $u3 = self::factory()->user->create();
     459        $u4 = self::factory()->user->create();
     460        $u5 = self::factory()->user->create();
     461        $a1 = self::factory()->activity->create( array( 'user_id' => $u1 ) );
     462        $a2 = self::factory()->activity->create( array( 'user_id' => $u2 ) );
     463        $a3 = self::factory()->activity->create( array( 'user_id' => $u3 ) );
     464        $a4 = self::factory()->activity->create( array( 'user_id' => $u4 ) );
     465        $a5 = self::factory()->activity->create( array( 'user_id' => $u5 ) );
     466
     467        $activities = BP_Activity_Activity::get( array(
     468            'user_id__in'     => array( $u1, $u2, $u4, $u5 ),
     469            'user_id__not_in' => array( $u4, $u5 ),
     470        ) );
     471
     472        $ids = wp_list_pluck( $activities['activities'], 'id' );
     473        sort( $ids );
     474        $this->assertEquals( array( $a1, $a2 ), $ids );
     475    }
     476
     477    /**
     478     * @group get
    415479     * @group count_total
    416480     */
Note: See TracChangeset for help on using the changeset viewer.