Skip to:
Content

BuddyPress.org

Ticket #6462: 6462.03.patch

File 6462.03.patch, 2.3 KB (added by dcavins, 9 years ago)

Adds unit tests to check draft invitation removal.

  • src/bp-groups/classes/class-bp-groups-member.php

    diff --git src/bp-groups/classes/class-bp-groups-member.php src/bp-groups/classes/class-bp-groups-member.php
    index 06a0705..cbebf75 100644
    class BP_Groups_Member { 
    733733
    734734                $bp = buddypress();
    735735
    736                 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id != 0 AND invite_sent = 1", $user_id, $group_id ) );
     736                return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id != 0", $user_id, $group_id ) );
    737737        }
    738738
    739739        /**
  • 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 1db0d5f..30b547a 100644
    class BP_Tests_BP_Groups_Member_TestCases extends BP_UnitTestCase { 
    445445         * @group group_invitations
    446446         * @group group_membership
    447447         */
     448        public function test_bp_groups_delete_invite_remove_draft_invite() {
     449                $u1 = $this->factory->user->create();
     450                $u2 = $this->factory->user->create();
     451                $g = $this->factory->group->create( array(
     452                        'status' => 'private',
     453                ) );
     454
     455                $now = time();
     456                $this->add_user_to_group( $u1, $g, array(
     457                        'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
     458                ) );
     459
     460                // Create the draft invitation.
     461                $args = array(
     462                        'user_id'       => $u2,
     463                        'group_id'      => $g,
     464                        'inviter_id'    => $u1
     465                );
     466                groups_invite_user( $args );
     467                // Check that the invite got created.
     468                $u2_has_invite = groups_check_user_has_invite( $u2, $g, $type = 'all' );
     469                $this->assertTrue( is_numeric( $u2_has_invite ) && $u2_has_invite > 0 );
     470
     471                // The invitation should be removed.
     472                groups_delete_invite( $u2, $g );
     473                $u2_has_invite = groups_check_user_has_invite( $u2, $g, $type = 'all' );
     474                $this->assertEquals( 0, $u2_has_invite );
     475        }
     476
     477        /**
     478         * @group groups_delete_invite
     479         * @group group_invitations
     480         * @group group_membership
     481         */
    448482        public function test_bp_groups_delete_invite_leave_memberships_intact() {
    449483                $u1 = $this->factory->user->create();
    450484                $g = $this->factory->group->create( array(