summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/core
diff options
context:
space:
mode:
authordchill42 <dchill42@gmail.com>2012-08-29 18:58:26 +0200
committerdchill42 <dchill42@gmail.com>2012-08-29 18:58:26 +0200
commit60d100f0fde3fba4fa4015f44f490b7ecac16138 (patch)
tree4568707c49c4ede4c195fca0db798918f2baa073 /tests/codeigniter/core
parent9a949fab0c8428233f0de5b199bf955e61fb0e0a (diff)
Added autoloader unit test with minor supporting change in Loader
Signed-off-by: dchill42 <dchill42@gmail.com>
Diffstat (limited to 'tests/codeigniter/core')
-rw-r--r--tests/codeigniter/core/Loader_test.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php
index bb8bfd733..db79e6a8b 100644
--- a/tests/codeigniter/core/Loader_test.php
+++ b/tests/codeigniter/core/Loader_test.php
@@ -368,6 +368,76 @@ class Loader_test extends CI_TestCase {
// --------------------------------------------------------------------
+ /**
+ * @covers CI_Loader::_ci_autoloader
+ */
+ public function test_autoloader()
+ {
+ $this->_setup_config_mock();
+
+ // Create helper directory in app path with test helper
+ $helper = 'autohelp';
+ $hlp_func = '_autohelp_test_func';
+ $this->_create_content('helpers', $helper.'_helper', '<?php function '.$hlp_func.'() { return true; } ');
+
+ // Create libraries directory in base path with test library
+ $lib = 'autolib';
+ $lib_class = 'CI_'.ucfirst($lib);
+ $this->_create_content('libraries', $lib, '<?php class '.$lib_class.' { } ', NULL, TRUE);
+
+ // Create libraries subdirectory with test driver
+ // Since libraries/ now exists, we have to look it up and
+ // add the subdir directly instead of using _create_content
+ $drv = 'autodrv';
+ $subdir = ucfirst($drv);
+ $drv_class = 'CI_'.$subdir;
+ $tree = array(
+ $subdir => array($drv.'.php' => '<?php class '.$drv_class.' { } ')
+ );
+ vfsStream::create($tree, $this->load->base_root->getChild('libraries'));
+
+ // Create package directory in app path with model
+ $dir = 'testdir';
+ $path = $this->load->app_path.$dir.'/';
+ $model = 'automod';
+ $mod_class = ucfirst($model);
+ $this->_create_content($dir, $model, '<?php class '.$mod_class.' { } ', 'models');
+
+ // Create autoloader config
+ $cfg = array(
+ 'packages' => array($path),
+ 'helper' => array($helper),
+ 'libraries' => array($lib),
+ 'drivers' => array($drv),
+ 'model' => array($model),
+ 'config' => array()
+ );
+ $this->_create_content('config', 'autoload', '<?php $autoload = '.var_export($cfg, TRUE).';');
+
+ // Run autoloader
+ $this->load->autoload();
+
+ // Verify path
+ $this->assertContains($path, $this->load->get_package_paths());
+
+ // Verify helper
+ $this->assertTrue(function_exists($hlp_func), $hlp_func.' does not exist');
+
+ // Verify library
+ $this->assertTrue(class_exists($lib_class), $lib_class.' does not exist');
+ $this->assertAttributeInstanceOf($lib_class, $lib, $this->ci_obj);
+
+ // Verify driver
+ $this->assertTrue(class_exists($drv_class), $drv_class.' does not exist');
+ $this->assertAttributeInstanceOf($drv_class, $drv, $this->ci_obj);
+
+ // Verify model
+ $this->assertTrue(class_exists($mod_class), $mod_class.' does not exist');
+ $this->assertAttributeInstanceOf($mod_class, $model, $this->ci_obj);
+ }
+
+ // --------------------------------------------------------------------
+
private function _setup_config_mock()
{
// Mock up a config object so config() has something to call