Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/21/2016 07:44:45 AM (8 years ago)
Author:
imath
Message:

Introduce screen notifications for activity comments and activity comment replies

Users will be notified about comments made on their activities and about replies made on their activity comments.

If there is only one notification of the above types, the WP Admin Bar bubble will link to the single activity. Clicking on this link will mark the notification as read.
If there are more than one, we use the notifications screen and an extra parameter to filter the notifications according to the type so that only these notifications are displayed. Clicking on the listed links will mark the notification as read.

Props dcavins, boonebgorges, DJPaul

Fixes #6057

File:
1 edited

Legend:

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

    r10457 r10715  
    288288        ) );
    289289    }
     290
     291    /**
     292     * @group bp_activity_format_notifications
     293     */
     294    public function test_bp_activity_format_notifications_new_at_mention() {
     295        $this->test_format_filter = array();
     296
     297        // Current user is $this->u1, so $this->u2 posted the mention
     298        $a = $this->factory->activity->create( array(
     299            'user_id' => $this->u2,
     300            'component' => buddypress()->activity->id,
     301            'type' => 'activity_update',
     302            'content' => 'fake new_at_mention activity',
     303        ) );
     304
     305        add_filter( 'bp_activity_single_at_mentions_notification', array( $this, 'format_notification_filter' ), 10, 1 );
     306        add_filter( 'bp_activity_multiple_at_mentions_notification', array( $this, 'format_notification_filter' ), 10, 1 );
     307
     308        $format_tests = array(
     309            'array_single'    => bp_activity_format_notifications( 'new_at_mention', $a, $this->u2, 1, 'array' ),
     310            'string_single'   => bp_activity_format_notifications( 'new_at_mention', $a, $this->u2, 1 ),
     311            'array_multiple'  => bp_activity_format_notifications( 'new_at_mention', $a, $this->u2, 2, 'array' ),
     312            'string_multiple' => bp_activity_format_notifications( 'new_at_mention', $a, $this->u2, 2 ),
     313        );
     314
     315        remove_filter( 'bp_activity_single_at_mentions_notification', array( $this, 'format_notification_filter' ), 10, 1 );
     316        remove_filter( 'bp_activity_multiple_at_mentions_notification', array( $this, 'format_notification_filter' ), 10, 1 );
     317
     318        $single = sprintf( __( '%1$s mentioned you', 'buddypress' ), bp_core_get_user_displayname( $this->u2 ) );
     319        $multiple = 'You have 2 new mentions';
     320
     321        $this->assertContains( $single, $format_tests['string_single'] );
     322        $this->assertContains( $single, $format_tests['array_single']['text'] );
     323        $this->assertContains( $multiple, $format_tests['string_multiple'] );
     324        $this->assertContains( $multiple, $format_tests['array_multiple']['text'] );
     325
     326        // Check filters
     327        $this->assertTrue( 4 === count( $this->test_format_filter ) );
     328    }
     329
     330    public function format_notification_filter( $return ) {
     331        $this->test_format_filter[] = current_filter();
     332        return $return;
     333    }
     334
     335    /**
     336     * @group bp_activity_update_reply_add_notification
     337     * @group bp_activity_comment_reply_add_notification
     338     */
     339    public function test_bp_activity_comment_add_notification() {
     340        $a = $this->factory->activity->create( array(
     341            'user_id' => $this->u1,
     342            'component' => buddypress()->activity->id,
     343            'type' => 'activity_update',
     344            'content' => 'Please comment this activity.',
     345        ) );
     346
     347        $c = bp_activity_new_comment( array(
     348            'content'     => 'this is the comment',
     349            'user_id'     => $this->u2,
     350            'activity_id' => $a, // ID of the root activity item.
     351            'parent_id'   => false  // ID of a parent comment (optional).
     352        ) );
     353
     354        $u3 = $this->factory->user->create();
     355
     356        $r3 = bp_activity_new_comment( array(
     357            'content'     => 'this is a reply to a comment',
     358            'user_id'     => $u3,
     359            'activity_id' => $a, // ID of the root activity item.
     360            'parent_id'   => $c  // ID of a parent comment (optional).
     361        ) );
     362
     363        $u1_notifications = BP_Notifications_Notification::get( array(
     364            'user_id' => $this->u1,
     365        ) );
     366
     367        $expected_commenters = array( $this->u2, $u3 );
     368        $this->assertEquals( $expected_commenters, wp_list_pluck( $u1_notifications, 'secondary_item_id' ) );
     369
     370        $u2_notifications = BP_Notifications_Notification::get( array(
     371            'user_id' => $this->u2,
     372        ) );
     373
     374        $expected_commenter = array( $u3 );
     375        $this->assertEquals( $expected_commenter, wp_list_pluck( $u2_notifications, 'secondary_item_id' ) );
     376    }
    290377}
Note: See TracChangeset for help on using the changeset viewer.