diff options
Diffstat (limited to 'tests/mocks')
-rw-r--r-- | tests/mocks/autoloader.php | 69 | ||||
-rw-r--r-- | tests/mocks/core/common.php | 60 | ||||
-rw-r--r-- | tests/mocks/core/uri.php | 14 | ||||
-rw-r--r-- | tests/mocks/core/utf8.php | 17 | ||||
-rw-r--r-- | tests/mocks/libraries/encryption.php | 39 |
5 files changed, 103 insertions, 96 deletions
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 3d216da1f..33942768d 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -14,26 +14,49 @@ function autoload($class) $dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR; $ci_core = array( - 'Benchmark', 'Config', 'Controller', - 'Exceptions', 'Hooks', 'Input', - 'Lang', 'Loader', 'Log', 'Model', - 'Output', 'Router', 'Security', - 'URI', 'Utf8', + 'Benchmark', + 'Config', + 'Controller', + 'Exceptions', + 'Hooks', + 'Input', + 'Lang', + 'Loader', + 'Log', + 'Model', + 'Output', + 'Router', + 'Security', + 'URI', + 'Utf8' ); $ci_libraries = array( - 'Calendar', 'Cart', 'Driver_Library', - 'Email', 'Encrypt', 'Form_validation', - 'Ftp', 'Image_lib', 'Javascript', - 'Migration', 'Pagination', 'Parser', - 'Profiler', 'Table', 'Trackback', - 'Typography', 'Unit_test', 'Upload', - 'User_agent', 'Xmlrpc', 'Zip' + 'Calendar', + 'Cart', + 'Driver_Library', + 'Email', + 'Encrypt', + 'Encryption', + 'Form_validation', + 'Ftp', + 'Image_lib', + 'Javascript', + 'Migration', + 'Pagination', + 'Parser', + 'Profiler', + 'Table', + 'Trackback', + 'Typography', + 'Unit_test', + 'Upload', + 'User_agent', + 'Xmlrpc', + 'Zip' ); - $ci_drivers = array( - 'Session', - ); + $ci_drivers = array('Session', 'Cache'); if (strpos($class, 'Mock_') === 0) { @@ -89,21 +112,7 @@ function autoload($class) if ( ! file_exists($file)) { - $trace = debug_backtrace(); - - if ($trace[2]['function'] === 'class_exists' OR $trace[2]['function'] === 'file_exists') - { - // If the autoload call came from `class_exists` or `file_exists`, - // we skipped and return FALSE - return FALSE; - } - elseif (($autoloader = spl_autoload_functions()) && end($autoloader) !== __FUNCTION__) - { - // If there was other custom autoloader, passed away - return FALSE; - } - - throw new InvalidArgumentException("Unable to load {$class}."); + return FALSE; } include_once($file); diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php index e5dc29c86..9eb6b0954 100644 --- a/tests/mocks/core/common.php +++ b/tests/mocks/core/common.php @@ -87,40 +87,6 @@ if ( ! function_exists('load_class')) } } -// This is sort of meh. Should probably be mocked up with -// controllable output, so that we can test some of our -// security code. The function itself will be tested in the -// bootstrap testsuite. -// -------------------------------------------------------------------- - -if ( ! function_exists('remove_invisible_characters')) -{ - function remove_invisible_characters($str, $url_encoded = TRUE) - { - $non_displayables = array(); - - // every control character except newline (dec 10) - // carriage return (dec 13), and horizontal tab (dec 09) - - if ($url_encoded) - { - $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15 - $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31 - } - - $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127 - - do - { - $str = preg_replace($non_displayables, '', $str, -1, $count); - } - while ($count); - - return $str; - } -} - - // Clean up error messages // -------------------------------------------------------------------- @@ -150,23 +116,6 @@ if ( ! function_exists('_exception_handler')) // We assume a few things about our environment ... // -------------------------------------------------------------------- - -if ( ! function_exists('is_php')) -{ - function is_php($version = '5.0.0') - { - return ! (version_compare(PHP_VERSION, $version) < 0); - } -} - -if ( ! function_exists('is_really_writable')) -{ - function is_really_writable($file) - { - return is_writable($file); - } -} - if ( ! function_exists('is_loaded')) { function &is_loaded() @@ -190,4 +139,13 @@ if ( ! function_exists('set_status_header')) { return TRUE; } +} + +if ( ! function_exists('is_cli')) +{ + // In order to test HTTP functionality, we need to lie about this + function is_cli() + { + return FALSE; + } }
\ No newline at end of file diff --git a/tests/mocks/core/uri.php b/tests/mocks/core/uri.php index 94f75df64..96ec5afa1 100644 --- a/tests/mocks/core/uri.php +++ b/tests/mocks/core/uri.php @@ -10,17 +10,23 @@ class Mock_Core_URI extends CI_URI { // set predictable config values $test->ci_set_config(array( 'index_page' => 'index.php', - 'base_url' => 'http://example.com/', - 'subclass_prefix' => 'MY_' + 'base_url' => 'http://example.com/', + 'subclass_prefix' => 'MY_', + 'enable_query_strings' => FALSE, + 'permitted_uri_chars' => 'a-z 0-9~%.:_\-' )); $this->config = new $cls; + if ($this->config->item('enable_query_strings') !== TRUE OR is_cli()) + { + $this->_permitted_uri_chars = $this->config->item('permitted_uri_chars'); + } } - protected function _is_cli_request() + public function _set_permitted_uri_chars($value) { - return FALSE; + $this->_permitted_uri_chars = $value; } }
\ No newline at end of file diff --git a/tests/mocks/core/utf8.php b/tests/mocks/core/utf8.php index 068e74ac1..30b78adfe 100644 --- a/tests/mocks/core/utf8.php +++ b/tests/mocks/core/utf8.php @@ -3,24 +3,19 @@ class Mock_Core_Utf8 extends CI_Utf8 { /** - * We need to define several constants as - * the same process within CI_Utf8 class constructor. + * We need to define UTF8_ENABLED the same way that + * CI_Utf8 constructor does. * * @covers CI_Utf8::__construct() */ public function __construct() { defined('UTF8_ENABLED') OR define('UTF8_ENABLED', TRUE); + } - if (extension_loaded('mbstring')) - { - defined('MB_ENABLED') OR define('MB_ENABLED', TRUE); - mb_internal_encoding('UTF-8'); - } - else - { - defined('MB_ENABLED') OR define('MB_ENABLED', FALSE); - } + public function is_ascii_test($str) + { + return $this->_is_ascii($str); } }
\ No newline at end of file diff --git a/tests/mocks/libraries/encryption.php b/tests/mocks/libraries/encryption.php new file mode 100644 index 000000000..028eecc72 --- /dev/null +++ b/tests/mocks/libraries/encryption.php @@ -0,0 +1,39 @@ +<?php + +class Mock_Libraries_Encryption extends CI_Encryption { + + /** + * __get_params() + * + * Allows public calls to the otherwise protected _get_params(). + */ + public function __get_params($params) + { + return $this->_get_params($params); + } + + // -------------------------------------------------------------------- + + /** + * get_key() + * + * Allows checking for key changes. + */ + public function get_key() + { + return $this->_key; + } + + // -------------------------------------------------------------------- + + /** + * __driver_get_handle() + * + * Allows checking for _mcrypt_get_handle(), _openssl_get_handle() + */ + public function __driver_get_handle($driver, $cipher, $mode) + { + return $this->{'_'.$driver.'_get_handle'}($cipher, $mode); + } + +}
\ No newline at end of file |