From 8da69039f6d855eb4f88de73702155e6899d2d23 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 11:28:27 -0500 Subject: Working on tests in the loader. Have generic model mocking working with vfsStream. --- tests/codeigniter/core/Loader_test.php | 134 ++++++++++++++++++++++----------- 1 file changed, 90 insertions(+), 44 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index c7085c439..2aa1b8cb9 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -1,5 +1,38 @@ 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; @@ -7,8 +40,7 @@ class Loader_test extends CI_TestCase { public function setUp() { // Instantiate a new loader - $cls = $this->ci_core_class('load'); - $this->_loader = new $cls; + $this->load = new Extended_Loader(); // mock up a ci instance $this->ci_obj = new StdClass; @@ -32,53 +64,67 @@ class Loader_test extends CI_TestCase { $this->ci_instance_var('config', $config); // Test loading as an array. - $this->assertEquals(NULL, $this->_loader->library(array('table'))); + $this->assertEquals(NULL, $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->_loader->library()); + $this->assertEquals(FALSE, $this->load->library()); // Test a string given to params - $this->assertEquals(NULL, $this->_loader->library('table', ' ')); + $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() { - // Test loading as an array. - $this->assertEquals(NULL, $this->_loader->model(array('foobar'))); + $this->ci_set_core_class('model', 'CI_Model'); + + $content = 'withContent($content) + ->at($this->load->models_dir); + + $this->assertNull($this->load->model('unit_test_model')); // Test no model given - $this->assertEquals(FALSE, $this->_loader->model('')); + $this->assertEquals(FALSE, $this->load->model('')); // Test a string given to params - $this->assertEquals(NULL, $this->_loader->model('foobar', ' ')); + // $this->assertEquals(NULL, $this->load->model('foobar', ' ')); } // -------------------------------------------------------------------- - public function testDatabase() - { - $this->assertEquals(NULL, $this->_loader->database()); - $this->assertEquals(NULL, $this->_loader->dbutil()); - } + // public function testDatabase() + // { + // $this->assertEquals(NULL, $this->load->database()); + // $this->assertEquals(NULL, $this->load->dbutil()); + // } // -------------------------------------------------------------------- - public function testView() + public function testNonExistentView() { - // I'm not entirely sure this is the proper way to handle this. - // So, let's revist it, m'kay? - try - { - $this->_loader->view('foo'); - } - catch (Exception $expected) - { - return; - } + $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')); } // -------------------------------------------------------------------- @@ -86,10 +132,9 @@ class Loader_test extends CI_TestCase { public function testFile() { // I'm not entirely sure this is the proper way to handle this. - // So, let's revist it, m'kay? try { - $this->_loader->file('foo'); + $this->load->file('foo'); } catch (Exception $expected) { @@ -105,39 +150,40 @@ class Loader_test extends CI_TestCase { 'foo' => 'bar' ); - $this->assertEquals(NULL, $this->_loader->vars($vars)); - $this->assertEquals(NULL, $this->_loader->vars('foo', 'bar')); + $this->assertEquals(NULL, $this->load->vars($vars)); + $this->assertEquals(NULL, $this->load->vars('foo', 'bar')); } // -------------------------------------------------------------------- - public function testHelper() - { - $this->assertEquals(NULL, $this->_loader->helper('array')); - $this->assertEquals(NULL, $this->_loader->helper('bad')); - } + // public function testHelper() + // { + // $this->assertEquals(NULL, $this->load->helper('array')); + // $this->assertEquals(NULL, $this->load->helper('bad')); + // } // -------------------------------------------------------------------- public function testHelpers() { - $this->assertEquals(NULL, $this->_loader->helpers(array('file', 'array', 'string'))); + $this->assertEquals(NULL, $this->load->helpers(array('file', 'array', 'string'))); } // -------------------------------------------------------------------- // public function testLanguage() // { - // $this->assertEquals(NULL, $this->_loader->language('test')); + // $this->assertEquals(NULL, $this->load->language('test')); // } // -------------------------------------------------------------------- - public function testLoadConfig() - { - $this->assertEquals(NULL, $this->_loader->config('config', FALSE, TRUE)); - } - - - -} \ No newline at end of file + // public function testLoadConfig() + // { + // $this->assertEquals(NULL, $this->load->config('config', FALSE, TRUE)); + // } +} + + + + -- cgit v1.2.3-24-g4f1b