From 924a75521ba8810a2afb36e4da7e04dfec8711ae Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 22 Jul 2013 14:35:02 +0300 Subject: Fix CI_Loader::model() tests --- tests/codeigniter/core/Loader_test.php | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'tests/codeigniter/core/Loader_test.php') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index ac2656e75..d7c393d61 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -181,16 +181,16 @@ class Loader_test extends CI_TestCase { $this->ci_set_core_class('model', 'CI_Model'); // Create model in VFS - $model = 'unit_test_model'; - $class = ucfirst($model); - $content = 'ci_vfs_create($model, $content, $this->ci_app_root, 'models'); // Load model $this->assertNull($this->load->model($model)); // Was the model class instantiated. - $this->assertTrue(class_exists($class)); + $this->assertTrue(class_exists($model)); + $this->assertObjectHasAttribute($model, $this->ci_obj); // Test no model given $this->assertNull($this->load->model('')); @@ -204,11 +204,10 @@ class Loader_test extends CI_TestCase { $this->ci_core_class('model'); // Create modelin VFS - $model = 'test_sub_model'; + $model = 'Test_sub_model'; $base = 'CI_Model'; - $class = ucfirst($model); $subdir = 'cars'; - $this->ci_vfs_create($model, 'ci_app_root, + $this->ci_vfs_create($model, 'ci_app_root, array('models', $subdir)); // Load model @@ -216,10 +215,10 @@ class Loader_test extends CI_TestCase { $this->assertNull($this->load->model($subdir.'/'.$model, $name)); // Was the model class instantiated? - $this->assertTrue(class_exists($class)); + $this->assertTrue(class_exists($model)); $this->assertObjectHasAttribute($name, $this->ci_obj); $this->assertAttributeInstanceOf($base, $name, $this->ci_obj); - $this->assertAttributeInstanceOf($class, $name, $this->ci_obj); + $this->assertAttributeInstanceOf($model, $name, $this->ci_obj); // Test name conflict $obj = 'conflict'; @@ -481,9 +480,8 @@ class Loader_test extends CI_TestCase { // Create model in VFS package path $dir = 'testdir'; $path = APPPATH.$dir.'/'; - $model = 'automod'; - $mod_class = ucfirst($model); - $this->ci_vfs_create($model, 'ci_app_root, array($dir, 'models')); + $model = 'Automod'; + $this->ci_vfs_create($model, 'ci_app_root, array($dir, 'models')); // Create autoloader config $cfg = array( @@ -513,8 +511,8 @@ class Loader_test extends CI_TestCase { $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); + $this->assertTrue(class_exists($model), $model.' does not exist'); + $this->assertAttributeInstanceOf($model, $model, $this->ci_obj); // Verify config calls $this->assertEquals($cfg['config'], $this->ci_obj->config->loaded); -- cgit v1.2.3-24-g4f1b From 20b0b2047c5b9ba363daaf46616fb43dc5d5bd02 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 22 Jul 2013 14:39:18 +0300 Subject: Fix Loader_test::test_non_existent_model() --- tests/codeigniter/core/Loader_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter/core/Loader_test.php') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index d7c393d61..18486cd05 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -236,7 +236,7 @@ class Loader_test extends CI_TestCase { { $this->setExpectedException( 'RuntimeException', - 'CI Error: Unable to locate the model you have specified: ci_test_nonexistent_model.php' + 'CI Error: Unable to locate the model you have specified: Ci_test_nonexistent_model.php' ); $this->load->model('ci_test_nonexistent_model.php'); -- cgit v1.2.3-24-g4f1b From 519f87a07bd1fe3a9ec037f727628bb6c7c8e251 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 23 Jul 2013 17:16:10 +0300 Subject: Loader changes & optimizations related to issue #2551 --- tests/codeigniter/core/Loader_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter/core/Loader_test.php') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 18486cd05..9ad3ca6b9 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -28,7 +28,7 @@ class Loader_test extends CI_TestCase { $this->ci_vfs_create(ucfirst($lib), 'ci_base_root, 'libraries'); // Test is_loaded fail - $this->assertFalse($this->load->is_loaded($lib)); + $this->assertFalse($this->load->is_loaded(ucfirst($lib))); // Test loading as an array. $this->assertNull($this->load->library(array($lib))); @@ -123,7 +123,7 @@ class Loader_test extends CI_TestCase { $this->assertEquals($cfg, $this->ci_obj->$obj->config); // Test is_loaded - $this->assertEquals($obj, $this->load->is_loaded($lib)); + $this->assertEquals($obj, $this->load->is_loaded(ucfirst($lib))); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From fd15a707ee8ec0749c8b51b0b21683b946160096 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 6 Jan 2014 13:37:45 +0200 Subject: Remove redudant Loader tests for library() & driver() with no parameters --- tests/codeigniter/core/Loader_test.php | 6 ------ 1 file changed, 6 deletions(-) (limited to 'tests/codeigniter/core/Loader_test.php') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 9ad3ca6b9..8fbeaec7b 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -35,9 +35,6 @@ class Loader_test extends CI_TestCase { $this->assertTrue(class_exists($class), $class.' does not exist'); $this->assertAttributeInstanceOf($class, $lib, $this->ci_obj); - // Test no lib given - $this->assertNull($this->load->library()); - // Test a string given to params $this->assertNull($this->load->library($lib, ' ')); @@ -167,9 +164,6 @@ class Loader_test extends CI_TestCase { $this->assertNull($this->load->library($driver, NULL, $obj)); $this->assertAttributeInstanceOf($class, $obj, $this->ci_obj); - // Test no driver given - $this->assertFalse($this->load->driver()); - // Test a string given to params $this->assertNull($this->load->driver($driver, ' ')); } -- cgit v1.2.3-24-g4f1b From 61a7b8f4b38bbca520c43ac100899449f73bf408 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 7 Jan 2014 13:36:50 +0200 Subject: Implement Loader method chaining Requested in issue #2165 Supersedes PR #2319 --- tests/codeigniter/core/Loader_test.php | 56 +++++++++++++++++----------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'tests/codeigniter/core/Loader_test.php') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 8fbeaec7b..799bcd967 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -31,12 +31,12 @@ class Loader_test extends CI_TestCase { $this->assertFalse($this->load->is_loaded(ucfirst($lib))); // Test loading as an array. - $this->assertNull($this->load->library(array($lib))); + $this->assertInstanceOf('CI_Loader', $this->load->library(array($lib))); $this->assertTrue(class_exists($class), $class.' does not exist'); $this->assertAttributeInstanceOf($class, $lib, $this->ci_obj); // Test a string given to params - $this->assertNull($this->load->library($lib, ' ')); + $this->assertInstanceOf('CI_Loader', $this->load->library($lib, ' ')); // Create library w/o class $lib = 'bad_test_lib'; @@ -47,7 +47,7 @@ class Loader_test extends CI_TestCase { 'RuntimeException', 'CI Error: Unable to load the requested class: '.ucfirst($lib) ); - $this->assertNull($this->load->library($lib)); + $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); } // -------------------------------------------------------------------- @@ -63,7 +63,7 @@ class Loader_test extends CI_TestCase { $this->ci_vfs_create($ext, 'ci_app_root, 'libraries'); // Test loading with extension - $this->assertNull($this->load->library($lib)); + $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); $this->assertTrue(class_exists($class), $class.' does not exist'); $this->assertTrue(class_exists($ext), $ext.' does not exist'); $this->assertAttributeInstanceOf($class, $name, $this->ci_obj); @@ -71,13 +71,13 @@ class Loader_test extends CI_TestCase { // Test reloading with object name $obj = 'exttest'; - $this->assertNull($this->load->library($lib, NULL, $obj)); + $this->assertInstanceOf('CI_Loader', $this->load->library($lib, NULL, $obj)); $this->assertAttributeInstanceOf($class, $obj, $this->ci_obj); $this->assertAttributeInstanceOf($ext, $obj, $this->ci_obj); // Test reloading unset($this->ci_obj->$name); - $this->assertNull($this->load->library($lib)); + $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); $this->assertObjectNotHasAttribute($name, $this->ci_obj); // Create baseless library @@ -91,7 +91,7 @@ class Loader_test extends CI_TestCase { 'RuntimeException', 'CI Error: Unable to load the requested class: '.$lib ); - $this->assertNull($this->load->library($lib)); + $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); } // -------------------------------------------------------------------- @@ -114,7 +114,7 @@ class Loader_test extends CI_TestCase { // Test object name and config $obj = 'testy'; - $this->assertNull($this->load->library($lib, NULL, $obj)); + $this->assertInstanceOf('CI_Loader', $this->load->library($lib, NULL, $obj)); $this->assertTrue(class_exists($class), $class.' does not exist'); $this->assertAttributeInstanceOf($class, $obj, $this->ci_obj); $this->assertEquals($cfg, $this->ci_obj->$obj->config); @@ -133,7 +133,7 @@ class Loader_test extends CI_TestCase { $this->ci_vfs_create(ucfirst($lib), 'ci_app_root, 'libraries'); // Load library - $this->assertNull($this->load->library($lib)); + $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); // Was the model class instantiated. $this->assertTrue(class_exists($class), $class.' does not exist'); @@ -155,17 +155,17 @@ class Loader_test extends CI_TestCase { $this->ci_vfs_create(ucfirst($driver), $content, $this->ci_base_root, 'libraries/'.$dir); // Test loading as an array. - $this->assertNull($this->load->driver(array($driver))); + $this->assertInstanceOf('CI_Loader', $this->load->driver(array($driver))); $this->assertTrue(class_exists($class), $class.' does not exist'); $this->assertAttributeInstanceOf($class, $driver, $this->ci_obj); // Test loading as a library with a name $obj = 'testdrive'; - $this->assertNull($this->load->library($driver, NULL, $obj)); + $this->assertInstanceOf('CI_Loader', $this->load->library($driver, NULL, $obj)); $this->assertAttributeInstanceOf($class, $obj, $this->ci_obj); // Test a string given to params - $this->assertNull($this->load->driver($driver, ' ')); + $this->assertInstanceOf('CI_Loader', $this->load->driver($driver, ' ')); } // -------------------------------------------------------------------- @@ -180,14 +180,14 @@ class Loader_test extends CI_TestCase { $this->ci_vfs_create($model, $content, $this->ci_app_root, 'models'); // Load model - $this->assertNull($this->load->model($model)); + $this->assertInstanceOf('CI_Loader', $this->load->model($model)); // Was the model class instantiated. $this->assertTrue(class_exists($model)); $this->assertObjectHasAttribute($model, $this->ci_obj); // Test no model given - $this->assertNull($this->load->model('')); + $this->assertInstanceOf('CI_Loader', $this->load->model('')); } // -------------------------------------------------------------------- @@ -206,7 +206,7 @@ class Loader_test extends CI_TestCase { // Load model $name = 'testors'; - $this->assertNull($this->load->model($subdir.'/'.$model, $name)); + $this->assertInstanceOf('CI_Loader', $this->load->model($subdir.'/'.$model, $name)); // Was the model class instantiated? $this->assertTrue(class_exists($model)); @@ -240,8 +240,8 @@ class Loader_test extends CI_TestCase { // public function testDatabase() // { - // $this->assertNull($this->load->database()); - // $this->assertNull($this->load->dbutil()); + // $this->assertInstanceOf('CI_Loader', $this->load->database()); + // $this->assertInstanceOf('CI_Loader', $this->load->dbutil()); // } // -------------------------------------------------------------------- @@ -265,7 +265,7 @@ class Loader_test extends CI_TestCase { $this->ci_instance_var('output', $output); // Test view output - $this->assertNull($this->load->view($view, array($var => $value))); + $this->assertInstanceOf('CI_Loader', $this->load->view($view, array($var => $value))); } // -------------------------------------------------------------------- @@ -311,8 +311,8 @@ class Loader_test extends CI_TestCase { $val1 = 'bar'; $key2 = 'boo'; $val2 = 'hoo'; - $this->assertNull($this->load->vars(array($key1 => $val1))); - $this->assertNull($this->load->vars($key2, $val2)); + $this->assertInstanceOf('CI_Loader', $this->load->vars(array($key1 => $val1))); + $this->assertInstanceOf('CI_Loader', $this->load->vars($key2, $val2)); $this->assertEquals($val1, $this->load->get_var($key1)); $this->assertEquals(array($key1 => $val1, $key2 => $val2), $this->load->get_vars()); } @@ -333,7 +333,7 @@ class Loader_test extends CI_TestCase { $this->ci_vfs_create($this->prefix.$helper.'_helper', $content, $this->ci_app_root, 'helpers'); // Load helper - $this->assertNull($this->load->helper($helper)); + $this->assertInstanceOf('CI_Loader', $this->load->helper($helper)); $this->assertTrue(function_exists($func), $func.' does not exist'); $this->assertTrue(function_exists($exfunc), $exfunc.' does not exist'); @@ -378,7 +378,7 @@ class Loader_test extends CI_TestCase { $this->ci_vfs_create($files, NULL, $this->ci_base_root, 'helpers'); // Load helpers - $this->assertNull($this->load->helpers($helpers)); + $this->assertInstanceOf('CI_Loader', $this->load->helpers($helpers)); // Verify helper existence foreach ($funcs as $func) { @@ -395,7 +395,7 @@ class Loader_test extends CI_TestCase { $lang = $this->getMock('CI_Lang', array('load')); $lang->expects($this->once())->method('load')->with($file); $this->ci_instance_var('lang', $lang); - $this->assertNull($this->load->language($file)); + $this->assertInstanceOf('CI_Loader', $this->load->language($file)); } // -------------------------------------------------------------------- @@ -413,24 +413,24 @@ class Loader_test extends CI_TestCase { // Add path and verify $path = APPPATH.$dir.'/'; - $this->assertNull($this->load->add_package_path($path)); + $this->assertInstanceOf('CI_Loader', $this->load->add_package_path($path)); $this->assertContains($path, $this->load->get_package_paths(TRUE)); // Test successful load - $this->assertNull($this->load->library($lib)); + $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); $this->assertTrue(class_exists($class), $class.' does not exist'); // Add another path $path2 = APPPATH.'another/'; - $this->assertNull($this->load->add_package_path($path2)); + $this->assertInstanceOf('CI_Loader', $this->load->add_package_path($path2)); $this->assertContains($path2, $this->load->get_package_paths(TRUE)); // Remove last path - $this->assertNull($this->load->remove_package_path()); + $this->assertInstanceOf('CI_Loader', $this->load->remove_package_path()); $this->assertNotContains($path2, $this->load->get_package_paths(TRUE)); // Remove path and verify restored paths - $this->assertNull($this->load->remove_package_path($path)); + $this->assertInstanceOf('CI_Loader', $this->load->remove_package_path($path)); $this->assertEquals($paths, $this->load->get_package_paths(TRUE)); // Test failed load without path -- cgit v1.2.3-24-g4f1b