<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][9797] trunk/tests/phpunit/testcases/groups/class-bp-groups-member.php: Passing tests for group membership</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/9797">9797</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/9797","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dcavins</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-04-24 15:20:20 +0000 (Fri, 24 Apr 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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()</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestcasesgroupsclassbpgroupsmemberphp">trunk/tests/phpunit/testcases/groups/class-bp-groups-member.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsphpunittestcasesgroupsclassbpgroupsmemberphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/testcases/groups/class-bp-groups-member.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/testcases/groups/class-bp-groups-member.php 2015-04-23 21:07:28 UTC (rev 9796)
+++ trunk/tests/phpunit/testcases/groups/class-bp-groups-member.php 2015-04-24 15:20:20 UTC (rev 9797)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -17,6 +17,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $invite->id;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function create_group_membership_request( $user_id, $group_id ) {
+ $request = new BP_Groups_Member;
+ $request->group_id = $group_id;
+ $request->user_id = $user_id;
+ $request->date_modified = bp_core_current_time();
+ $request->inviter_id = 0;
+ $request->is_confirmed = 0;
+
+ $request->save();
+ return $request->id;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> public function test_get_recently_joined_with_filter() {
</span><span class="cx" style="display: block; padding: 0 10px"> $g1 = $this->factory->group->create( array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'name' => 'Tab',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -215,5 +227,753 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->set_current_user( $old_current_user );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-}
</del><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @group groups_reject_membership_request
+ * @group group_membership_requests
+ * @group group_membership
+ */
+ public function test_bp_groups_reject_membership_request_remove_request() {
+ $u1 = $this->factory->user->create();
+ $g = $this->factory->group->create( array(
+ 'status' => 'private',
+ ) );
+
+ // Membership requests should be removed.
+ self::create_group_membership_request( $u1, $g );
+ groups_reject_membership_request( null, $u1, $g );
+ $u1_has_request = groups_check_for_membership_request( $u1, $g );
+ $this->assertEquals( 0, $u1_has_request );
+ }
+
+ /**
+ * @group groups_delete_membership_request
+ * @group group_membership_requests
+ * @group group_membership
+ */
+ public function test_bp_groups_delete_membership_request_remove_request() {
+ $u1 = $this->factory->user->create();
+ $g = $this->factory->group->create( array(
+ 'status' => 'private',
+ ) );
+
+ // Membership requests should be removed.
+ self::create_group_membership_request( $u1, $g );
+ groups_delete_membership_request( null, $u1, $g );
+ $u1_has_request = groups_check_for_membership_request( $u1, $g );
+ $this->assertEquals( 0, $u1_has_request );
+ }
+
+ /**
+ * @group groups_reject_invite
+ * @group group_invitations
+ * @group group_membership
+ */
+ public function test_bp_groups_reject_invite_remove_invite() {
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $g = $this->factory->group->create( array(
+ 'status' => 'private',
+ ) );
+
+ $now = time();
+ $this->add_user_to_group( $u1, $g, array(
+ 'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
+ ) );
+
+ // The invitation should be removed.
+ self::invite_user_to_group( $u2, $g, $u1 );
+ groups_reject_invite( $u2, $g );
+ $u2_has_invite = groups_check_user_has_invite( $u2, $g );
+ $this->assertEquals( 0, $u2_has_invite );
+ }
+
+ /**
+ * @group groups_delete_invite
+ * @group group_invitations
+ * @group group_membership
+ */
+ public function test_bp_groups_delete_invite_remove_invite() {
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $g = $this->factory->group->create( array(
+ 'status' => 'private',
+ ) );
+
+ $now = time();
+ $this->add_user_to_group( $u1, $g, array(
+ 'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
+ ) );
+
+ // The invitation should be removed.
+ self::invite_user_to_group( $u2, $g, $u1 );
+ groups_delete_invite( $u2, $g );
+ $u2_has_invite = groups_check_user_has_invite( $u2, $g );
+ $this->assertEquals( 0, $u2_has_invite );
+ }
+
+ /**
+ * @group groups_delete_invite
+ * @group group_invitations
+ * @group group_membership
+ */
+ public function test_bp_groups_delete_invite_leave_memberships_intact() {
+ $u1 = $this->factory->user->create();
+ $g = $this->factory->group->create( array(
+ 'status' => 'private',
+ ) );
+
+ $now = time();
+ $this->add_user_to_group( $u1, $g, array(
+ 'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
+ ) );
+
+ groups_delete_invite( $u1, $g );
+ $u1_is_member = groups_is_user_member( $u1, $g );
+ $this->assertTrue( is_numeric( $u1_is_member ) && $u1_is_member > 0 );
+ }
+
+ /**
+ * @group groups_delete_invite
+ * @group group_invitations
+ * @group group_membership
+ */
+ public function test_bp_groups_delete_invite_leave_requests_intact() {
+ $u1 = $this->factory->user->create();
+ $g = $this->factory->group->create( array(
+ 'status' => 'private',
+ ) );
+
+ // Membership requests should be left intact.
+ self::create_group_membership_request( $u1, $g );
+ groups_delete_invite( $u1, $g );
+ $u1_has_request = groups_check_for_membership_request( $u1, $g );
+ $this->assertTrue( is_numeric( $u1_has_request ) && $u1_has_request > 0 );
+ }
+
+ /**
+ * @group groups_uninvite_user
+ * @group group_invitations
+ * @group group_membership
+ */
+ public function test_bp_groups_uninvite_user_remove_invite() {
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $g = $this->factory->group->create( array(
+ 'status' => 'private',
+ ) );
+
+ $now = time();
+ $this->add_user_to_group( $u1, $g, array(
+ 'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
+ ) );
+
+ // The invitation should be removed.
+ self::invite_user_to_group( $u2, $g, $u1 );
+ groups_uninvite_user( $u2, $g );
+ $u2_has_invite = groups_check_user_has_invite( $u2, $g );
+ $this->assertEquals( 0, $u2_has_invite );
+ }
+
+ /**
+ * @group groups_join_group
+ * @group group_membership
+ */
+ public function test_groups_join_group_basic_join() {
+ $u1 = $this->factory->user->create();
+ $g = $this->factory->group->create();
+
+ groups_join_group( $g, $u1 );
+ $membership_id = groups_is_user_member( $u1, $g );
+ $this->assertTrue( is_numeric( $membership_id ) && $membership_id > 0 );
+ }
+
+ /**
+ * @group groups_join_group
+ * @group group_membership
+ */
+ public function test_groups_join_group_basic_join_use_current_user() {
+ $u1 = $this->factory->user->create();
+ $g = $this->factory->group->create();
+ $old_current_user = get_current_user_id();
+ $this->set_current_user( $u1 );
+
+ groups_join_group( $g );
+ $membership_id = groups_is_user_member( $u1, $g );
+ $this->assertTrue( is_numeric( $membership_id ) && $membership_id > 0 );
+ $this->set_current_user( $old_current_user );
+ }
+
+ /**
+ * @group groups_join_group
+ * @group group_membership
+ */
+ public function test_groups_join_group_already_member() {
+ $u1 = $this->factory->user->create();
+ $g = $this->factory->group->create();
+ $this->add_user_to_group( $u1, $g );
+
+ $this->assertTrue( groups_join_group( $g, $u1 ) );
+ }
+
+ /**
+ * @group groups_join_group
+ * @group group_membership
+ */
+ public function test_groups_join_group_cleanup_invites() {
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $g = $this->factory->group->create();
+ $this->add_user_to_group( $u1, $g );
+
+ $m1 = new BP_Groups_Member( $u1, $g );
+ $m1->promote( 'admin' );
+
+ self::invite_user_to_group( $u2, $g, $u1 );
+
+ groups_join_group( $g, $u2 );
+ // Upon joining the group, outstanding invitations should be cleaned up.
+ $this->assertEquals( null, groups_check_user_has_invite( $u2, $g, 'any' ) );
+ }
+
+ /**
+ * @group groups_join_group
+ * @group group_membership
+ */
+ public function test_groups_join_group_cleanup_requests() {
+ $u1 = $this->factory->user->create();
+ $g = $this->factory->group->create();
+ self::create_group_membership_request( $u1, $g );
+
+ groups_join_group( $g, $u1 );
+ // Upon joining the group, outstanding requests should be cleaned up.
+ $this->assertEquals( null, groups_check_for_membership_request( $u1, $g ) );
+ }
+
+ /**
+ * @group groups_leave_group
+ * @group group_membership
+ */
+ public function test_groups_leave_group_basic_leave_self_initiated() {
+ $old_current_user = get_current_user_id();
+ $u1 = $this->factory->user->create();
+ $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+ $u2 = $this->factory->user->create();
+ $this->add_user_to_group( $u2, $g );
+
+ $before = groups_get_total_member_count( $g );
+ $this->set_current_user( $u2 );
+ groups_leave_group( $g, $u2 );
+ $after = groups_get_total_member_count( $g );
+
+ $this->assertEquals( $before - 1, $after );
+ $this->set_current_user( $old_current_user );
+ }
+
+ /**
+ * @group groups_leave_group
+ * @group group_membership
+ */
+ public function test_groups_leave_group_basic_leave_use_current_user() {
+ $old_current_user = get_current_user_id();
+ $u1 = $this->factory->user->create();
+ $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+ $u2 = $this->factory->user->create();
+ $this->add_user_to_group( $u2, $g );
+
+ $before = groups_get_total_member_count( $g );
+ $this->set_current_user( $u2 );
+ groups_leave_group( $g );
+ $after = groups_get_total_member_count( $g );
+
+ $this->assertEquals( $before - 1, $after );
+ $this->set_current_user( $old_current_user );
+ }
+
+ /**
+ * @group groups_leave_group
+ * @group group_membership
+ */
+ public function test_groups_leave_group_basic_leave_group_admin_initiated() {
+ $old_current_user = get_current_user_id();
+ $u1 = $this->factory->user->create();
+ $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+ $u2 = $this->factory->user->create();
+ $this->add_user_to_group( $u2, $g );
+
+ $before = groups_get_total_member_count( $g );
+ $this->set_current_user( $u1 );
+ groups_leave_group( $g, $u2 );
+ $after = groups_get_total_member_count( $g );
+
+ $this->assertEquals( $before - 1, $after );
+ $this->set_current_user( $old_current_user );
+ }
+
+ /**
+ * @group groups_leave_group
+ * @group group_membership
+ */
+ public function test_groups_leave_group_basic_leave_site_admin_initiated() {
+ $old_current_user = get_current_user_id();
+ $u1 = $this->factory->user->create();
+ $u1_siteadmin = new WP_User( $u1 );
+ $u1_siteadmin->add_role( 'administrator' );
+ $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+ $u2 = $this->factory->user->create();
+ $this->add_user_to_group( $u2, $g );
+
+ $before = groups_get_total_member_count( $g );
+ $this->set_current_user( $u1 );
+ groups_leave_group( $g, $u2 );
+ $after = groups_get_total_member_count( $g );
+
+ $this->assertEquals( $before - 1, $after );
+ $this->set_current_user( $old_current_user );
+ }
+
+ /**
+ * @group groups_leave_group
+ * @group group_membership
+ */
+ public function test_groups_leave_group_single_admin_prevent_leave() {
+ $old_current_user = get_current_user_id();
+ $u1 = $this->factory->user->create();
+ $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+ $u2 = $this->factory->user->create();
+ $this->add_user_to_group( $u2, $g );
+
+ $before = groups_get_total_member_count( $g );
+ $this->set_current_user( $u1 );
+ groups_leave_group( $g, $u1 );
+ $after = groups_get_total_member_count( $g );
+
+ $this->assertEquals( $before, $after );
+ $this->set_current_user( $old_current_user );
+ }
+
+ /**
+ * @group groups_leave_group
+ * @group group_membership
+ */
+ public function test_groups_leave_group_multiple_admins_allow_leave() {
+ $old_current_user = get_current_user_id();
+ $u1 = $this->factory->user->create();
+ $g = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+ $u2 = $this->factory->user->create();
+ $this->add_user_to_group( $u2, $g );
+ $m2 = new BP_Groups_Member( $u2, $g );
+ $m2->promote( 'admin' );
+
+ $before = groups_get_total_member_count( $g );
+ $this->set_current_user( $u1 );
+ groups_leave_group( $g, $u1 );
+ $after = groups_get_total_member_count( $g );
+
+ $this->assertEquals( $before - 1, $after );
+ $this->set_current_user( $old_current_user );
+ }
+
+ /**
+ * @group groups_get_invites_for_user
+ * @group group_invitations
+ * @group group_membership
+ */
+ public function test_groups_get_invites_for_user() {
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+ $g2 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+ $g3 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+
+ self::invite_user_to_group( $u2, $g1, $u1 );
+ self::invite_user_to_group( $u2, $g2, $u1 );
+ self::invite_user_to_group( $u2, $g3, $u1 );
+
+ $groups = groups_get_invites_for_user( $u2 );
+
+ $this->assertEqualSets( array( $g1, $g2, $g3 ), wp_list_pluck( $groups['groups'], 'id' ) );
+ }
+
+ /**
+ * @group groups_get_invites_for_user
+ * @group group_invitations
+ * @group group_membership
+ */
+ public function test_groups_get_invites_for_user_infer_user() {
+ $old_current_user = get_current_user_id();
+
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+ $g2 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+ $g3 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+
+ self::invite_user_to_group( $u2, $g1, $u1 );
+ self::invite_user_to_group( $u2, $g2, $u1 );
+ self::invite_user_to_group( $u2, $g3, $u1 );
+
+ $this->set_current_user( $u2 );
+ $groups = groups_get_invites_for_user();
+ $this->assertEqualSets( array( $g1, $g2, $g3 ), wp_list_pluck( $groups['groups'], 'id' ) );
+
+ $this->set_current_user( $old_current_user );
+ }
+
+ /**
+ * @group groups_get_invites_for_user
+ * @group group_invitations
+ * @group group_membership
+ */
+ public function test_groups_get_invites_for_user_with_exclude() {
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+ $g2 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+ $g3 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+
+ self::invite_user_to_group( $u2, $g1, $u1 );
+ self::invite_user_to_group( $u2, $g2, $u1 );
+ self::invite_user_to_group( $u2, $g3, $u1 );
+
+ $groups = groups_get_invites_for_user( $u2, $limit = false, $page = false, $exclude = array( $g2 ) );
+ $this->assertEqualSets( array( $g1, $g3 ), wp_list_pluck( $groups['groups'], 'id' ) );
+ }
+
+ /**
+ * @group groups_get_invite_count_for_user
+ * @group group_invitations
+ * @group group_membership
+ */
+ public function test_groups_get_invite_count_for_user() {
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+ $g2 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+ $g3 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+
+ self::invite_user_to_group( $u2, $g1, $u1 );
+ self::invite_user_to_group( $u2, $g2, $u1 );
+ self::invite_user_to_group( $u2, $g3, $u1 );
+
+ $this->assertEquals( 3, groups_get_invite_count_for_user( $u2 ) );
+ }
+
+ /**
+ * @group groups_get_invite_count_for_user
+ * @group group_invitations
+ * @group group_membership
+ */
+ public function test_groups_get_invite_count_for_user_ignore_drafts() {
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+
+ $args = array(
+ 'user_id' => $u2,
+ 'group_id' => $g1,
+ 'inviter_id' => $u1,
+ 'date_modified' => bp_core_current_time(),
+ 'is_confirmed' => 0
+ );
+ // Create draft invitation.
+ groups_invite_user( $args );
+
+ // groups_get_invite_count_for_user should ignore draft invitations.
+ $this->assertEquals( 0, groups_get_invite_count_for_user( $u2 ) );
+ }
+
+ /**
+ * @group groups_invite_user
+ * @group group_invitations
+ * @group group_membership
+ */
+ public function test_groups_invite_user() {
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+
+ // Create draft invitation
+ $args = array(
+ 'user_id' => $u2,
+ 'group_id' => $g1,
+ 'inviter_id' => $u1,
+ 'date_modified' => bp_core_current_time(),
+ 'is_confirmed' => 0
+ );
+ groups_invite_user( $args );
+
+ // Check that the draft invitation has been created.
+ $draft = groups_check_user_has_invite( $u2, $g1, $type = 'all' );
+ $this->assertTrue( is_numeric( $draft ) && $draft > 0 );
+ }
+
+ /**
+ * @group groups_send_invites
+ * @group group_invitations
+ * @group group_membership
+ */
+ public function test_groups_send_invites() {
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+
+ // Create draft invitation
+ $args = array(
+ 'user_id' => $u2,
+ 'group_id' => $g1,
+ 'inviter_id' => $u1,
+ 'date_modified' => bp_core_current_time(),
+ 'is_confirmed' => 0
+ );
+ groups_invite_user( $args );
+
+ // Send the invitation
+ groups_send_invites( $u1, $g1 );
+ // Check that the invitation has been sent.
+ $sent = groups_check_user_has_invite( $u2, $g1, $type = 'sent' );
+ $this->assertTrue( is_numeric( $sent ) && $sent > 0 );
+ }
+
+ /**
+ * @group groups_accept_invite
+ * @group group_invitations
+ * @group group_membership
+ */
+ public function test_groups_accept_invite() {
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+
+ // Create draft invitation
+ $args = array(
+ 'user_id' => $u2,
+ 'group_id' => $g1,
+ 'inviter_id' => $u1,
+ 'date_modified' => bp_core_current_time(),
+ 'is_confirmed' => 0
+ );
+ groups_invite_user( $args );
+
+ // Send the invitation
+ groups_send_invites( $u1, $g1 );
+
+ // Accept the invitation
+ groups_accept_invite( $u2, $g1 );
+
+ // Check that the user is a member of the group.
+ $member = groups_is_user_member( $u2, $g1 );
+ $this->assertTrue( is_numeric( $member ) && $member > 0 );
+ // Check that the invite has been removed.
+ $invite = groups_check_user_has_invite( $u2, $g1, $type = 'all' );
+ $this->assertTrue( is_null( $invite ) );
+ }
+
+ /**
+ * @group groups_accept_invite
+ * @group group_invitations
+ * @group group_membership
+ */
+ public function test_groups_accept_invite_removes_membership_requests() {
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+
+ // Create draft invitation
+ $args = array(
+ 'user_id' => $u2,
+ 'group_id' => $g1,
+ 'inviter_id' => $u1,
+ 'date_modified' => bp_core_current_time(),
+ 'is_confirmed' => 0
+ );
+ groups_invite_user( $args );
+
+ // Create membership request
+ groups_send_membership_request( $u2, $g1 );
+ $request = groups_check_for_membership_request( $u2, $g1 );
+ $this->assertTrue( is_numeric( $request ) && $request > 0 );
+
+ // Send the invitation
+ groups_send_invites( $u1, $g1 );
+
+ // Accept the invitation
+ groups_accept_invite( $u2, $g1 );
+
+ // Check that the membership request has been removed.
+ $this->assertTrue( 0 == groups_check_for_membership_request( $u2, $g1 ) );
+ }
+
+ /**
+ * @group groups_send_invites
+ * @group group_invitations
+ * @group group_membership_requests
+ * @group group_membership
+ */
+ public function test_groups_sent_invite_plus_request_equals_member() {
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+
+ // Create draft invitation
+ $args = array(
+ 'user_id' => $u2,
+ 'group_id' => $g1,
+ 'inviter_id' => $u1,
+ 'date_modified' => bp_core_current_time(),
+ 'is_confirmed' => 0
+ );
+ groups_invite_user( $args );
+
+ // Send the invitation
+ groups_send_invites( $u1, $g1 );
+
+ // Create membership request
+ groups_send_membership_request( $u2, $g1 );
+
+ // User should now be a group member
+ $member = groups_is_user_member( $u2, $g1 );
+ $this->assertTrue( is_numeric( $member ) && $member > 0 );
+ }
+
+ /**
+ * @group groups_delete_all_group_invites
+ * @group group_invitations
+ * @group group_membership
+ */
+ public function test_groups_delete_all_group_invites() {
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $u3 = $this->factory->user->create();
+ $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+
+ self::invite_user_to_group( $u2, $g1, $u1 );
+ self::invite_user_to_group( $u3, $g1, $u1 );
+
+ groups_delete_all_group_invites( $g1 );
+
+ // Get group invitations of any type, from any user in the group.
+ $args = array(
+ 'group_id' => $g1,
+ 'is_confirmed' => 0,
+ 'invite_sent' => null,
+ 'inviter_id' => 'any',
+ );
+ $invitees = new BP_Group_Member_Query( $args );
+
+ $this->assertTrue( empty( $invitees->results ) );
+ }
+
+ /**
+ * @group groups_send_membership_request
+ * @group group_membership_requests
+ * @group group_membership
+ */
+ public function test_groups_send_membership_request() {
+ $u1 = $this->factory->user->create();
+ $g1 = $this->factory->group->create();
+
+ // Create membership request
+ groups_send_membership_request( $u1, $g1 );
+
+ $request = groups_check_for_membership_request( $u1, $g1 );
+ $this->assertTrue( is_numeric( $request ) && $request > 0 );
+ }
+
+ /**
+ * @group groups_accept_membership_request
+ * @group group_membership_requests
+ * @group group_membership
+ */
+ public function test_groups_accept_membership_request_by_membership_id() {
+ $u1 = $this->factory->user->create();
+ $g1 = $this->factory->group->create();
+
+ // Create membership request
+ groups_send_membership_request( $u1, $g1 );
+
+ // Get group invitations of any type, from any user in the group.
+ $member = new BP_Groups_Member( $u1, $g1 );
+
+ groups_accept_membership_request( $member->id );
+
+ // User should now be a group member.
+ $member = groups_is_user_member( $u1, $g1 );
+
+ $this->assertTrue( is_numeric( $member ) && $member > 0 );
+ }
+
+ /**
+ * @group groups_accept_membership_request
+ * @group group_membership_requests
+ * @group group_membership
+ */
+ public function test_groups_accept_membership_request_by_user_id_group_id() {
+ $u1 = $this->factory->user->create();
+ $g1 = $this->factory->group->create();
+
+ // Create membership request
+ groups_send_membership_request( $u1, $g1 );
+
+ groups_accept_membership_request( null, $u1, $g1 );
+
+ // User should now be a group member
+ $member = groups_is_user_member( $u1, $g1 );
+ $this->assertTrue( is_numeric( $member ) && $member > 0 );
+ }
+
+ /**
+ * @group groups_send_invites
+ * @group group_invitations
+ * @group group_membership_requests
+ * @group group_membership
+ */
+ public function test_groups_membership_request_plus_invite_equals_member() {
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
+
+ // Create membership request
+ groups_send_membership_request( $u2, $g1 );
+
+ // Create draft invitation
+ $args = array(
+ 'user_id' => $u2,
+ 'group_id' => $g1,
+ 'inviter_id' => $u1,
+ 'date_modified' => bp_core_current_time(),
+ 'is_confirmed' => 0
+ );
+ groups_invite_user( $args );
+
+ // Send the invitation
+ groups_send_invites( $u1, $g1 );
+
+ // User should now be a group member
+ $member = groups_is_user_member( $u2, $g1 );
+ $this->assertTrue( is_numeric( $member ) && $member > 0 );
+ }
+
+ /**
+ * @group groups_accept_all_pending_membership_requests
+ * @group group_membership_requests
+ * @group group_membership
+ */
+ public function test_groups_accept_all_pending_membership_requests() {
+ $u1 = $this->factory->user->create();
+ $u2 = $this->factory->user->create();
+ $u3 = $this->factory->user->create();
+ $g1 = $this->factory->group->create();
+
+ // Create membership request
+ groups_send_membership_request( $u1, $g1 );
+ groups_send_membership_request( $u2, $g1 );
+ groups_send_membership_request( $u3, $g1 );
+
+ groups_accept_all_pending_membership_requests( $g1 );
+
+ // All users should now be group members.
+ $members = new BP_Group_Member_Query( array( 'group_id' => $g1 ) );
+ $this->assertEqualSets( array( $u1, $u2, $u3 ), $members->user_ids );
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre>
</div>
</div>
</body>
</html>