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
53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* @group core
|
|
* @group template
|
|
*/
|
|
class BP_Tests_Core_Template_BpUserHasAccess extends BP_UnitTestCase {
|
|
protected $permalink_structure = '';
|
|
|
|
public function set_up() {
|
|
parent::set_up();
|
|
$this->permalink_structure = get_option( 'permalink_structure', '' );
|
|
}
|
|
|
|
public function tear_down() {
|
|
$this->set_permalink_structure( $this->permalink_structure );
|
|
|
|
parent::tear_down();
|
|
}
|
|
|
|
public function test_should_return_true_for_bp_moderate_user() {
|
|
$users = self::factory()->user->create_many( 2 );
|
|
|
|
$this->grant_bp_moderate( $users[0] );
|
|
wp_set_current_user( $users[0] );
|
|
$this->set_permalink_structure( '/%postname%/' );
|
|
|
|
$this->go_to( bp_members_get_user_url( $users[1] ) );
|
|
|
|
$this->assertTrue( bp_user_has_access( $users[0] ) );
|
|
}
|
|
|
|
public function test_should_return_false_on_anothers_profile_for_user_without_bp_moderate() {
|
|
$users = self::factory()->user->create_many( 2 );
|
|
|
|
wp_set_current_user( $users[0] );
|
|
$this->set_permalink_structure( '/%postname%/' );
|
|
|
|
$this->go_to( bp_members_get_user_url( $users[1] ) );
|
|
|
|
$this->assertFalse( bp_user_has_access( $users[0] ) );
|
|
}
|
|
|
|
public function test_should_return_true_on_own_profile() {
|
|
$users = self::factory()->user->create_many( 2 );
|
|
|
|
wp_set_current_user( $users[0] );
|
|
$this->set_permalink_structure( '/%postname%/' );
|
|
|
|
$this->go_to( bp_members_get_user_url( $users[0] ) );
|
|
|
|
$this->assertTrue( bp_user_has_access( $users[0] ) );
|
|
}
|
|
}
|