1
0
Fork 0
mirror of https://github.com/buddypress/buddypress.git synced 2026-07-23 21:06:56 +08:00
buddypress/tests/phpunit/testcases/groups/template/group-is-visible.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

118 lines
3 KiB
PHP

<?php
/**
* @group groups
* @group template
*/
#[AllowDynamicProperties]
class BP_Tests_Groups_Template_Is_Visible extends BP_UnitTestCase {
public function set_up() {
parent::set_up();
if ( isset( $GLOBALS['groups_template'] ) ) {
$this->groups_template = $GLOBALS['groups_template'];
}
}
public function tear_down() {
if ( $this->groups_template ) {
$GLOBALS['groups_template'] = $this->groups_template;
}
parent::tear_down();
}
public function test_bp_group_is_visible_no_member() {
$g = self::factory()->group->create( array( 'status' => 'private' ) );
$this->assertFalse( bp_group_is_visible( $g ) );
}
public function test_bp_group_is_visible_regular_member() {
$g = self::factory()->group->create( array( 'status' => 'private' ) );
$u = self::factory()->user->create();
wp_set_current_user( $u );
$this->assertFalse( bp_group_is_visible( $g ) );
}
public function test_bp_group_is_visible_regular_member_from_group() {
$g = self::factory()->group->create( array( 'status' => 'private' ) );
$u = self::factory()->user->create();
wp_set_current_user( $u );
$this->add_user_to_group( $u, $g );
$this->assertTrue( bp_group_is_visible( $g ) );
}
public function test_bp_group_is_visible_invalid_group() {
$u = self::factory()->user->create();
// Empty the current group.
$GLOBALS['groups_template'] = new stdClass;
$GLOBALS['groups_template']->group = null;
wp_set_current_user( $u );
$this->assertFalse( bp_group_is_visible() );
}
public function test_bp_group_is_visible_admin() {
$g = self::factory()->group->create( array( 'status' => 'private' ) );
$u = self::factory()->user->create( array( 'role' => 'administrator' ) );
wp_set_current_user( $u );
$this->assertTrue( bp_group_is_visible( $g ) );
}
public function test_bp_group_is_visible_using_user_id() {
$g = self::factory()->group->create( array( 'status' => 'hidden' ) );
$u = self::factory()->user->create();
$this->add_user_to_group( $u, $g );
$this->assertTrue( bp_group_is_visible( $g, $u ) );
}
public function test_bp_group_is_not_visible_using_user_id() {
$g = self::factory()->group->create( array( 'status' => 'private' ) );
$u = self::factory()->user->create();
$this->assertFalse( bp_group_is_visible( $g, $u ) );
}
public function test_bp_group_is_visible_with_group_slug() {
$slug = 'test-group';
self::factory()->group->create(
array(
'status' => 'private',
'slug' => $slug,
)
);
$u = self::factory()->user->create( array( 'role' => 'administrator' ) );
wp_set_current_user( $u );
$this->assertTrue( bp_group_is_visible( $slug ) );
}
public function test_bp_group_is_visible_from_current_group() {
$g = self::factory()->group->create( array( 'status' => 'private' ) );
$u = self::factory()->user->create( array( 'role' => 'administrator' ) );
// Fake the current group.
$GLOBALS['groups_template'] = new stdClass;
$GLOBALS['groups_template']->group = groups_get_group( $g );
wp_set_current_user( $u );
$this->assertTrue( bp_group_is_visible() );
}
}