diff options
Diffstat (limited to 'tests/mocks/libraries')
-rw-r--r-- | tests/mocks/libraries/calendar.php | 25 | ||||
-rw-r--r-- | tests/mocks/libraries/encrypt.php | 16 | ||||
-rw-r--r-- | tests/mocks/libraries/session.php | 43 | ||||
-rw-r--r-- | tests/mocks/libraries/table.php | 3 | ||||
-rw-r--r-- | tests/mocks/libraries/upload.php | 3 |
5 files changed, 89 insertions, 1 deletions
diff --git a/tests/mocks/libraries/calendar.php b/tests/mocks/libraries/calendar.php new file mode 100644 index 000000000..8fee5365e --- /dev/null +++ b/tests/mocks/libraries/calendar.php @@ -0,0 +1,25 @@ +<?php + +class Mock_Libraries_Calendar extends CI_Calendar { + + public function __construct($config = array()) + { + $this->CI = new stdClass; + $this->CI->lang = new Mock_Core_Lang(); + + if ( ! in_array('calendar_lang.php', $this->CI->lang->is_loaded, TRUE)) + { + $this->CI->lang->load('calendar'); + } + + $this->local_time = time(); + + if (count($config) > 0) + { + $this->initialize($config); + } + + log_message('debug', 'Calendar Class Initialized'); + } + +}
\ No newline at end of file diff --git a/tests/mocks/libraries/encrypt.php b/tests/mocks/libraries/encrypt.php new file mode 100644 index 000000000..f1859398f --- /dev/null +++ b/tests/mocks/libraries/encrypt.php @@ -0,0 +1,16 @@ +<?php + +class Mock_Libraries_Encrypt extends CI_Encrypt { + + // Overide inaccesible protected method + public function __call($method, $params) + { + if (is_callable(array($this, '_'.$method))) + { + return call_user_func_array(array($this, '_'.$method), $params); + } + + throw new BadMethodCallException('Method '.$method.' was not found'); + } + +}
\ No newline at end of file diff --git a/tests/mocks/libraries/session.php b/tests/mocks/libraries/session.php new file mode 100644 index 000000000..9d6feee42 --- /dev/null +++ b/tests/mocks/libraries/session.php @@ -0,0 +1,43 @@ +<?php + +/** + * Mock library to add testing features to Session driver library + */ +class Mock_Libraries_Session extends CI_Session { + /** + * Simulate new page load + */ + public function reload() + { + $this->_flashdata_sweep(); + $this->_flashdata_mark(); + $this->_tempdata_sweep(); + } +} + +/** + * Mock cookie driver to overload cookie setting + */ +class Mock_Libraries_Session_cookie extends CI_Session_cookie { + /** + * Overload _setcookie to manage $_COOKIE values, since actual cookies can't be set in unit testing + */ + protected function _setcookie($name, $value = '', $expire = 0, $path = '', $domain = '', $secure = false, + $httponly = false) + { + if (empty($value) || $expire <= time()) { + // Clear cookie + unset($_COOKIE[$name]); + } + else { + // Set cookie + $_COOKIE[$name] = $value; + } + } +} + +/** + * Mock native driver (just for consistency in loading) + */ +class Mock_Libraries_Session_native extends CI_Session_native { } + diff --git a/tests/mocks/libraries/table.php b/tests/mocks/libraries/table.php index 97fbb30bd..87c278bce 100644 --- a/tests/mocks/libraries/table.php +++ b/tests/mocks/libraries/table.php @@ -1,7 +1,7 @@ <?php class Mock_Libraries_Table extends CI_Table { - + // Overide inaccesible protected method public function __call($method, $params) { @@ -12,4 +12,5 @@ class Mock_Libraries_Table extends CI_Table { throw new BadMethodCallException('Method '.$method.' was not found'); } + }
\ No newline at end of file diff --git a/tests/mocks/libraries/upload.php b/tests/mocks/libraries/upload.php new file mode 100644 index 000000000..988723e45 --- /dev/null +++ b/tests/mocks/libraries/upload.php @@ -0,0 +1,3 @@ +<?php + +class Mock_Libraries_Upload extends CI_Upload {}
\ No newline at end of file |