1
0
Fork 0
mirror of https://github.com/buddypress/buddypress.git synced 2026-07-21 20:54:17 +08:00
buddypress/tests/phpunit/testcases/groups/functions/groupsCreateGroup.php
Boone B Gorges 958bc1eff8 Ensure that shared user fixtures are fully cleaned up.
It's not possible to inherit WP 4.4's user cleanup between tests, because
the the deletion routine runs after the core test suite has unhooked
certain actions (such as BP's that are hooked to `delete_user`). So
we are forced to run necessary cleanup tasks in our own `delete_user()`
method, and ensure that it's this method that is called in every case
where we're cleaning up after statically generated shared fixtures.
Otherwise leftover content in the activity table can leak to other
tests.

See #7620.

git-svn-id: https://buddypress.svn.wordpress.org/trunk@11739 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2017-11-03 21:11:52 +00:00

77 lines
1.7 KiB
PHP

<?php
/**
* Tests for the `groups_create_group()` function.
*
* @group groups
*/
class BP_Tests_Groups_Functions_GroupsCreateGroup extends BP_UnitTestCase {
static $user_id;
public static function wpSetUpBeforeClass( $factory ) {
self::$user_id = $factory->user->create();
}
public static function wpTearDownAfterClass() {
self::delete_user( self::$user_id );
}
/**
* @ticket BP7619
*/
public function test_should_respect_creator_id() {
$old_user_id = bp_loggedin_user_id();
$this->set_current_user( self::$user_id );
$group_id = groups_create_group( array(
'name' => 'Foo',
'creator_id' => self::$user_id + 1,
) );
$group = groups_get_group( $group_id );
$this->set_current_user( $old_user_id );
$this->assertSame( self::$user_id + 1, $group->creator_id );
}
/**
* @ticket BP7619
*/
public function test_creator_id_should_be_fall_back_to_loggedin_user_for_new_group() {
$old_user_id = bp_loggedin_user_id();
$this->set_current_user( self::$user_id );
$group_id = groups_create_group( array(
'name' => 'Foo',
) );
$group = groups_get_group( $group_id );
$this->set_current_user( $old_user_id );
$this->assertSame( self::$user_id, $group->creator_id );
}
/**
* @ticket BP7619
*/
public function test_creator_id_should_be_fall_back_to_existing_creator_id_for_existing_group() {
$group_id = self::factory()->group->create( array(
'creator_id' => self::$user_id + 1,
) );
$old_user_id = bp_loggedin_user_id();
$this->set_current_user( self::$user_id );
$group_id = groups_create_group( array(
'group_id' => $group_id,
) );
$group = groups_get_group( $group_id );
$this->set_current_user( $old_user_id );
$this->assertSame( self::$user_id + 1, $group->creator_id );
}
}