protected function DevelSwitchUserTest::assertSessionByUid in Devel 8
Same name and namespace in other branches
- 8.3 tests/src/Functional/DevelSwitchUserTest.php \Drupal\Tests\devel\Functional\DevelSwitchUserTest::assertSessionByUid()
- 8.2 tests/src/Functional/DevelSwitchUserTest.php \Drupal\Tests\devel\Functional\DevelSwitchUserTest::assertSessionByUid()
- 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.
Parameters
int $uid: The user ID for which to find a session record.
TODO find a cleaner way to do this check.
1 call to DevelSwitchUserTest::assertSessionByUid()
- DevelSwitchUserTest::testSwitchUser in tests/
src/ Functional/ DevelSwitchUserTest.php - Tests switch user.
File
- tests/
src/ Functional/ DevelSwitchUserTest.php, line 277
Class
- DevelSwitchUserTest
- Tests switch user.
Namespace
Drupal\Tests\devel\FunctionalCode
protected function assertSessionByUid($uid) {
$query = \Drupal::database()
->select('sessions');
$query
->fields('sessions', [
'uid',
]);
$query
->condition('uid', $uid);
$result = $query
->execute()
->fetchAll();
if (empty($result)) {
$this
->fail(new FormattableMarkup('No session found for uid @uid', [
'@uid' => $uid,
]));
}
elseif (count($result) > 1) {
// If there is more than one session, then that must be unexpected.
$this
->fail("Found more than 1 session for uid {$uid}.");
}
else {
$this
->pass("Found session for uid {$uid}.");
}
}