| 956 | /** |
| 957 | * @ticket 38961 |
| 958 | */ |
| 959 | public function test_user_with_promote_users_can_add_user_to_site() { |
| 960 | if ( ! is_multisite() ) { |
| 961 | $this->markTestSkipped( 'Test requires multisite.' ); |
| 962 | } |
| 963 | |
| 964 | $user_id = self::factory()->user->create( array( 'role' => 'subscriber' ) ); |
| 965 | |
| 966 | $user_id_promoter = self::factory()->user->create( array( |
| 967 | 'role' => 'subscriber', |
| 968 | 'user_login' => 'promote_users', |
| 969 | ) ); |
| 970 | |
| 971 | $user_promoter = new WP_User( $user_id_promoter ); |
| 972 | $user_promoter->add_cap( 'list_users' ); |
| 973 | $user_promoter->add_cap( 'promote_users' ); |
| 974 | |
| 975 | wp_set_current_user( $user_id_promoter ); |
| 976 | |
| 977 | switch_to_blog( self::$site ); |
| 978 | |
| 979 | $request = new WP_REST_Request( 'PUT', '/wp/v2/users/' . $user_id ); |
| 980 | $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); |
| 981 | $request->set_body_params( array( |
| 982 | 'roles' => array( 'editor' ), |
| 983 | ) ); |
| 984 | $this->server->dispatch( $request ); // This is rest_cannot_edit |
| 985 | |
| 986 | restore_current_blog(); |
| 987 | |
| 988 | $user_is_member = is_user_member_of_blog( $user_id, self::$site ); |
| 989 | |
| 990 | wpmu_delete_user( $user_id ); |
| 991 | |
| 992 | $this->assertTrue( $user_is_member ); |
| 993 | } |
| 994 | |