summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/session_test.module
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest/tests/session_test.module')
-rw-r--r--modules/simpletest/tests/session_test.module54
1 files changed, 53 insertions, 1 deletions
diff --git a/modules/simpletest/tests/session_test.module b/modules/simpletest/tests/session_test.module
index 842e8f014..12eabfe34 100644
--- a/modules/simpletest/tests/session_test.module
+++ b/modules/simpletest/tests/session_test.module
@@ -31,11 +31,42 @@ function session_test_menu() {
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
+ $items['session-test/set-message'] = array(
+ 'title' => t('Session value'),
+ 'page callback' => '_session_test_set_message',
+ 'access arguments' => array('access content'),
+ 'type' => MENU_CALLBACK,
+ );
+ $items['session-test/set-not-started'] = array(
+ 'title' => t('Session value'),
+ 'page callback' => '_session_test_set_not_started',
+ 'access arguments' => array('access content'),
+ 'type' => MENU_CALLBACK,
+ );
return $items;
}
/**
+ * Implement hook_boot().
+ */
+function session_test_boot() {
+ header('X-Session-Cookie: ' . intval(isset($_COOKIE[session_name()])));
+ header('X-Session-Started: ' . intval(drupal_session_is_started()));
+ header('X-Session-Empty: ' . intval(empty($_SESSION)));
+}
+
+/**
+ * Implement hook_init().
+ */
+function session_test_init() {
+ // hook_init() is called later in the bootstrap process, but not in cached
+ // requests. Here the header set in hook_boot() is overwritten, so the
+ // session state is reported as late in the bootstrap process as possible.
+ header('X-Session-Started: ' . intval(drupal_session_is_started()));
+}
+
+/**
* Page callback, prints the stored session value to the screen.
*/
function _session_test_get() {
@@ -51,7 +82,7 @@ function _session_test_get() {
* Page callback, stores a value in $_SESSION['session_test_value'].
*/
function _session_test_set($value) {
- $_SESSION['session_test_value'] = $value;
+ drupal_set_session('session_test_value', $value);
return t('The current value of the stored session variable has been set to %val', array('%val' => $value));
}
@@ -73,6 +104,27 @@ function _session_test_id() {
}
/**
+ * Menu callback, sets a message to me displayed on the following page.
+ */
+function _session_test_set_message() {
+ drupal_set_message(t('This is a dummy message.'));
+ print t('A message was set.');
+ // Do not return anything, so the current request does not result in a themed
+ // page with messages. The message will be displayed in the following request
+ // instead.
+}
+
+/**
+ * Menu callback, stores a value in $_SESSION['session_test_value'] without
+ * having started the session in advance.
+ */
+function _session_test_set_not_started() {
+ if (!drupal_session_is_started()) {
+ $_SESSION['session_test_value'] = t('Session was not started');
+ }
+}
+
+/**
* Implementation of hook_user().
*/
function session_test_user_login($edit = array(), $user = NULL) {