mirror of
https://github.com/buddypress/buddypress.git
synced 2026-07-22 20:56:55 +08:00
Props imath. Closes https://github.com/buddypress/buddypress/pull/295 Fixes #9081 git-svn-id: https://buddypress.svn.wordpress.org/trunk@13980 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
105 lines
2.3 KiB
PHP
105 lines
2.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group groups
|
|
* @group functions
|
|
*/
|
|
class BP_Tests_Get_Groups_Param extends BP_UnitTestCase {
|
|
public $groups_template = null;
|
|
|
|
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();
|
|
}
|
|
|
|
/**
|
|
* @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 = self::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 = self::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 = self::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 = self::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 = self::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 );
|
|
}
|
|
}
|