blob: c6e194f58b6a27be2fef1d98547f503a742af5c1 [file] [log] [blame]
dchill4257486002012-07-31 09:39:53 -04001<?php
2
3/**
4 * Mock library to add testing features to Session driver library
5 */
6class Mock_Libraries_Session extends CI_Session {
Andrey Andreev5fd3ae82012-10-24 14:55:35 +03007
dchill4257486002012-07-31 09:39:53 -04008 /**
9 * Simulate new page load
10 */
11 public function reload()
12 {
13 $this->_flashdata_sweep();
14 $this->_flashdata_mark();
15 $this->_tempdata_sweep();
16 }
17}
18
19/**
20 * Mock cookie driver to overload cookie setting
21 */
22class Mock_Libraries_Session_cookie extends CI_Session_cookie {
Andrey Andreev5fd3ae82012-10-24 14:55:35 +030023
dchill4257486002012-07-31 09:39:53 -040024 /**
25 * Overload _setcookie to manage $_COOKIE values, since actual cookies can't be set in unit testing
26 */
Andrey Andreev5fd3ae82012-10-24 14:55:35 +030027 protected function _setcookie($name, $value = '', $expire = 0, $path = '', $domain = '', $secure = FALSE, $httponly = FALSE)
dchill4257486002012-07-31 09:39:53 -040028 {
Andrey Andreev5fd3ae82012-10-24 14:55:35 +030029 if (empty($value) OR $expire <= time())
30 {
dchill4257486002012-07-31 09:39:53 -040031 unset($_COOKIE[$name]);
32 }
Andrey Andreev5fd3ae82012-10-24 14:55:35 +030033 else
34 {
dchill4257486002012-07-31 09:39:53 -040035 $_COOKIE[$name] = $value;
36 }
37 }
38}
39
40/**
41 * Mock native driver (just for consistency in loading)
42 */
Andrey Andreev5fd3ae82012-10-24 14:55:35 +030043class Mock_Libraries_Session_native extends CI_Session_native { }