function SessionApiTestCase::testFunctions in Session API 5
Same name and namespace in other branches
- 6 session_api.test \SessionApiTestCase::testFunctions()
- 7 session_api.test \SessionApiTestCase::testFunctions()
Verify functions.
File
- tests/
session_api.test, line 24 - Session API SimpleTests.
Class
- SessionApiTestCase
- Session API SimpleTest class
Code
function testFunctions() {
include_once drupal_get_path('module', 'session_api') . "/session_api.module";
// Capture existing values, which are restored at the end of this function.
$old_cookie = $_COOKIE;
$old_session_api_id = $_SESSION['session_api_id'];
$old_sid = session_id();
// session_api_available();
$_COOKIE = NULL;
$this
->assertFalse(session_api_available(), t('Function session_api_available() correctly returns FALSE when cookies are disabled.'));
$this
->assertFalse(session_api_get_sid(), t('Function session_api_get_sid() correctly returns FALSE when cookies are disabled.'));
// enable cookies
$_COOKIE = $old_cookie;
// Find correct sid
$fake_sid = rand(1, 2000000);
$_SESSION['session_api_id'] = $fake_sid;
$this
->assertTrue(session_api_get_sid() == $fake_sid, t('Function session_api_get_sid() returns expected value.'));
// Store ID in the db
session_id(md5(rand(1, 20000)));
$sid = db_next_id('{session_api}_sid');
db_query("INSERT INTO {session_api} (sid, session_id) VALUES (%d, '%s')", array(
$sid,
session_id(),
));
$_SESSION['session_api_id'] = NULL;
$this
->assertTrue(session_api_get_sid() == $sid, 'Function session_api_get_sid() correctly retrieves the session_api_id from the database.');
// restore pre-testing values
$_COOKIE = $old_cookie;
$_SESSION['session_api_id'] = $old_session_api_id;
db_query("DELETE FROM {session_api} WHERE session_id = '%s'", session_id());
session_id($old_sid);
}