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.

5 calls to UserCreationTrait::setCurrentUser()
UserCreationTrait::setUpCurrentUser in core/modules/user/tests/src/Traits/UserCreationTrait.php
Creates a random user account and sets it as current user.
WorkspaceAccessTest::testPublishWorkspaceAccess in core/modules/workspaces/tests/src/Kernel/WorkspaceAccessTest.php
Tests workspace publishing access.
WorkspaceAccessTest::testWorkspaceAccess in core/modules/workspaces/tests/src/Kernel/WorkspaceAccessTest.php
Verifies all workspace roles have the correct access for the operation.
WorkspaceAccessTest::testWorkspaceSelection in core/modules/workspaces/tests/src/Kernel/WorkspaceAccessTest.php
@coversDefaultClass \Drupal\workspaces\Plugin\EntityReferenceSelection\WorkspaceSelection[[api-linebreak]]
WorkspaceIntegrationTest::setUp in core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php

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.