models_dir = vfsStream::newDirectory('models')->at(vfsStreamWrapper::getRoot()); $this->libs_dir = vfsStream::newDirectory('libraries')->at(vfsStreamWrapper::getRoot()); $this->helpers_dir = vfsStream::newDirectory('helpers')->at(vfsStreamWrapper::getRoot()); $this->views_dir = vfsStream::newDirectory('views')->at(vfsStreamWrapper::getRoot()); $this->_ci_ob_level = ob_get_level(); $this->_ci_library_paths = array(vfsStream::url('application').'/', BASEPATH); $this->_ci_helper_paths = array(vfsStream::url('application').'/', BASEPATH); $this->_ci_model_paths = array(vfsStream::url('application').'/'); $this->_ci_view_paths = array(vfsStream::url('application').'/views/' => TRUE); } } class Loader_test extends CI_TestCase { private $ci_obj; public function setUp() { // Instantiate a new loader $this->load = new Extended_Loader(); // mock up a ci instance $this->ci_obj = new StdClass; // Fix get_instance() $this->ci_instance($this->ci_obj); } // -------------------------------------------------------------------- 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); // Test loading as an array. $this->assertNull($this->load->library(array('table'))); $this->assertTrue(class_exists('CI_Table'), 'Table class exists'); $this->assertAttributeInstanceOf('CI_Table', 'table', $this->ci_obj); // Test no lib given $this->assertEquals(FALSE, $this->load->library()); // Test a string given to params $this->assertEquals(NULL, $this->load->library('table', ' ')); } // -------------------------------------------------------------------- public function testNonExistentModel() { $this->setExpectedException( 'Exception', 'CI Error: Unable to locate the model you have specified: ci_test_nonexistent_mode.php' ); $this->load->model('ci_test_nonexistent_mode.php'); } // -------------------------------------------------------------------- public function testModels() { $this->ci_set_core_class('model', 'CI_Model'); $content = 'withContent($content) ->at($this->load->models_dir); $this->assertNull($this->load->model('unit_test_model')); // Was the model class instantiated. $this->assertTrue(class_exists('Unit_test_model')); // Test no model given $this->assertNull($this->load->model('')); } // -------------------------------------------------------------------- // public function testDatabase() // { // $this->assertEquals(NULL, $this->load->database()); // $this->assertEquals(NULL, $this->load->dbutil()); // } // -------------------------------------------------------------------- public function testNonExistentView() { $this->setExpectedException( 'Exception', 'CI Error: Unable to load the requested file: ci_test_nonexistent_view.php' ); $this->load->view('ci_test_nonexistent_view', array('foo' => 'bar')); } // -------------------------------------------------------------------- public function testFile() { // I'm not entirely sure this is the proper way to handle this. // $this->load->file('foo'); } // -------------------------------------------------------------------- public function testVars() { $vars = array( 'foo' => 'bar' ); $this->assertEquals(NULL, $this->load->vars($vars)); $this->assertEquals(NULL, $this->load->vars('foo', 'bar')); } // -------------------------------------------------------------------- public function testHelper() { $this->assertEquals(NULL, $this->load->helper('array')); $this->setExpectedException( 'Exception', 'CI Error: Unable to load the requested file: helpers/bad_helper.php' ); $this->load->helper('bad'); } // -------------------------------------------------------------------- public function testLoadingMultipleHelpers() { $this->assertEquals(NULL, $this->load->helpers(array('file', 'array', 'string'))); } // -------------------------------------------------------------------- // public function testLanguage() // { // $this->assertEquals(NULL, $this->load->language('test')); // } // -------------------------------------------------------------------- // public function testLoadConfig() // { // $this->assertEquals(NULL, $this->load->config('config', FALSE, TRUE)); // } }