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