You are here

public function UserPictureTest::saveUserPicture in Drupal 9

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

Edits the user picture for the test user.

2 calls to UserPictureTest::saveUserPicture()
UserPictureTest::testCreateDeletePicture in core/modules/user/tests/src/Functional/UserPictureTest.php
Tests creation, display, and deletion of user pictures.
UserPictureTest::testPictureOnNodeComment in core/modules/user/tests/src/Functional/UserPictureTest.php
Tests embedded users on node pages.

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);
}