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 ++++++++++++++++++++++++++++++++++ tests/mocks/core/loader.php | 9 +++++ 2 files changed, 79 insertions(+) (limited to 'tests') 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 diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php index e28650dba..c0e02139e 100644 --- a/tests/mocks/core/loader.php +++ b/tests/mocks/core/loader.php @@ -30,6 +30,15 @@ class Mock_Core_Loader extends CI_Loader { $this->_ci_helper_paths = array($this->app_path, $this->base_path); $this->_ci_model_paths = array($this->app_path); $this->_ci_view_paths = array($this->app_path.'views/' => TRUE); + $this->_ci_autoloader_path = $this->app_path; + } + + /** + * Give public access to _ci_autoloader for testing + */ + public function autoload() + { + $this->_ci_autoloader(); } } -- cgit v1.2.3-24-g4f1b