function UserSessionTest::createUserSession

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Session/UserSessionTest.php \Drupal\Tests\Core\Session\UserSessionTest::createUserSession()
  2. 10 core/tests/Drupal/Tests/Core/Session/UserSessionTest.php \Drupal\Tests\Core\Session\UserSessionTest::createUserSession()
  3. 11.x core/tests/Drupal/Tests/Core/Session/UserSessionTest.php \Drupal\Tests\Core\Session\UserSessionTest::createUserSession()

Setups a user session for the test.

Parameters

array $rids: The rids of the user.

bool $authenticated: TRUE if it is an authenticated user.

Return value

\Drupal\Core\Session\AccountInterface The created user session.

1 call to UserSessionTest::createUserSession()
UserSessionTest::setUp in core/tests/Drupal/Tests/Core/Session/UserSessionTest.php
1 method overrides UserSessionTest::createUserSession()
UserTest::createUserSession in core/modules/user/tests/src/Unit/Plugin/Core/Entity/UserTest.php
Setups a user session for the test.

File

core/tests/Drupal/Tests/Core/Session/UserSessionTest.php, line 49

Class

UserSessionTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Session%21UserSession.php/class/UserSession/9" title="An implementation of the user account interface for the global user." class="local">\Drupal\Core\Session\UserSession</a> @group Session

Namespace

Drupal\Tests\Core\Session

Code

protected function createUserSession(array $rids = [], $authenticated = FALSE) {
    array_unshift($rids, $authenticated ? RoleInterface::AUTHENTICATED_ID : RoleInterface::ANONYMOUS_ID);
    return new UserSession([
        'roles' => $rids,
    ]);
}

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