Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/05/2016 03:23:11 PM (4 years ago)
Author:
boonebgorges
Message:

Delete a user's notifications when the user is deleted.

Props henry.wright, Mamaduka.
Fixes #6681.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/notifications/functions.php

    r9888 r10437  
    234234        $this->assertEquals( 2, buddypress()->notifications->query_loop->total_notification_count );
    235235    }
     236
     237    /**
     238     * @group bp_notifications_delete_notifications_on_user_delete
     239     * @ticket BP6681
     240     */
     241    public function test_bp_notifications_delete_notifications_on_user_delete_should_delete_all_notifications() {
     242        $u = $this->factory->user->create();
     243
     244        // Create notifications
     245        $n1 = $this->factory->notification->create( array(
     246            'component_name'    => 'messages',
     247            'component_action'  => 'new_message',
     248            'item_id'           => 99,
     249            'user_id'           => $u,
     250        ) );
     251
     252        $n2 = $this->factory->notification->create( array(
     253            'component_name'    => 'activity',
     254            'component_action'  => 'new_at_mention',
     255            'item_id'           => 99,
     256            'user_id'           => $u,
     257        ) );
     258
     259        $n3 = $this->factory->notification->create( array(
     260            'component_name' => 'groups',
     261            'user_id'        => $u,
     262        ) );
     263
     264        $n4 = $this->factory->notification->create( array(
     265            'component_name'   => 'friends',
     266            'component_action' => 'friendship_request',
     267            'user_id'          => $u,
     268        ) );
     269
     270        // Create notification for non-core component
     271        $n5 = $this->factory->notification->create( array(
     272            'component_name'    => 'foo',
     273            'component_action'  => 'bar',
     274            'item_id'           => 99,
     275            'user_id'           => $u,
     276        ) );
     277
     278        global $wpdb, $bp;
     279
     280        /**
     281         * Can't use BP_Notifications_Notification::get(), because class::parse_args,
     282         * checks against bp_notifications_get_registered_components()
     283         * and if component is disabled it will be ignored.
     284         */
     285        $query = $wpdb->prepare( "SELECT id FROM {$bp->notifications->table_name} WHERE user_id = %d and is_new = 1", $u );
     286
     287        // Make sure notifications have been added.
     288        $found1 = $wpdb->get_col( $query );
     289        $this->assertEqualSets( array( $n1, $n2, $n3, $n4, $n5 ), $found1 );
     290
     291        wp_delete_user( $u );
     292
     293        // Check if notifications are deleted.
     294        $found2 = $wpdb->get_col( $query );
     295        $this->assertEmpty( $found2 );
     296    }
    236297}
Note: See TracChangeset for help on using the changeset viewer.