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