1
0
Fork 0
mirror of https://github.com/buddypress/buddypress.git synced 2026-07-22 20:56:55 +08:00
buddypress/tests/phpunit/testcases/messages/class.bp-messages-notice.php
Renato Alves f15348c102 A user is no longer de-authenticated when making REST API requests.
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
2024-11-03 18:19:06 +00:00

54 lines
1.4 KiB
PHP

<?php
/**
* @group notices
*/
class BP_Tests_BP_Messages_Notice_TestCases extends BP_UnitTestCase {
protected $old_current_user = 0;
public function set_up() {
parent::set_up();
$this->old_current_user = get_current_user_id();
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
}
public function tear_down() {
wp_set_current_user( $this->old_current_user );
parent::tear_down();
}
/**
* @group cache
*/
public function test_get_active_notices() {
// send notice
$subject = 'Test notice';
$message = 'This is a notice';
messages_send_notice( $subject, $message );
// now get the active notice and assert
$notice = BP_Messages_Notice::get_active();
$this->assertEquals( $subject, $notice->subject );
$this->assertEquals( $message, $notice->message );
// deactivate notice and make sure cache is invalidated
$notice->deactivate();
$this->assertFalse( wp_cache_get( 'active_notice', 'bp_messages' ) );
// create a new notice
$subject2 = 'Another notice';
$message2 = 'Say what?';
messages_send_notice( $subject2, $message2 );
// now get the new active notice
BP_Messages_Notice::get_active();
// grab the cache and make sure it equals our new notice
$cache = wp_cache_get( 'active_notice', 'bp_messages' );
$this->assertEquals( $subject2, $cache->subject );
$this->assertEquals( $message2, $cache->message );
}
}