Beispiel #1
0
 public function test_update_user()
 {
     $pw_before = $this->user_obj->user_pass;
     $data = array('first_name' => 'New Name');
     $response = $this->endpoint->edit_user($this->user, $data);
     $this->assertNotInstanceOf('WP_Error', $response);
     if (!$response instanceof WP_JSON_ResponseInterface) {
         $response = new WP_JSON_Response($response);
     }
     // Check that we succeeded
     $this->assertEquals(200, $response->get_status());
     // Check that the name has been updated correctly
     $new_data = $response->get_data();
     $this->assertEquals($data['first_name'], $new_data['first_name']);
     $user = get_userdata($this->user);
     $this->assertEquals($user->first_name, $data['first_name']);
     // Check that we haven't inadvertently changed the user's password,
     // as per https://core.trac.wordpress.org/ticket/21429
     $this->assertEquals($pw_before, $user->user_pass);
 }
 public function test_update_user_role()
 {
     $admin_id = $this->factory->user->create(array('role' => 'administrator'));
     $user_id = $this->factory->user->create(array('role' => 'author'));
     wp_set_current_user($admin_id);
     $admin = wp_get_current_user($admin_id);
     $this->allow_user_to_create_users($admin);
     $response = $this->endpoint->edit_user($user_id, array('role' => 'editor'));
     $this->assertNotInstanceOf('WP_Error', $response);
     if (!$response instanceof WP_JSON_ResponseInterface) {
         $response = new WP_JSON_Response($response);
     }
     // Check that we succeeded
     $this->assertEquals(200, $response->get_status());
     $user = get_userdata($user_id);
     $this->assertArrayHasKey('editor', $user->caps);
 }