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') 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') 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') 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 90f316a8615fbbbc0810d945dd1a237662c6bfbf Mon Sep 17 00:00:00 2001 From: vlakoff Date: Thu, 25 Jul 2013 04:33:56 +0200 Subject: Adjustments to the previous commit --- tests/codeigniter/core/Config_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php index e3be8a3fc..72f47cd51 100644 --- a/tests/codeigniter/core/Config_test.php +++ b/tests/codeigniter/core/Config_test.php @@ -24,18 +24,18 @@ class Config_test extends CI_TestCase { $this->assertEquals($this->cfg['base_url'], $this->config->item('base_url')); // Bad Config value - $this->assertFalse($this->config->item('no_good_item')); + $this->assertNull($this->config->item('no_good_item')); // Index - $this->assertFalse($this->config->item('no_good_item', 'bad_index')); - $this->assertFalse($this->config->item('no_good_item', 'default')); + $this->assertNull($this->config->item('no_good_item', 'bad_index')); + $this->assertNull($this->config->item('no_good_item', 'default')); } // -------------------------------------------------------------------- public function test_set_item() { - $this->assertFalse($this->config->item('not_yet_set')); + $this->assertNull($this->config->item('not_yet_set')); $this->config->set_item('not_yet_set', 'is set'); $this->assertEquals('is set', $this->config->item('not_yet_set')); -- cgit v1.2.3-24-g4f1b From c1044cb62e39709aa14f86a56bc950a78cfc713c Mon Sep 17 00:00:00 2001 From: vlakoff Date: Thu, 25 Jul 2013 12:18:43 +0200 Subject: Uniformize slash_item() with item() --- tests/codeigniter/core/Config_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php index 72f47cd51..ba9a2c070 100644 --- a/tests/codeigniter/core/Config_test.php +++ b/tests/codeigniter/core/Config_test.php @@ -46,7 +46,7 @@ class Config_test extends CI_TestCase { public function test_slash_item() { // Bad Config value - $this->assertFalse($this->config->slash_item('no_good_item')); + $this->assertNull($this->config->slash_item('no_good_item')); $this->assertEquals($this->cfg['base_url'], $this->config->slash_item('base_url')); $this->assertEquals($this->cfg['subclass_prefix'].'/', $this->config->slash_item('subclass_prefix')); -- cgit v1.2.3-24-g4f1b From 441fd264267ac526730d06183bd3cfebfd26df01 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sun, 11 Aug 2013 20:36:41 +0200 Subject: Input class: change behavior of get_post() method, add post_get() method followup to PR #2522 --- tests/codeigniter/core/Input_test.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 5cf25fefa..0a98e556c 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -82,11 +82,21 @@ class Input_test extends CI_TestCase { // -------------------------------------------------------------------- - public function test_get_post() + public function test_post_get() { $_SERVER['REQUEST_METHOD'] = 'POST'; $_POST['foo'] = 'bar'; + $this->assertEquals('bar', $this->input->post_get('foo')); + } + + // -------------------------------------------------------------------- + + public function test_get_post() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_GET['foo'] = 'bar'; + $this->assertEquals('bar', $this->input->get_post('foo')); } -- cgit v1.2.3-24-g4f1b From a1553a9a49b8d355de7892204759651aa3532dad Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 19 Aug 2013 20:12:19 +0300 Subject: Lower precision for the CI_Benchmark::elapsed_time() test - there's no way to reliably test it --- tests/codeigniter/core/Benchmark_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php index a239ba51d..aff736a40 100644 --- a/tests/codeigniter/core/Benchmark_test.php +++ b/tests/codeigniter/core/Benchmark_test.php @@ -30,7 +30,7 @@ class Benchmark_test extends CI_TestCase { sleep(1); $this->benchmark->mark('code_end'); - $this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1)); + $this->assertEquals('1', $this->benchmark->elapsed_time('code_start', 'code_end', 0)); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 3a3d5f6c2320a90436de241af41fe22df7344728 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Thu, 17 Oct 2013 22:22:16 +0200 Subject: Replace the last rand() with mt_rand() Better entropy, faster. Also fixed a few "it's" typos. --- tests/codeigniter/core/Security_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index 3f6e3b07a..433ad313f 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -5,7 +5,7 @@ class Security_test extends CI_TestCase { public function set_up() { // Set cookie for security test - $_COOKIE['ci_csrf_cookie'] = md5(uniqid(rand(), TRUE)); + $_COOKIE['ci_csrf_cookie'] = md5(uniqid(mt_rand(), TRUE)); // Set config for Security class $this->ci_set_config('csrf_protection', TRUE); -- 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') 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 a9c7d18dc4ba53507d6e606221f06aa3fafeaa8e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 6 Jan 2014 14:38:00 +0200 Subject: Fix #2237: Parser library failed if the same tag pair is used more than once within a template (manually applying PR #2238 + updated unit tests) --- tests/codeigniter/libraries/Parser_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php index 394c22692..6e5c192dd 100644 --- a/tests/codeigniter/libraries/Parser_test.php +++ b/tests/codeigniter/libraries/Parser_test.php @@ -76,9 +76,9 @@ class Parser_test extends CI_TestCase { ) ); - $template = "{title}\n{powers}{invisibility}\n{flying}{/powers}"; + $template = "{title}\n{powers}{invisibility}\n{flying}{/powers}\nsecond:{powers} {invisibility} {flying}{/powers}"; - $this->assertEquals("Super Heroes\nyes\nno", $this->parser->parse_string($template, $data, TRUE)); + $this->assertEquals("Super Heroes\nyes\nno\nsecond: yes no", $this->parser->parse_string($template, $data, TRUE)); } // -------------------------------------------------------------------- -- 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') 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 From 0bb32d3c71bfc797c64b0c6611c520f5beef5621 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 7 Jan 2014 16:30:42 +0200 Subject: Update Text helper highlight_phrase() tests and add one for custom tags --- tests/codeigniter/helpers/text_helper_test.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index d75d26208..7a7dc0a12 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -106,17 +106,19 @@ class Text_helper_test extends CI_TestCase { public function test_highlight_phrase() { $strs = array( - 'this is a phrase' => 'this is a phrase', - 'this is another' => 'this is another', - 'Gimme a test, Sally' => 'Gimme a test, Sally', - 'Or tell me what this is' => 'Or tell me what this is', - '' => '' + 'this is a phrase' => 'this is a phrase', + 'this is another' => 'this is another', + 'Gimme a test, Sally' => 'Gimme a test, Sally', + 'Or tell me what this is' => 'Or tell me what this is', + '' => '' ); foreach ($strs as $str => $expect) { $this->assertEquals($expect, highlight_phrase($str, 'this is')); } + + $this->assertEquals('this is a strong test', highlight_phrase('this is a strong test', 'this is', '', '')); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From d1755f81ac0f081e3acccbb54e2ab8ff46471ff4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 9 Jan 2014 13:54:47 +0200 Subject: Update Calendar library test following PR #2802 --- tests/codeigniter/libraries/Calendar_test.php | 33 +++++++++++++++------------ 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/libraries/Calendar_test.php b/tests/codeigniter/libraries/Calendar_test.php index 952e8a8d2..768bc8573 100644 --- a/tests/codeigniter/libraries/Calendar_test.php +++ b/tests/codeigniter/libraries/Calendar_test.php @@ -169,30 +169,33 @@ class Calendar_test extends CI_TestCase { $this->assertEquals(31, $this->calendar->get_total_days(12, 2012)); } - function test_default_template() + public function test_default_template() { $array = array( - 'table_open' => '', - 'heading_row_start' => '', + 'table_open' => '
', + 'heading_row_start' => '', 'heading_previous_cell' => '', 'heading_title_cell' => '', - 'heading_next_cell' => '', - 'heading_row_end' => '', - 'week_row_start' => '', - 'week_day_cell' => '', - 'week_row_end' => '', - 'cal_row_start' => '', - 'cal_cell_start' => '', + 'heading_row_end' => '', + 'week_row_start' => '', + 'week_day_cell' => '', + 'week_row_end' => '', + 'cal_row_start' => '', + 'cal_cell_start' => '', + 'cal_cell_blank' => ' ', + 'cal_cell_end' => '', 'cal_cell_end_today' => '', - 'cal_row_end' => '', - 'table_close' => '
<<{heading}>>
{week_day}
', + 'heading_next_cell' => '>>
{week_day}
', 'cal_cell_start_today' => '', - 'cal_cell_content' => '{day}', + 'cal_cell_content' => '{day}', 'cal_cell_content_today' => '{day}', 'cal_cell_no_content' => '{day}', 'cal_cell_no_content_today' => '{day}', - 'cal_cell_blank' => ' ', - 'cal_cell_end' => '
' + 'cal_row_end' => '', + 'table_close' => '', + 'cal_cell_start_other' => '', + 'cal_cell_other' => '{day}', + 'cal_cell_end_other' => '' ); $this->assertEquals($array, $this->calendar->default_template()); -- cgit v1.2.3-24-g4f1b From de14aa5a29b1b122bfd536f979dfda7f2fd9f53d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 15 Jan 2014 15:51:08 +0200 Subject: CI_URI changes related to the 'permitted_uri_chars' setting - Initialize and cache the value in the class constructor instead of searching for it every time - Removed the preg_quote() call from _filter_uri() to allow more fine-tuning from configuration - Renamed _filter_uri() to filter_uri() - it was public anyway and using it cannot break anything Related: issue #2799 --- tests/codeigniter/core/URI_test.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php index 7fa0e6265..99d79bbd2 100644 --- a/tests/codeigniter/core/URI_test.php +++ b/tests/codeigniter/core/URI_test.php @@ -112,11 +112,10 @@ class URI_test extends CI_TestCase { public function test_filter_uri() { - $this->uri->config->set_item('enable_query_strings', FALSE); - $this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-'); + $this->uri->_set_permitted_uri_chars('a-z 0-9~%.:_\-'); $str_in = 'abc01239~%.:_-'; - $str = $this->uri->_filter_uri($str_in); + $str = $this->uri->filter_uri($str_in); $this->assertEquals($str, $str_in); } @@ -126,11 +125,9 @@ class URI_test extends CI_TestCase { public function test_filter_uri_escaping() { // ensure escaping even if dodgey characters are permitted + $this->uri->_set_permitted_uri_chars('a-z 0-9~%.:_\-()$'); - $this->uri->config->set_item('enable_query_strings', FALSE); - $this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-()$'); - - $str = $this->uri->_filter_uri('$destroy_app(foo)'); + $str = $this->uri->filter_uri('$destroy_app(foo)'); $this->assertEquals($str, '$destroy_app(foo)'); } @@ -142,8 +139,8 @@ class URI_test extends CI_TestCase { $this->setExpectedException('RuntimeException'); $this->uri->config->set_item('enable_query_strings', FALSE); - $this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-'); - $this->uri->_filter_uri('$this()'); + $this->uri->_set_permitted_uri_chars('a-z 0-9~%.:_\-'); + $this->uri->filter_uri('$this()'); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 30d5324617ae136c7a91badb6ed8f7de418fd7f5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 16 Jan 2014 14:41:46 +0200 Subject: URI Routing overhaul - Allow multiple levels of controller directories (supersedes PRs #390, #2439) - Add support for per-directory 'defaul_controller' and '404_override' (resolves issue #2611; supersedes PR #939) - Fixed a bug where default_controller was called instead of triggering 404 if the current route is inside a directory - Removed a few calls from CI_Router to CI_URI that made a necessity for otherwise internal CI_URI methods to be public: - Removed CI_URI::_fetch_uri_string() and moved its logic into CI_URI::__construct() - Removed CI_URI::_remove_url_suffix, CI_URI::_explode_segments() and moved their logic into CI_URI::_set_uri_string() - Removed CI_URI::_reindex_segments() altogether ( doesn't need further manipulation, while is public anyway and can be properly (and more effectively) replaced on the spot) --- tests/codeigniter/core/URI_test.php | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php index 99d79bbd2..6589c1f5a 100644 --- a/tests/codeigniter/core/URI_test.php +++ b/tests/codeigniter/core/URI_test.php @@ -26,6 +26,10 @@ class URI_test extends CI_TestCase { // -------------------------------------------------------------------- + /* + + This has been moved to the constructor + public function test_fetch_uri_string() { define('SELF', 'index.php'); @@ -86,9 +90,14 @@ class URI_test extends CI_TestCase { // uri_protocol: REQUEST_URI // uri_protocol: CLI } + */ // -------------------------------------------------------------------- + /* + + This has been moved into _set_uri_string() + public function test_explode_segments() { // Let's test the function's ability to clean up this mess @@ -107,7 +116,7 @@ class URI_test extends CI_TestCase { $this->assertEquals($a, $this->uri->segments); } } - + */ // -------------------------------------------------------------------- public function test_filter_uri() @@ -145,23 +154,6 @@ class URI_test extends CI_TestCase { // -------------------------------------------------------------------- - public function test_remove_url_suffix() - { - $this->uri->config->set_item('url_suffix', '.html'); - - $this->uri->uri_string = 'controller/method/index.html'; - $this->uri->_remove_url_suffix(); - - $this->assertEquals($this->uri->uri_string, 'controller/method/index'); - - $this->uri->uri_string = 'controller/method/index.htmlify.html'; - $this->uri->_remove_url_suffix(); - - $this->assertEquals($this->uri->uri_string, 'controller/method/index.htmlify'); - } - - // -------------------------------------------------------------------- - public function test_segment() { $this->uri->segments = array(1 => 'controller'); -- cgit v1.2.3-24-g4f1b From 279459e42b3a7244ab5f6db8950ed47bf80590ad Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 16 Jan 2014 18:09:09 +0200 Subject: Add some unit tests for CI_Input --- tests/codeigniter/core/Input_test.php | 47 ++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 0a98e556c..95833fc91 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -138,13 +138,24 @@ class Input_test extends CI_TestCase { public function test_valid_ip() { - $ip_v4 = '192.18.0.1'; - $this->assertTrue($this->input->valid_ip($ip_v4)); + $this->assertTrue($this->input->valid_ip('192.18.0.1')); + $this->assertTrue($this->input->valid_ip('192.18.0.1', 'ipv4')); + $this->assertFalse($this->input->valid_ip('555.0.0.0')); + $this->assertFalse($this->input->valid_ip('2001:db8:0:85a3::ac1f:8001', 'ipv4')); + + // v6 tests + $this->assertFalse($this->input->valid_ip('192.18.0.1', 'ipv6')); + + $ip_v6 = array( + '2001:0db8:0000:85a3:0000:0000:ac1f:8001', + '2001:db8:0:85a3:0:0:ac1f:8001', + '2001:db8:0:85a3::ac1f:8001' + ); - $ip_v6 = array('2001:0db8:0000:85a3:0000:0000:ac1f:8001', '2001:db8:0:85a3:0:0:ac1f:8001', '2001:db8:0:85a3::ac1f:8001'); foreach ($ip_v6 as $ip) { $this->assertTrue($this->input->valid_ip($ip)); + $this->assertTrue($this->input->valid_ip($ip, 'ipv6')); } } @@ -171,4 +182,34 @@ class Input_test extends CI_TestCase { $this->assertTrue($this->input->is_ajax_request()); } + // -------------------------------------------------------------------- + + public function test_input_stream() + { + $this->markTestSkipped('TODO: Find a way to test input://'); + } + + // -------------------------------------------------------------------- + + public function test_set_cookie() + { + $this->markTestSkipped('TODO: Find a way to test HTTP headers'); + } + + public function test_ip_address() + { + // 127.0.0.1 is set in our Bootstrap file + $this->assertEquals('127.0.0.1', $this->input->ip_address()); + + // Invalid + $_SERVER['REMOTE_ADDR'] = 'invalid_ip_address'; + $this->input->ip_address = FALSE; // reset cached value + $this->assertEquals('0.0.0.0', $this->input->ip_address()); + + // TODO: Add proxy_ips tests + + // Back to reality + $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // back to reality + } + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 291676be2ca85581b48dfdc40889085f1928fabf Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 16 Jan 2014 18:39:52 +0200 Subject: Add a unit test for CI_Utf8::_is_ascii() --- tests/codeigniter/core/Utf8_test.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Utf8_test.php b/tests/codeigniter/core/Utf8_test.php index caa7b6986..71299134e 100644 --- a/tests/codeigniter/core/Utf8_test.php +++ b/tests/codeigniter/core/Utf8_test.php @@ -11,10 +11,15 @@ class Utf8_test extends CI_TestCase { public function test_convert_to_utf8() { - $this->assertEquals( - $this->utf8->convert_to_utf8('๒ๅ๑๒', 'WINDOWS-1251'), - 'ั‚ะตัั‚' - ); + $this->assertEquals('ั‚ะตัั‚', $this->utf8->convert_to_utf8('๒ๅ๑๒', 'WINDOWS-1251')); + } + + // -------------------------------------------------------------------- + + public function test_is_ascii() + { + $this->assertTrue($this->utf8->is_ascii_test('foo bar')); + $this->assertFalse($this->utf8->is_ascii_test('ั‚ะตัั‚')); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e33e9c1e5f0b600c0b14558fb74cf61258f7d684 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 17 Jan 2014 12:53:47 +0200 Subject: Add CI_Model unit test --- tests/codeigniter/core/Model_test.php | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/codeigniter/core/Model_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Model_test.php b/tests/codeigniter/core/Model_test.php new file mode 100644 index 000000000..80dc97b3b --- /dev/null +++ b/tests/codeigniter/core/Model_test.php @@ -0,0 +1,37 @@ +ci_core_class('loader'); + $this->load = new $loader(); + $this->ci_obj = $this->ci_instance(); + $this->ci_set_core_class('model', 'CI_Model'); + + $model_code =<<ci_vfs_create('Test_model', $model_code, $this->ci_app_root, 'models'); + $this->load->model('test_model'); + } + + // -------------------------------------------------------------------- + + public function test__get() + { + $this->assertEquals('foo', $this->ci_obj->test_model->property); + + $this->ci_obj->controller_property = 'bar'; + $this->assertEquals('bar', $this->ci_obj->test_model->controller_property); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6672b82087e8737b074f1b849aa77c9c761e2079 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 17 Jan 2014 13:19:33 +0200 Subject: Unit tests: Full code coverage of Benchmark class --- tests/codeigniter/core/Benchmark_test.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php index aff736a40..7fd0727e2 100644 --- a/tests/codeigniter/core/Benchmark_test.php +++ b/tests/codeigniter/core/Benchmark_test.php @@ -27,10 +27,34 @@ class Benchmark_test extends CI_TestCase { $this->assertEmpty($this->benchmark->elapsed_time('undefined_point')); $this->benchmark->mark('code_start'); - sleep(1); $this->benchmark->mark('code_end'); + // Override values, because time isn't testable, but make sure the markers were set + if (isset($this->benchmark->marker['code_start']) && is_float($this->benchmark->marker['code_start'])) + { + $this->benchmark->marker['code_start'] = 1389956144.1944; + } + + if (isset($this->benchmark->marker['code_end']) && is_float($this->benchmark->marker['code_end'])) + { + $this->benchmark->marker['code_end'] = 1389956145.1946; + } + $this->assertEquals('1', $this->benchmark->elapsed_time('code_start', 'code_end', 0)); + $this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1)); + $this->assertEquals('1.00', $this->benchmark->elapsed_time('code_start', 'code_end', 2)); + $this->assertEquals('1.000', $this->benchmark->elapsed_time('code_start', 'code_end', 3)); + $this->assertEquals('1.0002', $this->benchmark->elapsed_time('code_start', 'code_end', 4)); + $this->assertEquals('1.0002', $this->benchmark->elapsed_time('code_start', 'code_end')); + + // Test with non-existing 2nd marker, but again - we need to override the value + $this->benchmark->elapsed_time('code_start', 'code_end2'); + if (isset($this->benchmark->marker['code_end2']) && is_float($this->benchmark->marker['code_end2'])) + { + $this->benchmark->marker['code_end2'] = 1389956146.2046; + } + + $this->assertEquals('2.0102', $this->benchmark->elapsed_time('code_start', 'code_end2')); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From a9938a09e8214b778b8ab11f60501661bb2ac623 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 17 Jan 2014 14:55:56 +0200 Subject: Minor changes related to CI_User_agent Fixed a bug where both accept_charset() and accept_lang() improperly parsed headers if they contained spaces between data separators (which is valid). Also made is_referral() testable by replacing its static cache var with a class property and added some more unit tests for the library as a whole. --- tests/codeigniter/libraries/Parser_test.php | 14 ++----- tests/codeigniter/libraries/Useragent_test.php | 57 ++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 19 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php index 6e5c192dd..3755cf1a0 100644 --- a/tests/codeigniter/libraries/Parser_test.php +++ b/tests/codeigniter/libraries/Parser_test.php @@ -33,7 +33,7 @@ class Parser_test extends CI_TestCase { // -------------------------------------------------------------------- - public function test_parse_simple_string() + public function test_parse_string() { $data = array( 'title' => 'Page Title', @@ -69,11 +69,7 @@ class Parser_test extends CI_TestCase { { $data = array( 'title' => 'Super Heroes', - 'powers' => array( - array( - 'invisibility' => 'yes', - 'flying' => 'no'), - ) + 'powers' => array(array('invisibility' => 'yes', 'flying' => 'no')) ); $template = "{title}\n{powers}{invisibility}\n{flying}{/powers}\nsecond:{powers} {invisibility} {flying}{/powers}"; @@ -87,11 +83,7 @@ class Parser_test extends CI_TestCase { { $data = array( 'title' => 'Super Heroes', - 'powers' => array( - array( - 'invisibility' => 'yes', - 'flying' => 'no'), - ) + 'powers' => array(array('invisibility' => 'yes', 'flying' => 'no')) ); $template = "{title}\n{powers}{invisibility}\n{flying}"; diff --git a/tests/codeigniter/libraries/Useragent_test.php b/tests/codeigniter/libraries/Useragent_test.php index e3726554e..aed38b8c2 100644 --- a/tests/codeigniter/libraries/Useragent_test.php +++ b/tests/codeigniter/libraries/Useragent_test.php @@ -11,9 +11,7 @@ class UserAgent_test extends CI_TestCase { $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent; $this->ci_vfs_clone('application/config/user_agents.php'); - $this->agent = new Mock_Libraries_UserAgent(); - $this->ci_instance_var('agent', $this->agent); } @@ -40,12 +38,27 @@ class UserAgent_test extends CI_TestCase { // -------------------------------------------------------------------- - public function test_util_is_functions() + public function test_is_functions() { $this->assertTrue($this->agent->is_browser()); + $this->assertTrue($this->agent->is_browser('Safari')); + $this->assertFalse($this->agent->is_browser('Firefox')); $this->assertFalse($this->agent->is_robot()); $this->assertFalse($this->agent->is_mobile()); + } + + // -------------------------------------------------------------------- + + public function test_referrer() + { + $_SERVER['HTTP_REFERER'] = 'http://codeigniter.com/user_guide/'; + $this->assertTrue($this->agent->is_referral()); + $this->assertEquals('http://codeigniter.com/user_guide/', $this->agent->referrer()); + + $this->agent->referer = NULL; + unset($_SERVER['HTTP_REFERER']); $this->assertFalse($this->agent->is_referral()); + $this->assertEquals('', $this->agent->referrer()); } // -------------------------------------------------------------------- @@ -63,7 +76,6 @@ class UserAgent_test extends CI_TestCase { $this->assertEquals('Safari', $this->agent->browser()); $this->assertEquals('533.20.27', $this->agent->version()); $this->assertEquals('', $this->agent->robot()); - $this->assertEquals('', $this->agent->referrer()); } // -------------------------------------------------------------------- @@ -71,14 +83,43 @@ class UserAgent_test extends CI_TestCase { public function test_charsets() { $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8'; + $this->agent->charsets = array(); + $this->agent->charsets(); + $this->assertTrue($this->agent->accept_charset('utf8')); + $this->assertFalse($this->agent->accept_charset('foo')); + $this->assertEquals('utf8', $this->agent->charsets[0]); + + $_SERVER['HTTP_ACCEPT_CHARSET'] = ''; + $this->agent->charsets = array(); + $this->assertFalse($this->agent->accept_charset()); + $this->assertEquals('Undefined', $this->agent->charsets[0]); - $charsets = $this->agent->charsets(); - - $this->assertEquals('utf8', $charsets[0]); + $_SERVER['HTTP_ACCEPT_CHARSET'] = 'iso-8859-5, unicode-1-1; q=0.8'; + $this->agent->charsets = array(); + $this->assertTrue($this->agent->accept_charset('iso-8859-5')); + $this->assertTrue($this->agent->accept_charset('unicode-1-1')); + $this->assertFalse($this->agent->accept_charset('foo')); + $this->assertEquals('iso-8859-5', $this->agent->charsets[0]); + $this->assertEquals('unicode-1-1', $this->agent->charsets[1]); unset($_SERVER['HTTP_ACCEPT_CHARSET']); + } - $this->assertFalse($this->agent->accept_charset()); + public function test_parse() + { + $new_agent = 'Mozilla/5.0 (Android; Mobile; rv:13.0) Gecko/13.0 Firefox/13.0'; + $this->agent->parse($new_agent); + + $this->assertEquals('Android', $this->agent->platform()); + $this->assertEquals('Firefox', $this->agent->browser()); + $this->assertEquals('13.0', $this->agent->version()); + $this->assertEquals('', $this->agent->robot()); + $this->assertEquals('Android', $this->agent->mobile()); + $this->assertEquals($new_agent, $this->agent->agent_string()); + $this->assertTrue($this->agent->is_browser()); + $this->assertFalse($this->agent->is_robot()); + $this->assertTrue($this->agent->is_mobile()); + $this->assertTrue($this->agent->is_mobile('android')); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b