You are here

protected function DevelSwitchUserTest::assertSessionByUid in Devel 8.3

Same name and namespace in other branches
  1. 8 tests/src/Functional/DevelSwitchUserTest.php \Drupal\Tests\devel\Functional\DevelSwitchUserTest::assertSessionByUid()
  2. 8.2 tests/src/Functional/DevelSwitchUserTest.php \Drupal\Tests\devel\Functional\DevelSwitchUserTest::assertSessionByUid()
  3. 4.x tests/src/Functional/DevelSwitchUserTest.php \Drupal\Tests\devel\Functional\DevelSwitchUserTest::assertSessionByUid()

Asserts that there is a session for a given user ID.

Based off masquarade module.

@TODO find a cleaner way to do this check.

Parameters

int $uid: The user ID for which to find a session record.

1 call to DevelSwitchUserTest::assertSessionByUid()
DevelSwitchUserTest::testSwitchUserFunctionality in tests/src/Functional/DevelSwitchUserTest.php
Tests switch user basic functionality.

File

tests/src/Functional/DevelSwitchUserTest.php, line 276

Class

DevelSwitchUserTest
Tests switch user.

Namespace

Drupal\Tests\devel\Functional

Code

protected function assertSessionByUid($uid) {
  $query = \Drupal::database()
    ->select('sessions');
  $query
    ->fields('sessions', [
    'uid',
  ]);
  $query
    ->condition('uid', $uid);
  $result = $query
    ->execute()
    ->fetchAll();

  // Check that we have some results.
  $this
    ->assertNotEmpty($result, sprintf('No session found for uid %s', $uid));

  // If there is more than one session, then that must be unexpected.
  $this
    ->assertTrue(count($result) == 1, sprintf('Found more than one session for uid %s', $uid));
}