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