summaryrefslogtreecommitdiffstats
path: root/tests/mocks
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mocks')
-rw-r--r--tests/mocks/autoloader.php46
-rw-r--r--tests/mocks/ci_testcase.php203
-rw-r--r--tests/mocks/ci_testconfig.php20
-rw-r--r--tests/mocks/core/common.php30
-rw-r--r--tests/mocks/core/input.php10
-rw-r--r--tests/mocks/core/loader.php31
-rw-r--r--tests/mocks/database/config/mysqli.php34
-rw-r--r--tests/mocks/database/config/pdo/mysql.php10
-rw-r--r--tests/mocks/database/config/pdo/pgsql.php6
-rw-r--r--tests/mocks/database/config/pdo/sqlite.php6
-rw-r--r--tests/mocks/database/db.php53
-rw-r--r--tests/mocks/database/db/driver.php1
-rw-r--r--tests/mocks/database/drivers/mysqli.php17
-rw-r--r--tests/mocks/database/schema/skeleton.php11
-rw-r--r--tests/mocks/libraries/driver.php27
-rw-r--r--tests/mocks/libraries/session.php36
-rw-r--r--tests/mocks/libraries/upload.php3
-rw-r--r--tests/mocks/uploads/ci_logo.gifbin0 -> 3270 bytes
18 files changed, 465 insertions, 79 deletions
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
index be1c2220c..3d216da1f 100644
--- a/tests/mocks/autoloader.php
+++ b/tests/mocks/autoloader.php
@@ -16,7 +16,7 @@ function autoload($class)
$ci_core = array(
'Benchmark', 'Config', 'Controller',
'Exceptions', 'Hooks', 'Input',
- 'Lang', 'Loader', 'Model',
+ 'Lang', 'Loader', 'Log', 'Model',
'Output', 'Router', 'Security',
'URI', 'Utf8',
);
@@ -25,42 +25,58 @@ function autoload($class)
'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 = BASEPATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
+ $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 = BASEPATH.'database'.DIRECTORY_SEPARATOR;
+ $dir = SYSTEM_PATH.'database'.DIRECTORY_SEPARATOR;
$file = $dir.str_replace(array('CI_DB','active_record'), array('DB', 'active_rec'), $subclass).'.php';
}
else
@@ -69,7 +85,7 @@ function autoload($class)
}
}
- $file = (isset($file)) ? $file : $dir.$class.'.php';
+ $file = isset($file) ? $file : $dir.$class.'.php';
if ( ! file_exists($file))
{
diff --git a/tests/mocks/ci_testcase.php b/tests/mocks/ci_testcase.php
index eda9e1b60..f16492945 100644
--- a/tests/mocks/ci_testcase.php
+++ b/tests/mocks/ci_testcase.php
@@ -2,7 +2,9 @@
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;
@@ -25,13 +27,19 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
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();
@@ -57,15 +65,27 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
// --------------------------------------------------------------------
- public 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;
}
}
@@ -73,7 +93,7 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
public function ci_get_config()
{
- return $this->ci_config;
+ return isset($this->ci_instance->config) ? $this->ci_instance->config->config : array();
}
// --------------------------------------------------------------------
@@ -132,7 +152,7 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
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;
@@ -148,6 +168,165 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
$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
// --------------------------------------------------------------------
@@ -171,7 +350,15 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
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;
}
// --------------------------------------------------------------------
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/common.php b/tests/mocks/core/common.php
index a655ee1db..24d645ae3 100644
--- a/tests/mocks/core/common.php
+++ b/tests/mocks/core/common.php
@@ -39,6 +39,30 @@ if ( ! function_exists('config_item'))
}
}
+if ( ! function_exists('get_mimes'))
+{
+ /**
+ * Returns the MIME types array from config/mimes.php
+ *
+ * @return array
+ */
+ function &get_mimes()
+ {
+ static $_mimes = array();
+
+ if (empty($_mimes))
+ {
+ $path = realpath(PROJECT_BASE.'application/config/mimes.php');
+ if (is_file($path))
+ {
+ $_mimes = include($path);
+ }
+ }
+
+ return $_mimes;
+ }
+}
+
// --------------------------------------------------------------------
if ( ! function_exists('load_class'))
@@ -124,7 +148,6 @@ if ( ! function_exists('_exception_handler'))
}
}
-
// We assume a few things about our environment ...
// --------------------------------------------------------------------
@@ -146,9 +169,10 @@ if ( ! function_exists('is_really_writable'))
if ( ! function_exists('is_loaded'))
{
- function is_loaded()
+ function &is_loaded()
{
- throw new Exception('Bad Isolation: mock up environment');
+ $loaded = array();
+ return $loaded;
}
}
diff --git a/tests/mocks/core/input.php b/tests/mocks/core/input.php
index 2a4aa4997..0d1873849 100644
--- a/tests/mocks/core/input.php
+++ b/tests/mocks/core/input.php
@@ -28,4 +28,14 @@ class Mock_Core_Input extends CI_Input {
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 53d88d55b..000000000
--- a/tests/mocks/core/loader.php
+++ /dev/null
@@ -1,31 +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/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
index fefe0d624..96608f787 100644
--- a/tests/mocks/database/config/pdo/mysql.php
+++ b/tests/mocks/database/config/pdo/mysql.php
@@ -4,13 +4,13 @@ return array(
// Typical Database configuration
'pdo/mysql' => array(
- 'dsn' => '',
+ 'dsn' => 'mysql:host=localhost;dbname=ci_test',
'hostname' => 'localhost',
'username' => 'travis',
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'pdo',
- 'pdodriver' => 'mysql'
+ 'subdriver' => 'mysql'
),
// Database configuration with failover
@@ -21,16 +21,16 @@ return array(
'password' => 'wrong password',
'database' => 'not_ci_test',
'dbdriver' => 'pdo',
- 'pdodriver' => 'mysql',
+ 'subdriver' => 'mysql',
'failover' => array(
array(
- 'dsn' => '',
+ 'dsn' => 'mysql:host=localhost;dbname=ci_test',
'hostname' => 'localhost',
'username' => 'travis',
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'pdo',
- 'pdodriver' => 'mysql'
+ 'subdriver' => 'mysql'
)
)
)
diff --git a/tests/mocks/database/config/pdo/pgsql.php b/tests/mocks/database/config/pdo/pgsql.php
index ddd638c8a..e55e3ea77 100644
--- a/tests/mocks/database/config/pdo/pgsql.php
+++ b/tests/mocks/database/config/pdo/pgsql.php
@@ -10,7 +10,7 @@ return array(
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'pdo',
- 'pdodriver' => 'pgsql'
+ 'subdriver' => 'pgsql'
),
// Database configuration with failover
@@ -21,7 +21,7 @@ return array(
'password' => 'wrong password',
'database' => 'not_ci_test',
'dbdriver' => 'pdo',
- 'pdodriver' => 'pgsql',
+ 'subdriver' => 'pgsql',
'failover' => array(
array(
'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;',
@@ -30,7 +30,7 @@ return array(
'password' => '',
'database' => 'ci_test',
'dbdriver' => 'pdo',
- 'pdodriver' => 'pgsql'
+ 'subdriver' => 'pgsql'
)
)
)
diff --git a/tests/mocks/database/config/pdo/sqlite.php b/tests/mocks/database/config/pdo/sqlite.php
index 36461843d..1bf56b3ac 100644
--- a/tests/mocks/database/config/pdo/sqlite.php
+++ b/tests/mocks/database/config/pdo/sqlite.php
@@ -10,7 +10,7 @@ return array(
'password' => 'sqlite',
'database' => 'sqlite',
'dbdriver' => 'pdo',
- 'pdodriver' => 'sqlite'
+ 'subdriver' => 'sqlite'
),
// Database configuration with failover
@@ -21,7 +21,7 @@ return array(
'password' => 'sqlite',
'database' => 'sqlite',
'dbdriver' => 'pdo',
- 'pdodriver' => 'sqlite',
+ 'subdriver' => 'sqlite',
'failover' => array(
array(
'dsn' => 'sqlite:/'.realpath(__DIR__.'/../..').'/ci_test.sqlite',
@@ -30,7 +30,7 @@ return array(
'password' => 'sqlite',
'database' => 'sqlite',
'dbdriver' => 'pdo',
- 'pdodriver' => 'sqlite'
+ 'subdriver' => 'sqlite'
)
)
)
diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php
index 30504bba6..7e0030e15 100644
--- a/tests/mocks/database/db.php
+++ b/tests/mocks/database/db.php
@@ -8,6 +8,16 @@ class Mock_Database_DB {
private $config = array();
/**
+ * @var string DB driver name
+ */
+ private static $dbdriver = '';
+
+ /**
+ * @var string DB sub-driver name
+ */
+ private static $subdriver = '';
+
+ /**
* Prepare database configuration skeleton
*
* @param array DB configuration to set
@@ -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,17 +61,17 @@ class Mock_Database_DB {
);
$config = array_merge($this->config[$group], $params);
- $dsnstring = ( ! empty($config['dsn'])) ? $config['dsn'] : FALSE;
- $pdodriver = ( ! empty($config['pdodriver'])) ? $config['pdodriver'] : FALSE;
- $failover = ( ! empty($config['failover'])) ? $config['failover'] : FALSE;
+ $dsnstring = empty($config['dsn']) ? FALSE : $config['dsn'];
+ $subdriver = empty($config['subdriver']) ? FALSE: $config['subdriver'];
+ $failover = empty($config['failover']) ? FALSE : $config['failover'];
$dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password']
- .'@'.$config['hostname'].'/'.$config['database'];
+ .'@'.$config['hostname'].'/'.$config['database'];
// Build the parameter
$other_params = array_slice($config, 6);
if ($dsnstring) $other_params['dsn'] = $dsnstring;
- if ($pdodriver) $other_params['pdodriver'] = $pdodriver;
+ if ($subdriver) $other_params['subdriver'] = $subdriver;
if ($failover) $other_params['failover'] = $failover;
return $dsn.'?'.http_build_query($other_params);
@@ -83,7 +99,32 @@ class Mock_Database_DB {
*/
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');
+ }
+
+ include_once(SYSTEM_PATH.'database/DB.php');
try
{
diff --git a/tests/mocks/database/db/driver.php b/tests/mocks/database/db/driver.php
index 65ac2c4cc..2cf54b97b 100644
--- a/tests/mocks/database/db/driver.php
+++ b/tests/mocks/database/db/driver.php
@@ -34,6 +34,7 @@ class Mock_Database_DB_Driver extends CI_DB_driver {
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/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/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
index 18e1ddd4d..e5c536090 100644
--- a/tests/mocks/database/schema/skeleton.php
+++ b/tests/mocks/database/schema/skeleton.php
@@ -30,7 +30,7 @@ class Mock_Database_Schema_Skeleton {
CI_TestCase::instance()->ci_instance_var('db', $db);
- $loader = new Mock_Core_Loader();
+ $loader = new CI_Loader();
$loader->dbforge();
$forge = CI_TestCase::instance()->ci_instance_var('dbforge');
@@ -69,7 +69,7 @@ class Mock_Database_Schema_Skeleton {
)
));
static::$forge->add_key('id', TRUE);
- static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE));
+ static::$forge->create_table('user', TRUE);
// Job Table
static::$forge->add_field(array(
@@ -86,7 +86,7 @@ class Mock_Database_Schema_Skeleton {
)
));
static::$forge->add_key('id', TRUE);
- static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE));
+ static::$forge->create_table('job', TRUE);
// Misc Table
static::$forge->add_field(array(
@@ -103,7 +103,7 @@ class Mock_Database_Schema_Skeleton {
)
));
static::$forge->add_key('id', TRUE);
- static::$forge->create_table('misc', (strpos(static::$driver, 'pgsql') === FALSE));
+ static::$forge->create_table('misc', TRUE);
}
/**
@@ -129,7 +129,8 @@ class Mock_Database_Schema_Skeleton {
),
'misc' => array(
array('id' => 1, 'key' => '\\xxxfoo456', 'value' => 'Entry with \\xxx'),
- array('id' => 2, 'key' => '\\%foo456', 'value' => 'Entry with \\%')
+ array('id' => 2, 'key' => '\\%foo456', 'value' => 'Entry with \\%'),
+ array('id' => 3, 'key' => 'spaces and tabs', 'value' => ' One two three tab')
)
);
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/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/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