Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/21/2017 10:37:23 PM (2 years ago)
Author:
r-a-y
Message:

Groups: Add fine-grained querying of invite sent status in groups_get_invites_for_group().

This commit introduces a new $sent parameter to groups_get_invites_for_group()
and BP_Groups_Group::get_invites(). With this parameter, developers can
now query group invites by sent status or not.

See #7397.

File:
1 edited

Legend:

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

    r11378 r11604  
    11511151
    11521152    /**
    1153      * @group groups_send_membership_request
    1154      * @group group_membership_requests
    1155      * @group group_membership
    1156      */
    1157     public function test_groups_send_membership_request() {
    1158         $u1 = $this->factory->user->create();
    1159         $g1 = $this->factory->group->create();
    1160 
    1161         // Create membership request
    1162         groups_send_membership_request( $u1, $g1 );
    1163 
    1164         $request = groups_check_for_membership_request( $u1, $g1 );
    1165         $this->assertTrue( is_numeric( $request ) && $request > 0 );
    1166     }
    1167 
    1168     /**
    1169      * @group groups_accept_membership_request
    1170      * @group group_membership_requests
    1171      * @group group_membership
    1172      */
    1173     public function test_groups_accept_membership_request_by_membership_id() {
    1174         $u1 = $this->factory->user->create();
    1175         $g1 = $this->factory->group->create();
    1176 
    1177         // Create membership request
    1178         groups_send_membership_request( $u1, $g1 );
    1179 
    1180         // Get group invitations of any type, from any user in the group.
    1181         $member = new BP_Groups_Member( $u1, $g1 );
    1182 
    1183         groups_accept_membership_request( $member->id );
    1184 
    1185         // User should now be a group member.
    1186         $member = groups_is_user_member( $u1, $g1 );
    1187 
    1188         $this->assertTrue( is_numeric( $member ) && $member > 0 );
    1189     }
    1190 
    1191     /**
    1192      * @group groups_accept_membership_request
    1193      * @group group_membership_requests
    1194      * @group group_membership
    1195      */
    1196     public function test_groups_accept_membership_request_by_user_id_group_id() {
    1197         $u1 = $this->factory->user->create();
    1198         $g1 = $this->factory->group->create();
    1199 
    1200         // Create membership request
    1201         groups_send_membership_request( $u1, $g1 );
    1202 
    1203         groups_accept_membership_request( null, $u1, $g1 );
    1204 
    1205         // User should now be a group member
    1206         $member = groups_is_user_member( $u1, $g1 );
    1207         $this->assertTrue( is_numeric( $member ) && $member > 0 );
    1208     }
    1209 
    1210     /**
    1211      * @group groups_send_invites
    1212      * @group group_invitations
    1213      * @group group_membership_requests
    1214      * @group group_membership
    1215      */
    1216     public function test_groups_membership_request_plus_invite_equals_member() {
    1217         $u1 = $this->factory->user->create();
    1218         $u2 = $this->factory->user->create();
    1219         $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
    1220 
    1221         // Create membership request
    1222         groups_send_membership_request( $u2, $g1 );
     1153     * @group groups_get_invites_for_group
     1154     * @group group_send_invites
     1155     * @group group_invitations
     1156     * @group group_membership
     1157     */
     1158    public function test_groups_get_invites_for_group_with_sent_parameter() {
     1159        $u1 = $this->factory->user->create();
     1160        $u2 = $this->factory->user->create();
     1161        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
    12231162
    12241163        // Create draft invitation
     
    12311170        ) );
    12321171
     1172        // Send the invitation; this will set the 'invite_sent' value to 1.
     1173        groups_send_invites( $u1, $g1 );
     1174
     1175        // Default groups_get_invites_for_group() call
     1176        $i = groups_get_invites_for_group( $u1, $g1 );
     1177        $this->assertEqualSets( array( $u2 ), $i );
     1178
     1179        // Fetch users whose invites have been sent out; should be the same as above.
     1180        $i = groups_get_invites_for_group( $u1, $g1 );
     1181        $this->assertEqualSets( array( $u2 ), $i );
     1182
     1183        // Fetch users whose invites haven't been sent yet.
     1184        $i = groups_get_invites_for_group( $u1, $g1, 0 );
     1185        $this->assertEmpty( $i );
     1186    }
     1187
     1188    /**
     1189     * @group groups_send_membership_request
     1190     * @group group_membership_requests
     1191     * @group group_membership
     1192     */
     1193    public function test_groups_send_membership_request() {
     1194        $u1 = $this->factory->user->create();
     1195        $g1 = $this->factory->group->create();
     1196
     1197        // Create membership request
     1198        groups_send_membership_request( $u1, $g1 );
     1199
     1200        $request = groups_check_for_membership_request( $u1, $g1 );
     1201        $this->assertTrue( is_numeric( $request ) && $request > 0 );
     1202    }
     1203
     1204    /**
     1205     * @group groups_accept_membership_request
     1206     * @group group_membership_requests
     1207     * @group group_membership
     1208     */
     1209    public function test_groups_accept_membership_request_by_membership_id() {
     1210        $u1 = $this->factory->user->create();
     1211        $g1 = $this->factory->group->create();
     1212
     1213        // Create membership request
     1214        groups_send_membership_request( $u1, $g1 );
     1215
     1216        // Get group invitations of any type, from any user in the group.
     1217        $member = new BP_Groups_Member( $u1, $g1 );
     1218
     1219        groups_accept_membership_request( $member->id );
     1220
     1221        // User should now be a group member.
     1222        $member = groups_is_user_member( $u1, $g1 );
     1223
     1224        $this->assertTrue( is_numeric( $member ) && $member > 0 );
     1225    }
     1226
     1227    /**
     1228     * @group groups_accept_membership_request
     1229     * @group group_membership_requests
     1230     * @group group_membership
     1231     */
     1232    public function test_groups_accept_membership_request_by_user_id_group_id() {
     1233        $u1 = $this->factory->user->create();
     1234        $g1 = $this->factory->group->create();
     1235
     1236        // Create membership request
     1237        groups_send_membership_request( $u1, $g1 );
     1238
     1239        groups_accept_membership_request( null, $u1, $g1 );
     1240
     1241        // User should now be a group member
     1242        $member = groups_is_user_member( $u1, $g1 );
     1243        $this->assertTrue( is_numeric( $member ) && $member > 0 );
     1244    }
     1245
     1246    /**
     1247     * @group groups_send_invites
     1248     * @group group_invitations
     1249     * @group group_membership_requests
     1250     * @group group_membership
     1251     */
     1252    public function test_groups_membership_request_plus_invite_equals_member() {
     1253        $u1 = $this->factory->user->create();
     1254        $u2 = $this->factory->user->create();
     1255        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     1256
     1257        // Create membership request
     1258        groups_send_membership_request( $u2, $g1 );
     1259
     1260        // Create draft invitation
     1261        groups_invite_user( array(
     1262            'user_id'       => $u2,
     1263            'group_id'      => $g1,
     1264            'inviter_id'    => $u1,
     1265            'date_modified' => bp_core_current_time(),
     1266            'is_confirmed'  => 0
     1267        ) );
     1268
    12331269        // Send the invitation
    12341270        groups_send_invites( $u1, $g1 );
Note: See TracChangeset for help on using the changeset viewer.