1
0
Fork 0
mirror of https://github.com/buddypress/buddypress.git synced 2026-07-24 21:16:56 +08:00
buddypress/tests/phpunit/testcases/groups/template/group-is-visible.php
Mathieu Viet 89a6666dc6 Fully enjoy Yoast’s PHPUnit polyfills
Using these polyfills let us use PHPUnit v9.x for our tests and add PHP 8.1 to our testing matrix. Some additional edits to our PHP unit tests suite were needed:

- Stop using PHPunit deprecated functions.
- Rename some `BP_UnitTestCase` methods to use Yoast's polyfills.
- Edit the PHP Unit test GH action and also run this action on pull requests.
- Update some composer dependencies, remove the one about `phpunit/phpunit:^7.5` and add a new composer script to use PHPUnit v9.x. 

Props renatonascalves, rafiahmedd

Closes https://github.com/buddypress/buddypress/pull/13
Fixes #8649


git-svn-id: https://buddypress.svn.wordpress.org/trunk@13314 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2022-08-13 08:58:51 +00:00

117 lines
3 KiB
PHP

<?php
/**
* @group groups
* @group template
*/
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() );
}
}