Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/04/2018 08:43:08 PM (7 years ago)
Author:
boonebgorges
Message:

Introduce BP_Groups_Member::get_user_memberships().

This is a new low-level query method that allows a single syntax for fetching
a paginated set of results from the membership table, for different
values of is_pending, etc. Primarily for use in data exporters; see #7820.

Fixes #7859.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/groups/class-bp-groups-member.php

    r11737 r12162  
    55 */
    66class BP_Tests_BP_Groups_Member_TestCases extends BP_UnitTestCase {
     7    static public $user_ids;
     8    static public $group_ids;
     9
     10    public static function wpSetUpBeforeClass( $factory ) {
     11        global $wpdb, $bp;
     12        self::$user_ids  = $factory->user->create_many( 4 );
     13        self::$group_ids = $factory->group->create_many( 3, array(
     14            'creator_id' => self::$user_ids[3],
     15        ) );
     16    }
     17
     18    public static function wpTearDownAfterClass() {
     19        array_map( array( __CLASS__, 'delete_user' ), self::$user_ids );
     20        array_map( 'groups_delete_group', self::$group_ids );
     21    }
     22
    723    public static function invite_user_to_group( $user_id, $group_id, $inviter_id ) {
    824        $invite                = new BP_Groups_Member;
     
    13721388        $this->assertTrue( is_array( $admins ) && empty( $admins ) );
    13731389    }
     1390
     1391    /**
     1392     * @ticket BP7859
     1393     */
     1394    public function test_get_user_memberships_type_membership() {
     1395        groups_join_group( self::$group_ids[0], self::$user_ids[0] );
     1396
     1397        $memberships = BP_Groups_Member::get_user_memberships( self::$user_ids[0], array(
     1398            'type' => 'membership',
     1399        ) );
     1400
     1401        $this->assertCount( 1, $memberships );
     1402        $this->assertSame( self::$group_ids[0], $memberships[0]->group_id );
     1403    }
     1404
     1405    /**
     1406     * @ticket BP7859
     1407     */
     1408    public function test_get_user_memberships_type_pending_request() {
     1409        groups_join_group( self::$group_ids[0], self::$user_ids[0] );
     1410        groups_send_membership_request( self::$user_ids[0], self::$group_ids[1] );
     1411
     1412        $memberships = BP_Groups_Member::get_user_memberships( self::$user_ids[0], array(
     1413            'type' => 'pending_request',
     1414        ) );
     1415
     1416        $this->assertCount( 1, $memberships );
     1417        $this->assertSame( self::$group_ids[1], $memberships[0]->group_id );
     1418    }
     1419
     1420    /**
     1421     * @ticket BP7859
     1422     */
     1423    public function test_get_user_memberships_type_pending_received_invitation() {
     1424        groups_join_group( self::$group_ids[0], self::$user_ids[0] );
     1425        groups_invite_user( array(
     1426            'user_id'    => self::$user_ids[0],
     1427            'group_id'   => self::$group_ids[1],
     1428            'inviter_id' => self::$user_ids[1],
     1429        ) );
     1430
     1431        $memberships = BP_Groups_Member::get_user_memberships( self::$user_ids[0], array(
     1432            'type' => 'pending_received_invitation',
     1433        ) );
     1434
     1435        $this->assertCount( 1, $memberships );
     1436        $this->assertSame( self::$group_ids[1], $memberships[0]->group_id );
     1437    }
     1438
     1439    /**
     1440     * @ticket BP7859
     1441     */
     1442    public function test_get_user_memberships_type_pending_sent_invitation() {
     1443        groups_join_group( self::$group_ids[0], self::$user_ids[0] );
     1444        groups_invite_user( array(
     1445            'user_id'    => self::$user_ids[1],
     1446            'group_id'   => self::$group_ids[1],
     1447            'inviter_id' => self::$user_ids[0],
     1448        ) );
     1449
     1450        $memberships = BP_Groups_Member::get_user_memberships( self::$user_ids[0], array(
     1451            'type' => 'pending_sent_invitation',
     1452        ) );
     1453
     1454        $this->assertCount( 1, $memberships );
     1455        $this->assertSame( self::$group_ids[1], $memberships[0]->group_id );
     1456    }
    13741457}
Note: See TracChangeset for help on using the changeset viewer.