Multisite: Replace get_blog_details()
in add_user_to_blog()
with get_site()
.
Adds tests for `add_user_to_blog()`. Props flixos90. Fixes #38356. git-svn-id: https://develop.svn.wordpress.org/trunk@38903 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
9ae33a3be4
commit
701dbe4271
@ -161,8 +161,8 @@ function add_user_to_blog( $blog_id, $user_id, $role ) {
|
||||
|
||||
if ( !get_user_meta($user_id, 'primary_blog', true) ) {
|
||||
update_user_meta($user_id, 'primary_blog', $blog_id);
|
||||
$details = get_blog_details($blog_id);
|
||||
update_user_meta($user_id, 'source_domain', $details->domain);
|
||||
$site = get_site( $blog_id );
|
||||
update_user_meta( $user_id, 'source_domain', $site->domain );
|
||||
}
|
||||
|
||||
$user->set_role($role);
|
||||
|
@ -365,6 +365,37 @@ class Tests_Multisite_User extends WP_UnitTestCase {
|
||||
$this->assertFalse( wpmu_delete_user( $u_obj ) );
|
||||
$this->assertEquals( $u_obj->ID, username_exists( $u_obj->user_login ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38356
|
||||
*/
|
||||
public function test_add_user_to_blog_subscriber() {
|
||||
$site_id = self::factory()->blog->create();
|
||||
$user_id = self::factory()->user->create();
|
||||
|
||||
add_user_to_blog( $site_id, $user_id, 'subscriber' );
|
||||
|
||||
switch_to_blog( $site_id );
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
restore_current_blog();
|
||||
|
||||
wpmu_delete_blog( $site_id );
|
||||
wpmu_delete_user( $user_id );
|
||||
|
||||
$this->assertContains( 'subscriber', $user->roles );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38356
|
||||
*/
|
||||
public function test_add_user_to_blog_invalid_user() {
|
||||
$site_id = self::factory()->blog->create();
|
||||
|
||||
$result = add_user_to_blog( 73622, $site_id, 'subscriber' );
|
||||
wpmu_delete_blog( $site_id );
|
||||
|
||||
$this->assertWPError( $result );
|
||||
}
|
||||
}
|
||||
|
||||
endif ;
|
||||
|
Loading…
Reference in New Issue
Block a user