function UserBlocksUnitTests::insertSession

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 2065

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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.