Skip to content

Commit 7df6771

Browse files
committed
Improved unit test code coverage.
Signed-off-by:Heesung Ahn <ahn.heesung@gmail.com>
1 parent 138d0f5 commit 7df6771

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/codeigniter/core/Loader_test.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public function set_up()
2222

2323
public function test_library()
2424
{
25+
// Test getting CI_Loader object
26+
$this->assertInstanceOf('CI_Loader', $this->load->library(NULL));
27+
2528
// Create library in VFS
2629
$lib = 'unit_test_lib';
2730
$class = 'CI_'.ucfirst($lib);
@@ -34,6 +37,13 @@ public function test_library()
3437
$this->assertInstanceOf('CI_Loader', $this->load->library(array($lib)));
3538
$this->assertTrue(class_exists($class), $class.' does not exist');
3639
$this->assertAttributeInstanceOf($class, $lib, $this->ci_obj);
40+
41+
// Create library in VFS
42+
$lib = Array('unit_test_lib'=>'unit_test_lib');
43+
44+
// Test loading as an array (int).
45+
$this->assertInstanceOf('CI_Loader', $this->load->library($lib));
46+
$this->assertTrue(class_exists($class), $class.' does not exist');
3747

3848
// Test a string given to params
3949
$this->assertInstanceOf('CI_Loader', $this->load->library($lib, ' '));
@@ -316,6 +326,24 @@ public function test_vars()
316326
$this->assertEquals($val1, $this->load->get_var($key1));
317327
$this->assertEquals(array($key1 => $val1, $key2 => $val2), $this->load->get_vars());
318328
}
329+
330+
// --------------------------------------------------------------------
331+
332+
public function test_clear_vars()
333+
{
334+
$key1 = 'foo';
335+
$val1 = 'bar';
336+
$key2 = 'boo';
337+
$val2 = 'hoo';
338+
$this->assertInstanceOf('CI_Loader', $this->load->vars(array($key1 => $val1)));
339+
$this->assertInstanceOf('CI_Loader', $this->load->vars($key2, $val2));
340+
$this->assertEquals($val1, $this->load->get_var($key1));
341+
$this->assertEquals(array($key1 => $val1, $key2 => $val2), $this->load->get_vars());
342+
343+
$this->assertInstanceOf('CI_Loader', $this->load->clear_vars());
344+
$this->assertEquals('', $this->load->get_var($key1));
345+
$this->assertEquals('', $this->load->get_var($key2));
346+
}
319347

320348
// --------------------------------------------------------------------
321349

@@ -443,6 +471,24 @@ public function test_packages()
443471

444472
// --------------------------------------------------------------------
445473

474+
public function test_remove_package_path()
475+
{
476+
$dir = 'third-party';
477+
$path = APPPATH.$dir.'/';
478+
$path2 = APPPATH.'another/';
479+
$paths = $this->load->get_package_paths(TRUE);
480+
481+
$this->assertInstanceOf('CI_Loader', $this->load->add_package_path($path));
482+
$this->assertInstanceOf('CI_Loader', $this->load->remove_package_path($path));
483+
$this->assertEquals($paths, $this->load->get_package_paths(TRUE));
484+
485+
$this->assertInstanceOf('CI_Loader', $this->load->add_package_path($path2));
486+
$this->assertInstanceOf('CI_Loader', $this->load->remove_package_path());
487+
$this->assertNotContains($path2, $this->load->get_package_paths(TRUE));
488+
}
489+
490+
// --------------------------------------------------------------------
491+
446492
public function test_load_config()
447493
{
448494
$cfg = 'someconfig';

0 commit comments

Comments
 (0)