You are here

public function AutologoutSessionCleanupOnLoginTest::getSessions in Automated Logout 8

Gets active sessions for given user.

Parameters

\Drupal\user\Entity\User $account: User account object.

Return value

array Array of sessions of the user.

1 call to AutologoutSessionCleanupOnLoginTest::getSessions()
AutologoutSessionCleanupOnLoginTest::testSessionCleanupAtLogin in tests/src/Functional/AutologoutSessionCleanupOnLoginTest.php
Tests that stale sessions are cleaned up at login.

File

tests/src/Functional/AutologoutSessionCleanupOnLoginTest.php, line 148

Class

AutologoutSessionCleanupOnLoginTest
Tests session cleanup on login.

Namespace

Drupal\Tests\autologout\Functional

Code

public function getSessions(User $account) {

  // Check there is one session in the sessions table.
  $result = $this->database
    ->select('sessions', 's')
    ->fields('s')
    ->condition('uid', $account
    ->id())
    ->orderBy('timestamp', 'DESC')
    ->execute();
  $sessions = [];
  foreach ($result as $session) {
    $sessions[] = $session;
  }
  return $sessions;
}