summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-12-28 21:00:16 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-12-28 21:00:16 +0000
commite3794e438e28daac6381183eff4f478c213b10f3 (patch)
tree54eccc515bf16025689dd83cfd80cc0755229e58 /modules
parent0e48fc4eced57b2d8dc7e3fe336b49e83a97663a (diff)
downloadbrdo-e3794e438e28daac6381183eff4f478c213b10f3.tar.gz
brdo-e3794e438e28daac6381183eff4f478c213b10f3.tar.bz2
#663814 by dereine, dww, and chx: Add helper function for testing session implementations.
Diffstat (limited to 'modules')
-rw-r--r--modules/simpletest/tests/session.test41
1 files changed, 31 insertions, 10 deletions
diff --git a/modules/simpletest/tests/session.test b/modules/simpletest/tests/session.test
index c3340e308..2118f8501 100644
--- a/modules/simpletest/tests/session.test
+++ b/modules/simpletest/tests/session.test
@@ -273,9 +273,9 @@ class SessionHttpsTestCase extends DrupalWebTestCase {
$this->assertTrue($this->cookies[$secure_session_name]['secure'], 'The secure cookie has the secure attribute');
// Check insecure cookie is not set.
$this->assertFalse(isset($this->cookies[$insecure_session_name]));
- $args = array_fill_keys(array(':sid', ':ssid'), $this->cookies[$secure_session_name]['value']);
- $this->assertTrue(db_query('SELECT sid FROM {sessions} WHERE sid = :sid AND ssid = :ssid', $args)->fetchField(), 'Session has both SIDs');
- $cookie = $secure_session_name . '=' . $args[':ssid'];
+ $ssid = $this->cookies[$secure_session_name]['value'];
+ $this->assertSessionIds($ssid, $ssid, 'Session has two secure SIDs');
+ $cookie = $secure_session_name . '=' . $ssid;
// Verify that user is logged in on secure URL.
$this->curlClose();
@@ -330,14 +330,13 @@ class SessionHttpsTestCase extends DrupalWebTestCase {
$this->assertTrue($this->cookies[$secure_session_name]['secure'], 'The secure cookie has the secure attribute');
// Check insecure cookie on secure page.
$this->assertFalse($this->cookies[$insecure_session_name]['secure'], 'The insecure cookie does not have the secure attribute');
- $args = array(
- ':sid' => $this->cookies[$insecure_session_name]['value'],
- ':ssid' => $this->cookies[$secure_session_name]['value'],
- );
- $this->assertTrue(db_query('SELECT sid FROM {sessions} WHERE sid = :sid AND ssid = :ssid', $args)->fetchField(), 'Session has both SIDs');
+
+ $sid = $this->cookies[$insecure_session_name]['value'];
+ $ssid = $this->cookies[$secure_session_name]['value'];
+ $this->assertSessionIds($sid, $ssid, 'Session has both secure and insecure SIDs');
$cookies = array(
- $insecure_session_name . '=' . $args[':sid'],
- $secure_session_name . '=' . $args[':ssid'],
+ $insecure_session_name . '=' . $sid,
+ $secure_session_name . '=' . $ssid,
);
foreach ($cookies as $cookie_key => $cookie) {
@@ -357,6 +356,28 @@ class SessionHttpsTestCase extends DrupalWebTestCase {
}
}
+ /**
+ * Test that there exists a session with two specific session IDs.
+ *
+ * @param $sid
+ * The insecure session ID to search for.
+ * @param $ssid
+ * The secure session ID to search for.
+ * @param $assertion_text
+ * The text to display when we perform the assertion.
+ *
+ * @return
+ * The result of assertTrue() that there's a session in the system that
+ * has the given insecure and secure session IDs.
+ */
+ protected function assertSessionIds($sid, $ssid, $assertion_text) {
+ $args = array(
+ ':sid' => $sid,
+ ':ssid' => $ssid,
+ );
+ return $this->assertTrue(db_query('SELECT sid FROM {sessions} WHERE sid = :sid AND ssid = :ssid', $args)->fetchField(), $assertion_text);
+ }
+
protected function httpsUrl($url) {
global $base_url;
return $base_url . '/modules/simpletest/tests/https.php?q=' . $url;