function UserCreationTrait::setCurrentUser

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

33 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.
CommentActionsTest::setUp in core/modules/comment/tests/src/Kernel/CommentActionsTest.php
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.
EntityReferenceSelectionAccessTest::testCommentHandler in core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
Tests the comment-specific overrides of the entity handler.

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

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