dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Session driver library unit test |
| 5 | */ |
| 6 | class Session_test extends CI_TestCase { |
Andrey Andreev | 838a9d6 | 2012-12-03 14:37:47 +0200 | [diff] [blame] | 7 | |
dchill42 | 4153c92 | 2012-07-31 10:38:21 -0400 | [diff] [blame] | 8 | protected $settings = array( |
| 9 | 'use_cookies' => 0, |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 10 | 'use_only_cookies' => 0, |
darwinel | 1993aab | 2014-02-08 00:48:38 +0100 | [diff] [blame] | 11 | 'cache_limiter' => FALSE |
dchill42 | 4153c92 | 2012-07-31 10:38:21 -0400 | [diff] [blame] | 12 | ); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 13 | protected $setting_vals = array(); |
| 14 | protected $cookie_vals; |
| 15 | protected $session; |
| 16 | |
| 17 | /** |
| 18 | * Set up test framework |
| 19 | */ |
| 20 | public function set_up() |
| 21 | { |
Andrey Andreev | a2cf6fa | 2014-06-02 11:19:23 +0300 | [diff] [blame] | 22 | return; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 23 | // Override settings |
| 24 | foreach ($this->settings as $name => $value) { |
| 25 | $this->setting_vals[$name] = ini_get('session.'.$name); |
| 26 | ini_set('session.'.$name, $value); |
| 27 | } |
| 28 | |
| 29 | // Start with clean environment |
| 30 | $this->cookie_vals = $_COOKIE; |
| 31 | $_COOKIE = array(); |
| 32 | |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 33 | // Set subclass prefix to match our mock |
| 34 | $this->ci_set_config('subclass_prefix', 'Mock_Libraries_'); |
| 35 | |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 36 | // Establish necessary support classes |
dchill42 | 7ecc5cd | 2012-10-12 16:25:51 -0400 | [diff] [blame] | 37 | $ci = $this->ci_instance(); |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 38 | $ldr = $this->ci_core_class('load'); |
dchill42 | 7ecc5cd | 2012-10-12 16:25:51 -0400 | [diff] [blame] | 39 | $ci->load = new $ldr(); |
| 40 | $ci->input = new Mock_Core_Input(NULL, NULL); |
| 41 | |
| 42 | // Make sure string helper is available |
| 43 | $this->ci_vfs_clone('system/helpers/string_helper.php'); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 44 | |
| 45 | // Attach session instance locally |
dchill42 | 4153c92 | 2012-07-31 10:38:21 -0400 | [diff] [blame] | 46 | $config = array( |
| 47 | 'sess_encrypt_cookie' => FALSE, |
| 48 | 'sess_use_database' => FALSE, |
| 49 | 'sess_table_name' => '', |
| 50 | 'sess_expiration' => 7200, |
| 51 | 'sess_expire_on_close' => FALSE, |
| 52 | 'sess_match_ip' => FALSE, |
| 53 | 'sess_match_useragent' => TRUE, |
| 54 | 'sess_cookie_name' => 'ci_session', |
| 55 | 'cookie_path' => '', |
| 56 | 'cookie_domain' => '', |
| 57 | 'cookie_secure' => FALSE, |
| 58 | 'cookie_httponly' => FALSE, |
| 59 | 'sess_time_to_update' => 300, |
| 60 | 'time_reference' => 'local', |
| 61 | 'cookie_prefix' => '', |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 62 | 'encryption_key' => 'foobar' |
dchill42 | 4153c92 | 2012-07-31 10:38:21 -0400 | [diff] [blame] | 63 | ); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 64 | $this->session = new Mock_Libraries_Session($config); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Tear down test framework |
| 69 | */ |
| 70 | public function tear_down() |
| 71 | { |
Andrey Andreev | a2cf6fa | 2014-06-02 11:19:23 +0300 | [diff] [blame] | 72 | return; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 73 | // Restore environment |
| 74 | if (session_id()) session_destroy(); |
| 75 | $_SESSION = array(); |
| 76 | $_COOKIE = $this->cookie_vals; |
| 77 | |
| 78 | // Restore settings |
| 79 | foreach ($this->settings as $name => $value) { |
| 80 | ini_set('session.'.$name, $this->setting_vals[$name]); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Test set_userdata() function |
| 86 | */ |
| 87 | public function test_set_userdata() |
| 88 | { |
Andrey Andreev | a2cf6fa | 2014-06-02 11:19:23 +0300 | [diff] [blame] | 89 | return; |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 90 | // Set userdata values for each driver |
| 91 | $key1 = 'test1'; |
| 92 | $ckey2 = 'test2'; |
| 93 | $nkey2 = 'test3'; |
| 94 | $cmsg1 = 'Some test data'; |
| 95 | $cmsg2 = 42; |
| 96 | $nmsg1 = 'Other test data'; |
darwinel | 2c2722e | 2014-02-11 20:43:16 +0100 | [diff] [blame] | 97 | $nmsg2 = TRUE; |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 98 | $this->session->cookie->set_userdata($key1, $cmsg1); |
| 99 | $this->session->set_userdata($ckey2, $cmsg2); |
| 100 | $this->session->native->set_userdata($key1, $nmsg1); |
| 101 | $this->session->set_userdata($nkey2, $nmsg2); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 102 | |
| 103 | // Verify independent messages |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 104 | $this->assertEquals($cmsg1, $this->session->cookie->userdata($key1)); |
| 105 | $this->assertEquals($nmsg1, $this->session->native->userdata($key1)); |
| 106 | |
| 107 | // Verify pre-selected driver sets |
| 108 | $this->assertEquals($cmsg2, $this->session->cookie->userdata($ckey2)); |
| 109 | $this->assertEquals($nmsg2, $this->session->native->userdata($nkey2)); |
| 110 | |
| 111 | // Verify no crossover |
| 112 | $this->assertNull($this->session->cookie->userdata($nkey2)); |
| 113 | $this->assertNull($this->session->native->userdata($ckey2)); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Test the has_userdata() function |
| 118 | */ |
| 119 | public function test_has_userdata() |
| 120 | { |
Andrey Andreev | a2cf6fa | 2014-06-02 11:19:23 +0300 | [diff] [blame] | 121 | return; |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 122 | // Set a userdata value for each driver |
| 123 | $key = 'hastest'; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 124 | $cmsg = 'My test data'; |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 125 | $this->session->cookie->set_userdata($key, $cmsg); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 126 | $nmsg = 'Your test data'; |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 127 | $this->session->native->set_userdata($key, $nmsg); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 128 | |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 129 | // Verify values exist |
| 130 | $this->assertTrue($this->session->cookie->has_userdata($key)); |
| 131 | $this->assertTrue($this->session->native->has_userdata($key)); |
| 132 | |
| 133 | // Verify non-existent values |
| 134 | $nokey = 'hasnot'; |
| 135 | $this->assertFalse($this->session->cookie->has_userdata($nokey)); |
| 136 | $this->assertFalse($this->session->native->has_userdata($nokey)); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Test the all_userdata() function |
| 141 | */ |
| 142 | public function test_all_userdata() |
| 143 | { |
Andrey Andreev | a2cf6fa | 2014-06-02 11:19:23 +0300 | [diff] [blame] | 144 | return; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 145 | // Set a specific series of data for each driver |
dchill42 | 4153c92 | 2012-07-31 10:38:21 -0400 | [diff] [blame] | 146 | $cdata = array( |
| 147 | 'one' => 'first', |
| 148 | 'two' => 'second', |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 149 | 'three' => 'third', |
| 150 | 'foo' => 'bar', |
| 151 | 'bar' => 'baz' |
dchill42 | 4153c92 | 2012-07-31 10:38:21 -0400 | [diff] [blame] | 152 | ); |
| 153 | $ndata = array( |
| 154 | 'one' => 'gold', |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 155 | 'two' => 'silver', |
| 156 | 'three' => 'bronze', |
| 157 | 'foo' => 'baz', |
| 158 | 'bar' => 'foo' |
dchill42 | 4153c92 | 2012-07-31 10:38:21 -0400 | [diff] [blame] | 159 | ); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 160 | $this->session->cookie->set_userdata($cdata); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 161 | $this->session->native->set_userdata($ndata); |
| 162 | |
| 163 | // Make sure all values are present |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 164 | $call = $this->session->cookie->userdata(); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 165 | foreach ($cdata as $key => $value) { |
| 166 | $this->assertEquals($value, $call[$key]); |
| 167 | } |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 168 | $nall = $this->session->native->userdata(); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 169 | foreach ($ndata as $key => $value) { |
| 170 | $this->assertEquals($value, $nall[$key]); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Test the unset_userdata() function |
| 176 | */ |
| 177 | public function test_unset_userdata() |
| 178 | { |
Andrey Andreev | a2cf6fa | 2014-06-02 11:19:23 +0300 | [diff] [blame] | 179 | return; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 180 | // Set a userdata message for each driver |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 181 | $key = 'untest'; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 182 | $cmsg = 'Other test data'; |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 183 | $this->session->cookie->set_userdata($key, $cmsg); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 184 | $nmsg = 'Sundry test data'; |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 185 | $this->session->native->set_userdata($key, $nmsg); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 186 | |
| 187 | // Verify independent messages |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 188 | $this->assertEquals($this->session->cookie->userdata($key), $cmsg); |
| 189 | $this->assertEquals($this->session->native->userdata($key), $nmsg); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 190 | |
| 191 | // Unset them and verify absence |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 192 | $this->session->cookie->unset_userdata($key); |
| 193 | $this->session->native->unset_userdata($key); |
| 194 | $this->assertNull($this->session->cookie->userdata($key)); |
| 195 | $this->assertNull($this->session->native->userdata($key)); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | /** |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 199 | * Test the flashdata() functions |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 200 | */ |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 201 | public function test_flashdata() |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 202 | { |
Andrey Andreev | a2cf6fa | 2014-06-02 11:19:23 +0300 | [diff] [blame] | 203 | return; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 204 | // Set flashdata message for each driver |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 205 | $key = 'fltest'; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 206 | $cmsg = 'Some flash data'; |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 207 | $this->session->cookie->set_flashdata($key, $cmsg); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 208 | $nmsg = 'Other flash data'; |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 209 | $this->session->native->set_flashdata($key, $nmsg); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 210 | |
| 211 | // Simulate page reload |
| 212 | $this->session->cookie->reload(); |
| 213 | $this->session->native->reload(); |
| 214 | |
| 215 | // Verify independent messages |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 216 | $this->assertEquals($cmsg, $this->session->cookie->flashdata($key)); |
| 217 | $this->assertEquals($nmsg, $this->session->native->flashdata($key)); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 218 | |
| 219 | // Simulate next page reload |
| 220 | $this->session->cookie->reload(); |
| 221 | $this->session->native->reload(); |
| 222 | |
| 223 | // Verify absence of messages |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 224 | $this->assertNull($this->session->cookie->flashdata($key)); |
| 225 | $this->assertNull($this->session->native->flashdata($key)); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Test the keep_flashdata() function |
| 230 | */ |
| 231 | public function test_keep_flashdata() |
| 232 | { |
Andrey Andreev | a2cf6fa | 2014-06-02 11:19:23 +0300 | [diff] [blame] | 233 | return; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 234 | // Set flashdata message for each driver |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 235 | $key = 'kfltest'; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 236 | $cmsg = 'My flash data'; |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 237 | $this->session->cookie->set_flashdata($key, $cmsg); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 238 | $nmsg = 'Your flash data'; |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 239 | $this->session->native->set_flashdata($key, $nmsg); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 240 | |
| 241 | // Simulate page reload and verify independent messages |
| 242 | $this->session->cookie->reload(); |
| 243 | $this->session->native->reload(); |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 244 | $this->assertEquals($cmsg, $this->session->cookie->flashdata($key)); |
| 245 | $this->assertEquals($nmsg, $this->session->native->flashdata($key)); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 246 | |
| 247 | // Keep messages |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 248 | $this->session->cookie->keep_flashdata($key); |
| 249 | $this->session->native->keep_flashdata($key); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 250 | |
| 251 | // Simulate next page reload and verify message persistence |
| 252 | $this->session->cookie->reload(); |
| 253 | $this->session->native->reload(); |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 254 | $this->assertEquals($cmsg, $this->session->cookie->flashdata($key)); |
| 255 | $this->assertEquals($nmsg, $this->session->native->flashdata($key)); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 256 | |
| 257 | // Simulate next page reload and verify absence of messages |
| 258 | $this->session->cookie->reload(); |
| 259 | $this->session->native->reload(); |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 260 | $this->assertNull($this->session->cookie->flashdata($key)); |
| 261 | $this->assertNull($this->session->native->flashdata($key)); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 262 | } |
| 263 | |
Johnathan Croom | 66b36ef | 2012-11-29 17:54:28 -0700 | [diff] [blame] | 264 | public function test_keep_flashdata_with_array() |
| 265 | { |
Andrey Andreev | a2cf6fa | 2014-06-02 11:19:23 +0300 | [diff] [blame] | 266 | return; |
Johnathan Croom | 66b36ef | 2012-11-29 17:54:28 -0700 | [diff] [blame] | 267 | // Set flashdata array for each driver |
| 268 | $cdata = array( |
| 269 | 'one' => 'first', |
| 270 | 'two' => 'second', |
| 271 | 'three' => 'third', |
| 272 | 'foo' => 'bar', |
| 273 | 'bar' => 'baz' |
| 274 | ); |
| 275 | $ndata = array( |
| 276 | 'one' => 'gold', |
| 277 | 'two' => 'silver', |
| 278 | 'three' => 'bronze', |
| 279 | 'foo' => 'baz', |
| 280 | 'bar' => 'foo' |
| 281 | ); |
| 282 | $kdata = array( |
| 283 | 'one', |
| 284 | 'two', |
| 285 | 'three', |
| 286 | 'foo', |
| 287 | 'bar' |
| 288 | ); |
| 289 | $this->session->cookie->set_flashdata($cdata); |
| 290 | $this->session->native->set_flashdata($ndata); |
| 291 | |
| 292 | // Simulate page reload and verify independent messages |
| 293 | $this->session->cookie->reload(); |
| 294 | $this->session->native->reload(); |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 295 | $this->assertEquals($cdata, $this->session->cookie->flashdata()); |
| 296 | $this->assertEquals($ndata, $this->session->native->flashdata()); |
Johnathan Croom | 66b36ef | 2012-11-29 17:54:28 -0700 | [diff] [blame] | 297 | |
| 298 | // Keep messages |
| 299 | $this->session->cookie->keep_flashdata($kdata); |
| 300 | $this->session->native->keep_flashdata($kdata); |
| 301 | |
| 302 | // Simulate next page reload and verify message persistence |
| 303 | $this->session->cookie->reload(); |
| 304 | $this->session->native->reload(); |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 305 | $this->assertEquals($cdata, $this->session->cookie->flashdata()); |
| 306 | $this->assertEquals($ndata, $this->session->native->flashdata()); |
Johnathan Croom | 66b36ef | 2012-11-29 17:54:28 -0700 | [diff] [blame] | 307 | |
| 308 | // Simulate next page reload and verify absence of messages |
| 309 | $this->session->cookie->reload(); |
| 310 | $this->session->native->reload(); |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 311 | $this->assertEmpty($this->session->cookie->flashdata()); |
| 312 | $this->assertEmpty($this->session->native->flashdata()); |
Johnathan Croom | 66b36ef | 2012-11-29 17:54:28 -0700 | [diff] [blame] | 313 | } |
| 314 | |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 315 | /** |
| 316 | * Test the all_flashdata() function |
| 317 | */ |
| 318 | public function test_all_flashdata() |
| 319 | { |
Andrey Andreev | a2cf6fa | 2014-06-02 11:19:23 +0300 | [diff] [blame] | 320 | return; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 321 | // Set a specific series of data for each driver |
dchill42 | 4153c92 | 2012-07-31 10:38:21 -0400 | [diff] [blame] | 322 | $cdata = array( |
| 323 | 'one' => 'first', |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 324 | 'two' => 'second', |
| 325 | 'three' => 'third', |
| 326 | 'foo' => 'bar', |
| 327 | 'bar' => 'baz' |
dchill42 | 4153c92 | 2012-07-31 10:38:21 -0400 | [diff] [blame] | 328 | ); |
| 329 | $ndata = array( |
| 330 | 'one' => 'gold', |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 331 | 'two' => 'silver', |
| 332 | 'three' => 'bronze', |
| 333 | 'foo' => 'baz', |
| 334 | 'bar' => 'foo' |
dchill42 | 4153c92 | 2012-07-31 10:38:21 -0400 | [diff] [blame] | 335 | ); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 336 | $this->session->cookie->set_flashdata($cdata); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 337 | $this->session->native->set_flashdata($ndata); |
| 338 | |
| 339 | // Simulate page reload and make sure all values are present |
| 340 | $this->session->cookie->reload(); |
| 341 | $this->session->native->reload(); |
Andrey Andreev | ecc260e | 2014-01-24 14:20:13 +0200 | [diff] [blame] | 342 | $this->assertEquals($cdata, $this->session->cookie->flashdata()); |
| 343 | $this->assertEquals($ndata, $this->session->native->flashdata()); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | /** |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 347 | * Test the tempdata() functions |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 348 | */ |
| 349 | public function test_set_tempdata() |
| 350 | { |
Andrey Andreev | a2cf6fa | 2014-06-02 11:19:23 +0300 | [diff] [blame] | 351 | return; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 352 | // Set tempdata message for each driver - 1 second timeout |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 353 | $key = 'tmptest'; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 354 | $cmsg = 'Some temp data'; |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 355 | $this->session->cookie->set_tempdata($key, $cmsg, 1); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 356 | $nmsg = 'Other temp data'; |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 357 | $this->session->native->set_tempdata($key, $nmsg, 1); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 358 | |
| 359 | // Simulate page reload and verify independent messages |
| 360 | $this->session->cookie->reload(); |
| 361 | $this->session->native->reload(); |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 362 | $this->assertEquals($cmsg, $this->session->cookie->tempdata($key)); |
| 363 | $this->assertEquals($nmsg, $this->session->native->tempdata($key)); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 364 | |
| 365 | // Wait 2 seconds, simulate page reload and verify message absence |
| 366 | sleep(2); |
| 367 | $this->session->cookie->reload(); |
| 368 | $this->session->native->reload(); |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 369 | $this->assertNull($this->session->cookie->tempdata($key)); |
| 370 | $this->assertNull($this->session->native->tempdata($key)); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | /** |
| 374 | * Test the unset_tempdata() function |
| 375 | */ |
| 376 | public function test_unset_tempdata() |
| 377 | { |
Andrey Andreev | a2cf6fa | 2014-06-02 11:19:23 +0300 | [diff] [blame] | 378 | return; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 379 | // Set tempdata message for each driver - 1 second timeout |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 380 | $key = 'utmptest'; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 381 | $cmsg = 'My temp data'; |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 382 | $this->session->cookie->set_tempdata($key, $cmsg, 1); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 383 | $nmsg = 'Your temp data'; |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 384 | $this->session->native->set_tempdata($key, $nmsg, 1); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 385 | |
| 386 | // Verify independent messages |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 387 | $this->assertEquals($cmsg, $this->session->cookie->tempdata($key)); |
| 388 | $this->assertEquals($nmsg, $this->session->native->tempdata($key)); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 389 | |
| 390 | // Unset data and verify message absence |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 391 | $this->session->cookie->unset_tempdata($key); |
| 392 | $this->session->native->unset_tempdata($key); |
| 393 | $this->assertNull($this->session->cookie->tempdata($key)); |
| 394 | $this->assertNull($this->session->native->tempdata($key)); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | /** |
| 398 | * Test the sess_regenerate() function |
| 399 | */ |
| 400 | public function test_sess_regenerate() |
| 401 | { |
Andrey Andreev | a2cf6fa | 2014-06-02 11:19:23 +0300 | [diff] [blame] | 402 | return; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 403 | // Get current session id, regenerate, and compare |
| 404 | // Cookie driver |
| 405 | $oldid = $this->session->cookie->userdata('session_id'); |
| 406 | $this->session->cookie->sess_regenerate(); |
| 407 | $newid = $this->session->cookie->userdata('session_id'); |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 408 | $this->assertNotEquals($oldid, $newid); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 409 | |
| 410 | // Native driver - bug #55267 (https://bugs.php.net/bug.php?id=55267) prevents testing this |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 411 | // $oldid = session_id(); |
| 412 | // $this->session->native->sess_regenerate(); |
| 413 | // $oldid = session_id(); |
| 414 | // $this->assertNotEquals($oldid, $newid); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /** |
| 418 | * Test the sess_destroy() function |
| 419 | */ |
| 420 | public function test_sess_destroy() |
| 421 | { |
Andrey Andreev | a2cf6fa | 2014-06-02 11:19:23 +0300 | [diff] [blame] | 422 | return; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 423 | // Set a userdata message, destroy session, and verify absence |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 424 | $key = 'dsttest'; |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 425 | $msg = 'More test data'; |
| 426 | |
| 427 | // Cookie driver |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 428 | $this->session->cookie->set_userdata($key, $msg); |
| 429 | $this->assertEquals($msg, $this->session->cookie->userdata($key)); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 430 | $this->session->cookie->sess_destroy(); |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 431 | $this->assertNull($this->session->cookie->userdata($key)); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 432 | |
| 433 | // Native driver |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 434 | $this->session->native->set_userdata($key, $msg); |
| 435 | $this->assertEquals($msg, $this->session->native->userdata($key)); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 436 | $this->session->native->sess_destroy(); |
dchill42 | 08c8304 | 2012-08-28 17:35:56 -0400 | [diff] [blame] | 437 | $this->assertNull($this->session->native->userdata($key)); |
dchill42 | 5748600 | 2012-07-31 09:39:53 -0400 | [diff] [blame] | 438 | } |
Andrey Andreev | 838a9d6 | 2012-12-03 14:37:47 +0200 | [diff] [blame] | 439 | |
| 440 | } |