mirror of
https://github.com/buddypress/buddypress.git
synced 2026-07-22 20:56:55 +08:00
We are introducing a new `BP_LoggedIn_User` class to fetch data about a BuddyPress logged-in user. This new addition fixes an issue where a user could be de-authenticated when making REST API requests. Props dcavins, DJPaul, johnjamesjacoby, and imath. Closes https://github.com/buddypress/buddypress/pull/395 See #9229 and #9145 Fixes #7658 git-svn-id: https://buddypress.svn.wordpress.org/trunk@14070 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
73 lines
2.9 KiB
PHP
73 lines
2.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group friends
|
|
*/
|
|
class BP_Tests_Friends_Notifications extends BP_UnitTestcase {
|
|
protected $filter_fired;
|
|
protected $current_user;
|
|
protected $friend;
|
|
|
|
public function set_up() {
|
|
parent::set_up();
|
|
$this->current_user = get_current_user_id();
|
|
wp_set_current_user( self::factory()->user->create() );
|
|
|
|
$this->friend = self::factory()->user->create();
|
|
$this->filter_fired = '';
|
|
}
|
|
|
|
public function tear_down() {
|
|
wp_set_current_user( $this->current_user );
|
|
parent::tear_down();
|
|
}
|
|
|
|
/**
|
|
* @group friends_format_notifications
|
|
*/
|
|
public function test_friends_format_notifications_bp_friends_multiple_friendship_accepted_notification_filter() {
|
|
add_filter( 'bp_friends_multiple_friendship_accepted_notification', array( $this, 'notification_filter_callback' ) );
|
|
$n = friends_format_notifications( 'friendship_accepted', $this->friend, 0, 5 );
|
|
remove_filter( 'bp_friends_multiple_friendship_accepted_notification', array( $this, 'notification_filter_callback' ) );
|
|
|
|
$this->assertSame( 'bp_friends_multiple_friendship_accepted_notification', $this->filter_fired );
|
|
}
|
|
|
|
/**
|
|
* @group friends_format_notifications
|
|
*/
|
|
public function test_friends_format_notifications_bp_friends_single_friendship_accepted_notification_filter() {
|
|
add_filter( 'bp_friends_single_friendship_accepted_notification', array( $this, 'notification_filter_callback' ) );
|
|
$n = friends_format_notifications( 'friendship_accepted', $this->friend, 0, 1 );
|
|
remove_filter( 'bp_friends_single_friendship_accepted_notification', array( $this, 'notification_filter_callback' ) );
|
|
|
|
$this->assertSame( 'bp_friends_single_friendship_accepted_notification', $this->filter_fired );
|
|
}
|
|
|
|
/**
|
|
* @group friends_format_notifications
|
|
*/
|
|
public function test_friends_format_notifications_bp_friends_multiple_friendship_request_notification_filter() {
|
|
add_filter( 'bp_friends_multiple_friendship_request_notification', array( $this, 'notification_filter_callback' ) );
|
|
$n = friends_format_notifications( 'friendship_request', $this->friend, 0, 5 );
|
|
remove_filter( 'bp_friends_multiple_friendship_request_notification', array( $this, 'notification_filter_callback' ) );
|
|
|
|
$this->assertSame( 'bp_friends_multiple_friendship_request_notification', $this->filter_fired );
|
|
}
|
|
|
|
/**
|
|
* @group friends_format_notifications
|
|
*/
|
|
public function test_friends_format_notifications_bp_friends_single_friendship_request_notification_filter() {
|
|
add_filter( 'bp_friends_single_friendship_request_notification', array( $this, 'notification_filter_callback' ) );
|
|
$n = friends_format_notifications( 'friendship_request', $this->friend, 0, 1 );
|
|
remove_filter( 'bp_friends_single_friendship_request_notification', array( $this, 'notification_filter_callback' ) );
|
|
|
|
$this->assertSame( 'bp_friends_single_friendship_request_notification', $this->filter_fired );
|
|
}
|
|
|
|
public function notification_filter_callback( $value ) {
|
|
$this->filter_fired = current_filter();
|
|
return $value;
|
|
}
|
|
}
|