Same name and namespace in other branches
  1. 8.9.x core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::setCurrentUser()
  2. 9 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.

19 calls to UserCreationTrait::setCurrentUser()
ArgumentValidatorTermNameTest::testArgumentValidatorTermNameAccess in core/modules/taxonomy/tests/src/Kernel/Views/ArgumentValidatorTermNameTest.php
Tests the access checking in term name argument validator plugin.
CommentValidationTest::testValidationOfCommentOfUnpublishedNode in core/modules/comment/tests/src/Kernel/CommentValidationTest.php
Tests that comments of unpublished nodes are not valid.
EntityAutocompleteTest::testEntityReferenceAutocompletion in core/tests/Drupal/KernelTests/Core/Entity/EntityAutocompleteTest.php
Tests autocompletion edge cases with slashes in the names.
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.

... See full list

File

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

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