private function UserBlocksUnitTests::insertSession in Drupal 7
Insert a user session into the {sessions} table. This function is used since we cannot log in more than one user at the same time in tests.
1 call to UserBlocksUnitTests::insertSession()
- UserBlocksUnitTests::testWhosOnlineBlock in modules/
user/ user.test - Test the Who's Online block.
File
- modules/
user/ user.test, line 2024 - Tests for user.module.
Class
- UserBlocksUnitTests
- Test user blocks.
Code
private function insertSession(array $fields = array()) {
$fields += array(
'uid' => 0,
'sid' => drupal_hash_base64(uniqid(mt_rand(), TRUE)),
'timestamp' => REQUEST_TIME,
);
db_insert('sessions')
->fields($fields)
->execute();
$this
->assertEqual(db_query("SELECT COUNT(*) FROM {sessions} WHERE uid = :uid AND sid = :sid AND timestamp = :timestamp", array(
':uid' => $fields['uid'],
':sid' => $fields['sid'],
':timestamp' => $fields['timestamp'],
))
->fetchField(), 1, 'Session record inserted.');
}