Skip to:
Content

BuddyPress.org

Ticket #7375: 7375.diff

File 7375.diff, 2.8 KB (added by boonebgorges, 9 years ago)
  • src/bp-groups/bp-groups-notifications.php

    diff --git src/bp-groups/bp-groups-notifications.php src/bp-groups/bp-groups-notifications.php
    index ac9e8c4..327da19 100644
    add_action( 'groups_reject_invite', 'bp_groups_accept_invite_mark_notifications' 
    967967add_action( 'groups_delete_invite', 'bp_groups_accept_invite_mark_notifications', 10, 2 );
    968968
    969969/**
     970 * Mark notifications read when a member's group membership request is granted.
     971 *
     972 * @since 2.8.0
     973 *
     974 * @param int $user_id  ID of the user.
     975 * @param int $group_id ID of the group.
     976 */
     977function bp_groups_accept_request_mark_notifications( $user_id, $group_id ) {
     978        if ( bp_is_active( 'notifications' ) ) {
     979                // First null parameter marks read for all admins.
     980                bp_notifications_mark_notifications_by_item_id( null, $group_id, buddypress()->groups->id, 'new_membership_request', $user_id );
     981        }
     982}
     983add_action( 'groups_membership_accepted', 'bp_groups_accept_request_mark_notifications', 10, 2 );
     984add_action( 'groups_membership_rejected', 'bp_groups_accept_request_mark_notifications', 10, 2 );
     985
     986/**
    970987 * Mark notifications read when a member views their group memberships.
    971988 *
    972989 * @since 1.9.0
  • tests/phpunit/testcases/groups/notifications.php

    diff --git tests/phpunit/testcases/groups/notifications.php tests/phpunit/testcases/groups/notifications.php
    index 6600daa..103c1c1 100644
    class BP_Tests_Groups_Notifications extends BP_UnitTestCase { 
    218218                $this->filter_fired = current_filter();
    219219                return $value;
    220220        }
     221
     222        /**
     223         * @group BP7375
     224         */
     225        public function test_membership_request_notifications_should_be_cleared_when_request_is_accepted() {
     226                $users = $this->factory->user->create_many( 3 );
     227
     228                $this->add_user_to_group( $users[0], $this->group, array(
     229                        'is_admin' => 1,
     230                ) );
     231                $this->add_user_to_group( $users[1], $this->group, array(
     232                        'is_admin' => 1,
     233                ) );
     234
     235                groups_send_membership_request( $users[2], $this->group );
     236
     237                // Both admins should get a notification.
     238                $get_args = array(
     239                        'user_id' => $users[0],
     240                        'item_id' => $this->group,
     241                        'secondary_item_id' => $users[2],
     242                        'component_action' => 'new_membership_request',
     243                        'is_new' => true,
     244                );
     245                $u0_notifications = BP_Notifications_Notification::get( $get_args );
     246                $u1_notifications = BP_Notifications_Notification::get( $get_args );
     247                $this->assertNotEmpty( $u0_notifications );
     248                $this->assertNotEmpty( $u1_notifications );
     249
     250                $this->assertTrue( groups_invite_user( array(
     251                        'user_id' => $users[2],
     252                        'group_id' => $this->group,
     253                ) ) );
     254
     255                $u0_notifications = BP_Notifications_Notification::get( $get_args );
     256                $u1_notifications = BP_Notifications_Notification::get( $get_args );
     257                $this->assertEmpty( $u0_notifications );
     258                $this->assertEmpty( $u1_notifications );
     259        }
     260
    221261}