summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/session_test.module
blob: 842e8f0144a37939213801203b343a5562eda02f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
// $Id$

/**
 * Implementation of hook_menu().
 */
function session_test_menu() {
  $items['session-test/get'] = array(
    'title' => t('Session value'),
    'page callback' => '_session_test_get',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  $items['session-test/id'] = array(
    'title' => t('Session ID value'),
    'page callback' => '_session_test_id',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  $items['session-test/set/%'] = array(
    'title' => t('Set Session value'),
    'page callback' => '_session_test_set',
    'page arguments' => array(2),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  $items['session-test/no-set/%'] = array(
    'title' => t('Disabled session set value'),
    'page callback' => '_session_test_no_set',
    'page arguments' => array(2),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}

/**
 * Page callback, prints the stored session value to the screen.
 */
function _session_test_get() {
  if (!empty($_SESSION['session_test_value'])) {
    return t('The current value of the stored session variable is: %val', array('%val' => $_SESSION['session_test_value']));
  }
  else {
    return "";
  }
}

/**
 * Page callback, stores a value in $_SESSION['session_test_value'].
 */
function _session_test_set($value) {
  $_SESSION['session_test_value'] = $value;
  return t('The current value of the stored session variable has been set to %val', array('%val' => $value));
}

/**
 * Menu callback: turns off session saving and then tries to save a value
 * anyway.
 */
function _session_test_no_set($value) {
  drupal_save_session(FALSE);
  _session_test_set($value);
  return t('session saving was disabled, and then %val was set', array('%val' => $value));
}

/**
 * Menu callback: print the current session ID.
 */
function _session_test_id() {
  return 'session_id:' . session_id() . "\n";
}

/**
 * Implementation of hook_user().
 */
function session_test_user_login($edit = array(), $user = NULL) {
  if ($edit['name'] == 'session_test_user') {
    // Exit so we can verify that the session was regenerated
    // before hook_user() was called.
    exit;
  }
}