From 60d100f0fde3fba4fa4015f44f490b7ecac16138 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Wed, 29 Aug 2012 12:58:26 -0400 Subject: Added autoloader unit test with minor supporting change in Loader Signed-off-by: dchill42 --- tests/codeigniter/core/Loader_test.php | 70 ++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'tests/codeigniter/core') 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', '_create_content('libraries', $lib, ' array($drv.'.php' => '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, ' array($path), + 'helper' => array($helper), + 'libraries' => array($lib), + 'drivers' => array($drv), + 'model' => array($model), + 'config' => array() + ); + $this->_create_content('config', 'autoload', '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 -- cgit v1.2.3-24-g4f1b