From 6858fb92133afa127eff6f11dd29abf554e1b2d1 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 12:27:23 -0500 Subject: Adding mock testing of libraries in the application directory --- tests/codeigniter/core/Loader_test.php | 58 +++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 12 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 782751cd7..1e32c7e0a 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -53,15 +53,7 @@ class Loader_test extends CI_TestCase { public function testLibrary() { - // Mock up a config object until we - // figure out how to test the library configs - $config = $this->getMock('CI_Config', NULL, array(), '', FALSE); - $config->expects($this->any()) - ->method('load') - ->will($this->returnValue(TRUE)); - - // Add the mock to our stdClass - $this->ci_instance_var('config', $config); + $this->_setup_config_mock(); // Test loading as an array. $this->assertNull($this->load->library(array('table'))); @@ -73,22 +65,58 @@ class Loader_test extends CI_TestCase { // Test a string given to params $this->assertEquals(NULL, $this->load->library('table', ' ')); - } + } + + // -------------------------------------------------------------------- + + public function testLoadLibraryInApplicationDir() + { + $this->_setup_config_mock(); + + $content = 'withContent($content) + ->at($this->load->libs_dir); + + $this->assertNull($this->load->library('super_test_library')); + + // Was the model class instantiated. + $this->assertTrue(class_exists('Super_test_library')); + } // -------------------------------------------------------------------- + private function _setup_config_mock() + { + // Mock up a config object until we + // figure out how to test the library configs + $config = $this->getMock('CI_Config', NULL, array(), '', FALSE); + $config->expects($this->any()) + ->method('load') + ->will($this->returnValue(TRUE)); + + // Add the mock to our stdClass + $this->ci_instance_var('config', $config); + } + + // -------------------------------------------------------------------- + + public function testNonExistentModel() { $this->setExpectedException( 'Exception', - 'CI Error: Unable to locate the model you have specified: ci_test_nonexistent_mode.php' + 'CI Error: Unable to locate the model you have specified: ci_test_nonexistent_model.php' ); - $this->load->model('ci_test_nonexistent_mode.php'); + $this->load->model('ci_test_nonexistent_model.php'); } // -------------------------------------------------------------------- + /** + * @coverts CI_Loader::model + */ public function testModels() { $this->ci_set_core_class('model', 'CI_Model'); @@ -117,6 +145,9 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- + /** + * @coverts CI_Loader::view + */ public function testLoadView() { $this->ci_set_core_class('output', 'CI_Output'); @@ -134,6 +165,9 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- + /** + * @coverts CI_Loader::view + */ public function testNonExistentView() { $this->setExpectedException( -- cgit v1.2.3-24-g4f1b