You are here

public function UserPictureTest::saveUserPicture in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Functional/UserPictureTest.php \Drupal\Tests\user\Functional\UserPictureTest::saveUserPicture()
  2. 9 core/modules/user/tests/src/Functional/UserPictureTest.php \Drupal\Tests\user\Functional\UserPictureTest::saveUserPicture()

Edits the user picture for the test user.

File

core/modules/user/tests/src/Functional/UserPictureTest.php, line 154

Class

UserPictureTest
Tests user picture functionality.

Namespace

Drupal\Tests\user\Functional

Code

public function saveUserPicture($image) {
  $edit = [
    'files[user_picture_0]' => \Drupal::service('file_system')
      ->realpath($image->uri),
  ];
  $this
    ->drupalGet('user/' . $this->webUser
    ->id() . '/edit');
  $this
    ->submitForm($edit, 'Save');

  // Load actual user data from database.
  $user_storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('user');
  $user_storage
    ->resetCache([
    $this->webUser
      ->id(),
  ]);
  $account = $user_storage
    ->load($this->webUser
    ->id());
  return File::load($account->user_picture->target_id);
}