JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Fix db_get_value after mysql->mysqli upgrade
[wfpl.git] / test / session_test.php
1 <?php
2
3 # This program is in the public domain within the United States. Additionally,
4 # we waive copyright and related rights in the work worldwide through the CC0
5 # 1.0 Universal public domain dedication, which can be found at
6 # http://creativecommons.org/publicdomain/zero/1.0/
7
8
9 # To run this file:
10 #
11 # 1) edit inc/wfpl/test/session_test_db_connect.php to connect to your TESTING database
12 #
13 # 2) add the wfpl_session tables to your TESTING database:
14 #
15 # create table wfpl_sessions (id int unique auto_increment, session_key varchar(16), length int, expires int);
16 # create table wfpl_session_data (id int unique auto_increment, session_id int, name varchar(100), value text);
17
18 ##############
19 # WARNING: this code deletes all wfpl sessions. Do not use on a live site's database
20 ##############
21
22 require_once(__DIR__.'/'.'session_test_db_connect.php');
23 require_once(__DIR__.'/../'.'session.php');
24
25 function session_dump($message) {
26         $ses = db_get_rows('wfpl_sessions', 'id,session_key,length,expires');
27         if($ses) foreach($ses as $row) {
28                 list($id, $session_key, $length, $expires) = $row;
29                 tem_set('id', $id);
30                 tem_set('session_key', $session_key);
31                 tem_set('length', $length);
32                 tem_set('expires', $expires);
33                 tem_sub('wfpl_sessions_row');
34         }
35
36         $data = db_get_rows('wfpl_session_data', 'id,session_id,name,value');
37         if($data) foreach($data as $row) {
38                 list($id, $session_id, $name, $value) = $row;
39                 tem_set('id', $id);
40                 tem_set('session_id', $session_id);
41                 tem_set('name', $name);
42                 tem_set('value', $value);
43                 tem_sub('wfpl_session_data_row');
44         }
45
46         tem_set('message', $message);
47         tem_sub('block');
48 }
49
50
51 function session_test() {
52         tem_load(__DIR__.'/'.'session_test.html');
53
54         db_delete('wfpl_sessions');
55         db_delete('wfpl_session_data');
56         session_dump('Clean slate');
57
58         session_new();
59         session_dump('new session');
60
61         session_set('username', 'jason');
62         session_dump('username jason');
63
64         session_set('username', 'phil');
65         session_dump('overwrote username as phil');
66
67         $old = $GLOBALS['session_id'];
68
69         session_new();
70         session_dump('new session');
71
72         session_set('username', 'jason');
73         session_set('bamph', 'foo');
74         session_dump('set username=jason and bamph=foo in new session');
75
76         session_clear('username');
77         session_dump('cleared username in new session');
78
79         _kill_session($old);
80         session_dump('killed old session');
81
82         kill_session();
83         session_dump('kill_session()');
84
85         tem_output();
86 }