function UserCreationTrait::setCurrentUser

Same name and namespace in other branches
  1. 11.x core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::setCurrentUser()
  2. 10 core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::setCurrentUser()
  3. 8.9.x core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::setCurrentUser()

Switch the current logged in user.

Parameters

\Drupal\Core\Session\AccountInterface $account: The user account object.

3 calls to UserCreationTrait::setCurrentUser()
LinkCollectionNormalizerTest::getNormalizer in core/modules/jsonapi/tests/src/Kernel/Normalizer/LinkCollectionNormalizerTest.php
Get an instance of the normalizer to test.
MediaLibraryAccessTest::testAddFormAccess in core/modules/media_library/tests/src/Kernel/MediaLibraryAccessTest.php
Tests that the media library respects arbitrary access to the add form.
MediaLibraryAddFormTest::testMediaTypeAddForm in core/modules/media_library/tests/src/Kernel/MediaLibraryAddFormTest.php
Tests the media library add form.

File

core/modules/user/tests/src/Traits/UserCreationTrait.php, line 134

Class

UserCreationTrait
Provides test methods for user creation and authentication.

Namespace

Drupal\Tests\user\Traits

Code

protected function setCurrentUser(AccountInterface $account) {
  \Drupal::currentUser()->setAccount($account);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.