summaryrefslogtreecommitdiffstats
path: root/tests/mocks
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mocks')
-rw-r--r--tests/mocks/autoloader.php73
-rw-r--r--tests/mocks/ci_testcase.php285
-rw-r--r--tests/mocks/ci_testconfig.php20
-rw-r--r--tests/mocks/core/benchmark.php3
-rw-r--r--tests/mocks/core/common.php197
-rw-r--r--tests/mocks/core/input.php41
-rw-r--r--tests/mocks/core/loader.php30
-rw-r--r--tests/mocks/core/security.php30
-rw-r--r--tests/mocks/core/uri.php9
-rw-r--r--tests/mocks/core/utf8.php26
-rwxr-xr-xtests/mocks/database/ci_test.sqlitebin17408 -> 19456 bytes
-rw-r--r--tests/mocks/database/config/mysql.php10
-rw-r--r--tests/mocks/database/config/mysqli.php34
-rw-r--r--tests/mocks/database/config/pdo/mysql.php37
-rw-r--r--tests/mocks/database/config/pdo/pgsql.php37
-rw-r--r--tests/mocks/database/config/pdo/sqlite.php37
-rw-r--r--tests/mocks/database/config/pgsql.php10
-rw-r--r--tests/mocks/database/config/sqlite.php15
-rw-r--r--tests/mocks/database/db.php80
-rw-r--r--tests/mocks/database/db/driver.php40
-rw-r--r--tests/mocks/database/db/querybuilder.php3
-rw-r--r--tests/mocks/database/drivers/mysql.php17
-rw-r--r--tests/mocks/database/drivers/mysqli.php17
-rw-r--r--tests/mocks/database/drivers/pdo.php16
-rw-r--r--tests/mocks/database/drivers/postgre.php17
-rw-r--r--tests/mocks/database/drivers/sqlite.php17
-rw-r--r--tests/mocks/database/schema/.gitkeep0
-rw-r--r--tests/mocks/database/schema/skeleton.php148
-rw-r--r--tests/mocks/libraries/driver.php27
-rw-r--r--tests/mocks/libraries/encrypt.php16
-rw-r--r--tests/mocks/libraries/session.php36
-rw-r--r--tests/mocks/libraries/table.php5
-rw-r--r--tests/mocks/libraries/upload.php3
-rw-r--r--tests/mocks/uploads/ci_logo.gifbin0 -> 3270 bytes
34 files changed, 1123 insertions, 213 deletions
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
index dd5929206..3d216da1f 100644
--- a/tests/mocks/autoloader.php
+++ b/tests/mocks/autoloader.php
@@ -6,73 +6,104 @@
//
// Prototype :
//
-// include_once('Mock_Core_Loader') // Will load ./mocks/core/loader.php
// $mock_table = new Mock_Libraries_Table(); // Will load ./mocks/libraries/table.php
-// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php
+// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php
// and so on...
-function autoload($class)
+function autoload($class)
{
$dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR;
$ci_core = array(
'Benchmark', 'Config', 'Controller',
'Exceptions', 'Hooks', 'Input',
- 'Lang', 'Loader', 'Model',
+ 'Lang', 'Loader', 'Log', 'Model',
'Output', 'Router', 'Security',
'URI', 'Utf8',
);
$ci_libraries = array(
- 'Calendar', 'Cart', 'Driver',
+ 'Calendar', 'Cart', 'Driver_Library',
'Email', 'Encrypt', 'Form_validation',
'Ftp', 'Image_lib', 'Javascript',
- 'Log', 'Migration', 'Pagination',
- 'Parser', 'Profiler', 'Session',
- 'Table', 'Trackback', 'Typography',
- 'Unit_test', 'Upload', 'User_agent',
- 'Xmlrpc', 'Zip',
+ 'Migration', 'Pagination', 'Parser',
+ 'Profiler', 'Table', 'Trackback',
+ 'Typography', 'Unit_test', 'Upload',
+ 'User_agent', 'Xmlrpc', 'Zip'
+ );
+
+ $ci_drivers = array(
+ 'Session',
);
if (strpos($class, 'Mock_') === 0)
{
- $class = str_replace(array('Mock_', '_'), array('', DIRECTORY_SEPARATOR), $class);
- $class = strtolower($class);
+ $class = strtolower(str_replace(array('Mock_', '_'), array('', DIRECTORY_SEPARATOR), $class));
}
elseif (strpos($class, 'CI_') === 0)
{
- $fragments = explode('_', $class, 2);
- $subclass = next($fragments);
+ $subclass = substr($class, 3);
if (in_array($subclass, $ci_core))
{
- $dir = BASEPATH.'core'.DIRECTORY_SEPARATOR;
+ $dir = SYSTEM_PATH.'core'.DIRECTORY_SEPARATOR;
$class = $subclass;
}
elseif (in_array($subclass, $ci_libraries))
{
- $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR;
+ $dir = SYSTEM_PATH.'libraries'.DIRECTORY_SEPARATOR;
+ $class = ($subclass === 'Driver_Library') ? 'Driver' : $subclass;
+ }
+ elseif (in_array($subclass, $ci_drivers))
+ {
+ $dir = SYSTEM_PATH.'libraries'.DIRECTORY_SEPARATOR.$subclass.DIRECTORY_SEPARATOR;
$class = $subclass;
}
+ elseif (in_array(($parent = strtok($subclass, '_')), $ci_drivers)) {
+ $dir = SYSTEM_PATH.'libraries'.DIRECTORY_SEPARATOR.$parent.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
+ $class = $subclass;
+ }
+ elseif (preg_match('/^CI_DB_(.+)_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) === 4)
+ {
+ $driver_path = SYSTEM_PATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
+ $dir = $driver_path.$m[1].DIRECTORY_SEPARATOR.'subdrivers'.DIRECTORY_SEPARATOR;
+ $file = $dir.$m[1].'_'.$m[2].'_'.$m[3].'.php';
+ }
+ elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) === 3)
+ {
+ $driver_path = SYSTEM_PATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
+ $dir = $driver_path.$m[1].DIRECTORY_SEPARATOR;
+ $file = $dir.$m[1].'_'.$m[2].'.php';
+ }
+ elseif (strpos($class, 'CI_DB') === 0)
+ {
+ $dir = SYSTEM_PATH.'database'.DIRECTORY_SEPARATOR;
+ $file = $dir.str_replace(array('CI_DB','active_record'), array('DB', 'active_rec'), $subclass).'.php';
+ }
else
{
$class = strtolower($class);
}
}
- $file = $dir.$class.'.php';
+ $file = isset($file) ? $file : $dir.$class.'.php';
if ( ! file_exists($file))
{
$trace = debug_backtrace();
- // If the autoload call came from `class_exists` or `file_exists`,
- // we skipped and return FALSE
- if ($trace[2]['function'] == 'class_exists' OR $trace[2]['function'] == 'file_exists')
+ 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.");
+ throw new InvalidArgumentException("Unable to load {$class}.");
}
include_once($file);
diff --git a/tests/mocks/ci_testcase.php b/tests/mocks/ci_testcase.php
index f327e6b07..f16492945 100644
--- a/tests/mocks/ci_testcase.php
+++ b/tests/mocks/ci_testcase.php
@@ -1,11 +1,13 @@
<?php
class CI_TestCase extends PHPUnit_Framework_TestCase {
-
- protected $ci_config;
+
+ public $ci_vfs_root;
+ public $ci_app_root;
+ public $ci_base_root;
protected $ci_instance;
protected static $ci_test_instance;
-
+
private $global_map = array(
'benchmark' => 'bm',
'config' => 'cfg',
@@ -19,29 +21,34 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
'loader' => 'load',
'model' => 'model'
);
-
+
// --------------------------------------------------------------------
-
+
public function __construct()
{
parent::__construct();
-
- $this->ci_config = array();
+ $this->ci_instance = new StdClass();
}
-
+
// --------------------------------------------------------------------
-
+
public function setUp()
{
+ // Setup VFS with base directories
+ $this->ci_vfs_root = vfsStream::setup();
+ $this->ci_app_root = vfsStream::newDirectory('application')->at($this->ci_vfs_root);
+ $this->ci_base_root = vfsStream::newDirectory('system')->at($this->ci_vfs_root);
+ $this->ci_view_root = vfsStream::newDirectory('views')->at($this->ci_app_root);
+
if (method_exists($this, 'set_up'))
{
$this->set_up();
}
}
-
+
// --------------------------------------------------------------------
-
- public function tearDown()
+
+ public function tearDown()
{
if (method_exists($this, 'tear_down'))
{
@@ -50,57 +57,69 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
}
// --------------------------------------------------------------------
-
+
public static function instance()
{
return self::$ci_test_instance;
}
-
+
// --------------------------------------------------------------------
-
- function ci_set_config($key, $val = '')
+
+ public function ci_set_config($key = '', $val = '')
{
+ // Add test config
+ if ( ! isset($this->ci_instance->config))
+ {
+ $this->ci_instance->config = new CI_TestConfig();
+ }
+
+ // Empty key means just do setup above
+ if ($key === '')
+ {
+ return;
+ }
+
if (is_array($key))
{
- $this->ci_config = $key;
+ $this->ci_instance->config->config = $key;
}
else
{
- $this->ci_config[$key] = $val;
+ $this->ci_instance->config->config[$key] = $val;
}
}
// --------------------------------------------------------------------
-
- function ci_get_config()
+
+ public function ci_get_config()
{
- return $this->ci_config;
+ return isset($this->ci_instance->config) ? $this->ci_instance->config->config : array();
}
-
+
// --------------------------------------------------------------------
-
- function ci_instance($obj = FALSE)
+
+ public function ci_instance($obj = FALSE)
{
if ( ! is_object($obj))
{
return $this->ci_instance;
}
-
+
$this->ci_instance = $obj;
}
-
+
// --------------------------------------------------------------------
-
- function ci_instance_var($name, $obj = FALSE)
+
+ public function ci_instance_var($name, $obj = FALSE)
{
if ( ! is_object($obj))
{
return $this->ci_instance->$name;
}
-
+
$this->ci_instance->$name =& $obj;
}
-
+
// --------------------------------------------------------------------
/**
@@ -112,10 +131,10 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
* test can modify the variable it assigns to and
* still maintain the global.
*/
- function &ci_core_class($name)
+ public function &ci_core_class($name)
{
$name = strtolower($name);
-
+
if (isset($this->global_map[$name]))
{
$class_name = ucfirst($name);
@@ -130,29 +149,188 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
{
throw new Exception('Not a valid core class.');
}
-
+
if ( ! class_exists('CI_'.$class_name))
{
- require_once BASEPATH.'core/'.$class_name.'.php';
+ require_once SYSTEM_PATH.'core/'.$class_name.'.php';
}
-
+
$GLOBALS[strtoupper($global_name)] = 'CI_'.$class_name;
return $GLOBALS[strtoupper($global_name)];
}
-
+
// --------------------------------------------------------------------
-
+
// convenience function for global mocks
- function ci_set_core_class($name, $obj)
+ public function ci_set_core_class($name, $obj)
{
$orig =& $this->ci_core_class($name);
$orig = $obj;
}
-
+
+ /**
+ * Create VFS directory
+ *
+ * @param string Directory name
+ * @param object Optional root to create in
+ * @return object New directory object
+ */
+ public function ci_vfs_mkdir($name, $root = NULL)
+ {
+ // Check for root
+ if ( ! $root)
+ {
+ $root = $this->ci_vfs_root;
+ }
+
+ // Return new directory object
+ return vfsStream::newDirectory($name)->at($root);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Create VFS content
+ *
+ * @param string File name
+ * @param string File content
+ * @param object VFS directory object
+ * @param mixed Optional subdirectory path or array of subs
+ * @return void
+ */
+ public function ci_vfs_create($file, $content = '', $root = NULL, $path = NULL)
+ {
+ // Check for array
+ if (is_array($file))
+ {
+ foreach ($file as $name => $content)
+ {
+ $this->ci_vfs_create($name, $content, $root, $path);
+ }
+ return;
+ }
+
+ // Assert .php extension if none given
+ if (pathinfo($file, PATHINFO_EXTENSION) == '')
+ {
+ $file .= '.php';
+ }
+
+ // Build content
+ $tree = array($file => $content);
+
+ // Check for path
+ $subs = array();
+ if ($path)
+ {
+ // Explode if not array
+ $subs = is_array($path) ? $path : explode('/', trim($path, '/'));
+ }
+
+ // Check for root
+ if ( ! $root)
+ {
+ // Use base VFS root
+ $root = $this->ci_vfs_root;
+ }
+
+ // Handle subdirectories
+ while (($dir = array_shift($subs)))
+ {
+ // See if subdir exists under current root
+ $dir_root = $root->getChild($dir);
+ if ($dir_root)
+ {
+ // Yes - recurse into subdir
+ $root = $dir_root;
+ }
+ else
+ {
+ // No - put subdirectory back and quit
+ array_unshift($subs, $dir);
+ break;
+ }
+ }
+
+ // Create any remaining subdirectories
+ if ($subs)
+ {
+ foreach (array_reverse($subs) as $dir)
+ {
+ // Wrap content in subdirectory for creation
+ $tree = array($dir => $tree);
+ }
+ }
+
+ // Create tree
+ vfsStream::create($tree, $root);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Clone a real file into VFS
+ *
+ * @param string Path from base directory
+ * @return bool TRUE on success, otherwise FALSE
+ */
+ public function ci_vfs_clone($path)
+ {
+ // Check for array
+ if (is_array($path))
+ {
+ foreach ($path as $file)
+ {
+ $this->ci_vfs_clone($file);
+ }
+ return;
+ }
+
+ // Get real file contents
+ $content = file_get_contents(PROJECT_BASE.$path);
+ if ($content === FALSE)
+ {
+ // Couldn't find file to clone
+ return FALSE;
+ }
+
+ $this->ci_vfs_create(basename($path), $content, NULL, dirname($path));
+ return TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Helper to get a VFS URL path
+ *
+ * @param string Path
+ * @param string Optional base path
+ * @return string Path URL
+ */
+ public function ci_vfs_path($path, $base = '')
+ {
+ // Check for base path
+ if ($base)
+ {
+ // Prepend to path
+ $path = rtrim($base, '/').'/'.ltrim($path, '/');
+
+ // Is it already in URL form?
+ if (strpos($path, '://') !== FALSE)
+ {
+ // Done - return path
+ return $path;
+ }
+ }
+
+ // Trim leading slash and return URL
+ return vfsStream::url(ltrim($path, '/'));
+ }
+
// --------------------------------------------------------------------
// Internals
// --------------------------------------------------------------------
-
+
/**
* Overwrite runBare
*
@@ -169,28 +347,35 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
}
// --------------------------------------------------------------------
-
- function helper($name)
+
+ public function helper($name)
{
- require_once(BASEPATH.'helpers/'.$name.'_helper.php');
+ require_once(SYSTEM_PATH.'helpers/'.$name.'_helper.php');
}
// --------------------------------------------------------------------
-
+
+ public function lang($name)
+ {
+ require(SYSTEM_PATH.'language/english/'.$name.'_lang.php');
+ return $lang;
+ }
+
+ // --------------------------------------------------------------------
+
/**
* This overload is useful to create a stub, that need to have a specific method.
*/
- function __call($method, $args)
+ public function __call($method, $args)
{
- if ($this->{$method} instanceof Closure)
+ if ($this->{$method} instanceof Closure)
{
return call_user_func_array($this->{$method},$args);
- }
- else
+ }
+ else
{
return parent::__call($method, $args);
}
}
-}
-// EOF \ No newline at end of file
+} \ No newline at end of file
diff --git a/tests/mocks/ci_testconfig.php b/tests/mocks/ci_testconfig.php
new file mode 100644
index 000000000..f80adc5d4
--- /dev/null
+++ b/tests/mocks/ci_testconfig.php
@@ -0,0 +1,20 @@
+<?php
+
+class CI_TestConfig {
+
+ public $config = array();
+ public $_config_paths = array(APPPATH);
+ public $loaded = array();
+
+ public function item($key)
+ {
+ return isset($this->config[$key]) ? $this->config[$key] : FALSE;
+ }
+
+ public function load($file, $arg2 = FALSE, $arg3 = FALSE)
+ {
+ $this->loaded[] = $file;
+ return TRUE;
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/core/benchmark.php b/tests/mocks/core/benchmark.php
new file mode 100644
index 000000000..d92be21db
--- /dev/null
+++ b/tests/mocks/core/benchmark.php
@@ -0,0 +1,3 @@
+<?php
+
+class Mock_Core_Benchmark extends CI_Benchmark {} \ No newline at end of file
diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php
index fc94d7fff..24d645ae3 100644
--- a/tests/mocks/core/common.php
+++ b/tests/mocks/core/common.php
@@ -2,53 +2,89 @@
// Set up the global CI functions in their most minimal core representation
-function &get_instance()
+if ( ! function_exists('get_instance'))
{
- $test = CI_TestCase::instance();
- $instance = $test->ci_instance();
- return $instance;
+ function &get_instance()
+ {
+ $test = CI_TestCase::instance();
+ $test = $test->ci_instance();
+ return $test;
+ }
}
// --------------------------------------------------------------------
-function &get_config() {
- $test = CI_TestCase::instance();
- $config = $test->ci_get_config();
-
- return $config;
+if ( ! function_exists('get_config'))
+{
+ function &get_config()
+ {
+ $test = CI_TestCase::instance();
+ $config = $test->ci_get_config();
+ return $config;
+ }
}
-function config_item($item)
+if ( ! function_exists('config_item'))
{
- $config =& get_config();
-
- if ( ! isset($config[$item]))
+ function config_item($item)
{
- return FALSE;
+ $config =& get_config();
+
+ if ( ! isset($config[$item]))
+ {
+ return FALSE;
+ }
+
+ return $config[$item];
}
-
- return $config[$item];
}
-// --------------------------------------------------------------------
-
-function load_class($class, $directory = 'libraries', $prefix = 'CI_')
+if ( ! function_exists('get_mimes'))
{
- if ($directory != 'core' OR $prefix != 'CI_')
+ /**
+ * Returns the MIME types array from config/mimes.php
+ *
+ * @return array
+ */
+ function &get_mimes()
{
- throw new Exception('Not Implemented: Non-core load_class()');
+ static $_mimes = array();
+
+ if (empty($_mimes))
+ {
+ $path = realpath(PROJECT_BASE.'application/config/mimes.php');
+ if (is_file($path))
+ {
+ $_mimes = include($path);
+ }
+ }
+
+ return $_mimes;
}
-
- $test = CI_TestCase::instance();
-
- $obj =& $test->ci_core_class($class);
-
- if (is_string($obj))
+}
+
+// --------------------------------------------------------------------
+
+if ( ! function_exists('load_class'))
+{
+ function load_class($class, $directory = 'libraries', $prefix = 'CI_')
{
- throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class.'');
+ if ($directory !== 'core' OR $prefix !== 'CI_')
+ {
+ throw new Exception('Not Implemented: Non-core load_class()');
+ }
+
+ $test = CI_TestCase::instance();
+
+ $obj =& $test->ci_core_class($class);
+
+ if (is_string($obj))
+ {
+ throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class);
+ }
+
+ return $obj;
}
-
- return $obj;
}
// This is sort of meh. Should probably be mocked up with
@@ -57,76 +93,101 @@ function load_class($class, $directory = 'libraries', $prefix = 'CI_')
// bootstrap testsuite.
// --------------------------------------------------------------------
-function remove_invisible_characters($str, $url_encoded = TRUE)
+if ( ! function_exists('remove_invisible_characters'))
{
- $non_displayables = array();
-
- // every control character except newline (dec 10)
- // carriage return (dec 13), and horizontal tab (dec 09)
-
- if ($url_encoded)
+ function remove_invisible_characters($str, $url_encoded = TRUE)
{
- $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
+ $non_displayables = array();
- do
- {
- $str = preg_replace($non_displayables, '', $str, -1, $count);
- }
- while ($count);
+ // 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
+ }
- return $str;
+ $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
// --------------------------------------------------------------------
-function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
+if ( ! function_exists('show_error'))
{
- throw new RuntimeException('CI Error: '.$message);
+ function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
+ {
+ throw new RuntimeException('CI Error: '.$message);
+ }
}
-function show_404($page = '', $log_error = TRUE)
+if ( ! function_exists('show_404'))
{
- throw new RuntimeException('CI Error: 404');
+ function show_404($page = '', $log_error = TRUE)
+ {
+ throw new RuntimeException('CI Error: 404');
+ }
}
-function _exception_handler($severity, $message, $filepath, $line)
+if ( ! function_exists('_exception_handler'))
{
- throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line);
+ function _exception_handler($severity, $message, $filepath, $line)
+ {
+ throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line);
+ }
}
-
// We assume a few things about our environment ...
// --------------------------------------------------------------------
-function is_php($version = '5.0.0')
+if ( ! function_exists('is_php'))
{
- return ! (version_compare(PHP_VERSION, $version) < 0);
+ function is_php($version = '5.0.0')
+ {
+ return ! (version_compare(PHP_VERSION, $version) < 0);
+ }
}
-function is_really_writable($file)
+if ( ! function_exists('is_really_writable'))
{
- return is_writable($file);
+ function is_really_writable($file)
+ {
+ return is_writable($file);
+ }
}
-function is_loaded()
+if ( ! function_exists('is_loaded'))
{
- throw new Exception('Bad Isolation: mock up environment');
+ function &is_loaded()
+ {
+ $loaded = array();
+ return $loaded;
+ }
}
-function log_message($level = 'error', $message, $php_error = FALSE)
+if ( ! function_exists('log_message'))
{
- return TRUE;
+ function log_message($level = 'error', $message, $php_error = FALSE)
+ {
+ return TRUE;
+ }
}
-function set_status_header($code = 200, $text = '')
+if ( ! function_exists('set_status_header'))
{
- return TRUE;
-}
-
-// EOF \ No newline at end of file
+ function set_status_header($code = 200, $text = '')
+ {
+ return TRUE;
+ }
+} \ No newline at end of file
diff --git a/tests/mocks/core/input.php b/tests/mocks/core/input.php
new file mode 100644
index 000000000..0d1873849
--- /dev/null
+++ b/tests/mocks/core/input.php
@@ -0,0 +1,41 @@
+<?php
+
+class Mock_Core_Input extends CI_Input {
+
+ /**
+ * Since we use GLOBAL to fetch Security and Utf8 classes,
+ * we need to use inversion of control to mock up
+ * the same process within CI_Input class constructor.
+ *
+ * @covers CI_Input::__construct()
+ */
+ public function __construct($security, $utf8)
+ {
+ $this->_allow_get_array = (config_item('allow_get_array') === TRUE);
+ $this->_enable_xss = (config_item('global_xss_filtering') === TRUE);
+ $this->_enable_csrf = (config_item('csrf_protection') === TRUE);
+
+ // Assign Security and Utf8 classes
+ $this->security = $security;
+ $this->uni = $utf8;
+
+ // Sanitize global arrays
+ $this->_sanitize_globals();
+ }
+
+ public function fetch_from_array($array, $index = '', $xss_clean = FALSE)
+ {
+ return parent::_fetch_from_array($array, $index, $xss_clean);
+ }
+
+ /**
+ * Lie about being a CLI request
+ *
+ * We take advantage of this in libraries/Session_test
+ */
+ public function is_cli_request()
+ {
+ return FALSE;
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php
deleted file mode 100644
index d4b29bb3d..000000000
--- a/tests/mocks/core/loader.php
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-
-class Mock_Core_Loader extends CI_Loader {
-
- /**
- * Since we use paths to load up models, views, etc, we need the ability to
- * mock up the file system so when core tests are run, we aren't mucking
- * in the application directory. this will give finer grained control over
- * these tests. So yeah, while this looks odd, I need to overwrite protected
- * class vars in the loader. So here we go...
- *
- * @covers CI_Loader::__construct()
- */
- public function __construct()
- {
- vfsStreamWrapper::register();
- vfsStreamWrapper::setRoot(new vfsStreamDirectory('application'));
-
- $this->models_dir = vfsStream::newDirectory('models')->at(vfsStreamWrapper::getRoot());
- $this->libs_dir = vfsStream::newDirectory('libraries')->at(vfsStreamWrapper::getRoot());
- $this->helpers_dir = vfsStream::newDirectory('helpers')->at(vfsStreamWrapper::getRoot());
- $this->views_dir = vfsStream::newDirectory('views')->at(vfsStreamWrapper::getRoot());
-
- $this->_ci_ob_level = ob_get_level();
- $this->_ci_library_paths = array(vfsStream::url('application').'/', BASEPATH);
- $this->_ci_helper_paths = array(vfsStream::url('application').'/', BASEPATH);
- $this->_ci_model_paths = array(vfsStream::url('application').'/');
- $this->_ci_view_paths = array(vfsStream::url('application').'/views/' => TRUE);
- }
-} \ No newline at end of file
diff --git a/tests/mocks/core/security.php b/tests/mocks/core/security.php
new file mode 100644
index 000000000..e19a8b20b
--- /dev/null
+++ b/tests/mocks/core/security.php
@@ -0,0 +1,30 @@
+<?php
+
+class Mock_Core_Security extends CI_Security {
+
+ public function csrf_set_cookie()
+ {
+ // We cannot set cookie in CLI mode, so for csrf test, who rely on $_COOKIE,
+ // we superseded set_cookie with directly set the cookie variable,
+ // @see : ./tests/codeigniter/core/Security_test.php, line 8
+ return $this;
+ }
+
+ // Overide inaccesible protected properties
+ public function __get($property)
+ {
+ return isset($this->{'_'.$property}) ? $this->{'_'.$property} : NULL;
+ }
+
+ // 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/core/uri.php b/tests/mocks/core/uri.php
index b6946091e..94f75df64 100644
--- a/tests/mocks/core/uri.php
+++ b/tests/mocks/core/uri.php
@@ -1,12 +1,12 @@
<?php
class Mock_Core_URI extends CI_URI {
-
+
public function __construct()
{
$test = CI_TestCase::instance();
$cls =& $test->ci_core_class('cfg');
-
+
// set predictable config values
$test->ci_set_config(array(
'index_page' => 'index.php',
@@ -14,12 +14,13 @@ class Mock_Core_URI extends CI_URI {
'subclass_prefix' => 'MY_'
));
- $this->config = new $cls;
+ $this->config = new $cls;
}
-
+
protected function _is_cli_request()
{
return FALSE;
}
+
} \ No newline at end of file
diff --git a/tests/mocks/core/utf8.php b/tests/mocks/core/utf8.php
new file mode 100644
index 000000000..068e74ac1
--- /dev/null
+++ b/tests/mocks/core/utf8.php
@@ -0,0 +1,26 @@
+<?php
+
+class Mock_Core_Utf8 extends CI_Utf8 {
+
+ /**
+ * We need to define several constants as
+ * the same process within CI_Utf8 class constructor.
+ *
+ * @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);
+ }
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite
index 37ce4f870..44dcef9ec 100755
--- a/tests/mocks/database/ci_test.sqlite
+++ b/tests/mocks/database/ci_test.sqlite
Binary files differ
diff --git a/tests/mocks/database/config/mysql.php b/tests/mocks/database/config/mysql.php
index ace0a31b1..a590b9f53 100644
--- a/tests/mocks/database/config/mysql.php
+++ b/tests/mocks/database/config/mysql.php
@@ -1,7 +1,7 @@
<?php
return array(
-
+
// Typical Database configuration
'mysql' => array(
'dsn' => '',
@@ -9,7 +9,7 @@ return array(
'username' => 'travis',
'password' => '',
'database' => 'ci_test',
- 'dbdriver' => 'mysql',
+ 'dbdriver' => 'mysql'
),
// Database configuration with failover
@@ -28,7 +28,7 @@ return array(
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'mysql',
- ),
- ),
- ),
+ )
+ )
+ )
); \ No newline at end of file
diff --git a/tests/mocks/database/config/mysqli.php b/tests/mocks/database/config/mysqli.php
new file mode 100644
index 000000000..5dd08abb2
--- /dev/null
+++ b/tests/mocks/database/config/mysqli.php
@@ -0,0 +1,34 @@
+<?php
+
+return array(
+
+ // Typical Database configuration
+ 'mysqli' => array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'travis',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'mysqli'
+ ),
+
+ // Database configuration with failover
+ 'mysqli_failover' => array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'not_travis',
+ 'password' => 'wrong password',
+ 'database' => 'not_ci_test',
+ 'dbdriver' => 'mysqli',
+ 'failover' => array(
+ array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'travis',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'mysqli',
+ )
+ )
+ )
+); \ No newline at end of file
diff --git a/tests/mocks/database/config/pdo/mysql.php b/tests/mocks/database/config/pdo/mysql.php
new file mode 100644
index 000000000..96608f787
--- /dev/null
+++ b/tests/mocks/database/config/pdo/mysql.php
@@ -0,0 +1,37 @@
+<?php
+
+return array(
+
+ // Typical Database configuration
+ 'pdo/mysql' => array(
+ 'dsn' => 'mysql:host=localhost;dbname=ci_test',
+ 'hostname' => 'localhost',
+ 'username' => 'travis',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'mysql'
+ ),
+
+ // Database configuration with failover
+ 'pdo/mysql_failover' => array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'not_travis',
+ 'password' => 'wrong password',
+ 'database' => 'not_ci_test',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'mysql',
+ 'failover' => array(
+ array(
+ 'dsn' => 'mysql:host=localhost;dbname=ci_test',
+ 'hostname' => 'localhost',
+ 'username' => 'travis',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'mysql'
+ )
+ )
+ )
+); \ No newline at end of file
diff --git a/tests/mocks/database/config/pdo/pgsql.php b/tests/mocks/database/config/pdo/pgsql.php
new file mode 100644
index 000000000..e55e3ea77
--- /dev/null
+++ b/tests/mocks/database/config/pdo/pgsql.php
@@ -0,0 +1,37 @@
+<?php
+
+return array(
+
+ // Typical Database configuration
+ 'pdo/pgsql' => array(
+ 'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;',
+ 'hostname' => 'localhost',
+ 'username' => 'postgres',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'pgsql'
+ ),
+
+ // Database configuration with failover
+ 'pdo/pgsql_failover' => array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'not_travis',
+ 'password' => 'wrong password',
+ 'database' => 'not_ci_test',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'pgsql',
+ 'failover' => array(
+ array(
+ 'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;',
+ 'hostname' => 'localhost',
+ 'username' => 'postgres',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'pgsql'
+ )
+ )
+ )
+); \ No newline at end of file
diff --git a/tests/mocks/database/config/pdo/sqlite.php b/tests/mocks/database/config/pdo/sqlite.php
new file mode 100644
index 000000000..1bf56b3ac
--- /dev/null
+++ b/tests/mocks/database/config/pdo/sqlite.php
@@ -0,0 +1,37 @@
+<?php
+
+return array(
+
+ // Typical Database configuration
+ 'pdo/sqlite' => array(
+ 'dsn' => 'sqlite:/'.realpath(__DIR__.'/../..').'/ci_test.sqlite',
+ 'hostname' => 'localhost',
+ 'username' => 'sqlite',
+ 'password' => 'sqlite',
+ 'database' => 'sqlite',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'sqlite'
+ ),
+
+ // Database configuration with failover
+ 'pdo/sqlite_failover' => array(
+ 'dsn' => 'sqlite:not_exists.sqlite',
+ 'hostname' => 'localhost',
+ 'username' => 'sqlite',
+ 'password' => 'sqlite',
+ 'database' => 'sqlite',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'sqlite',
+ 'failover' => array(
+ array(
+ 'dsn' => 'sqlite:/'.realpath(__DIR__.'/../..').'/ci_test.sqlite',
+ 'hostname' => 'localhost',
+ 'username' => 'sqlite',
+ 'password' => 'sqlite',
+ 'database' => 'sqlite',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'sqlite'
+ )
+ )
+ )
+); \ No newline at end of file
diff --git a/tests/mocks/database/config/pgsql.php b/tests/mocks/database/config/pgsql.php
index c06af8ce0..1444b0066 100644
--- a/tests/mocks/database/config/pgsql.php
+++ b/tests/mocks/database/config/pgsql.php
@@ -1,7 +1,7 @@
<?php
return array(
-
+
// Typical Database configuration
'pgsql' => array(
'dsn' => '',
@@ -9,7 +9,7 @@ return array(
'username' => 'postgres',
'password' => '',
'database' => 'ci_test',
- 'dbdriver' => 'postgre',
+ 'dbdriver' => 'postgre'
),
// Database configuration with failover
@@ -28,7 +28,7 @@ return array(
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'postgre',
- ),
- ),
- ),
+ )
+ )
+ )
); \ No newline at end of file
diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php
index 8665e208d..d37ee4871 100644
--- a/tests/mocks/database/config/sqlite.php
+++ b/tests/mocks/database/config/sqlite.php
@@ -1,5 +1,4 @@
<?php
-$dbdriver = is_php('5.4') ? 'sqlite3' : 'sqlite';
return array(
@@ -10,7 +9,7 @@ return array(
'username' => 'sqlite',
'password' => 'sqlite',
'database' => realpath(__DIR__.'/..').'/ci_test.sqlite',
- 'dbdriver' => $dbdriver,
+ 'dbdriver' => 'sqlite3'
),
// Database configuration with failover
@@ -20,16 +19,16 @@ return array(
'username' => 'sqlite',
'password' => 'sqlite',
'database' => '../not_exists.sqlite',
- 'dbdriver' => $dbdriver,
+ 'dbdriver' => 'sqlite3',
'failover' => array(
array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'sqlite',
'password' => 'sqlite',
- 'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite',
- 'dbdriver' => $dbdriver,
- ),
- ),
- ),
+ 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite',
+ 'dbdriver' => 'sqlite3'
+ )
+ )
+ )
); \ No newline at end of file
diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php
index 43a0d391f..7e0030e15 100644
--- a/tests/mocks/database/db.php
+++ b/tests/mocks/database/db.php
@@ -6,7 +6,17 @@ class Mock_Database_DB {
* @var array DB configuration
*/
private $config = array();
-
+
+ /**
+ * @var string DB driver name
+ */
+ private static $dbdriver = '';
+
+ /**
+ * @var string DB sub-driver name
+ */
+ private static $subdriver = '';
+
/**
* Prepare database configuration skeleton
*
@@ -21,7 +31,7 @@ class Mock_Database_DB {
/**
* Build DSN connection string for DB driver instantiate process
*
- * @param string Group name
+ * @param string Group name
* @return string DSN Connection string
*/
public function set_dsn($group = 'default')
@@ -31,6 +41,12 @@ class Mock_Database_DB {
throw new InvalidArgumentException('Group '.$group.' not exists');
}
+ self::$dbdriver = $this->config[$group]['dbdriver'];
+ if (isset($this->config[$group]['subdriver']))
+ {
+ self::$subdriver = $this->config[$group]['subdriver'];
+ }
+
$params = array(
'dbprefix' => '',
'pconnect' => FALSE,
@@ -45,19 +61,18 @@ class Mock_Database_DB {
);
$config = array_merge($this->config[$group], $params);
+ $dsnstring = empty($config['dsn']) ? FALSE : $config['dsn'];
+ $subdriver = empty($config['subdriver']) ? FALSE: $config['subdriver'];
+ $failover = empty($config['failover']) ? FALSE : $config['failover'];
- if ( ! empty($config['dsn']))
- {
- $dsn = $config['dsn'];
- }
- else
- {
- $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password']
- .'@'.$config['hostname'].'/'.$config['database'];
-
- }
+ $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password']
+ .'@'.$config['hostname'].'/'.$config['database'];
+ // Build the parameter
$other_params = array_slice($config, 6);
+ if ($dsnstring) $other_params['dsn'] = $dsnstring;
+ if ($subdriver) $other_params['subdriver'] = $subdriver;
+ if ($failover) $other_params['failover'] = $failover;
return $dsn.'?'.http_build_query($other_params);
}
@@ -66,28 +81,52 @@ class Mock_Database_DB {
* Return a database config array
*
* @see ./config
- * @param string Driver based configuration
- * @return array
+ * @param string Driver based configuration
+ * @return array
*/
public static function config($driver)
{
$dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR;
-
return include($dir.'config'.DIRECTORY_SEPARATOR.$driver.'.php');
}
/**
* Main DB method wrapper
*
- * @param string Group or DSN string
- * @param bool
- * @return object
+ * @param string Group or DSN string
+ * @param bool
+ * @return object
*/
public static function DB($group, $query_builder = FALSE)
{
- include_once(BASEPATH.'database/DB.php');
+ // Create dummy driver and builder files to "load" - the mocks have
+ // already triggered autoloading of the real files
+ $case = CI_TestCase::instance();
+ $driver = self::$dbdriver;
+ $subdriver = self::$subdriver;
+ $case->ci_vfs_create(array(
+ 'DB_driver.php' => '',
+ 'DB_forge.php' => '',
+ 'DB_query_builder.php' => ''
+ ), '', $case->ci_base_root, 'database');
+ if (file_exists(SYSTEM_PATH.'database/drivers/'.$driver.'/'.$driver.'_driver.php'))
+ {
+ $case->ci_vfs_create(array(
+ $driver.'_driver.php' => '',
+ $driver.'_forge.php' => ''
+ ), '', $case->ci_base_root, 'database/drivers/'.$driver);
+ }
+ if ($subdriver)
+ {
+ $case->ci_vfs_create(array(
+ $driver.'_'.$subdriver.'_driver.php' => '',
+ $driver.'_'.$subdriver.'_forge.php' => ''
+ ), '', $case->ci_base_root, 'database/drivers/'.$driver.'/subdrivers');
+ }
- try
+ include_once(SYSTEM_PATH.'database/DB.php');
+
+ try
{
$db = DB($group, $query_builder);
}
@@ -98,4 +137,5 @@ class Mock_Database_DB {
return $db;
}
+
} \ No newline at end of file
diff --git a/tests/mocks/database/db/driver.php b/tests/mocks/database/db/driver.php
new file mode 100644
index 000000000..2cf54b97b
--- /dev/null
+++ b/tests/mocks/database/db/driver.php
@@ -0,0 +1,40 @@
+<?php
+
+class Mock_Database_DB_Driver extends CI_DB_driver {
+
+ /**
+ * @var object The actual Driver
+ */
+ protected $ci_db_driver;
+
+ /**
+ * Instantiate the database driver
+ *
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($driver_class, $config = array())
+ {
+ if (is_string($driver_class))
+ {
+ $this->ci_db_driver = new $driver_class($config);
+ }
+ }
+
+ /**
+ * Overloading method, emulate the actual driver method (multiple inheritance workaround)
+ */
+ public function __call($method, $arguments)
+ {
+ if ( ! is_callable(array($this->ci_db_driver, $method)))
+ {
+ throw new BadMethodCallException($method. ' not exists or not implemented');
+ }
+
+ return call_user_func_array(array($this->ci_db_driver, $method), $arguments);
+ }
+
+}
+
+class CI_DB extends Mock_Database_DB_QueryBuilder {} \ No newline at end of file
diff --git a/tests/mocks/database/db/querybuilder.php b/tests/mocks/database/db/querybuilder.php
new file mode 100644
index 000000000..3f2252622
--- /dev/null
+++ b/tests/mocks/database/db/querybuilder.php
@@ -0,0 +1,3 @@
+<?php
+
+class Mock_Database_DB_QueryBuilder extends CI_DB_query_builder {} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/mysql.php b/tests/mocks/database/drivers/mysql.php
new file mode 100644
index 000000000..e0c1fb06c
--- /dev/null
+++ b/tests/mocks/database/drivers/mysql.php
@@ -0,0 +1,17 @@
+<?php
+
+class Mock_Database_Drivers_Mysql extends Mock_Database_DB_Driver {
+
+ /**
+ * Instantiate the database driver
+ *
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($config = array())
+ {
+ parent::__construct('CI_DB_mysql_driver', $config);
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/mysqli.php b/tests/mocks/database/drivers/mysqli.php
new file mode 100644
index 000000000..73c35b609
--- /dev/null
+++ b/tests/mocks/database/drivers/mysqli.php
@@ -0,0 +1,17 @@
+<?php
+
+class Mock_Database_Drivers_Mysqli extends Mock_Database_DB_Driver {
+
+ /**
+ * Instantiate the database driver
+ *
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($config = array())
+ {
+ parent::__construct('CI_DB_mysqli_driver', $config);
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/pdo.php b/tests/mocks/database/drivers/pdo.php
new file mode 100644
index 000000000..17768eed7
--- /dev/null
+++ b/tests/mocks/database/drivers/pdo.php
@@ -0,0 +1,16 @@
+<?php
+
+class Mock_Database_Drivers_PDO extends Mock_Database_DB_Driver {
+
+ /**
+ * Instantiate the database driver
+ *
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($config = array())
+ {
+ parent::__construct('CI_DB_pdo_driver', $config);
+ }
+} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/postgre.php b/tests/mocks/database/drivers/postgre.php
new file mode 100644
index 000000000..5a45115fa
--- /dev/null
+++ b/tests/mocks/database/drivers/postgre.php
@@ -0,0 +1,17 @@
+<?php
+
+class Mock_Database_Drivers_Postgre extends Mock_Database_DB_Driver {
+
+ /**
+ * Instantiate the database driver
+ *
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($config = array())
+ {
+ parent::__construct('CI_DB_postgre_driver', $config);
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/sqlite.php b/tests/mocks/database/drivers/sqlite.php
new file mode 100644
index 000000000..512467520
--- /dev/null
+++ b/tests/mocks/database/drivers/sqlite.php
@@ -0,0 +1,17 @@
+<?php
+
+class Mock_Database_Drivers_Sqlite extends Mock_Database_DB_Driver {
+
+ /**
+ * Instantiate the database driver
+ *
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($config = array())
+ {
+ parent::__construct('CI_DB_sqlite3_driver', $config);
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/database/schema/.gitkeep b/tests/mocks/database/schema/.gitkeep
deleted file mode 100644
index e69de29bb..000000000
--- a/tests/mocks/database/schema/.gitkeep
+++ /dev/null
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
new file mode 100644
index 000000000..e5c536090
--- /dev/null
+++ b/tests/mocks/database/schema/skeleton.php
@@ -0,0 +1,148 @@
+<?php
+
+class Mock_Database_Schema_Skeleton {
+
+ /**
+ * @var object Database Holder
+ */
+ public static $db;
+
+ /**
+ * @var object Forge Holder
+ */
+ public static $forge;
+
+ /**
+ * @var object Driver Holder
+ */
+ public static $driver;
+
+ /**
+ * Initialize both database and forge components
+ */
+ public static function init($driver)
+ {
+ if (empty(static::$db) && empty(static::$forge))
+ {
+ $config = Mock_Database_DB::config($driver);
+ $connection = new Mock_Database_DB($config);
+ $db = Mock_Database_DB::DB($connection->set_dsn($driver), TRUE);
+
+ CI_TestCase::instance()->ci_instance_var('db', $db);
+
+ $loader = new CI_Loader();
+ $loader->dbforge();
+ $forge = CI_TestCase::instance()->ci_instance_var('dbforge');
+
+ static::$db = $db;
+ static::$forge = $forge;
+ static::$driver = $driver;
+ }
+
+ return static::$db;
+ }
+
+ /**
+ * Create the dummy tables
+ *
+ * @return void
+ */
+ public static function create_tables()
+ {
+ // User Table
+ static::$forge->add_field(array(
+ 'id' => array(
+ 'type' => 'INTEGER',
+ 'constraint' => 3
+ ),
+ 'name' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40
+ ),
+ 'email' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 100
+ ),
+ 'country' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40
+ )
+ ));
+ static::$forge->add_key('id', TRUE);
+ static::$forge->create_table('user', TRUE);
+
+ // Job Table
+ static::$forge->add_field(array(
+ 'id' => array(
+ 'type' => 'INTEGER',
+ 'constraint' => 3
+ ),
+ 'name' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40
+ ),
+ 'description' => array(
+ 'type' => 'TEXT'
+ )
+ ));
+ static::$forge->add_key('id', TRUE);
+ static::$forge->create_table('job', TRUE);
+
+ // Misc Table
+ static::$forge->add_field(array(
+ 'id' => array(
+ 'type' => 'INTEGER',
+ 'constraint' => 3
+ ),
+ 'key' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40
+ ),
+ 'value' => array(
+ 'type' => 'TEXT'
+ )
+ ));
+ static::$forge->add_key('id', TRUE);
+ static::$forge->create_table('misc', TRUE);
+ }
+
+ /**
+ * Create the dummy datas
+ *
+ * @return void
+ */
+ public static function create_data()
+ {
+ // Job Data
+ $data = array(
+ 'user' => array(
+ array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com', 'country' => 'US'),
+ array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com', 'country' => 'Iran'),
+ array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com', 'country' => 'US'),
+ array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com', 'country' => 'UK')
+ ),
+ 'job' => array(
+ array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'),
+ array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'),
+ array('id' => 3, 'name' => 'Accountant', 'description' => 'Boring job, but you will get free snack at lunch'),
+ array('id' => 4, 'name' => 'Musician', 'description' => 'Only Coldplay can actually called Musician')
+ ),
+ 'misc' => array(
+ array('id' => 1, 'key' => '\\xxxfoo456', 'value' => 'Entry with \\xxx'),
+ array('id' => 2, 'key' => '\\%foo456', 'value' => 'Entry with \\%'),
+ array('id' => 3, 'key' => 'spaces and tabs', 'value' => ' One two three tab')
+ )
+ );
+
+ foreach ($data as $table => $dummy_data)
+ {
+ static::$db->truncate($table);
+
+ foreach ($dummy_data as $single_dummy_data)
+ {
+ static::$db->insert($table, $single_dummy_data);
+ }
+ }
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/libraries/driver.php b/tests/mocks/libraries/driver.php
new file mode 100644
index 000000000..633194345
--- /dev/null
+++ b/tests/mocks/libraries/driver.php
@@ -0,0 +1,27 @@
+<?php
+
+/**
+ * Mock library to subclass Driver for testing
+ */
+class Mock_Libraries_Driver extends CI_Driver_Library {
+ /**
+ * Set valid drivers list
+ */
+ public function driver_list($drivers = NULL)
+ {
+ if (empty($drivers))
+ {
+ return $this->valid_drivers;
+ }
+
+ $this->valid_drivers = (array) $drivers;
+ }
+
+ /**
+ * Get library name
+ */
+ public function get_name()
+ {
+ return $this->lib_name;
+ }
+} \ 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..562033bbf
--- /dev/null
+++ b/tests/mocks/libraries/session.php
@@ -0,0 +1,36 @@
+<?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) OR $expire <= time())
+ {
+ unset($_COOKIE[$name]);
+ }
+ else
+ {
+ $_COOKIE[$name] = $value;
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/mocks/libraries/table.php b/tests/mocks/libraries/table.php
index 1a6ff8d35..87c278bce 100644
--- a/tests/mocks/libraries/table.php
+++ b/tests/mocks/libraries/table.php
@@ -1,8 +1,8 @@
<?php
class Mock_Libraries_Table extends CI_Table {
-
- // Overide inaccesible private or protected method
+
+ // Overide inaccesible protected method
public function __call($method, $params)
{
if (is_callable(array($this, '_'.$method)))
@@ -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
diff --git a/tests/mocks/uploads/ci_logo.gif b/tests/mocks/uploads/ci_logo.gif
new file mode 100644
index 000000000..073ec14b4
--- /dev/null
+++ b/tests/mocks/uploads/ci_logo.gif
Binary files differ