mirror of
https://github.com/buddypress/buddypress.git
synced 2026-07-23 21:06:56 +08:00
- Add the `#[AllowDynamicProperties]` attribute to classes when we add dynamic properties to these into our codebase. - Add PHP 8.2 to our PHPUnit testing matrix Closes https://github.com/buddypress/buddypress/pull/62 Fixes #8820 git-svn-id: https://buddypress.svn.wordpress.org/trunk@13414 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
118 lines
3 KiB
PHP
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 = $this->factory->group->create( array( 'status' => 'private' ) );
|
|
|
|
$this->assertFalse( bp_group_is_visible( $g ) );
|
|
}
|
|
|
|
public function test_bp_group_is_visible_regular_member() {
|
|
$g = $this->factory->group->create( array( 'status' => 'private' ) );
|
|
$u = $this->factory->user->create();
|
|
|
|
$this->set_current_user( $u );
|
|
|
|
$this->assertFalse( bp_group_is_visible( $g ) );
|
|
}
|
|
|
|
public function test_bp_group_is_visible_regular_member_from_group() {
|
|
$g = $this->factory->group->create( array( 'status' => 'private' ) );
|
|
$u = $this->factory->user->create();
|
|
|
|
$this->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 = $this->factory->user->create();
|
|
|
|
// Empty the current group.
|
|
$GLOBALS['groups_template'] = new stdClass;
|
|
$GLOBALS['groups_template']->group = null;
|
|
|
|
$this->set_current_user( $u );
|
|
|
|
$this->assertFalse( bp_group_is_visible() );
|
|
}
|
|
|
|
public function test_bp_group_is_visible_admin() {
|
|
$g = $this->factory->group->create( array( 'status' => 'private' ) );
|
|
$u = $this->factory->user->create( array( 'role' => 'administrator' ) );
|
|
|
|
$this->set_current_user( $u );
|
|
|
|
$this->assertTrue( bp_group_is_visible( $g ) );
|
|
}
|
|
|
|
public function test_bp_group_is_visible_using_user_id() {
|
|
$g = $this->factory->group->create( array( 'status' => 'hidden' ) );
|
|
$u = $this->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 = $this->factory->group->create( array( 'status' => 'private' ) );
|
|
$u = $this->factory->user->create();
|
|
|
|
$this->assertFalse( bp_group_is_visible( $g, $u ) );
|
|
}
|
|
|
|
public function test_bp_group_is_visible_with_group_slug() {
|
|
$slug = 'test-group';
|
|
|
|
$this->factory->group->create(
|
|
array(
|
|
'status' => 'private',
|
|
'slug' => $slug,
|
|
)
|
|
);
|
|
|
|
$u = $this->factory->user->create( array( 'role' => 'administrator' ) );
|
|
|
|
$this->set_current_user( $u );
|
|
|
|
$this->assertTrue( bp_group_is_visible( $slug ) );
|
|
}
|
|
|
|
public function test_bp_group_is_visible_from_current_group() {
|
|
$g = $this->factory->group->create( array( 'status' => 'private' ) );
|
|
$u = $this->factory->user->create( array( 'role' => 'administrator' ) );
|
|
|
|
// Fake the current group.
|
|
$GLOBALS['groups_template'] = new stdClass;
|
|
$GLOBALS['groups_template']->group = groups_get_group( $g );
|
|
|
|
$this->set_current_user( $u );
|
|
|
|
$this->assertTrue( bp_group_is_visible() );
|
|
}
|
|
}
|