Skip to:
Content

BuddyPress.org

Changeset 9810


Ignore:
Timestamp:
04/27/2015 07:09:05 PM (9 years ago)
Author:
dcavins
Message:

Limit scope of group invitation delete functions.

Change behavior of groups_uninvite_user(),
groups_reject_invite() and
groups_delete_membership_request(),
to affect only the membership types referred to
by the function name. Adds tests to support the
new behavior.

See #6209.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-functions.php

    r9654 r9810  
    10881088function groups_uninvite_user( $user_id, $group_id ) {
    10891089
    1090     if ( !BP_Groups_Member::delete( $user_id, $group_id ) )
     1090    if ( ! BP_Groups_Member::delete_invite( $user_id, $group_id ) )
    10911091        return false;
    10921092
     
    11651165 */
    11661166function groups_reject_invite( $user_id, $group_id ) {
    1167     if ( ! BP_Groups_Member::delete( $user_id, $group_id ) )
     1167    if ( ! BP_Groups_Member::delete_invite( $user_id, $group_id ) )
    11681168        return false;
    11691169
     
    15751575        $membership = new BP_Groups_Member( false, false, $membership_id );
    15761576
    1577     if ( !BP_Groups_Member::delete( $membership->user_id, $membership->group_id ) )
     1577    if ( ! BP_Groups_Member::delete_request( $membership->user_id, $membership->group_id ) )
    15781578        return false;
    15791579
  • trunk/tests/phpunit/testcases/groups/class-bp-groups-member.php

    r9797 r9810  
    248248
    249249    /**
     250     * @group groups_reject_membership_request
     251     * @group group_membership_requests
     252     * @group group_membership
     253     */
     254    public function test_bp_groups_reject_membership_request_leave_memberships_intact() {
     255        $u1 = $this->factory->user->create();
     256        $g = $this->factory->group->create( array(
     257            'status' => 'private',
     258        ) );
     259
     260        $now = time();
     261        $this->add_user_to_group( $u1, $g );
     262
     263        // Confirmed memberships should be left intact.
     264        groups_reject_membership_request( null, $u1, $g );
     265        $u1_is_member = groups_is_user_member( $u1, $g );
     266        $this->assertTrue( is_numeric( $u1_is_member ) && $u1_is_member > 0 );
     267    }
     268
     269    /**
     270     * @group groups_reject_membership_request
     271     * @group group_membership_requests
     272     * @group group_membership
     273     */
     274    public function test_bp_groups_reject_membership_request_leave_invites_intact() {
     275        $u1 = $this->factory->user->create();
     276        $u2 = $this->factory->user->create();
     277        $g = $this->factory->group->create( array(
     278            'status' => 'private',
     279        ) );
     280
     281        $now = time();
     282        $this->add_user_to_group( $u1, $g, array(
     283            'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
     284        ) );
     285
     286        // Outstanding invitations should be left intact.
     287        self::invite_user_to_group( $u2, $g, $u1 );
     288        groups_reject_membership_request( null, $u2, $g );
     289        $u2_has_invite = groups_check_user_has_invite( $u2, $g );
     290        $this->assertTrue( is_numeric( $u2_has_invite ) && $u2_has_invite > 0 );
     291    }
     292
     293    /**
    250294     * @group groups_delete_membership_request
    251295     * @group group_membership_requests
     
    266310
    267311    /**
     312     * @group groups_delete_membership_request
     313     * @group group_membership_requests
     314     * @group group_membership
     315     */
     316    public function test_bp_groups_delete_membership_request_leave_memberships_intact() {
     317        $u1 = $this->factory->user->create();
     318        $g = $this->factory->group->create( array(
     319            'status' => 'private',
     320        ) );
     321
     322        $now = time();
     323        $this->add_user_to_group( $u1, $g );
     324
     325        // Confirmed memberships should be left intact.
     326        groups_delete_membership_request( null, $u1, $g );
     327        $u1_is_member = groups_is_user_member( $u1, $g );
     328        $this->assertTrue( is_numeric( $u1_is_member )  && $u1_is_member > 0 );
     329    }
     330
     331    /**
     332     * @group groups_delete_membership_request
     333     * @group group_membership_requests
     334     * @group group_membership
     335     */
     336    public function test_bp_groups_delete_membership_request_leave_invites_intact() {
     337        $u1 = $this->factory->user->create();
     338        $u2 = $this->factory->user->create();
     339        $g = $this->factory->group->create( array(
     340            'status' => 'private',
     341        ) );
     342
     343        $now = time();
     344        $this->add_user_to_group( $u1, $g, array(
     345            'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
     346        ) );
     347
     348        // Outstanding invitations should be left intact.
     349        self::invite_user_to_group( $u2, $g, $u1 );
     350        groups_delete_membership_request( null, $u2, $g );
     351        $u2_has_invite = groups_check_user_has_invite( $u2, $g );
     352        $this->assertTrue( is_numeric( $u2_has_invite ) && $u2_has_invite > 0 );
     353    }
     354
     355    /**
    268356     * @group groups_reject_invite
    269357     * @group group_invitations
     
    290378
    291379    /**
     380     * @group groups_reject_invite
     381     * @group group_invitations
     382     * @group group_membership
     383     */
     384    public function test_bp_groups_reject_invite_leave_memberships_intact() {
     385        $u1 = $this->factory->user->create();
     386        $g = $this->factory->group->create( array(
     387            'status' => 'private',
     388        ) );
     389
     390        $now = time();
     391        $this->add_user_to_group( $u1, $g, array(
     392            'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
     393        ) );
     394
     395        // Confirmed memberships should be left intact.
     396        groups_reject_invite( $u1, $g );
     397        $u1_is_member = groups_is_user_member( $u1, $g );
     398        $this->assertTrue( is_numeric( $u1_is_member ) && $u1_is_member > 0 );
     399    }
     400
     401    /**
     402     * @group groups_reject_invite
     403     * @group group_invitations
     404     * @group group_membership
     405     */
     406    public function test_bp_groups_reject_invite_leave_requests_intact() {
     407        $u1 = $this->factory->user->create();
     408        $g = $this->factory->group->create( array(
     409            'status' => 'private',
     410        ) );
     411
     412        // Membership requests should be left intact.
     413        self::create_group_membership_request( $u1, $g );
     414        groups_reject_invite( $u1, $g );
     415        $u1_has_request = groups_check_for_membership_request( $u1, $g );
     416        $this->assertTrue( is_numeric( $u1_has_request ) && $u1_has_request > 0 );
     417    }
     418
     419    /**
    292420     * @group groups_delete_invite
    293421     * @group group_invitations
     
    374502        $u2_has_invite = groups_check_user_has_invite( $u2, $g );
    375503        $this->assertEquals( 0, $u2_has_invite );
     504    }
     505
     506    /**
     507     * @group groups_uninvite_user
     508     * @group group_invitations
     509     * @group group_membership
     510     */
     511    public function test_bp_groups_uninvite_user_leave_memberships_intact() {
     512        $u1 = $this->factory->user->create();
     513        $g = $this->factory->group->create( array(
     514            'status' => 'private',
     515        ) );
     516
     517        $now = time();
     518        $this->add_user_to_group( $u1, $g, array(
     519            'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
     520        ) );
     521
     522        // Confirmed memberships should be left intact.
     523        $u1_is_member_before = groups_is_user_member( $u1, $g );
     524        groups_uninvite_user( $u1, $g );
     525        $u1_is_member = groups_is_user_member( $u1, $g );
     526        $this->assertTrue( is_numeric( $u1_is_member ) && $u1_is_member > 0 );
     527    }
     528
     529    /**
     530     * @group groups_uninvite_user
     531     * @group group_invitations
     532     * @group group_membership
     533     */
     534    public function test_bp_groups_uninvite_user_leave_requests_intact() {
     535        $u1 = $this->factory->user->create();
     536        $g = $this->factory->group->create( array(
     537            'status' => 'private',
     538        ) );
     539
     540        // Membership requests should be left intact.
     541        self::create_group_membership_request( $u1, $g );
     542        groups_uninvite_user( $u1, $g );
     543        $u1_has_request = groups_check_for_membership_request( $u1, $g );
     544        $this->assertTrue( is_numeric( $u1_has_request ) && $u1_has_request > 0 );
    376545    }
    377546
Note: See TracChangeset for help on using the changeset viewer.