Skip to:
Content

BuddyPress.org

Ticket #6209: 6209-correct-behavior.10.patch

File 6209-correct-behavior.10.patch, 7.5 KB (added by dcavins, 5 years ago)

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

  • src/bp-groups/bp-groups-functions.php

    diff --git src/bp-groups/bp-groups-functions.php src/bp-groups/bp-groups-functions.php
    index 011231f..8b19738 100644
    function groups_invite_user( $args = '' ) { 
    10831083 */
    10841084function groups_uninvite_user( $user_id, $group_id ) {
    10851085
    1086         if ( !BP_Groups_Member::delete( $user_id, $group_id ) )
     1086        if ( ! BP_Groups_Member::delete_invite( $user_id, $group_id ) )
    10871087                return false;
    10881088
    10891089        /**
    function groups_accept_invite( $user_id, $group_id ) { 
    11601160 * @return bool True on success, false on failure.
    11611161 */
    11621162function groups_reject_invite( $user_id, $group_id ) {
    1163         if ( ! BP_Groups_Member::delete( $user_id, $group_id ) )
     1163        if ( ! BP_Groups_Member::delete_invite( $user_id, $group_id ) )
    11641164                return false;
    11651165
    11661166        /**
    function groups_delete_membership_request( $membership_id, $user_id = 0, $group_ 
    15701570        else
    15711571                $membership = new BP_Groups_Member( false, false, $membership_id );
    15721572
    1573         if ( !BP_Groups_Member::delete( $membership->user_id, $membership->group_id ) )
     1573        if ( ! BP_Groups_Member::delete_request( $membership->user_id, $membership->group_id ) )
    15741574                return false;
    15751575
    15761576        return $membership;
  • tests/phpunit/testcases/groups/class-bp-groups-member.php

    diff --git tests/phpunit/testcases/groups/class-bp-groups-member.php tests/phpunit/testcases/groups/class-bp-groups-member.php
    index 2f92182..1db0d5f 100644
    class BP_Tests_BP_Groups_Member_TestCases extends BP_UnitTestCase { 
    247247        }
    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
    252296         * @group group_membership
    class BP_Tests_BP_Groups_Member_TestCases extends BP_UnitTestCase { 
    265309        }
    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
    270358         * @group group_membership
    class BP_Tests_BP_Groups_Member_TestCases extends BP_UnitTestCase { 
    289377        }
    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
    294422         * @group group_membership
    class BP_Tests_BP_Groups_Member_TestCases extends BP_UnitTestCase { 
    376504        }
    377505
    378506        /**
     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 );
     545        }
     546
     547        /**
    379548         * @group groups_join_group
    380549         * @group group_membership
    381550         */