Skip to:
Content

BuddyPress.org

Changeset 9797


Ignore:
Timestamp:
04/24/2015 03:20:20 PM (9 years ago)
Author:
dcavins
Message:

Passing tests for group membership

Tests for groups_reject_membership_request(),
groups_delete_membership_request(), groups_reject_invite(),
groups_delete_invite(), groups_uninvite_user(), groups_join_group(),
groups_leave_group(), groups_get_invites_for_user(),
groups_get_invite_count_for_user(), groups_send_invites(),
groups_accept_invite(), groups_delete_all_group_invites(),
groups_send_membership_request(), groups_accept_membership_request(),
groups_accept_all_pending_membership_requests()

File:
1 edited

Legend:

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

    r9561 r9797  
    1818    }
    1919
     20    public static function create_group_membership_request( $user_id, $group_id ) {
     21        $request                = new BP_Groups_Member;
     22        $request->group_id      = $group_id;
     23        $request->user_id       = $user_id;
     24        $request->date_modified = bp_core_current_time();
     25        $request->inviter_id    = 0;
     26        $request->is_confirmed  = 0;
     27
     28        $request->save();
     29        return $request->id;
     30    }
     31
    2032    public function test_get_recently_joined_with_filter() {
    2133        $g1 = $this->factory->group->create( array(
     
    216228        $this->set_current_user( $old_current_user );
    217229    }
     230
     231    /**
     232     * @group groups_reject_membership_request
     233     * @group group_membership_requests
     234     * @group group_membership
     235     */
     236    public function test_bp_groups_reject_membership_request_remove_request() {
     237        $u1 = $this->factory->user->create();
     238        $g = $this->factory->group->create( array(
     239            'status' => 'private',
     240        ) );
     241
     242        // Membership requests should be removed.
     243        self::create_group_membership_request( $u1, $g );
     244        groups_reject_membership_request( null, $u1, $g );
     245        $u1_has_request = groups_check_for_membership_request( $u1, $g );
     246        $this->assertEquals( 0, $u1_has_request );
     247    }
     248
     249    /**
     250     * @group groups_delete_membership_request
     251     * @group group_membership_requests
     252     * @group group_membership
     253     */
     254    public function test_bp_groups_delete_membership_request_remove_request() {
     255        $u1 = $this->factory->user->create();
     256        $g = $this->factory->group->create( array(
     257            'status' => 'private',
     258        ) );
     259
     260        // Membership requests should be removed.
     261        self::create_group_membership_request( $u1, $g );
     262        groups_delete_membership_request( null, $u1, $g );
     263        $u1_has_request = groups_check_for_membership_request( $u1, $g );
     264        $this->assertEquals( 0, $u1_has_request );
     265    }
     266
     267    /**
     268     * @group groups_reject_invite
     269     * @group group_invitations
     270     * @group group_membership
     271     */
     272    public function test_bp_groups_reject_invite_remove_invite() {
     273        $u1 = $this->factory->user->create();
     274        $u2 = $this->factory->user->create();
     275        $g = $this->factory->group->create( array(
     276            'status' => 'private',
     277        ) );
     278
     279        $now = time();
     280        $this->add_user_to_group( $u1, $g, array(
     281            'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
     282        ) );
     283
     284        // The invitation should be removed.
     285        self::invite_user_to_group( $u2, $g, $u1 );
     286        groups_reject_invite( $u2, $g );
     287        $u2_has_invite = groups_check_user_has_invite( $u2, $g );
     288        $this->assertEquals( 0, $u2_has_invite );
     289    }
     290
     291    /**
     292     * @group groups_delete_invite
     293     * @group group_invitations
     294     * @group group_membership
     295     */
     296    public function test_bp_groups_delete_invite_remove_invite() {
     297        $u1 = $this->factory->user->create();
     298        $u2 = $this->factory->user->create();
     299        $g = $this->factory->group->create( array(
     300            'status' => 'private',
     301        ) );
     302
     303        $now = time();
     304        $this->add_user_to_group( $u1, $g, array(
     305            'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
     306        ) );
     307
     308        // The invitation should be removed.
     309        self::invite_user_to_group( $u2, $g, $u1 );
     310        groups_delete_invite( $u2, $g );
     311        $u2_has_invite = groups_check_user_has_invite( $u2, $g );
     312        $this->assertEquals( 0, $u2_has_invite );
     313    }
     314
     315    /**
     316     * @group groups_delete_invite
     317     * @group group_invitations
     318     * @group group_membership
     319     */
     320    public function test_bp_groups_delete_invite_leave_memberships_intact() {
     321        $u1 = $this->factory->user->create();
     322        $g = $this->factory->group->create( array(
     323            'status' => 'private',
     324        ) );
     325
     326        $now = time();
     327        $this->add_user_to_group( $u1, $g, array(
     328            'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
     329        ) );
     330
     331        groups_delete_invite( $u1, $g );
     332        $u1_is_member = groups_is_user_member( $u1, $g );
     333        $this->assertTrue( is_numeric( $u1_is_member ) && $u1_is_member > 0 );
     334    }
     335
     336    /**
     337     * @group groups_delete_invite
     338     * @group group_invitations
     339     * @group group_membership
     340     */
     341    public function test_bp_groups_delete_invite_leave_requests_intact() {
     342        $u1 = $this->factory->user->create();
     343        $g = $this->factory->group->create( array(
     344            'status' => 'private',
     345        ) );
     346
     347        // Membership requests should be left intact.
     348        self::create_group_membership_request( $u1, $g );
     349        groups_delete_invite( $u1, $g );
     350        $u1_has_request = groups_check_for_membership_request( $u1, $g );
     351        $this->assertTrue( is_numeric( $u1_has_request ) && $u1_has_request > 0 );
     352    }
     353
     354    /**
     355     * @group groups_uninvite_user
     356     * @group group_invitations
     357     * @group group_membership
     358     */
     359    public function test_bp_groups_uninvite_user_remove_invite() {
     360        $u1 = $this->factory->user->create();
     361        $u2 = $this->factory->user->create();
     362        $g = $this->factory->group->create( array(
     363            'status' => 'private',
     364        ) );
     365
     366        $now = time();
     367        $this->add_user_to_group( $u1, $g, array(
     368            'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
     369        ) );
     370
     371        // The invitation should be removed.
     372        self::invite_user_to_group( $u2, $g, $u1 );
     373        groups_uninvite_user( $u2, $g );
     374        $u2_has_invite = groups_check_user_has_invite( $u2, $g );
     375        $this->assertEquals( 0, $u2_has_invite );
     376    }
     377
     378    /**
     379     * @group groups_join_group
     380     * @group group_membership
     381     */
     382    public function test_groups_join_group_basic_join() {
     383        $u1 = $this->factory->user->create();
     384        $g = $this->factory->group->create();
     385
     386        groups_join_group( $g, $u1 );
     387        $membership_id = groups_is_user_member( $u1, $g );
     388        $this->assertTrue( is_numeric( $membership_id ) && $membership_id > 0 );
     389    }
     390
     391    /**
     392     * @group groups_join_group
     393     * @group group_membership
     394     */
     395    public function test_groups_join_group_basic_join_use_current_user() {
     396        $u1 = $this->factory->user->create();
     397        $g = $this->factory->group->create();
     398        $old_current_user = get_current_user_id();
     399        $this->set_current_user( $u1 );
     400
     401        groups_join_group( $g );
     402        $membership_id = groups_is_user_member( $u1, $g );
     403        $this->assertTrue( is_numeric( $membership_id ) && $membership_id > 0 );
     404        $this->set_current_user( $old_current_user );
     405    }
     406
     407    /**
     408     * @group groups_join_group
     409     * @group group_membership
     410     */
     411    public function test_groups_join_group_already_member() {
     412        $u1 = $this->factory->user->create();
     413        $g = $this->factory->group->create();
     414        $this->add_user_to_group( $u1, $g );
     415
     416        $this->assertTrue( groups_join_group( $g, $u1 ) );
     417    }
     418
     419    /**
     420     * @group groups_join_group
     421     * @group group_membership
     422     */
     423    public function test_groups_join_group_cleanup_invites() {
     424        $u1 = $this->factory->user->create();
     425        $u2 = $this->factory->user->create();
     426        $g = $this->factory->group->create();
     427        $this->add_user_to_group( $u1, $g );
     428
     429        $m1 = new BP_Groups_Member( $u1, $g );
     430        $m1->promote( 'admin' );
     431
     432        self::invite_user_to_group( $u2, $g, $u1 );
     433
     434        groups_join_group( $g, $u2 );
     435        // Upon joining the group, outstanding invitations should be cleaned up.
     436        $this->assertEquals( null, groups_check_user_has_invite( $u2, $g, 'any' ) );
     437    }
     438
     439    /**
     440     * @group groups_join_group
     441     * @group group_membership
     442     */
     443    public function test_groups_join_group_cleanup_requests() {
     444        $u1 = $this->factory->user->create();
     445        $g = $this->factory->group->create();
     446        self::create_group_membership_request( $u1, $g );
     447
     448        groups_join_group( $g, $u1 );
     449        // Upon joining the group, outstanding requests should be cleaned up.
     450        $this->assertEquals( null, groups_check_for_membership_request( $u1, $g ) );
     451    }
     452
     453    /**
     454     * @group groups_leave_group
     455     * @group group_membership
     456     */
     457    public function test_groups_leave_group_basic_leave_self_initiated() {
     458        $old_current_user = get_current_user_id();
     459        $u1 = $this->factory->user->create();
     460        $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     461        $u2 = $this->factory->user->create();
     462        $this->add_user_to_group( $u2, $g );
     463
     464        $before = groups_get_total_member_count( $g );
     465        $this->set_current_user( $u2 );
     466        groups_leave_group( $g, $u2 );
     467        $after = groups_get_total_member_count( $g );
     468
     469        $this->assertEquals( $before - 1, $after );
     470        $this->set_current_user( $old_current_user );
     471    }
     472
     473    /**
     474     * @group groups_leave_group
     475     * @group group_membership
     476     */
     477    public function test_groups_leave_group_basic_leave_use_current_user() {
     478        $old_current_user = get_current_user_id();
     479        $u1 = $this->factory->user->create();
     480        $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     481        $u2 = $this->factory->user->create();
     482        $this->add_user_to_group( $u2, $g );
     483
     484        $before = groups_get_total_member_count( $g );
     485        $this->set_current_user( $u2 );
     486        groups_leave_group( $g );
     487        $after = groups_get_total_member_count( $g );
     488
     489        $this->assertEquals( $before - 1, $after );
     490        $this->set_current_user( $old_current_user );
     491    }
     492
     493    /**
     494     * @group groups_leave_group
     495     * @group group_membership
     496     */
     497    public function test_groups_leave_group_basic_leave_group_admin_initiated() {
     498        $old_current_user = get_current_user_id();
     499        $u1 = $this->factory->user->create();
     500        $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     501        $u2 = $this->factory->user->create();
     502        $this->add_user_to_group( $u2, $g );
     503
     504        $before = groups_get_total_member_count( $g );
     505        $this->set_current_user( $u1 );
     506        groups_leave_group( $g, $u2 );
     507        $after = groups_get_total_member_count( $g );
     508
     509        $this->assertEquals( $before - 1, $after );
     510        $this->set_current_user( $old_current_user );
     511    }
     512
     513    /**
     514     * @group groups_leave_group
     515     * @group group_membership
     516     */
     517    public function test_groups_leave_group_basic_leave_site_admin_initiated() {
     518        $old_current_user = get_current_user_id();
     519        $u1 = $this->factory->user->create();
     520        $u1_siteadmin = new WP_User( $u1 );
     521        $u1_siteadmin->add_role( 'administrator' );
     522        $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     523        $u2 = $this->factory->user->create();
     524        $this->add_user_to_group( $u2, $g );
     525
     526        $before = groups_get_total_member_count( $g );
     527        $this->set_current_user( $u1 );
     528        groups_leave_group( $g, $u2 );
     529        $after = groups_get_total_member_count( $g );
     530
     531        $this->assertEquals( $before - 1, $after );
     532        $this->set_current_user( $old_current_user );
     533    }
     534
     535    /**
     536     * @group groups_leave_group
     537     * @group group_membership
     538     */
     539    public function test_groups_leave_group_single_admin_prevent_leave() {
     540        $old_current_user = get_current_user_id();
     541        $u1 = $this->factory->user->create();
     542        $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     543        $u2 = $this->factory->user->create();
     544        $this->add_user_to_group( $u2, $g );
     545
     546        $before = groups_get_total_member_count( $g );
     547        $this->set_current_user( $u1 );
     548        groups_leave_group( $g, $u1 );
     549        $after = groups_get_total_member_count( $g );
     550
     551        $this->assertEquals( $before, $after );
     552        $this->set_current_user( $old_current_user );
     553    }
     554
     555    /**
     556     * @group groups_leave_group
     557     * @group group_membership
     558     */
     559    public function test_groups_leave_group_multiple_admins_allow_leave() {
     560        $old_current_user = get_current_user_id();
     561        $u1 = $this->factory->user->create();
     562        $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     563        $u2 = $this->factory->user->create();
     564        $this->add_user_to_group( $u2, $g );
     565        $m2 = new BP_Groups_Member( $u2, $g );
     566        $m2->promote( 'admin' );
     567
     568        $before = groups_get_total_member_count( $g );
     569        $this->set_current_user( $u1 );
     570        groups_leave_group( $g, $u1 );
     571        $after = groups_get_total_member_count( $g );
     572
     573        $this->assertEquals( $before - 1, $after );
     574        $this->set_current_user( $old_current_user );
     575    }
     576
     577    /**
     578     * @group groups_get_invites_for_user
     579     * @group group_invitations
     580     * @group group_membership
     581     */
     582    public function test_groups_get_invites_for_user() {
     583        $u1 = $this->factory->user->create();
     584        $u2 = $this->factory->user->create();
     585        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     586        $g2 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     587        $g3 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     588
     589        self::invite_user_to_group( $u2, $g1, $u1 );
     590        self::invite_user_to_group( $u2, $g2, $u1 );
     591        self::invite_user_to_group( $u2, $g3, $u1 );
     592
     593        $groups = groups_get_invites_for_user( $u2 );
     594
     595        $this->assertEqualSets( array( $g1, $g2, $g3 ), wp_list_pluck( $groups['groups'], 'id' ) );
     596    }
     597
     598    /**
     599     * @group groups_get_invites_for_user
     600     * @group group_invitations
     601     * @group group_membership
     602     */
     603    public function test_groups_get_invites_for_user_infer_user() {
     604        $old_current_user = get_current_user_id();
     605
     606        $u1 = $this->factory->user->create();
     607        $u2 = $this->factory->user->create();
     608        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     609        $g2 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     610        $g3 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     611
     612        self::invite_user_to_group( $u2, $g1, $u1 );
     613        self::invite_user_to_group( $u2, $g2, $u1 );
     614        self::invite_user_to_group( $u2, $g3, $u1 );
     615
     616        $this->set_current_user( $u2 );
     617        $groups = groups_get_invites_for_user();
     618        $this->assertEqualSets( array( $g1, $g2, $g3 ), wp_list_pluck( $groups['groups'], 'id' ) );
     619
     620        $this->set_current_user( $old_current_user );
     621    }
     622
     623    /**
     624     * @group groups_get_invites_for_user
     625     * @group group_invitations
     626     * @group group_membership
     627     */
     628    public function test_groups_get_invites_for_user_with_exclude() {
     629        $u1 = $this->factory->user->create();
     630        $u2 = $this->factory->user->create();
     631        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     632        $g2 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     633        $g3 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     634
     635        self::invite_user_to_group( $u2, $g1, $u1 );
     636        self::invite_user_to_group( $u2, $g2, $u1 );
     637        self::invite_user_to_group( $u2, $g3, $u1 );
     638
     639        $groups = groups_get_invites_for_user( $u2, $limit = false, $page = false, $exclude = array( $g2 ) );
     640        $this->assertEqualSets( array( $g1, $g3 ), wp_list_pluck( $groups['groups'], 'id' ) );
     641    }
     642
     643    /**
     644     * @group groups_get_invite_count_for_user
     645     * @group group_invitations
     646     * @group group_membership
     647     */
     648    public function test_groups_get_invite_count_for_user() {
     649        $u1 = $this->factory->user->create();
     650        $u2 = $this->factory->user->create();
     651        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     652        $g2 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     653        $g3 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     654
     655        self::invite_user_to_group( $u2, $g1, $u1 );
     656        self::invite_user_to_group( $u2, $g2, $u1 );
     657        self::invite_user_to_group( $u2, $g3, $u1 );
     658
     659        $this->assertEquals( 3, groups_get_invite_count_for_user( $u2 ) );
     660    }
     661
     662    /**
     663     * @group groups_get_invite_count_for_user
     664     * @group group_invitations
     665     * @group group_membership
     666     */
     667    public function test_groups_get_invite_count_for_user_ignore_drafts() {
     668        $u1 = $this->factory->user->create();
     669        $u2 = $this->factory->user->create();
     670        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     671
     672        $args = array(
     673            'user_id'       => $u2,
     674            'group_id'      => $g1,
     675            'inviter_id'    => $u1,
     676            'date_modified' => bp_core_current_time(),
     677            'is_confirmed'  => 0
     678        );
     679        // Create draft invitation.
     680        groups_invite_user( $args );
     681
     682        // groups_get_invite_count_for_user should ignore draft invitations.
     683        $this->assertEquals( 0, groups_get_invite_count_for_user( $u2 ) );
     684    }
     685
     686    /**
     687     * @group groups_invite_user
     688     * @group group_invitations
     689     * @group group_membership
     690     */
     691    public function test_groups_invite_user() {
     692        $u1 = $this->factory->user->create();
     693        $u2 = $this->factory->user->create();
     694        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     695
     696        // Create draft invitation
     697        $args = array(
     698            'user_id'       => $u2,
     699            'group_id'      => $g1,
     700            'inviter_id'    => $u1,
     701            'date_modified' => bp_core_current_time(),
     702            'is_confirmed'  => 0
     703        );
     704        groups_invite_user( $args );
     705
     706        // Check that the draft invitation has been created.
     707        $draft = groups_check_user_has_invite( $u2, $g1, $type = 'all' );
     708        $this->assertTrue( is_numeric( $draft ) && $draft > 0 );
     709    }
     710
     711    /**
     712     * @group groups_send_invites
     713     * @group group_invitations
     714     * @group group_membership
     715     */
     716    public function test_groups_send_invites() {
     717        $u1 = $this->factory->user->create();
     718        $u2 = $this->factory->user->create();
     719        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     720
     721        // Create draft invitation
     722        $args = array(
     723            'user_id'       => $u2,
     724            'group_id'      => $g1,
     725            'inviter_id'    => $u1,
     726            'date_modified' => bp_core_current_time(),
     727            'is_confirmed'  => 0
     728        );
     729        groups_invite_user( $args );
     730
     731        // Send the invitation
     732        groups_send_invites( $u1, $g1 );
     733        // Check that the invitation has been sent.
     734        $sent = groups_check_user_has_invite( $u2, $g1, $type = 'sent' );
     735        $this->assertTrue( is_numeric( $sent ) && $sent > 0 );
     736    }
     737
     738    /**
     739     * @group groups_accept_invite
     740     * @group group_invitations
     741     * @group group_membership
     742     */
     743    public function test_groups_accept_invite() {
     744        $u1 = $this->factory->user->create();
     745        $u2 = $this->factory->user->create();
     746        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     747
     748        // Create draft invitation
     749        $args = array(
     750            'user_id'       => $u2,
     751            'group_id'      => $g1,
     752            'inviter_id'    => $u1,
     753            'date_modified' => bp_core_current_time(),
     754            'is_confirmed'  => 0
     755        );
     756        groups_invite_user( $args );
     757
     758        // Send the invitation
     759        groups_send_invites( $u1, $g1 );
     760
     761        // Accept the invitation
     762        groups_accept_invite( $u2, $g1 );
     763
     764        // Check that the user is a member of the group.
     765        $member = groups_is_user_member( $u2, $g1 );
     766        $this->assertTrue( is_numeric( $member ) && $member > 0 );
     767        // Check that the invite has been removed.
     768        $invite = groups_check_user_has_invite( $u2, $g1, $type = 'all' );
     769        $this->assertTrue( is_null( $invite ) );
     770    }
     771
     772    /**
     773     * @group groups_accept_invite
     774     * @group group_invitations
     775     * @group group_membership
     776     */
     777    public function test_groups_accept_invite_removes_membership_requests() {
     778        $u1 = $this->factory->user->create();
     779        $u2 = $this->factory->user->create();
     780        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     781
     782        // Create draft invitation
     783        $args = array(
     784            'user_id'       => $u2,
     785            'group_id'      => $g1,
     786            'inviter_id'    => $u1,
     787            'date_modified' => bp_core_current_time(),
     788            'is_confirmed'  => 0
     789        );
     790        groups_invite_user( $args );
     791
     792        // Create membership request
     793        groups_send_membership_request( $u2, $g1 );
     794        $request = groups_check_for_membership_request( $u2, $g1 );
     795        $this->assertTrue( is_numeric( $request ) && $request > 0 );
     796
     797        // Send the invitation
     798        groups_send_invites( $u1, $g1 );
     799
     800        // Accept the invitation
     801        groups_accept_invite( $u2, $g1 );
     802
     803        // Check that the membership request has been removed.
     804        $this->assertTrue( 0 == groups_check_for_membership_request( $u2, $g1 ) );
     805    }
     806
     807    /**
     808     * @group groups_send_invites
     809     * @group group_invitations
     810     * @group group_membership_requests
     811     * @group group_membership
     812     */
     813    public function test_groups_sent_invite_plus_request_equals_member() {
     814        $u1 = $this->factory->user->create();
     815        $u2 = $this->factory->user->create();
     816        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     817
     818        // Create draft invitation
     819        $args = array(
     820            'user_id'       => $u2,
     821            'group_id'      => $g1,
     822            'inviter_id'    => $u1,
     823            'date_modified' => bp_core_current_time(),
     824            'is_confirmed'  => 0
     825        );
     826        groups_invite_user( $args );
     827
     828        // Send the invitation
     829        groups_send_invites( $u1, $g1 );
     830
     831        // Create membership request
     832        groups_send_membership_request( $u2, $g1 );
     833
     834        // User should now be a group member
     835        $member = groups_is_user_member( $u2, $g1 );
     836        $this->assertTrue( is_numeric( $member ) && $member > 0 );
     837    }
     838
     839    /**
     840     * @group groups_delete_all_group_invites
     841     * @group group_invitations
     842     * @group group_membership
     843     */
     844    public function test_groups_delete_all_group_invites() {
     845        $u1 = $this->factory->user->create();
     846        $u2 = $this->factory->user->create();
     847        $u3 = $this->factory->user->create();
     848        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     849
     850        self::invite_user_to_group( $u2, $g1, $u1 );
     851        self::invite_user_to_group( $u3, $g1, $u1 );
     852
     853        groups_delete_all_group_invites( $g1 );
     854
     855        // Get group invitations of any type, from any user in the group.
     856        $args = array(
     857            'group_id'     => $g1,
     858            'is_confirmed' => 0,
     859            'invite_sent'  => null,
     860            'inviter_id'   => 'any',
     861        );
     862        $invitees = new BP_Group_Member_Query( $args );
     863
     864        $this->assertTrue( empty( $invitees->results ) );
     865    }
     866
     867    /**
     868     * @group groups_send_membership_request
     869     * @group group_membership_requests
     870     * @group group_membership
     871     */
     872    public function test_groups_send_membership_request() {
     873        $u1 = $this->factory->user->create();
     874        $g1 = $this->factory->group->create();
     875
     876        // Create membership request
     877        groups_send_membership_request( $u1, $g1 );
     878
     879        $request = groups_check_for_membership_request( $u1, $g1 );
     880        $this->assertTrue( is_numeric( $request ) && $request > 0 );
     881    }
     882
     883    /**
     884     * @group groups_accept_membership_request
     885     * @group group_membership_requests
     886     * @group group_membership
     887     */
     888    public function test_groups_accept_membership_request_by_membership_id() {
     889        $u1 = $this->factory->user->create();
     890        $g1 = $this->factory->group->create();
     891
     892        // Create membership request
     893        groups_send_membership_request( $u1, $g1 );
     894
     895        // Get group invitations of any type, from any user in the group.
     896        $member = new BP_Groups_Member( $u1, $g1 );
     897
     898        groups_accept_membership_request( $member->id );
     899
     900        // User should now be a group member.
     901        $member = groups_is_user_member( $u1, $g1 );
     902
     903        $this->assertTrue( is_numeric( $member ) && $member > 0 );
     904    }
     905
     906    /**
     907     * @group groups_accept_membership_request
     908     * @group group_membership_requests
     909     * @group group_membership
     910     */
     911    public function test_groups_accept_membership_request_by_user_id_group_id() {
     912        $u1 = $this->factory->user->create();
     913        $g1 = $this->factory->group->create();
     914
     915        // Create membership request
     916        groups_send_membership_request( $u1, $g1 );
     917
     918        groups_accept_membership_request( null, $u1, $g1 );
     919
     920        // User should now be a group member
     921        $member = groups_is_user_member( $u1, $g1 );
     922        $this->assertTrue( is_numeric( $member ) && $member > 0 );
     923    }
     924
     925    /**
     926     * @group groups_send_invites
     927     * @group group_invitations
     928     * @group group_membership_requests
     929     * @group group_membership
     930     */
     931    public function test_groups_membership_request_plus_invite_equals_member() {
     932        $u1 = $this->factory->user->create();
     933        $u2 = $this->factory->user->create();
     934        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     935
     936        // Create membership request
     937        groups_send_membership_request( $u2, $g1 );
     938
     939        // Create draft invitation
     940        $args = array(
     941            'user_id'       => $u2,
     942            'group_id'      => $g1,
     943            'inviter_id'    => $u1,
     944            'date_modified' => bp_core_current_time(),
     945            'is_confirmed'  => 0
     946        );
     947        groups_invite_user( $args );
     948
     949        // Send the invitation
     950        groups_send_invites( $u1, $g1 );
     951
     952        // User should now be a group member
     953        $member = groups_is_user_member( $u2, $g1 );
     954        $this->assertTrue( is_numeric( $member ) && $member > 0 );
     955    }
     956
     957    /**
     958     * @group groups_accept_all_pending_membership_requests
     959     * @group group_membership_requests
     960     * @group group_membership
     961     */
     962    public function test_groups_accept_all_pending_membership_requests() {
     963        $u1 = $this->factory->user->create();
     964        $u2 = $this->factory->user->create();
     965        $u3 = $this->factory->user->create();
     966        $g1 = $this->factory->group->create();
     967
     968        // Create membership request
     969        groups_send_membership_request( $u1, $g1 );
     970        groups_send_membership_request( $u2, $g1 );
     971        groups_send_membership_request( $u3, $g1 );
     972
     973        groups_accept_all_pending_membership_requests( $g1 );
     974
     975        // All users should now be group members.
     976        $members = new BP_Group_Member_Query( array( 'group_id' => $g1 ) );
     977        $this->assertEqualSets( array( $u1, $u2, $u3 ), $members->user_ids );
     978    }
    218979}
    219 
Note: See TracChangeset for help on using the changeset viewer.