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