private function UserBlocksUnitTests::insertSession
7.x user.test | private UserBlocksUnitTests::insertSession(array $fields = array()) |
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 drupal-7.x/
modules/ user/ user.test - Test the Who's Online block.
File
- drupal-7.x/
modules/ user/ user.test, line 1674 - 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.');
}