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/functions/get-group.php
Renato Alves 00f15df9f6 Improving the group member count routine and the function helper.
The group member count routine was updated to avoid direct, uncached, SQL query and unnecessary cache refresh when a group's Members page was viewed.
 is now being used to get the group member count which takes into account users' existence in the site,
the query is now cached and filterable.

 was also updated to get the current group from  if available.

Props imath
Fixes #7614 and see #6749

git-svn-id: https://buddypress.svn.wordpress.org/trunk@13103 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2021-09-09 14:01:40 +00:00

104 lines
2.3 KiB
PHP

<?php
/**
* @group groups
* @group functions
*/
class BP_Tests_Get_Groups_Param 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();
}
/**
* @group bp_get_group
*/
public function test_bp_get_group_with_no_group() {
$this->assertFalse( bp_get_group() );
$this->assertFalse( bp_get_group_by( 'id', 0 ) );
}
/**
* @group bp_get_group
*/
public function test_bp_get_group_with_id() {
$g = $this->factory->group->create();
$this->assertSame( $g, bp_get_group( $g )->id );
$this->assertSame( $g, bp_get_group_by( 'id', $g )->id );
$this->assertSame( $g, bp_get_group_by( 'ID', $g )->id );
}
/**
* @group bp_get_group
*/
public function test_bp_get_group_with_slug() {
$slug = 'test-group';
$g = $this->factory->group->create( array( 'slug' => $slug ) );
$g1 = bp_get_group( $slug );
$this->assertSame( $g, $g1->id );
$this->assertSame( $slug, $g1->slug );
$g2 = bp_get_group_by( 'slug', $slug );
$this->assertSame( $g, $g2->id );
$this->assertSame( $slug, $g2->slug );
}
/**
* @group bp_get_group
*/
public function test_bp_get_group_with_object() {
$g = $this->factory->group->create_and_get();
$this->assertSame( $g->id, bp_get_group( $g )->id );
}
/**
* @group bp_get_group
*/
public function test_bp_get_group_from_groups_template() {
$g = $this->factory->group->create( array( 'status' => 'private' ) );
if ( bp_has_groups( array( 'include' => array( $g ) ) ) ) {
while ( bp_groups() ) {
bp_the_group();
$group = bp_get_group();
}
}
$this->assertSame( $g, $group->id );
}
/**
* @group bp_get_group
*/
public function test_bp_get_group_from_current_group() {
$bp = buddypress();
$g = $this->factory->group->create_and_get( array( 'name' => 'foo' ) );
// Set the current group.
$bp->groups->current_group = $g;
// Change the name to check the current group was used.
$bp->groups->current_group->name = 'bar';
// Override the name
do_action( 'bp_groups_set_current_group' );
$this->assertSame( 'bar', bp_get_group( $g->id )->name );
}
}