summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/core/Loader_test.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/codeigniter/core/Loader_test.php')
-rw-r--r--tests/codeigniter/core/Loader_test.php36
1 files changed, 34 insertions, 2 deletions
diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php
index 6a7aa916a..df9c9f44b 100644
--- a/tests/codeigniter/core/Loader_test.php
+++ b/tests/codeigniter/core/Loader_test.php
@@ -277,6 +277,25 @@ class Loader_test extends CI_TestCase {
// --------------------------------------------------------------------
+ public function test_invalid_model()
+ {
+ $this->ci_set_core_class('model', 'CI_Model');
+
+ // Create model in VFS
+ $model = 'Unit_test_invalid_model';
+ $content = '<?php class '.$model.' {} ';
+ $this->ci_vfs_create($model, $content, $this->ci_app_root, 'models');
+
+ // Test no extending
+ $this->setExpectedException(
+ 'RuntimeException',
+ 'Class '.$model.' doesn\'t extend CI_Model'
+ );
+ $this->load->model($model);
+ }
+
+ // --------------------------------------------------------------------
+
// public function testDatabase()
// {
// $this->assertInstanceOf('CI_Loader', $this->load->database());
@@ -292,12 +311,16 @@ class Loader_test extends CI_TestCase {
$var = 'hello';
$value = 'World!';
$content = 'This is my test page. ';
- $this->ci_vfs_create($view, $content.'<?php echo $'.$var.';', $this->ci_app_root, 'views');
+ $this->ci_vfs_create($view, $content.'<?php echo (isset($'.$var.') ? $'.$var.' : "undefined");', $this->ci_app_root, 'views');
// Test returning view
$out = $this->load->view($view, array($var => $value), TRUE);
$this->assertEquals($content.$value, $out);
+ // Test view with missing parameter in $vars
+ $out = $this->load->view($view, [], TRUE);
+ $this->assertEquals($content.'undefined', $out);
+
// Mock output class
$output = $this->getMockBuilder('CI_Output')->setMethods(array('append_output'))->getMock();
$output->expects($this->once())->method('append_output')->with($content.$value);
@@ -307,6 +330,15 @@ class Loader_test extends CI_TestCase {
$vars = new stdClass();
$vars->$var = $value;
$this->assertInstanceOf('CI_Loader', $this->load->view($view, $vars));
+
+ // Create another view in VFS, nesting the first one without its own $vars
+ $nesting_view = 'unit_test_nesting_view';
+ $nesting_content = 'Here comes a nested view. ';
+ $this->ci_vfs_create($nesting_view, $nesting_content.'<?php $loader->view("'.$view.'");', $this->ci_app_root, 'views');
+
+ // Test $vars inheritance to nested views
+ $out = $this->load->view($nesting_view, array("loader" => $this->load, $var => $value), TRUE);
+ $this->assertEquals($nesting_content.$content.$value, $out);
}
// --------------------------------------------------------------------
@@ -552,7 +584,7 @@ class Loader_test extends CI_TestCase {
$dir = 'testdir';
$path = APPPATH.$dir.'/';
$model = 'Automod';
- $this->ci_vfs_create($model, '<?php class '.$model.' { }', $this->ci_app_root, array($dir, 'models'));
+ $this->ci_vfs_create($model, '<?php class '.$model.' extends CI_Model { }', $this->ci_app_root, array($dir, 'models'));
// Create autoloader config
$cfg = array(