summaryrefslogtreecommitdiffstats
path: root/tests/lib/ci_testcase.php
diff options
context:
space:
mode:
authorPascal Kriete <pascal.kriete@ellislab.com>2011-04-21 03:44:54 +0200
committerPascal Kriete <pascal.kriete@ellislab.com>2011-04-21 03:44:54 +0200
commit69c97a71476e4eaa6c629022fcd4ec7f36d4ec0d (patch)
tree5cba214cb636df83b41a3aa7f29f9b191c3ab70b /tests/lib/ci_testcase.php
parentba2430b5778b5b2414b94b818354fa1ff7cfd0db (diff)
Adding early bootstrap ideas for core test suite
Diffstat (limited to 'tests/lib/ci_testcase.php')
-rw-r--r--tests/lib/ci_testcase.php110
1 files changed, 110 insertions, 0 deletions
diff --git a/tests/lib/ci_testcase.php b/tests/lib/ci_testcase.php
new file mode 100644
index 000000000..a8a272db2
--- /dev/null
+++ b/tests/lib/ci_testcase.php
@@ -0,0 +1,110 @@
+<?php
+
+
+// Need a way to change dependencies (core libs and laoded libs)
+// Need a way to set the CI class
+
+class CodeIgniterTestCase extends PHPUnit_Framework_TestCase {
+
+ public $ci_instance;
+ public static $test_instance;
+ public static $global_map = array(
+ 'benchmark' => 'bm',
+ 'config' => 'cfg',
+ 'hooks' => 'ext',
+ 'utf8' => 'uni',
+ 'router' => 'rtr',
+ 'output' => 'out',
+ 'security' => 'sec',
+ 'input' => 'in',
+ 'lang' => 'lang',
+
+ // @todo the loader is an edge case
+ 'loader' => 'load'
+ );
+
+ function __construct()
+ {
+ parent::__construct();
+ }
+
+ // --------------------------------------------------------------------
+
+ // Change what get_instance returns
+ function ci_instance($obj)
+ {
+ $this->ci_instance = $obj;
+ }
+
+ // --------------------------------------------------------------------
+
+ function ci_set_instance_var($name, $obj)
+ {
+ $this->ci_instance->$name =& $obj;
+ }
+
+ // --------------------------------------------------------------------
+
+ // Set a class to a mock before it is loaded
+ function ci_library($name)
+ {
+
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Grab a core class
+ *
+ * Loads the correct core class without extensions
+ * and returns a reference to the class name in the
+ * globals array with the correct key. This way the
+ * test can modify the variable it assigns to and
+ * still maintain the global.
+ */
+ function &ci_core_class($name)
+ {
+ $name = strtolower($name);
+
+ if (isset(self::$global_map[$name]))
+ {
+ $class_name = ucfirst($name);
+ $global_name = self::$global_map[$name];
+ }
+ elseif (in_array($name, self::$global_map))
+ {
+ $class_name = ucfirst(array_search($name, self::$global_map));
+ $global_name = $name;
+ }
+ else
+ {
+ throw new Exception('Not a valid core class.');
+ }
+
+ if ( ! class_exists('CI_'.$class_name))
+ {
+ require_once BASEPATH.'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)
+ {
+ $orig =& $this->ci_core_class($name);
+ $orig = $obj;
+ }
+
+ // --------------------------------------------------------------------
+
+ static function ci_config($item)
+ {
+ return '';
+ }
+}
+
+// EOF \ No newline at end of file