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 1b2c2a9801 Adding the newly created helper functions bp_get_group_by and bp_get_group for Groups related functions
and template files.

Also, adding several PHP fixes/tweaks. And unit tests.

Fixes #6749

git-svn-id: https://buddypress.svn.wordpress.org/trunk@13097 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2021-08-26 01:29:03 +00:00

117 lines
3 KiB
PHP

<?php
/**
* @group groups
* @group template
*/
class BP_Tests_Groups_Template_Is_Visible extends BP_UnitTestCase {
public function setUp() {
parent::setUp();
if ( isset( $GLOBALS['groups_template'] ) ) {
$this->groups_template = $GLOBALS['groups_template'];
}
}
public function tearDown() {
if ( $this->groups_template ) {
$GLOBALS['groups_template'] = $this->groups_template;
}
parent::tearDown();
}
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() );
}
}