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/bpGroupStatusMessage.php
Renato Alves 516f8d995f We are introducing in this commit two new helper functions to get a group: bp_get_group_by and bp_get_group. The former allows for getting a group by id/ID or slug.
And the latter allows for getting a group by id/ID, group object, slug. And when used in the context of a Group loop built by the `BP_Groups_Template` class, it defaults to the Group being iterated on.

- The new helper functions were applied to several functions in the Group component.
- `bp_group_is_visible` was updated to check against a specific user ID. Previously, only the current logged in user was verified.
- `bp_get_group_avatar` was updated to use the new functions and new arguments that are passed to `bp_core_fetch_avatar` were added.
- PHPDoc were updated to reflect those changes.

Props imath, boonebgorges and DJPaul

Fixes #6749 (trunk)

git-svn-id: https://buddypress.svn.wordpress.org/trunk@13085 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2021-08-22 00:38:43 +00:00

163 lines
4.4 KiB
PHP

<?php
/**
* @group groups
* @group template
*/
class BP_Tests_Groups_Template_Status_Message extends BP_UnitTestCase {
private $current_user;
private $groups_template = null;
public function setUp() {
parent::setUp();
$this->current_user = bp_loggedin_user_id();
$this->set_current_user( 0 );
if ( isset( $GLOBALS['groups_template'] ) ) {
$this->groups_template = $GLOBALS['groups_template'];
}
}
public function tearDown() {
$this->set_current_user( $this->current_user );
if ( $this->groups_template ) {
$GLOBALS['groups_template'] = $this->groups_template;
}
parent::tearDown();
}
/**
* @group BP6319
*/
public function test_private_group_where_logged_in_user_has_not_requested_membership_but_has_been_invited() {
$users = self::factory()->user->create_many( 2 );
$g = self::factory()->group->create( array( 'status' => 'private' ) );
$this->set_current_user( $users[0] );
groups_invite_user( array(
'user_id' => $users[0],
'group_id' => $g,
'inviter_id' => $users[1],
) );
if ( bp_has_groups( array( 'include' => array( $g ) ) ) ) {
while ( bp_groups() ) {
bp_the_group();
$found = get_echo( 'bp_group_status_message' );
}
}
$expected = __( 'This is a private group and you must request group membership in order to join.', 'buddypress' );
$this->assertSame( $expected, $found );
}
/**
* @group BP6319
*/
public function test_private_group_where_logged_in_user_has_not_requested_membership_and_has_not_been_invited() {
$u = self::factory()->user->create();
$g = self::factory()->group->create( array( 'status' => 'private' ) );
$this->set_current_user( $u );
if ( bp_has_groups( array( 'include' => array( $g ) ) ) ) {
while ( bp_groups() ) {
bp_the_group();
$found = get_echo( 'bp_group_status_message' );
}
}
$expected = __( 'This is a private group and you must request group membership in order to join.', 'buddypress' );
$this->assertSame( $expected, $found );
}
/**
* @group BP6319
*/
public function test_private_group_visited_by_a_non_logged_in_user() {
$g = self::factory()->group->create( array( 'status' => 'private' ) );
if ( bp_has_groups( array( 'include' => array( $g ) ) ) ) {
while ( bp_groups() ) {
bp_the_group();
$found = get_echo( 'bp_group_status_message' );
}
}
$expected = __( 'This is a private group. To join you must be a registered site member and request group membership.', 'buddypress' );
$this->assertSame( $expected, $found );
}
/**
* @group BP6319
*/
public function test_private_group_where_loggedin_user_has_requested_membership() {
$u = self::factory()->user->create();
$g = self::factory()->group->create( array( 'status' => 'private' ) );
$this->set_current_user( $u );
groups_send_membership_request( array(
'user_id' => $u,
'group_id' => $g
) );
if ( bp_has_groups( array( 'include' => array( $g ) ) ) ) {
while ( bp_groups() ) {
bp_the_group();
$found = get_echo( 'bp_group_status_message' );
}
}
$expected = __( 'This is a private group. Your membership request is awaiting approval from the group administrator.', 'buddypress' );
$this->assertSame( $expected, $found );
}
/**
* @group BP6319
*/
public function test_hidden_group() {
$u = self::factory()->user->create();
$g = self::factory()->group->create( array( 'status' => 'hidden' ) );
$this->set_current_user( $u );
$group = groups_get_group( $g );
$found = get_echo( 'bp_group_status_message', array( $group ) );
$expected = __( 'This is a hidden group and only invited members can join.', 'buddypress' );
$this->assertSame( $expected, $found );
}
/**
* @group BP6319
*/
public function test_group_parameter_should_be_obeyed() {
$u = self::factory()->user->create();
$groups = self::factory()->group->create_many( 2, array( 'status' => 'private' ) );
$this->set_current_user( $u );
// Fake the current group.
$GLOBALS['groups_template'] = new stdClass;
$GLOBALS['groups_template']->group = groups_get_group( $groups[0] );
groups_send_membership_request( array(
'user_id' => $u,
'group_id' => $groups[1]
) );
$group1 = groups_get_group( array(
'group_id' => $groups[1],
'populate_extras' => true,
) );
$found = get_echo( 'bp_group_status_message', array( $group1 ) );
$expected = __( 'This is a private group. Your membership request is awaiting approval from the group administrator.', 'buddypress' );
$this->assertSame( $expected, $found );
}
}