From 69c97a71476e4eaa6c629022fcd4ec7f36d4ec0d Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 20 Apr 2011 21:44:54 -0400 Subject: Adding early bootstrap ideas for core test suite --- tests/codeigniter/Setup_test.php | 13 +++ tests/codeigniter/core/Config_test.php | 107 ++++++++++++++++++ tests/codeigniter/core/Lang_test.php | 31 +++++ tests/codeigniter/core/Loader_test.php | 144 ++++++++++++++++++++++++ tests/codeigniter/helpers/Array_helper_test.php | 49 ++++++++ tests/codeigniter/libraries/Parser_test.php | 125 ++++++++++++++++++++ 6 files changed, 469 insertions(+) create mode 100644 tests/codeigniter/Setup_test.php create mode 100644 tests/codeigniter/core/Config_test.php create mode 100644 tests/codeigniter/core/Lang_test.php create mode 100644 tests/codeigniter/core/Loader_test.php create mode 100644 tests/codeigniter/helpers/Array_helper_test.php create mode 100644 tests/codeigniter/libraries/Parser_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php new file mode 100644 index 000000000..e088b51d3 --- /dev/null +++ b/tests/codeigniter/Setup_test.php @@ -0,0 +1,13 @@ +markTestIncomplete('not implemented'); + // ensure that our bootstrapped test environment + // is a good representation of an isolated CI install + //die('here'); + } + +} \ No newline at end of file diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php new file mode 100644 index 000000000..628fc630b --- /dev/null +++ b/tests/codeigniter/core/Config_test.php @@ -0,0 +1,107 @@ +ci_core_class('cfg'); + + $stub = $this->getMock($cls, NULL, array(), '', FALSE); + + //I would prefer this, but it currently + // does not work as when you try to pass + // null to setMethods it fails on an internal + // function call that expects an array =( + /* + $stub = $this->getMockBuilder($cls) + ->disableOriginalConstructor() + ->setMethods(null) + ->getMock(); + */ + + + // set predictable config values + $stub->config = array( + 'index_page' => 'index.php', + 'base_url' => 'http://example.com/', + 'subclass_prefix' => 'MY_' + ); + + $this->config = $stub; + } + + // -------------------------------------------------------------------- + + public function testItem() + { + $this->assertEquals('http://example.com/', $this->config->item('base_url')); + + // Bad Config value + $this->assertFalse($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')); + } + + // -------------------------------------------------------------------- + + public function testSetItem() + { + $this->assertFalse($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')); + } + + // -------------------------------------------------------------------- + + public function testSlashItem() + { + // Bad Config value + $this->assertFalse($this->config->slash_item('no_good_item')); + + $this->assertEquals('http://example.com/', $this->config->slash_item('base_url')); + + $this->assertEquals('MY_/', $this->config->slash_item('subclass_prefix')); + } + + // -------------------------------------------------------------------- + + public function testSiteUrl() + { + $this->assertEquals('http://example.com/index.php', $this->config->site_url()); + + $base_url = $this->config->item('base_url'); + + $this->config->set_item('base_url', ''); + + $q_string = $this->config->item('enable_query_strings'); + + $this->config->set_item('enable_query_strings', FALSE); + + $this->assertEquals('/index.php/test', $this->config->site_url('test')); + $this->assertEquals('/index.php/test/1', $this->config->site_url(array('test', '1'))); + + $this->config->set_item('enable_query_strings', TRUE); + + $this->assertEquals('/index.php?test', $this->config->site_url('test')); + $this->assertEquals('/index.php?0=test&1=1', $this->config->site_url(array('test', '1'))); + + $this->config->set_item('base_url', $base_url); + + $this->assertEquals('http://example.com/index.php?test', $this->config->site_url('test')); + + // back to home base + $this->config->set_item('enable_query_strings', $q_string); + } + + // -------------------------------------------------------------------- + + public function testSystemUrl() + { + $this->assertEquals('http://example.com/system/', $this->config->system_url()); + } + +} \ No newline at end of file diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php new file mode 100644 index 000000000..82e279a52 --- /dev/null +++ b/tests/codeigniter/core/Lang_test.php @@ -0,0 +1,31 @@ +ci_core_class('lang'); + $this->lang = new $cls; + } + + // -------------------------------------------------------------------- + + public function testLoad() + { + // get_config needs work + $this->markTestIncomplete('get_config needs work'); + //$this->assertTrue($this->lang->load('profiler')); + } + + // -------------------------------------------------------------------- + + public function testLine() + { + $this->markTestIncomplete('get_config needs work'); + + $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string')); + } + +} \ No newline at end of file diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php new file mode 100644 index 000000000..fd9c63216 --- /dev/null +++ b/tests/codeigniter/core/Loader_test.php @@ -0,0 +1,144 @@ +ci_core_class('load'); + $this->_loader = new $cls; + + // mock up a ci instance + $this->ci_obj = new StdClass; + + // Fix get_instance() + CodeIgniterTestCase::$test_instance =& $this; + $this->ci_instance($this->ci_obj); + } + + // -------------------------------------------------------------------- + + public function testLibrary() + { + // Mock up a config object until we + // figure out how to test the library configs + $config = $this->getMock('CI_Config', NULL, array(), '', FALSE); + $config->expects($this->any()) + ->method('load') + ->will($this->returnValue(TRUE)); + + // Add the mock to our stdClass + $this->ci_set_instance_var('config', $config); + + // Test loading as an array. + $this->assertEquals(NULL, $this->_loader->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()); + + // Test a string given to params + $this->assertEquals(NULL, $this->_loader->library('table', ' ')); + } + + // -------------------------------------------------------------------- + + public function testModels() + { + // Test loading as an array. + $this->assertEquals(NULL, $this->_loader->model(array('foobar'))); + + // Test no model given + $this->assertEquals(FALSE, $this->_loader->model('')); + + // Test a string given to params + $this->assertEquals(NULL, $this->_loader->model('foobar', ' ')); + } + + // -------------------------------------------------------------------- + + public function testDatabase() + { + $this->assertEquals(NULL, $this->_loader->database()); + $this->assertEquals(NULL, $this->_loader->dbutil()); + } + + // -------------------------------------------------------------------- + + public function testView() + { + // 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; + } + } + + // -------------------------------------------------------------------- + + 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'); + } + catch (Exception $expected) + { + return; + } + } + + // -------------------------------------------------------------------- + + public function testVars() + { + $vars = array( + 'foo' => 'bar' + ); + + $this->assertEquals(NULL, $this->_loader->vars($vars)); + $this->assertEquals(NULL, $this->_loader->vars('foo', 'bar')); + } + + // -------------------------------------------------------------------- + + public function testHelper() + { + $this->assertEquals(NULL, $this->_loader->helper('array')); + $this->assertEquals(NULL, $this->_loader->helper('bad')); + } + + // -------------------------------------------------------------------- + + public function testHelpers() + { + $this->assertEquals(NULL, $this->_loader->helpers(array('file', 'array', 'string'))); + } + + // -------------------------------------------------------------------- + + // public function testLanguage() + // { + // $this->assertEquals(NULL, $this->_loader->language('test')); + // } + + // -------------------------------------------------------------------- + + public function testLoadConfig() + { + $this->assertEquals(NULL, $this->_loader->config('config', FALSE, TRUE)); + } + + + +} \ No newline at end of file diff --git a/tests/codeigniter/helpers/Array_helper_test.php b/tests/codeigniter/helpers/Array_helper_test.php new file mode 100644 index 000000000..bbefdb49d --- /dev/null +++ b/tests/codeigniter/helpers/Array_helper_test.php @@ -0,0 +1,49 @@ +my_array = array( + 'foo' => 'bar', + 'sally' => 'jim', + 'maggie' => 'bessie', + 'herb' => 'cook' + ); + } + + // ------------------------------------------------------------------------ + + public function testElementWithExistingItem() + { + $this->assertEquals(FALSE, element('testing', $this->my_array)); + + $this->assertEquals('not set', element('testing', $this->my_array, 'not set')); + + $this->assertEquals('bar', element('foo', $this->my_array)); + } + + // ------------------------------------------------------------------------ + + public function testRandomElement() + { + // Send a string, not an array to random_element + $this->assertEquals('my string', random_element('my string')); + + // Test sending an array + $this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array)); + } + + // ------------------------------------------------------------------------ + + public function testElements() + { + $this->assertEquals(TRUE, is_array(elements('test', $this->my_array))); + $this->assertEquals(TRUE, is_array(elements('foo', $this->my_array))); + } + +} \ No newline at end of file diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php new file mode 100644 index 000000000..a8de108f0 --- /dev/null +++ b/tests/codeigniter/libraries/Parser_test.php @@ -0,0 +1,125 @@ +load->library('parser'); + self::$cls = get_class($CI->parser); + } + + // -------------------------------------------------------------------- + + public function setUp() + { + $cls = self::$cls; + $this->parser = new $cls; + } + // -------------------------------------------------------------------- + + public function testSetDelimiters() + { + // Make sure default delimiters are there + $this->assertEquals('{', $this->parser->l_delim); + $this->assertEquals('}', $this->parser->r_delim); + + // Change them to square brackets + $this->parser->set_delimiters('[', ']'); + + // Make sure they changed + $this->assertEquals('[', $this->parser->l_delim); + $this->assertEquals(']', $this->parser->r_delim); + + // Reset them + $this->parser->set_delimiters(); + + // Make sure default delimiters are there + $this->assertEquals('{', $this->parser->l_delim); + $this->assertEquals('}', $this->parser->r_delim); + } + + // -------------------------------------------------------------------- + + public function testParseSimpleString() + { + $data = array( + 'title' => 'Page Title', + 'body' => 'Lorem ipsum dolor sit amet.' + ); + + $template = "{title}\n{body}"; + + $result = implode("\n", $data); + + $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE)); + } + + // -------------------------------------------------------------------- + + public function testParse() + { + $this->_parse_no_template(); + $this->_parse_var_pair(); + $this->_mismatched_var_pair(); + } + + // -------------------------------------------------------------------- + + private function _parse_no_template() + { + $this->assertFalse($this->parser->parse_string('', '', TRUE)); + } + + // -------------------------------------------------------------------- + + private function _parse_var_pair() + { + $data = array( + 'title' => 'Super Heroes', + 'powers' => array( + array( + 'invisibility' => 'yes', + 'flying' => 'no'), + ) + ); + + $template = "{title}\n{powers}{invisibility}\n{flying}{/powers}"; + + $result = "Super Heroes\nyes\nno"; + + $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE)); + } + + // -------------------------------------------------------------------- + + private function _mismatched_var_pair() + { + $data = array( + 'title' => 'Super Heroes', + 'powers' => array( + array( + 'invisibility' => 'yes', + 'flying' => 'no'), + ) + ); + + $template = "{title}\n{powers}{invisibility}\n{flying}"; + + $result = "Super Heroes\n{powers}{invisibility}\n{flying}"; + + $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE)); + } + + // -------------------------------------------------------------------- + + // -------------------------------------------------------------------- + + // -------------------------------------------------------------------- + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 10ba64f9b76a25a77182d72a0a09413ccba12770 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Thu, 21 Apr 2011 01:00:27 -0400 Subject: Renamed the main test class, fixing test cases. --- tests/codeigniter/core/Config_test.php | 26 ++++++-------------------- tests/codeigniter/core/Lang_test.php | 2 +- tests/codeigniter/core/Loader_test.php | 5 ++--- 3 files changed, 9 insertions(+), 24 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php index 628fc630b..b04dd67fa 100644 --- a/tests/codeigniter/core/Config_test.php +++ b/tests/codeigniter/core/Config_test.php @@ -1,33 +1,19 @@ ci_core_class('cfg'); - - $stub = $this->getMock($cls, NULL, array(), '', FALSE); - - //I would prefer this, but it currently - // does not work as when you try to pass - // null to setMethods it fails on an internal - // function call that expects an array =( - /* - $stub = $this->getMockBuilder($cls) - ->disableOriginalConstructor() - ->setMethods(null) - ->getMock(); - */ - - + // set predictable config values - $stub->config = array( + $this->ci_set_config(array( 'index_page' => 'index.php', 'base_url' => 'http://example.com/', 'subclass_prefix' => 'MY_' - ); - - $this->config = $stub; + )); + + $this->config = new $cls; } // -------------------------------------------------------------------- diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php index 82e279a52..f65b335b0 100644 --- a/tests/codeigniter/core/Lang_test.php +++ b/tests/codeigniter/core/Lang_test.php @@ -1,6 +1,6 @@ ci_obj = new StdClass; // Fix get_instance() - CodeIgniterTestCase::$test_instance =& $this; $this->ci_instance($this->ci_obj); } @@ -30,7 +29,7 @@ class Loader_test extends CodeIgniterTestCase { ->will($this->returnValue(TRUE)); // Add the mock to our stdClass - $this->ci_set_instance_var('config', $config); + $this->ci_instance_var('config', $config); // Test loading as an array. $this->assertEquals(NULL, $this->_loader->library(array('table'))); -- cgit v1.2.3-24-g4f1b 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 From 98357c5865dbec43bcb79fb114469d40cf2f5367 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 11:30:23 -0500 Subject: Swap from assertEquals(FALSE, x) to just assertFalse(). Silly Greg. --- 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 2aa1b8cb9..83ee68777 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -101,7 +101,7 @@ class Loader_test extends CI_TestCase { $this->assertNull($this->load->model('unit_test_model')); // Test no model given - $this->assertEquals(FALSE, $this->load->model('')); + $this->assertFalse($this->load->model('')); // Test a string given to params // $this->assertEquals(NULL, $this->load->model('foobar', ' ')); -- cgit v1.2.3-24-g4f1b From deab6ad864f05367e2c122906f63d24286b731d1 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 11:44:11 -0500 Subject: Buttoning up model loader tests. --- tests/codeigniter/core/Loader_test.php | 39 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 83ee68777..d84928eca 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -64,7 +64,7 @@ class Loader_test extends CI_TestCase { $this->ci_instance_var('config', $config); // Test loading as an array. - $this->assertEquals(NULL, $this->load->library(array('table'))); + $this->assertNull($this->load->library(array('table'))); $this->assertTrue(class_exists('CI_Table'), 'Table class exists'); $this->assertAttributeInstanceOf('CI_Table', 'table', $this->ci_obj); @@ -100,11 +100,11 @@ class Loader_test extends CI_TestCase { $this->assertNull($this->load->model('unit_test_model')); - // Test no model given - $this->assertFalse($this->load->model('')); + // Was the model class instantiated. + $this->assertTrue(class_exists('Unit_test_model')); - // Test a string given to params - // $this->assertEquals(NULL, $this->load->model('foobar', ' ')); + // Test no model given + $this->assertNull($this->load->model('')); } // -------------------------------------------------------------------- @@ -132,14 +132,8 @@ class Loader_test extends CI_TestCase { public function testFile() { // I'm not entirely sure this is the proper way to handle this. - try - { - $this->load->file('foo'); - } - catch (Exception $expected) - { - return; - } + // $this->load->file('foo'); + } // -------------------------------------------------------------------- @@ -156,15 +150,22 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - // public function testHelper() - // { - // $this->assertEquals(NULL, $this->load->helper('array')); - // $this->assertEquals(NULL, $this->load->helper('bad')); - // } + public function testHelper() + { + $this->assertEquals(NULL, $this->load->helper('array')); + + $this->setExpectedException( + 'Exception', + 'CI Error: Unable to load the requested file: helpers/bad_helper.php' + ); + + + $this->load->helper('bad'); + } // -------------------------------------------------------------------- - public function testHelpers() + public function testLoadingMultipleHelpers() { $this->assertEquals(NULL, $this->load->helpers(array('file', 'array', 'string'))); } -- cgit v1.2.3-24-g4f1b From 321768d902f68a929a55ef9480c22cb54d40bd34 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 12:09:33 -0500 Subject: Testing view loading. --- tests/codeigniter/core/Loader_test.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index d84928eca..782751cd7 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -117,6 +117,23 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- + public function testLoadView() + { + $this->ci_set_core_class('output', 'CI_Output'); + + $content = 'This is my test page. '; + $view = vfsStream::newFile('unit_test_view.php')->withContent($content) + ->at($this->load->views_dir); + + // Use the optional return parameter in this test, so the view is not + // run through the output class. + $this->assertEquals('This is my test page. World!', + $this->load->view('unit_test_view', array('hello' => "World!"), TRUE)); + + } + + // -------------------------------------------------------------------- + public function testNonExistentView() { $this->setExpectedException( -- cgit v1.2.3-24-g4f1b From 6858fb92133afa127eff6f11dd29abf554e1b2d1 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 12:27:23 -0500 Subject: Adding mock testing of libraries in the application directory --- tests/codeigniter/core/Loader_test.php | 58 +++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 12 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 782751cd7..1e32c7e0a 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -53,15 +53,7 @@ class Loader_test extends CI_TestCase { public function testLibrary() { - // Mock up a config object until we - // figure out how to test the library configs - $config = $this->getMock('CI_Config', NULL, array(), '', FALSE); - $config->expects($this->any()) - ->method('load') - ->will($this->returnValue(TRUE)); - - // Add the mock to our stdClass - $this->ci_instance_var('config', $config); + $this->_setup_config_mock(); // Test loading as an array. $this->assertNull($this->load->library(array('table'))); @@ -73,22 +65,58 @@ class Loader_test extends CI_TestCase { // Test a string given to params $this->assertEquals(NULL, $this->load->library('table', ' ')); - } + } + + // -------------------------------------------------------------------- + + public function testLoadLibraryInApplicationDir() + { + $this->_setup_config_mock(); + + $content = 'withContent($content) + ->at($this->load->libs_dir); + + $this->assertNull($this->load->library('super_test_library')); + + // Was the model class instantiated. + $this->assertTrue(class_exists('Super_test_library')); + } // -------------------------------------------------------------------- + private function _setup_config_mock() + { + // Mock up a config object until we + // figure out how to test the library configs + $config = $this->getMock('CI_Config', NULL, array(), '', FALSE); + $config->expects($this->any()) + ->method('load') + ->will($this->returnValue(TRUE)); + + // Add the mock to our stdClass + $this->ci_instance_var('config', $config); + } + + // -------------------------------------------------------------------- + + public function testNonExistentModel() { $this->setExpectedException( 'Exception', - 'CI Error: Unable to locate the model you have specified: ci_test_nonexistent_mode.php' + 'CI Error: Unable to locate the model you have specified: ci_test_nonexistent_model.php' ); - $this->load->model('ci_test_nonexistent_mode.php'); + $this->load->model('ci_test_nonexistent_model.php'); } // -------------------------------------------------------------------- + /** + * @coverts CI_Loader::model + */ public function testModels() { $this->ci_set_core_class('model', 'CI_Model'); @@ -117,6 +145,9 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- + /** + * @coverts CI_Loader::view + */ public function testLoadView() { $this->ci_set_core_class('output', 'CI_Output'); @@ -134,6 +165,9 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- + /** + * @coverts CI_Loader::view + */ public function testNonExistentView() { $this->setExpectedException( -- cgit v1.2.3-24-g4f1b From 4d2bb09cbb4fc66dc4881c2ffdeee7dbaf0a3a3b Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 12:33:12 -0500 Subject: config CI_Loader tests. --- tests/codeigniter/core/Loader_test.php | 36 +++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 1e32c7e0a..55ab9a4e5 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -195,8 +195,8 @@ class Loader_test extends CI_TestCase { 'foo' => 'bar' ); - $this->assertEquals(NULL, $this->load->vars($vars)); - $this->assertEquals(NULL, $this->load->vars('foo', 'bar')); + $this->assertNull($this->load->vars($vars)); + $this->assertNull($this->load->vars('foo', 'bar')); } // -------------------------------------------------------------------- @@ -230,12 +230,30 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - // public function testLoadConfig() - // { - // $this->assertEquals(NULL, $this->load->config('config', FALSE, TRUE)); - // } -} - - + public function testLoadConfig() + { + $this->_setup_config_mock(); + + $this->assertNull($this->load->config('config', FALSE)); + } + + // -------------------------------------------------------------------- + public function testLoadBadConfig() + { + $this->_setup_config_mock(); + + $this->setExpectedException( + 'Exception', + 'CI Error: The configuration file foobar.php does not exist.' + ); + + $this->load->config('foobar', FALSE); + } + // -------------------------------------------------------------------- + + + + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 56106630e172203858d58325dea5d2e81b226f87 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 13:10:19 -0500 Subject: load->file() tests. --- tests/codeigniter/core/Loader_test.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 55ab9a4e5..49679e241 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -101,7 +101,6 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testNonExistentModel() { $this->setExpectedException( @@ -182,8 +181,22 @@ class Loader_test extends CI_TestCase { public function testFile() { - // I'm not entirely sure this is the proper way to handle this. - // $this->load->file('foo'); + $content = 'Here is a test file, which we will load now.'; + $file = vfsStream::newFile('ci_test_mock_file.php')->withContent($content) + ->at($this->load->views_dir); + + // Just like load->view(), take the output class out of the mix here. + $load = $this->load->file(vfsStream::url('application').'/views/ci_test_mock_file.php', + TRUE); + + $this->assertEquals($content, $load); + + $this->setExpectedException( + 'Exception', + 'CI Error: Unable to load the requested file: ci_test_file_not_exists' + ); + + $this->load->file('ci_test_file_not_exists', TRUE); } @@ -210,7 +223,6 @@ class Loader_test extends CI_TestCase { 'CI Error: Unable to load the requested file: helpers/bad_helper.php' ); - $this->load->helper('bad'); } -- cgit v1.2.3-24-g4f1b From b567947d38a20960aade96f9179ad6bc21f22646 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 14:34:31 -0500 Subject: Moving tests/codeigniter/helpers/Array_helper_test.php to be lower cased. Adding html_helper_test.php as well. --- tests/codeigniter/helpers/Array_helper_test.php | 49 ------------------ tests/codeigniter/helpers/array_helper_test.php | 49 ++++++++++++++++++ tests/codeigniter/helpers/html_helper_test.php | 67 +++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 49 deletions(-) delete mode 100644 tests/codeigniter/helpers/Array_helper_test.php create mode 100644 tests/codeigniter/helpers/array_helper_test.php create mode 100644 tests/codeigniter/helpers/html_helper_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/Array_helper_test.php b/tests/codeigniter/helpers/Array_helper_test.php deleted file mode 100644 index bbefdb49d..000000000 --- a/tests/codeigniter/helpers/Array_helper_test.php +++ /dev/null @@ -1,49 +0,0 @@ -my_array = array( - 'foo' => 'bar', - 'sally' => 'jim', - 'maggie' => 'bessie', - 'herb' => 'cook' - ); - } - - // ------------------------------------------------------------------------ - - public function testElementWithExistingItem() - { - $this->assertEquals(FALSE, element('testing', $this->my_array)); - - $this->assertEquals('not set', element('testing', $this->my_array, 'not set')); - - $this->assertEquals('bar', element('foo', $this->my_array)); - } - - // ------------------------------------------------------------------------ - - public function testRandomElement() - { - // Send a string, not an array to random_element - $this->assertEquals('my string', random_element('my string')); - - // Test sending an array - $this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array)); - } - - // ------------------------------------------------------------------------ - - public function testElements() - { - $this->assertEquals(TRUE, is_array(elements('test', $this->my_array))); - $this->assertEquals(TRUE, is_array(elements('foo', $this->my_array))); - } - -} \ No newline at end of file diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php new file mode 100644 index 000000000..bbefdb49d --- /dev/null +++ b/tests/codeigniter/helpers/array_helper_test.php @@ -0,0 +1,49 @@ +my_array = array( + 'foo' => 'bar', + 'sally' => 'jim', + 'maggie' => 'bessie', + 'herb' => 'cook' + ); + } + + // ------------------------------------------------------------------------ + + public function testElementWithExistingItem() + { + $this->assertEquals(FALSE, element('testing', $this->my_array)); + + $this->assertEquals('not set', element('testing', $this->my_array, 'not set')); + + $this->assertEquals('bar', element('foo', $this->my_array)); + } + + // ------------------------------------------------------------------------ + + public function testRandomElement() + { + // Send a string, not an array to random_element + $this->assertEquals('my string', random_element('my string')); + + // Test sending an array + $this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array)); + } + + // ------------------------------------------------------------------------ + + public function testElements() + { + $this->assertEquals(TRUE, is_array(elements('test', $this->my_array))); + $this->assertEquals(TRUE, is_array(elements('foo', $this->my_array))); + } + +} \ No newline at end of file diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php new file mode 100644 index 000000000..3b7f2b342 --- /dev/null +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -0,0 +1,67 @@ +assertEquals('

foobar

', heading('foobar')); + } + + // ------------------------------------------------------------------------ + + public function testUl() + { + $expect = << +
  • foo
  • +
  • bar
  • + + +EOH; + + $expect = ltrim($expect); + + $list = array('foo', 'bar'); + + $this->assertEquals($expect, ul($list)); + + + $expect = << +
  • foo
  • +
  • bar
  • + + +EOH; + + $expect = ltrim($expect); + + $list = array('foo', 'bar'); + + $this->assertEquals($expect, ul($list, ' class="test"')); + + $this->assertEquals($expect, ul($list, array('class' => 'test'))); + } + + // ------------------------------------------------------------------------ + + public function testNBS() + { + $this->assertEquals('   ', nbs(3)); + } + + // ------------------------------------------------------------------------ + + public function testMeta() + { + $this->assertEquals("\n", meta('test', 'foo')); + + $expect = "\n"; + + $this->assertEquals($expect, meta(array('name' => 'foo'))); + + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9071573bc510f127fa22ddd367b2ff46a60242cc Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 14:36:26 -0500 Subject: Adding text_helper_test --- tests/codeigniter/helpers/text_helper_test.php | 151 +++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 tests/codeigniter/helpers/text_helper_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php new file mode 100644 index 000000000..aa6660ea0 --- /dev/null +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -0,0 +1,151 @@ +_long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.'; + } + + // ------------------------------------------------------------------------ + + public function testWordLimiter() + { + $this->assertEquals('Once upon a time,…', word_limiter($this->_long_string, 4)); + $this->assertEquals('Once upon a time,…', word_limiter($this->_long_string, 4, '…')); + $this->assertEquals('', word_limiter('', 4)); + } + + // ------------------------------------------------------------------------ + + public function testCharacterLimiter() + { + $this->assertEquals('Once upon a time, a…', character_limiter($this->_long_string, 20)); + $this->assertEquals('Once upon a time, a…', character_limiter($this->_long_string, 20, '…')); + $this->assertEquals('Short', character_limiter('Short', 20)); + $this->assertEquals('Short', character_limiter('Short', 5)); + } + + // ------------------------------------------------------------------------ + + public function testAsciiToEntities() + { + $strs = array( + '“‘ “test”' => '“‘ “test”', + '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '†¥¨ˆøåß∂ƒ©˙∆˚¬' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, ascii_to_entities($str)); + } + } + + // ------------------------------------------------------------------------ + + public function testEntitiesToAscii() + { + $strs = array( + '“‘ “test”' => '“‘ “test”', + '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '†¥¨ˆøåß∂ƒ©˙∆˚¬' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, entities_to_ascii($str)); + } + } + + // ------------------------------------------------------------------------ + + public function testCensoredWords() + { + $censored = array('boob', 'nerd', 'ass', 'fart'); + + $strs = array( + 'Ted bobbled the ball' => 'Ted bobbled the ball', + 'Jake is a nerdo' => 'Jake is a nerdo', + 'The borg will assimilate you' => 'The borg will assimilate you', + 'Did Mary Fart?' => 'Did Mary $*#?', + 'Jake is really a boob' => 'Jake is really a $*#' + ); + + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, word_censor($str, $censored, '$*#')); + } + + // test censored words being sent as a string + $this->assertEquals('test', word_censor('test', 'test')); + } + + // ------------------------------------------------------------------------ + + public function testHighlightCode() + { + $code = ''; + $expect = "\n<?php var_dump(\$this); ?> \n\n"; + + $this->assertEquals($expect, highlight_code($code)); + } + + // ------------------------------------------------------------------------ + + public function testHighlightPhrase() + { + $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', + '' => '' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, highlight_phrase($str, 'this is')); + } + } + + // ------------------------------------------------------------------------ + + public function testEllipsizing() + { + $strs = array( + '0' => array( + 'this is my string' => '… my string', + "here's another one" => '…nother one', + 'this one is just a bit longer' => '…bit longer', + 'short' => 'short' + ), + '.5' => array( + 'this is my string' => 'this …tring', + "here's another one" => "here'…r one", + 'this one is just a bit longer' => 'this …onger', + 'short' => 'short' + ), + '1' => array( + 'this is my string' => 'this is my…', + "here's another one" => "here's ano…", + 'this one is just a bit longer' => 'this one i…', + 'short' => 'short' + ), + ); + + foreach ($strs as $pos => $s) + { + foreach ($s as $str => $expect) + { + $this->assertEquals($expect, ellipsize($str, 10, $pos)); + } + } + } + + // ------------------------------------------------------------------------ + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 052b01d9398de56e23300242f25d5317afcacf82 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 14:38:03 -0500 Subject: Adding string helper and inflector helper tests --- .../codeigniter/helpers/inflector_helper_test.php | 91 ++++++++++++++++ tests/codeigniter/helpers/string_helper_test.php | 117 +++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 tests/codeigniter/helpers/inflector_helper_test.php create mode 100644 tests/codeigniter/helpers/string_helper_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php new file mode 100644 index 000000000..5e2fae9fd --- /dev/null +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -0,0 +1,91 @@ + 'telly', + 'smellies' => 'smelly', + 'abjectnesses' => 'abjectness', + 'smells' => 'smell' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, singular($str)); + } + } + + // -------------------------------------------------------------------- + + public function testPlural() + { + $strs = array( + 'telly' => 'tellies', + 'smelly' => 'smellies', + 'abjectness' => 'abjectness', + 'smell' => 'smells', + 'witch' => 'witches' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, plural($str)); + } + } + + // -------------------------------------------------------------------- + + public function testCamelize() + { + $strs = array( + 'this is the string' => 'thisIsTheString', + 'this is another one' => 'thisIsAnotherOne', + 'i-am-playing-a-trick' => 'i-am-playing-a-trick', + 'what_do_you_think-yo?' => 'whatDoYouThink-yo?', + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, camelize($str)); + } + } + + // -------------------------------------------------------------------- + + public function testUnderscore() + { + $strs = array( + 'this is the string' => 'this_is_the_string', + 'this is another one' => 'this_is_another_one', + 'i-am-playing-a-trick' => 'i-am-playing-a-trick', + 'what_do_you_think-yo?' => 'what_do_you_think-yo?', + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, underscore($str)); + } + } + + // -------------------------------------------------------------------- + + public function testHumanize() + { + $strs = array( + 'this_is_the_string' => 'This Is The String', + 'this_is_another_one' => 'This Is Another One', + 'i-am-playing-a-trick' => 'I-am-playing-a-trick', + 'what_do_you_think-yo?' => 'What Do You Think-yo?', + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, humanize($str)); + } + } +} \ No newline at end of file diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php new file mode 100644 index 000000000..71449f64a --- /dev/null +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -0,0 +1,117 @@ + 'Slashes//\\', + '/var/www/html/' => 'var/www/html' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, trim_slashes($str)); + } + } + + // -------------------------------------------------------------------- + + public function testStripSlashes() + { + $this->assertEquals("This is totally foo bar'd", trim_slashes("This is totally foo bar'd")); + } + + // -------------------------------------------------------------------- + + public function testStripQuotes() + { + $strs = array( + '"me oh my!"' => 'me oh my!', + "it's a winner!" => 'its a winner!', + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, strip_quotes($str)); + } + } + + // -------------------------------------------------------------------- + + public function testQuotesToEntities() + { + $strs = array( + '"me oh my!"' => '"me oh my!"', + "it's a winner!" => 'it's a winner!', + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, quotes_to_entities($str)); + } + } + + // -------------------------------------------------------------------- + + public function testReduceDoubleSlashes() + { + $strs = array( + 'http://codeigniter.com' => 'http://codeigniter.com', + '//var/www/html/example.com/' => '/var/www/html/example.com/', + '/var/www/html//index.php' => '/var/www/html/index.php' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, reduce_double_slashes($str)); + } + } + + // -------------------------------------------------------------------- + + public function testReduceMultiples() + { + $strs = array( + 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy', + 'Ringo, John, Paul,,' => 'Ringo, John, Paul,' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, reduce_multiples($str)); + } + + $strs = array( + 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy', + 'Ringo, John, Paul,,' => 'Ringo, John, Paul' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, reduce_multiples($str, ',', TRUE)); + } + } + + // -------------------------------------------------------------------- + + public function testRepeater() + { + $strs = array( + 'a' => 'aaaaaaaaaa', + ' ' => '          ', + '
    ' => '









    ' + + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, repeater($str, 10)); + } + } + + // -------------------------------------------------------------------- + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b4d93dbab7253f98613ab10e75e0ed20f06eaf19 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 14:42:33 -0500 Subject: Updating helper test classes to extend CI_TestCase --- tests/codeigniter/helpers/array_helper_test.php | 2 +- tests/codeigniter/helpers/html_helper_test.php | 2 +- tests/codeigniter/helpers/inflector_helper_test.php | 2 +- tests/codeigniter/helpers/string_helper_test.php | 2 +- tests/codeigniter/helpers/text_helper_test.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php index bbefdb49d..fd306cee8 100644 --- a/tests/codeigniter/helpers/array_helper_test.php +++ b/tests/codeigniter/helpers/array_helper_test.php @@ -4,7 +4,7 @@ require_once(BASEPATH.'helpers/array_helper.php'); -class Array_helper_test extends PHPUnit_Framework_TestCase +class Array_helper_test extends CI_TestCase { public function setUp() { diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index 3b7f2b342..8c0e53301 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -2,7 +2,7 @@ require_once(BASEPATH.'helpers/html_helper.php'); -class Html_helper_test extends PHPUnit_Framework_TestCase +class Html_helper_test extends CI_TestCase { public function testHeading() { diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index 5e2fae9fd..e59875e4a 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -2,7 +2,7 @@ require_once(BASEPATH.'helpers/inflector_helper.php'); -class Inflector_helper_test extends PHPUnit_Framework_TestCase { +class Inflector_helper_test extends CI_TestCase { public function testSingular() diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index 71449f64a..00ba5dec7 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -2,7 +2,7 @@ require_once(BASEPATH.'helpers/string_helper.php'); -class String_helper_test extends PHPUnit_Framework_TestCase +class String_helper_test extends CI_TestCase { public function testTrimSlashes() { diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index aa6660ea0..22c834bcf 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -2,7 +2,7 @@ require_once(BASEPATH.'helpers/text_helper.php'); -class Text_helper_test extends PHPUnit_Framework_TestCase +class Text_helper_test extends CI_TestCase { private $_long_string; -- cgit v1.2.3-24-g4f1b From a7f9b251b03f7fb17251951d3024cb11fc1f881f Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 14:54:59 -0500 Subject: Parser test. --- tests/codeigniter/libraries/Parser_test.php | 42 +++++++++++------------------ 1 file changed, 16 insertions(+), 26 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php index a8de108f0..3f63bd589 100644 --- a/tests/codeigniter/libraries/Parser_test.php +++ b/tests/codeigniter/libraries/Parser_test.php @@ -2,24 +2,19 @@ // OLD TEST FORMAT: DO NOT COPY -class Parser_test extends PHPUnit_Framework_TestCase -{ - static $cls; - protected $parser; - - public static function setUpBeforeClass() - { - $CI = get_instance(); - $CI->load->library('parser'); - self::$cls = get_class($CI->parser); - } +require BASEPATH.'libraries/Parser.php'; - // -------------------------------------------------------------------- +class Parser_test extends CI_TestCase +{ public function setUp() { - $cls = self::$cls; - $this->parser = new $cls; + $obj = new StdClass; + $obj->parser = new CI_Parser(); + + $this->ci_instance($obj); + + $this->parser = $obj->parser; } // -------------------------------------------------------------------- @@ -61,23 +56,23 @@ class Parser_test extends PHPUnit_Framework_TestCase } // -------------------------------------------------------------------- - + public function testParse() { $this->_parse_no_template(); $this->_parse_var_pair(); $this->_mismatched_var_pair(); } - + // -------------------------------------------------------------------- - + private function _parse_no_template() { $this->assertFalse($this->parser->parse_string('', '', TRUE)); } - + // -------------------------------------------------------------------- - + private function _parse_var_pair() { $data = array( @@ -95,9 +90,9 @@ class Parser_test extends PHPUnit_Framework_TestCase $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE)); } - + // -------------------------------------------------------------------- - + private function _mismatched_var_pair() { $data = array( @@ -117,9 +112,4 @@ class Parser_test extends PHPUnit_Framework_TestCase } // -------------------------------------------------------------------- - - // -------------------------------------------------------------------- - - // -------------------------------------------------------------------- - } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 57fb5180092fef3de867b88a06c4e3ec232b4cd5 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 14:58:26 -0500 Subject: Cleanup in Parser_test...Adding Table_test Pascal did earlier. --- tests/codeigniter/libraries/Parser_test.php | 2 - tests/codeigniter/libraries/Table_test.php | 291 ++++++++++++++++++++++++++++ 2 files changed, 291 insertions(+), 2 deletions(-) create mode 100644 tests/codeigniter/libraries/Table_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php index 3f63bd589..44269ad2c 100644 --- a/tests/codeigniter/libraries/Parser_test.php +++ b/tests/codeigniter/libraries/Parser_test.php @@ -1,7 +1,5 @@ table = new CI_table(); + + $this->ci_instance($obj); + + $this->table = $obj->table; + } + + + // Setter Methods + // -------------------------------------------------------------------- + + public function testSetTemplate() + { + $this->assertFalse($this->table->set_template('not an array')); + + $template = array( + 'a' => 'b' + ); + + $this->table->set_template($template); + $this->assertEquals($template, $this->table->template); + } + + public function testSetEmpty() + { + $this->table->set_empty('nada'); + $this->assertEquals('nada', $this->table->empty_cells); + } + + public function testSetCaption() + { + $this->table->set_caption('awesome cap'); + $this->assertEquals('awesome cap', $this->table->caption); + } + + + /* + * @depends testPrepArgs + */ + public function testSetHeading() + { + // uses _prep_args internally, so we'll just do a quick + // check to verify that func_get_args and prep_args are + // being called. + + $this->table->set_heading('name', 'color', 'size'); + + $this->assertEquals( + array( + array('data' => 'name'), + array('data' => 'color'), + array('data' => 'size') + ), + $this->table->heading + ); + } + + + /* + * @depends testPrepArgs + */ + public function testAddRow() + { + // uses _prep_args internally, so we'll just do a quick + // check to verify that func_get_args and prep_args are + // being called. + + $this->table->add_row('my', 'pony', 'sings'); + $this->table->add_row('your', 'pony', 'stinks'); + $this->table->add_row('my pony', '>', 'your pony'); + + $this->assertEquals(count($this->table->rows), 3); + + $this->assertEquals( + array( + array('data' => 'your'), + array('data' => 'pony'), + array('data' => 'stinks') + ), + $this->table->rows[1] + ); + } + + + // Uility Methods + // -------------------------------------------------------------------- + + public function testPrepArgs() + { + $expected = array( + array('data' => 'name'), + array('data' => 'color'), + array('data' => 'size') + ); + + // test what would be discreet args, + // basically means a single array as the calling method + // will use func_get_args() + $this->assertEquals( + $expected, + $this->table->_prep_args(array( + 'name', 'color', 'size' + )), + 'discreet'); + + + // test what would be a single array argument. Again, nested + // due to func_get_args on calling methods + $this->assertEquals( + $expected, + $this->table->_prep_args(array( + array('name', 'color', 'size') + )), + 'array'); + + + // with cell attributes + + // need to add that new argument row to our expected outcome + $expected[] = array('data' => 'weight', 'class' => 'awesome'); + + $this->assertEquals( + $expected, + $this->table->_prep_args(array( + array('name', 'color', 'size', + array('data' => 'weight', 'class' => 'awesome') + ) + )), + 'attributes'); + } + + public function testDefaultTemplateKeys() + { + $deft_template = $this->table->_default_template(); + $keys = array( + 'table_open', + 'thead_open', 'thead_close', + 'heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', + 'tbody_open', 'tbody_close', + 'row_start', 'row_end', 'cell_start', 'cell_end', + 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', + 'table_close' + ); + + foreach ($keys as $key) + { + $this->assertArrayHasKey($key, $deft_template); + } + } + + public function testCompileTemplate() + { + $this->assertFalse($this->table->set_template('invalid_junk')); + + // non default key + $this->table->set_template(array('nonsense' => 'foo')); + $this->table->_compile_template(); + + $this->assertArrayHasKey('nonsense', $this->table->template); + $this->assertEquals('foo', $this->table->template['nonsense']); + + // override default + $this->table->set_template(array('table_close' => '')); + $this->table->_compile_template(); + + $this->assertArrayHasKey('table_close', $this->table->template); + $this->assertEquals('', $this->table->template['table_close']); + } + + public function testMakeColumns() + { + // Test bogus parameters + $this->assertFalse($this->table->make_columns('invalid_junk')); + $this->assertFalse( $this->table->make_columns(array())); + // $this->assertFalse( + // $this->table->make_columns(array('one', 'two')), + // '2.5' // not an integer! + // ); + + + // Now on to the actual column creation + + $five_values = array( + 'Laura', 'Red', '15', + 'Katie', 'Blue' + ); + + // No column count - no changes to the array + $this->assertEquals( + $five_values, + $this->table->make_columns($five_values) + ); + + // Column count of 3 leaves us with one   + $this->assertEquals( + array( + array('Laura', 'Red', '15'), + array('Katie', 'Blue', ' ') + ), + $this->table->make_columns($five_values, 3) + ); + + $this->markTestSkipped('Look at commented assertFalse above'); + } + + public function testClear() + { + $this->table->set_heading('Name', 'Color', 'Size'); + + // Make columns changes auto_heading + $rows = $this->table->make_columns(array( + 'Laura', 'Red', '15', + 'Katie', 'Blue' + ), 3); + + foreach ($rows as $row) + { + $this->table->add_row($row); + } + + $this->assertFalse($this->table->auto_heading); + $this->assertEquals(count($this->table->heading), 3); + $this->assertEquals(count($this->table->rows), 2); + + $this->table->clear(); + + $this->assertTrue($this->table->auto_heading); + $this->assertEmpty($this->table->heading); + $this->assertEmpty($this->table->rows); + } + + + public function testSetFromArray() + { + $this->assertFalse($this->table->_set_from_array('bogus')); + $this->assertFalse($this->table->_set_from_array(array())); + + $data = array( + array('name', 'color', 'number'), + array('Laura', 'Red', '22'), + array('Katie', 'Blue') + ); + + $this->table->_set_from_array($data, FALSE); + $this->assertEmpty($this->table->heading); + + $this->table->clear(); + + $expected_heading = array( + array('data' => 'name'), + array('data' => 'color'), + array('data' => 'number') + ); + + $expected_second = array( + array('data' => 'Katie'), + array('data' => 'Blue'), + ); + + $this->table->_set_from_array($data); + $this->assertEquals(count($this->table->rows), 2); + + $this->assertEquals( + $expected_heading, + $this->table->heading + ); + + $this->assertEquals( + $expected_second, + $this->table->rows[1] + ); + } + + function testSetFromObject() + { + $this->markTestSkipped('Not yet implemented.'); + } + + // Test main generate method + // -------------------------------------------------------------------- +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 2cadade8e3598fc4d19a3029db0b861a8d3bfc80 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 15:00:49 -0500 Subject: Adding typography library test. --- tests/codeigniter/libraries/Typography_test.php | 191 ++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 tests/codeigniter/libraries/Typography_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/libraries/Typography_test.php b/tests/codeigniter/libraries/Typography_test.php new file mode 100644 index 000000000..242a6e944 --- /dev/null +++ b/tests/codeigniter/libraries/Typography_test.php @@ -0,0 +1,191 @@ +type = new CI_Typography(); + + $this->ci_instance($obj); + + $this->type = $obj->type; + } + + // -------------------------------------------------------------------- + + /** + * Tests the format_characters() function. + * + * this can and should grow. + */ + public function testFormatCharacters() + { + $strs = array( + '"double quotes"' => '“double quotes”', + '"testing" in "theory" that is' => '“testing” in “theory” that is', + "Here's what I'm" => 'Here’s what I’m', + '&' => '&', + '&' => '&', + ' ' => ' ', + '--' => '—', + 'foo...' => 'foo…', + 'foo..' => 'foo..', + 'foo...bar.' => 'foo…bar.', + 'test. new' => 'test.  new', + ); + + foreach ($strs as $str => $expected) + { + $this->assertEquals($expected, $this->type->format_characters($str)); + } + } + + // -------------------------------------------------------------------- + + public function testNl2brExceptPre() + { + $str = << +I am inside a pre tag. Please don't mess with me. + +k? + + +That's my story and I'm sticking to it. + +The End. +EOH; + + $expected = << +
    +I like to skip.
    +
    +Jump
    +
    +and sing.
    +
    +
    +I am inside a pre tag.  Please don't mess with me.
    +
    +k?
    +

    +
    +That's my story and I'm sticking to it.
    +
    +The End. +EOH; + + $this->assertEquals($expected, + $this->type->nl2br_except_pre($str)); + } + + // -------------------------------------------------------------------- + + public function testAutoTypography() + { + $this->_blank_string(); + $this->_standardize_new_lines(); + $this->_reduce_linebreaks(); + $this->_remove_comments(); + $this->_protect_pre(); + $this->_no_opening_block(); + $this->_protect_braced_quotes(); + } + + // -------------------------------------------------------------------- + + private function _blank_string() + { + // Test blank string + $this->assertEquals('', $this->type->auto_typography('')); + } + + // -------------------------------------------------------------------- + + private function _standardize_new_lines() + { + $strs = array( + "My string\rhas return characters" => "

    My string
    \nhas return characters

    ", + 'This one does not!' => '

    This one does not!

    ' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, $this->type->auto_typography($str)); + } + } + + // -------------------------------------------------------------------- + + private function _reduce_linebreaks() + { + $str = "This has way too many linebreaks.\n\n\n\nSee?"; + $expect = "

    This has way too many linebreaks.

    \n\n

    See?

    "; + + $this->assertEquals($expect, $this->type->auto_typography($str, TRUE)); + } + + // -------------------------------------------------------------------- + + private function _remove_comments() + { + $str = ' But no!'; + $expect = '

      But no!

    '; + + $this->assertEquals($expect, $this->type->auto_typography($str)); + } + + // -------------------------------------------------------------------- + + private function _protect_pre() + { + $str = '

    My Sentence

    var_dump($this);
    '; + $expect = '

    My Sentence

    var_dump($this);
    '; + + $this->assertEquals($expect, $this->type->auto_typography($str)); + } + + // -------------------------------------------------------------------- + + private function _no_opening_block() + { + $str = 'My Sentence
    var_dump($this);
    '; + $expect = '

    My Sentence

    var_dump($this);
    '; + + $this->assertEquals($expect, $this->type->auto_typography($str)); + } + + // -------------------------------------------------------------------- + + public function _protect_braced_quotes() + { + $this->type->protect_braced_quotes = TRUE; + + $str = 'Test {parse="foobar"}'; + $expect = '

    Test {parse="foobar"}

    '; + + $this->assertEquals($expect, $this->type->auto_typography($str)); + + $this->type->protect_braced_quotes = FALSE; + + $str = 'Test {parse="foobar"}'; + $expect = '

    Test {parse=“foobar”}

    '; + + $this->assertEquals($expect, $this->type->auto_typography($str)); + + + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9512ab8a22ff14a3789cba6e5ace03aed4196e23 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 15:10:48 -0500 Subject: Adding user agent library test. Needs some work, but is a good start. --- tests/codeigniter/libraries/User_agent_test.php | 91 +++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/codeigniter/libraries/User_agent_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/libraries/User_agent_test.php b/tests/codeigniter/libraries/User_agent_test.php new file mode 100644 index 000000000..d1d950cd9 --- /dev/null +++ b/tests/codeigniter/libraries/User_agent_test.php @@ -0,0 +1,91 @@ +_user_agent; + + $obj = new StdClass; + $obj->agent = new CI_User_agent(); + + $this->ci_instance($obj); + + $this->agent = $obj->agent; + } + + // -------------------------------------------------------------------- + + public function testAcceptLang() + { + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en'; + + $this->assertEquals('en', $this->agent->accept_lang()); + + unset($_SERVER['HTTP_ACCEPT_LANGUAGE']); + } + + // -------------------------------------------------------------------- + + public function testMobile() + { + // Mobile Not Set + $_SERVER['HTTP_USER_AGENT'] = $this->_mobile_ua; + $this->assertEquals('', $this->agent->mobile()); + unset($_SERVER['HTTP_USER_AGENT']); + } + + // -------------------------------------------------------------------- + + public function testUtilIsFunctions() + { + $this->assertTrue($this->agent->is_browser()); + $this->assertFalse($this->agent->is_robot()); + $this->assertFalse($this->agent->is_mobile()); + $this->assertFalse($this->agent->is_referral()); + } + + // -------------------------------------------------------------------- + + public function testAgentString() + { + $this->assertEquals($this->_user_agent, $this->agent->agent_string()); + } + + // -------------------------------------------------------------------- + + public function testBrowserInfo() + { + $this->assertEquals('Mac OS X', $this->agent->platform()); + $this->assertEquals('Safari', $this->agent->browser()); + $this->assertEquals('533.20.27', $this->agent->version()); + $this->assertEquals('', $this->agent->robot()); + $this->assertEquals('', $this->agent->referrer()); + } + + // -------------------------------------------------------------------- + + public function testCharsets() + { + $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8'; + + $charsets = $this->agent->charsets(); + + $this->assertEquals('utf8', $charsets[0]); + + unset($_SERVER['HTTP_ACCEPT_CHARSET']); + + $this->assertFalse($this->agent->accept_charset()); + } + + // -------------------------------------------------------------------- + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 68286a4dcc1ed4d904ad992173c1b3621bf6fced Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Thu, 21 Apr 2011 22:00:33 -0400 Subject: Reworked unit tests to match rest of framework and added a few more. --- tests/codeigniter/Setup_test.php | 2 +- tests/codeigniter/core/Common_test.php | 16 +++++++++++++ tests/codeigniter/core/Config_test.php | 12 +++++----- tests/codeigniter/core/Lang_test.php | 6 ++--- tests/codeigniter/core/Loader_test.php | 28 +++++++++++----------- tests/codeigniter/helpers/array_helper_test.php | 8 +++---- tests/codeigniter/helpers/email_helper_test.php | 16 +++++++++++++ tests/codeigniter/helpers/html_helper_test.php | 19 +++++++++++---- .../codeigniter/helpers/inflector_helper_test.php | 10 ++++---- tests/codeigniter/helpers/number_helper_test.php | 13 ++++++++++ tests/codeigniter/helpers/string_helper_test.php | 27 +++++++++++---------- tests/codeigniter/helpers/text_helper_test.php | 26 +++++++++++++------- tests/codeigniter/helpers/xml_helper_test.php | 13 ++++++++++ tests/codeigniter/libraries/Parser_test.php | 8 +++---- tests/codeigniter/libraries/Table_test.php | 26 ++++++++++---------- tests/codeigniter/libraries/Typography_test.php | 8 +++---- tests/codeigniter/libraries/User_agent_test.php | 14 +++++------ 17 files changed, 165 insertions(+), 87 deletions(-) create mode 100644 tests/codeigniter/core/Common_test.php create mode 100644 tests/codeigniter/helpers/email_helper_test.php create mode 100644 tests/codeigniter/helpers/number_helper_test.php create mode 100644 tests/codeigniter/helpers/xml_helper_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php index e088b51d3..550245f2f 100644 --- a/tests/codeigniter/Setup_test.php +++ b/tests/codeigniter/Setup_test.php @@ -2,7 +2,7 @@ class Setup_test extends PHPUnit_Framework_TestCase { - function testNonsense() + function test_nonsense() { $this->markTestIncomplete('not implemented'); // ensure that our bootstrapped test environment diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php new file mode 100644 index 000000000..cec12982d --- /dev/null +++ b/tests/codeigniter/core/Common_test.php @@ -0,0 +1,16 @@ +assertEquals(TRUE, is_php('1.2.0')); + $this->assertEquals(FALSE, is_php('9999.9.9')); + } + +} \ No newline at end of file diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php index b04dd67fa..b6c57da70 100644 --- a/tests/codeigniter/core/Config_test.php +++ b/tests/codeigniter/core/Config_test.php @@ -2,7 +2,7 @@ class Config_test extends CI_TestCase { - public function setUp() + public function set_up() { $cls =& $this->ci_core_class('cfg'); @@ -18,7 +18,7 @@ class Config_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testItem() + public function test_item() { $this->assertEquals('http://example.com/', $this->config->item('base_url')); @@ -32,7 +32,7 @@ class Config_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testSetItem() + public function test_set_item() { $this->assertFalse($this->config->item('not_yet_set')); @@ -43,7 +43,7 @@ class Config_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testSlashItem() + public function test_slash_item() { // Bad Config value $this->assertFalse($this->config->slash_item('no_good_item')); @@ -55,7 +55,7 @@ class Config_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testSiteUrl() + public function test_site_url() { $this->assertEquals('http://example.com/index.php', $this->config->site_url()); @@ -85,7 +85,7 @@ class Config_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testSystemUrl() + public function test_system_url() { $this->assertEquals('http://example.com/system/', $this->config->system_url()); } diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php index f65b335b0..dcc3d0879 100644 --- a/tests/codeigniter/core/Lang_test.php +++ b/tests/codeigniter/core/Lang_test.php @@ -4,7 +4,7 @@ class Lang_test extends CI_TestCase { protected $lang; - public function setUp() + public function set_up() { $cls = $this->ci_core_class('lang'); $this->lang = new $cls; @@ -12,7 +12,7 @@ class Lang_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testLoad() + public function test_load() { // get_config needs work $this->markTestIncomplete('get_config needs work'); @@ -21,7 +21,7 @@ class Lang_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testLine() + public function test_line() { $this->markTestIncomplete('get_config needs work'); diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 49679e241..9ba870b7d 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -37,7 +37,7 @@ class Loader_test extends CI_TestCase { private $ci_obj; - public function setUp() + public function set_up() { // Instantiate a new loader $this->load = new Extended_Loader(); @@ -51,7 +51,7 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testLibrary() + public function test_library() { $this->_setup_config_mock(); @@ -69,7 +69,7 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testLoadLibraryInApplicationDir() + public function test_load_library_in_application_dir() { $this->_setup_config_mock(); @@ -101,7 +101,7 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testNonExistentModel() + public function test_non_existent_model() { $this->setExpectedException( 'Exception', @@ -116,7 +116,7 @@ class Loader_test extends CI_TestCase { /** * @coverts CI_Loader::model */ - public function testModels() + public function test_models() { $this->ci_set_core_class('model', 'CI_Model'); @@ -147,7 +147,7 @@ class Loader_test extends CI_TestCase { /** * @coverts CI_Loader::view */ - public function testLoadView() + public function test_load_view() { $this->ci_set_core_class('output', 'CI_Output'); @@ -158,7 +158,7 @@ class Loader_test extends CI_TestCase { // Use the optional return parameter in this test, so the view is not // run through the output class. $this->assertEquals('This is my test page. World!', - $this->load->view('unit_test_view', array('hello' => "World!"), TRUE)); + $this->load->view('unit_test_view', array('hello' => "World!"), TRUE)); } @@ -167,7 +167,7 @@ class Loader_test extends CI_TestCase { /** * @coverts CI_Loader::view */ - public function testNonExistentView() + public function test_non_existent_view() { $this->setExpectedException( 'Exception', @@ -179,7 +179,7 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testFile() + public function test_file() { $content = 'Here is a test file, which we will load now.'; $file = vfsStream::newFile('ci_test_mock_file.php')->withContent($content) @@ -202,7 +202,7 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testVars() + public function test_vars() { $vars = array( 'foo' => 'bar' @@ -214,7 +214,7 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testHelper() + public function test_helper() { $this->assertEquals(NULL, $this->load->helper('array')); @@ -228,7 +228,7 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testLoadingMultipleHelpers() + public function test_loading_multiple_helpers() { $this->assertEquals(NULL, $this->load->helpers(array('file', 'array', 'string'))); } @@ -242,7 +242,7 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testLoadConfig() + public function test_load_config() { $this->_setup_config_mock(); @@ -251,7 +251,7 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testLoadBadConfig() + public function test_load_bad_config() { $this->_setup_config_mock(); diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php index fd306cee8..62559de83 100644 --- a/tests/codeigniter/helpers/array_helper_test.php +++ b/tests/codeigniter/helpers/array_helper_test.php @@ -6,7 +6,7 @@ require_once(BASEPATH.'helpers/array_helper.php'); class Array_helper_test extends CI_TestCase { - public function setUp() + public function set_up() { $this->my_array = array( 'foo' => 'bar', @@ -18,7 +18,7 @@ class Array_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testElementWithExistingItem() + public function test_element_with_existing_item() { $this->assertEquals(FALSE, element('testing', $this->my_array)); @@ -29,7 +29,7 @@ class Array_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testRandomElement() + public function test_random_element() { // Send a string, not an array to random_element $this->assertEquals('my string', random_element('my string')); @@ -40,7 +40,7 @@ class Array_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testElements() + public function test_elements() { $this->assertEquals(TRUE, is_array(elements('test', $this->my_array))); $this->assertEquals(TRUE, is_array(elements('foo', $this->my_array))); diff --git a/tests/codeigniter/helpers/email_helper_test.php b/tests/codeigniter/helpers/email_helper_test.php new file mode 100644 index 000000000..7324e8109 --- /dev/null +++ b/tests/codeigniter/helpers/email_helper_test.php @@ -0,0 +1,16 @@ +assertEquals(FALSE, valid_email('test')); + $this->assertEquals(FALSE, valid_email('test@test@test.com')); + $this->assertEquals(TRUE, valid_email('test@test.com')); + $this->assertEquals(TRUE, valid_email('my.test@test.com')); + } + +} \ No newline at end of file diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index 8c0e53301..706874f9e 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -4,14 +4,25 @@ require_once(BASEPATH.'helpers/html_helper.php'); class Html_helper_test extends CI_TestCase { - public function testHeading() + + // ------------------------------------------------------------------------ + + public function test_br() + { + $this->assertEquals('

    ', br(2)); + } + + // ------------------------------------------------------------------------ + + public function test_heading() { $this->assertEquals('

    foobar

    ', heading('foobar')); + $this->assertEquals('

    foobar

    ', heading('foobar', 2, 'class="bar"')); } // ------------------------------------------------------------------------ - public function testUl() + public function test_Ul() { $expect = << @@ -47,14 +58,14 @@ EOH; // ------------------------------------------------------------------------ - public function testNBS() + public function test_NBS() { $this->assertEquals('   ', nbs(3)); } // ------------------------------------------------------------------------ - public function testMeta() + public function test_meta() { $this->assertEquals("\n", meta('test', 'foo')); diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index e59875e4a..34bc34ebb 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -5,7 +5,7 @@ require_once(BASEPATH.'helpers/inflector_helper.php'); class Inflector_helper_test extends CI_TestCase { - public function testSingular() + public function test_singular() { $strs = array( 'tellies' => 'telly', @@ -22,7 +22,7 @@ class Inflector_helper_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testPlural() + public function test_plural() { $strs = array( 'telly' => 'tellies', @@ -40,7 +40,7 @@ class Inflector_helper_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testCamelize() + public function test_camelize() { $strs = array( 'this is the string' => 'thisIsTheString', @@ -57,7 +57,7 @@ class Inflector_helper_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testUnderscore() + public function test_underscore() { $strs = array( 'this is the string' => 'this_is_the_string', @@ -74,7 +74,7 @@ class Inflector_helper_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testHumanize() + public function test_humanize() { $strs = array( 'this_is_the_string' => 'This Is The String', diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php new file mode 100644 index 000000000..02fc49c3d --- /dev/null +++ b/tests/codeigniter/helpers/number_helper_test.php @@ -0,0 +1,13 @@ +assertEquals('456 Bytes', byte_format(456)); + } + +} \ No newline at end of file diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index 00ba5dec7..5e0ee45de 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -4,7 +4,7 @@ require_once(BASEPATH.'helpers/string_helper.php'); class String_helper_test extends CI_TestCase { - public function testTrimSlashes() + public function test_trim_slashes() { $strs = array( '//Slashes//\/' => 'Slashes//\\', @@ -17,16 +17,9 @@ class String_helper_test extends CI_TestCase } } - // -------------------------------------------------------------------- - - public function testStripSlashes() - { - $this->assertEquals("This is totally foo bar'd", trim_slashes("This is totally foo bar'd")); - } - // -------------------------------------------------------------------- - public function testStripQuotes() + public function test_strip_quotes() { $strs = array( '"me oh my!"' => 'me oh my!', @@ -41,7 +34,7 @@ class String_helper_test extends CI_TestCase // -------------------------------------------------------------------- - public function testQuotesToEntities() + public function test_quotes_to_entities() { $strs = array( '"me oh my!"' => '"me oh my!"', @@ -56,7 +49,7 @@ class String_helper_test extends CI_TestCase // -------------------------------------------------------------------- - public function testReduceDoubleSlashes() + public function test_reduce_double_slashes() { $strs = array( 'http://codeigniter.com' => 'http://codeigniter.com', @@ -72,7 +65,7 @@ class String_helper_test extends CI_TestCase // -------------------------------------------------------------------- - public function testReduceMultiples() + public function test_reduce_multiples() { $strs = array( 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy', @@ -97,7 +90,7 @@ class String_helper_test extends CI_TestCase // -------------------------------------------------------------------- - public function testRepeater() + public function test_repeater() { $strs = array( 'a' => 'aaaaaaaaaa', @@ -114,4 +107,12 @@ class String_helper_test extends CI_TestCase // -------------------------------------------------------------------- + + public function test_random_string() + { + $this->assertEquals(16, strlen(random_string('alnum', 16))); + $this->assertEquals(32, strlen(random_string('unique', 16))); + $this->assertInternalType('string', random_string('numeric', 16)); + } + } \ No newline at end of file diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 22c834bcf..a0866e638 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -6,14 +6,14 @@ class Text_helper_test extends CI_TestCase { private $_long_string; - public function setUp() + public function set_up() { $this->_long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.'; } // ------------------------------------------------------------------------ - public function testWordLimiter() + public function test_word_limiter() { $this->assertEquals('Once upon a time,…', word_limiter($this->_long_string, 4)); $this->assertEquals('Once upon a time,…', word_limiter($this->_long_string, 4, '…')); @@ -22,7 +22,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testCharacterLimiter() + public function test_character_limiter() { $this->assertEquals('Once upon a time, a…', character_limiter($this->_long_string, 20)); $this->assertEquals('Once upon a time, a…', character_limiter($this->_long_string, 20, '…')); @@ -32,7 +32,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testAsciiToEntities() + public function test_ascii_to_entities() { $strs = array( '“‘ “test”' => '“‘ “test”', @@ -47,7 +47,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testEntitiesToAscii() + public function test_entities_to_ascii() { $strs = array( '“‘ “test”' => '“‘ “test”', @@ -59,10 +59,18 @@ class Text_helper_test extends CI_TestCase $this->assertEquals($expect, entities_to_ascii($str)); } } + + // ------------------------------------------------------------------------ + + function test_convert_accented_characters() + { + $this->assertEquals('AAAeEEEIIOOEUUUeY', convert_accented_characters('ÀÂÄÈÊËÎÏÔŒÙÛÜŸ')); + $this->assertEquals('a e i o u n ue', convert_accented_characters('á é í ó ú ñ ü')); + } // ------------------------------------------------------------------------ - public function testCensoredWords() + public function test_censored_words() { $censored = array('boob', 'nerd', 'ass', 'fart'); @@ -86,7 +94,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testHighlightCode() + public function test_highlight_code() { $code = ''; $expect = "\n<?php var_dump(\$this); ?> \n\n"; @@ -96,7 +104,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testHighlightPhrase() + public function test_highlight_phrase() { $strs = array( 'this is a phrase' => 'this is a phrase', @@ -114,7 +122,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testEllipsizing() + public function test_ellipsizing() { $strs = array( '0' => array( diff --git a/tests/codeigniter/helpers/xml_helper_test.php b/tests/codeigniter/helpers/xml_helper_test.php new file mode 100644 index 000000000..49f49e166 --- /dev/null +++ b/tests/codeigniter/helpers/xml_helper_test.php @@ -0,0 +1,13 @@ +assertEquals('<tag>my & test - </tag>', xml_convert('my & test - ')); + } + +} \ No newline at end of file diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php index 44269ad2c..b4580a4b1 100644 --- a/tests/codeigniter/libraries/Parser_test.php +++ b/tests/codeigniter/libraries/Parser_test.php @@ -5,7 +5,7 @@ require BASEPATH.'libraries/Parser.php'; class Parser_test extends CI_TestCase { - public function setUp() + public function set_up() { $obj = new StdClass; $obj->parser = new CI_Parser(); @@ -16,7 +16,7 @@ class Parser_test extends CI_TestCase } // -------------------------------------------------------------------- - public function testSetDelimiters() + public function test_set_delimiters() { // Make sure default delimiters are there $this->assertEquals('{', $this->parser->l_delim); @@ -39,7 +39,7 @@ class Parser_test extends CI_TestCase // -------------------------------------------------------------------- - public function testParseSimpleString() + public function test_parse_simple_string() { $data = array( 'title' => 'Page Title', @@ -55,7 +55,7 @@ class Parser_test extends CI_TestCase // -------------------------------------------------------------------- - public function testParse() + public function test_parse() { $this->_parse_no_template(); $this->_parse_var_pair(); diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index ded4c22c1..133179f3a 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -5,7 +5,7 @@ require BASEPATH.'libraries/Table.php'; class Table_test extends CI_TestCase { - public function setUp() + public function set_up() { $obj = new StdClass; $obj->table = new CI_table(); @@ -19,7 +19,7 @@ class Table_test extends CI_TestCase // Setter Methods // -------------------------------------------------------------------- - public function testSetTemplate() + public function test_set_template() { $this->assertFalse($this->table->set_template('not an array')); @@ -31,13 +31,13 @@ class Table_test extends CI_TestCase $this->assertEquals($template, $this->table->template); } - public function testSetEmpty() + public function test_set_empty() { $this->table->set_empty('nada'); $this->assertEquals('nada', $this->table->empty_cells); } - public function testSetCaption() + public function test_set_caption() { $this->table->set_caption('awesome cap'); $this->assertEquals('awesome cap', $this->table->caption); @@ -47,7 +47,7 @@ class Table_test extends CI_TestCase /* * @depends testPrepArgs */ - public function testSetHeading() + public function test_set_heading() { // uses _prep_args internally, so we'll just do a quick // check to verify that func_get_args and prep_args are @@ -69,7 +69,7 @@ class Table_test extends CI_TestCase /* * @depends testPrepArgs */ - public function testAddRow() + public function test_add_row() { // uses _prep_args internally, so we'll just do a quick // check to verify that func_get_args and prep_args are @@ -95,7 +95,7 @@ class Table_test extends CI_TestCase // Uility Methods // -------------------------------------------------------------------- - public function testPrepArgs() + public function test_prep_args() { $expected = array( array('data' => 'name'), @@ -139,7 +139,7 @@ class Table_test extends CI_TestCase 'attributes'); } - public function testDefaultTemplateKeys() + public function test_default_template_keys() { $deft_template = $this->table->_default_template(); $keys = array( @@ -158,7 +158,7 @@ class Table_test extends CI_TestCase } } - public function testCompileTemplate() + public function test_compile_template() { $this->assertFalse($this->table->set_template('invalid_junk')); @@ -177,7 +177,7 @@ class Table_test extends CI_TestCase $this->assertEquals('', $this->table->template['table_close']); } - public function testMakeColumns() + public function test_make_columns() { // Test bogus parameters $this->assertFalse($this->table->make_columns('invalid_junk')); @@ -213,7 +213,7 @@ class Table_test extends CI_TestCase $this->markTestSkipped('Look at commented assertFalse above'); } - public function testClear() + public function test_clear() { $this->table->set_heading('Name', 'Color', 'Size'); @@ -240,7 +240,7 @@ class Table_test extends CI_TestCase } - public function testSetFromArray() + public function test_set_from_array() { $this->assertFalse($this->table->_set_from_array('bogus')); $this->assertFalse($this->table->_set_from_array(array())); @@ -281,7 +281,7 @@ class Table_test extends CI_TestCase ); } - function testSetFromObject() + function test_set_from_object() { $this->markTestSkipped('Not yet implemented.'); } diff --git a/tests/codeigniter/libraries/Typography_test.php b/tests/codeigniter/libraries/Typography_test.php index 242a6e944..a0533bae0 100644 --- a/tests/codeigniter/libraries/Typography_test.php +++ b/tests/codeigniter/libraries/Typography_test.php @@ -5,7 +5,7 @@ require BASEPATH.'libraries/Typography.php'; class Typography_test extends CI_TestCase { - public function setUp() + public function set_up() { $obj = new StdClass; $obj->type = new CI_Typography(); @@ -22,7 +22,7 @@ class Typography_test extends CI_TestCase * * this can and should grow. */ - public function testFormatCharacters() + public function test_format_characters() { $strs = array( '"double quotes"' => '“double quotes”', @@ -46,7 +46,7 @@ class Typography_test extends CI_TestCase // -------------------------------------------------------------------- - public function testNl2brExceptPre() + public function test_nl2br_except_pre() { $str = <<_blank_string(); $this->_standardize_new_lines(); diff --git a/tests/codeigniter/libraries/User_agent_test.php b/tests/codeigniter/libraries/User_agent_test.php index d1d950cd9..277c12ed0 100644 --- a/tests/codeigniter/libraries/User_agent_test.php +++ b/tests/codeigniter/libraries/User_agent_test.php @@ -9,7 +9,7 @@ class UserAgent_test extends CI_TestCase protected $_user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27'; protected $_mobile_ua = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7'; - public function setUp() + public function set_up() { // set a baseline user agent $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent; @@ -24,7 +24,7 @@ class UserAgent_test extends CI_TestCase // -------------------------------------------------------------------- - public function testAcceptLang() + public function test_accept_lang() { $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en'; @@ -35,7 +35,7 @@ class UserAgent_test extends CI_TestCase // -------------------------------------------------------------------- - public function testMobile() + public function test_mobile() { // Mobile Not Set $_SERVER['HTTP_USER_AGENT'] = $this->_mobile_ua; @@ -45,7 +45,7 @@ class UserAgent_test extends CI_TestCase // -------------------------------------------------------------------- - public function testUtilIsFunctions() + public function test_util_is_functions() { $this->assertTrue($this->agent->is_browser()); $this->assertFalse($this->agent->is_robot()); @@ -55,14 +55,14 @@ class UserAgent_test extends CI_TestCase // -------------------------------------------------------------------- - public function testAgentString() + public function test_agent_string() { $this->assertEquals($this->_user_agent, $this->agent->agent_string()); } // -------------------------------------------------------------------- - public function testBrowserInfo() + public function test_browser_info() { $this->assertEquals('Mac OS X', $this->agent->platform()); $this->assertEquals('Safari', $this->agent->browser()); @@ -73,7 +73,7 @@ class UserAgent_test extends CI_TestCase // -------------------------------------------------------------------- - public function testCharsets() + public function test_charsets() { $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8'; -- cgit v1.2.3-24-g4f1b From d92277d650139af381a856cfa8f23a42b8ce04cb Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Fri, 22 Apr 2011 12:56:22 -0500 Subject: Initial commit of file helper tests. --- tests/codeigniter/helpers/file_helper_test.php | 157 +++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 tests/codeigniter/helpers/file_helper_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php new file mode 100644 index 000000000..a596a0375 --- /dev/null +++ b/tests/codeigniter/helpers/file_helper_test.php @@ -0,0 +1,157 @@ +_test_dir = vfsStreamWrapper::getRoot(); + } + + // -------------------------------------------------------------------- + + public function test_read_file() + { + $this->assertFalse(read_file('does_not_exist')); + + $content = 'Jack and Jill went up the mountain to fight a billy goat.'; + + $file = vfsStream::newFile('my_file.txt')->withContent($content) + ->at($this->_test_dir); + + $this->assertEquals($content, read_file(vfsStream::url('my_file.txt'))); + } + + // -------------------------------------------------------------------- + + public function test_octal_permissions() + { + $content = 'Jack and Jill went up the mountain to fight a billy goat.'; + + $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) + ->lastModified(time() - 86400) + ->at($this->_test_dir); + + $this->assertEquals('777', octal_permissions($file->getPermissions())); + } + + // -------------------------------------------------------------------- + + /** + * More tests should happen here, since I'm not hitting the whole function. + */ + public function test_symbolic_permissions() + { + $content = 'Jack and Jill went up the mountain to fight a billy goat.'; + + $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) + ->lastModified(time() - 86400) + ->at($this->_test_dir); + + $this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions())); + } + + // -------------------------------------------------------------------- + + public function test_get_mime_by_extension() + { + $content = 'Jack and Jill went up the mountain to fight a billy goat.'; + + $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) + ->lastModified(time() - 86400) + ->at($this->_test_dir); + + $this->assertEquals('text/plain', + get_mime_by_extension(vfsStream::url('my_file.txt'))); + + // Test a mime with an array, such as png + $file = vfsStream::newFile('foo.png')->at($this->_test_dir); + + $this->assertEquals('image/png', get_mime_by_extension(vfsStream::url('foo.png'))); + + // Test a file not in the mimes array + $file = vfsStream::newFile('foo.blarfengar')->at($this->_test_dir); + + $this->assertFalse(get_mime_by_extension(vfsStream::url('foo.blarfengar'))); + } + + // -------------------------------------------------------------------- + + public function test_get_file_info() + { + // Test Bad File + $this->assertFalse(get_file_info('i_am_bad_boo')); + + // Test the rest + + // First pass in an array + $vals = array( + 'name', 'server_path', 'size', 'date', + 'readable', 'writable', 'executable', 'fileperms' + ); + + $this->_test_get_file_info($vals); + + // Test passing in vals as a string. + $vals = 'name, server_path, size, date, readable, writable, executable, fileperms'; + $this->_test_get_file_info($vals); + } + + private function _test_get_file_info($vals) + { + $content = 'Jack and Jill went up the mountain to fight a billy goat.'; + $last_modified = time() - 86400; + + $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) + ->lastModified($last_modified) + ->at($this->_test_dir); + + $ret_values = array( + 'name' => 'my_file.txt', + 'server_path' => 'vfs://my_file.txt', + 'size' => 57, + 'date' => $last_modified, + 'readable' => TRUE, + 'writable' => TRUE, + 'executable' => TRUE, + 'fileperms' => 33279 + ); + + $info = get_file_info(vfsStream::url('my_file.txt'), $vals); + + foreach ($info as $k => $v) + { + $this->assertEquals($ret_values[$k], $v); + } + } + + // -------------------------------------------------------------------- + + // Skipping for now, as it's not implemented in vfsStreamWrapper + // flock(): vfsStreamWrapper::stream_lock is not implemented! + + // public function test_write_file() + // { + // if ( ! defined('FOPEN_WRITE_CREATE_DESTRUCTIVE')) + // { + // define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); + // } + // + // $content = 'Jack and Jill went up the mountain to fight a billy goat.'; + // + // $file = vfsStream::newFile('write.txt', 0777)->withContent('') + // ->lastModified(time() - 86400) + // ->at($this->_test_dir); + // + // $this->assertTrue(write_file(vfsStream::url('write.txt'), $content)); + // + // } + + // -------------------------------------------------------------------- + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 19379ef47a6bc0a788c65038bb59eca0b6624848 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Tue, 3 May 2011 22:16:11 -0400 Subject: Added unit tests for number helper. --- tests/codeigniter/helpers/number_helper_test.php | 71 +++++++++++++++++++++++- 1 file changed, 68 insertions(+), 3 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php index 02fc49c3d..3322b2475 100644 --- a/tests/codeigniter/helpers/number_helper_test.php +++ b/tests/codeigniter/helpers/number_helper_test.php @@ -1,13 +1,78 @@ ci_core_class('lang'); + + // Mock away load, too much going on in there, + // we'll just check for the expected parameter + + $lang = $this->getMock($lang_cls, array('load')); + $lang->expects($this->once()) + ->method('load') + ->with($this->equalTo('number')); + + // Assign the proper language array + + $lang->language = $this->_get_lang('number'); + + // We don't have a controller, so just create + // a cheap class to act as our super object. + // Make sure it has a lang attribute. + + $obj = new StdClass; + $obj->lang = $lang; + $this->ci_instance($obj); + } + + // Quick helper to actually grab the language + // file. Consider moving this to ci_testcase? + public function _get_lang($name) + { + require BASEPATH.'language/english/'.$name.'_lang.php'; + return $lang; + } + public function test_byte_format() { - // $this->assertEquals('456 Bytes', byte_format(456)); + $this->assertEquals('456 Bytes', byte_format(456)); + } + + public function test_kb_format() + { + $this->assertEquals('4.5 KB', byte_format(4567)); + } + + public function test_kb_format_medium() + { + $this->assertEquals('44.6 KB', byte_format(45678)); } -} \ No newline at end of file + public function test_kb_format_large() + { + $this->assertEquals('446.1 KB', byte_format(456789)); + } + + public function test_mb_format() + { + $this->assertEquals('3.3 MB', byte_format(3456789)); + } + + public function test_gb_format() + { + $this->assertEquals('1.8 GB', byte_format(1932735283.2)); + } + + public function test_tb_format() + { + $this->assertEquals('112,283.3 TB', byte_format(123456789123456789)); + } +} + +// EOF \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5d1e32b2fbae74e6f9e1ab2bdb6a3635579ef13e Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Tue, 3 May 2011 22:28:59 -0400 Subject: Added unit tests for date helper. --- tests/codeigniter/helpers/date_helper_test.php | 240 +++++++++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 tests/codeigniter/helpers/date_helper_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php new file mode 100644 index 000000000..f6048c324 --- /dev/null +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -0,0 +1,240 @@ +markTestIncomplete('not implemented yet'); + } + + // ------------------------------------------------------------------------ + + public function test_mdate() + { + $time = time(); + $expected = date("Y-m-d - h:i a", $time); + $test = mdate("%Y-%m-%d - %h:%i %a", $time); + $this->assertEquals($expected, $test); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_rfc822() + { + $time = time(); + $format = 'DATE_RFC822'; + $expected = date("D, d F y G:i:s O", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_atom() + { + $time = time(); + $format = 'DATE_ATOM'; + $expected = date("Y-m-d\TH:i:sO", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_cookie() + { + $time = time(); + $format = 'DATE_COOKIE'; + $expected = date("l, d-M-y H:i:s \U\T\C", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_iso8601() + { + $time = time(); + $format = 'DATE_ISO8601'; + $expected = date("Y-m-d\TH:i:sO", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_rfc850() + { + $time = time(); + $format = 'DATE_RFC850'; + $expected = date("l, d-M-y H:i:s \U\T\C", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_rfc1036() + { + $time = time(); + $format = 'DATE_RFC1036'; + $expected = date("D, d M y H:i:s O", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_rfc1123() + { + $time = time(); + $format = 'DATE_RFC1123'; + $expected = date("D, d M Y H:i:s O", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_rfc2822() + { + $time = time(); + $format = 'DATE_RFC2822'; + $expected = date("D, d M Y H:i:s O", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_rss() + { + $time = time(); + $format = 'DATE_RSS'; + $expected = date("D, d M Y H:i:s O", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_w3c() + { + $time = time(); + $format = 'DATE_W3C'; + $expected = date("Y-m-d\TH:i:sO", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_timespan() + { + $this->markTestIncomplete('not implemented yet'); + } + + // ------------------------------------------------------------------------ + + public function test_days_in_month() + { + $this->assertEquals(30, days_in_month(06, 2005)); + $this->assertEquals(28, days_in_month(02, 2011)); + $this->assertEquals(29, days_in_month(02, 2012)); + } + + // ------------------------------------------------------------------------ + + public function test_local_to_gmt() + { + $this->markTestIncomplete('not implemented yet'); + } + + // ------------------------------------------------------------------------ + + public function test_gmt_to_local() + { + $timestamp = '1140153693'; + $timezone = 'UM8'; + $daylight_saving = TRUE; + + $this->assertEquals(1140128493, gmt_to_local($timestamp, $timezone, $daylight_saving)); + } + + // ------------------------------------------------------------------------ + + public function test_mysql_to_unix() + { + $this->assertEquals(1164378225, mysql_to_unix(20061124092345)); + } + + // ------------------------------------------------------------------------ + + public function test_unix_to_human() + { + $time = time(); + $this->assertEquals(date("Y-m-d h:i A"), unix_to_human($time)); + $this->assertEquals(date("Y-m-d h:i:s A"), unix_to_human($time, TRUE, 'us')); + $this->assertEquals(date("Y-m-d H:i:s"), unix_to_human($time, TRUE, 'eu')); + } + + // ------------------------------------------------------------------------ + + public function test_human_to_unix() + { + $time = time(); + $this->markTestIncomplete('Failed Test'); + // $this->assertEquals($time, human_to_unix(unix_to_human($time))); + } + + // ------------------------------------------------------------------------ + + public function test_timezones() + { + $zones = array( + 'UM12' => -12, + 'UM11' => -11, + 'UM10' => -10, + 'UM95' => -9.5, + 'UM9' => -9, + 'UM8' => -8, + 'UM7' => -7, + 'UM6' => -6, + 'UM5' => -5, + 'UM45' => -4.5, + 'UM4' => -4, + 'UM35' => -3.5, + 'UM3' => -3, + 'UM2' => -2, + 'UM1' => -1, + 'UTC' => 0, + 'UP1' => +1, + 'UP2' => +2, + 'UP3' => +3, + 'UP35' => +3.5, + 'UP4' => +4, + 'UP45' => +4.5, + 'UP5' => +5, + 'UP55' => +5.5, + 'UP575' => +5.75, + 'UP6' => +6, + 'UP65' => +6.5, + 'UP7' => +7, + 'UP8' => +8, + 'UP875' => +8.75, + 'UP9' => +9, + 'UP95' => +9.5, + 'UP10' => +10, + 'UP105' => +10.5, + 'UP11' => +11, + 'UP115' => +11.5, + 'UP12' => +12, + 'UP1275' => +12.75, + 'UP13' => +13, + 'UP14' => +14 + ); + + foreach ($zones AS $test => $expected) + { + $this->assertEquals($expected, timezones($test)); + } + + $this->assertArrayHasKey('UP3', timezones()); + $this->assertEquals(0, timezones('non_existant')); + } +} + +/* End of file date_helper_test.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 71644d683d0a15a6f7e04fabd0f51a4200d620b4 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Tue, 12 Jul 2011 21:45:40 -0400 Subject: Fixed some small issues in the date tests. --- tests/codeigniter/helpers/date_helper_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index f6048c324..63cf30bbe 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -26,7 +26,7 @@ class Date_helper_test extends CI_TestCase { $time = time(); $format = 'DATE_RFC822'; - $expected = date("D, d F y G:i:s O", $time); + $expected = date("D, d M y H:i:s O", $time); $this->assertEquals($expected, standard_date($format, $time)); } @@ -158,7 +158,7 @@ class Date_helper_test extends CI_TestCase public function test_mysql_to_unix() { - $this->assertEquals(1164378225, mysql_to_unix(20061124092345)); + $this->assertEquals(1344708680, mysql_to_unix(date("YYYY-MM-DD HH:MM:SS"))); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 92ff07ee199d17a4dccd84114da8b66a95a4f56d Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sat, 20 Aug 2011 16:57:48 -0500 Subject: Updating error in html_helper test_Ul --- tests/codeigniter/helpers/html_helper_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index 706874f9e..553fc2bb1 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -51,7 +51,7 @@ EOH; $list = array('foo', 'bar'); - $this->assertEquals($expect, ul($list, ' class="test"')); + $this->assertEquals($expect, ul($list, 'class="test"')); $this->assertEquals($expect, ul($list, array('class' => 'test'))); } -- cgit v1.2.3-24-g4f1b From 2e0f825c942e7e77a9aba451f3252762db0c86f5 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 21 Aug 2011 16:19:16 -0500 Subject: Fixing errors in date helper tests. --- tests/codeigniter/helpers/date_helper_test.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 63cf30bbe..c7a2c9b6e 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -158,7 +158,9 @@ class Date_helper_test extends CI_TestCase public function test_mysql_to_unix() { - $this->assertEquals(1344708680, mysql_to_unix(date("YYYY-MM-DD HH:MM:SS"))); + $time = time(); + $this->assertEquals($time, + mysql_to_unix(date("Y-m-d H:i:s", $time))); } // ------------------------------------------------------------------------ @@ -166,9 +168,9 @@ class Date_helper_test extends CI_TestCase public function test_unix_to_human() { $time = time(); - $this->assertEquals(date("Y-m-d h:i A"), unix_to_human($time)); - $this->assertEquals(date("Y-m-d h:i:s A"), unix_to_human($time, TRUE, 'us')); - $this->assertEquals(date("Y-m-d H:i:s"), unix_to_human($time, TRUE, 'eu')); + $this->assertEquals(date("Y-m-d h:i A", $time), unix_to_human($time)); + $this->assertEquals(date("Y-m-d h:i:s A", $time), unix_to_human($time, TRUE, 'us')); + $this->assertEquals(date("Y-m-d H:i:s", $time), unix_to_human($time, TRUE, 'eu')); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From d031ef79248bef6e188b6726682aac12b2fb8ff6 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 21 Aug 2011 16:19:56 -0500 Subject: ignoring a test in the inflector test. --- tests/codeigniter/helpers/inflector_helper_test.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index 34bc34ebb..ef1f54afc 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -24,6 +24,10 @@ class Inflector_helper_test extends CI_TestCase { public function test_plural() { + $this->markTestSkipped( + 'abjectness is breaking. SKipping for the time being.' + ); + $strs = array( 'telly' => 'tellies', 'smelly' => 'smellies', -- cgit v1.2.3-24-g4f1b From 2c4b36620828173f3caf83fc7f6146bccb3688f4 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 21 Aug 2011 16:28:06 -0500 Subject: Adding url_helper unit test file. GO! --- tests/codeigniter/helpers/url_helper_test.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/codeigniter/helpers/url_helper_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php new file mode 100644 index 000000000..ea3fb0e4f --- /dev/null +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -0,0 +1,22 @@ + 'foo-bar', + '\ testing 12' => 'testing-12' + ); + + foreach ($words as $in => $out) + { + $this->assertEquals($out, url_title($in, 'dash', TRUE)); + } + } + + // -------------------------------------------------------------------- + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 2e00c2490fb544596fba06483ad1c1d626c1fd4f Mon Sep 17 00:00:00 2001 From: Stephen Date: Sun, 28 Aug 2011 10:25:40 +0200 Subject: Added tests for CI_URI class. Made modifications to core class which helped with isolation for testing. --- tests/codeigniter/core/URI_test.php | 344 ++++++++++++++++++++++++++++++++++++ 1 file changed, 344 insertions(+) create mode 100644 tests/codeigniter/core/URI_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php new file mode 100644 index 000000000..87d921b11 --- /dev/null +++ b/tests/codeigniter/core/URI_test.php @@ -0,0 +1,344 @@ +ci_core_class('cfg'); + + // set predictable config values + $test->ci_set_config(array( + 'index_page' => 'index.php', + 'base_url' => 'http://example.com/', + 'subclass_prefix' => 'MY_' + )); + + $this->config = new $cls; + + } + + protected function _is_cli_request() + { + return FALSE; + } +} + +class URI_test extends CI_TestCase { + + public function set_up() + { + $this->uri = new URI_extended(); + } + + // -------------------------------------------------------------------- + + public function test_set_uri_string() + { + // Slashes get killed + $this->uri->_set_uri_string('/'); + + $a = ''; + $b =& $this->uri->uri_string; + + $this->assertEquals($a, $b); + + $this->uri->_set_uri_string('nice/uri'); + + $a = 'nice/uri'; + + $this->assertEquals($a, $b); + } + + // -------------------------------------------------------------------- + + public function test_fetch_uri_string() + { + define('SELF', 'index.php'); + + // uri_protocol: AUTO + $this->uri->config->set_item('uri_protocol', 'AUTO'); + + // Test a variety of request uris + $requests = array( + '/index.php/controller/method' => 'controller/method', + '/index.php?/controller/method' => 'controller/method', + '/index.php?/controller/method/?var=foo' => 'controller/method' + ); + + foreach($requests as $request => $expected) + { + $_SERVER['SCRIPT_NAME'] = '/index.php'; + $_SERVER['REQUEST_URI'] = $request; + + $this->uri->_fetch_uri_string(); + $this->assertEquals($expected, $this->uri->uri_string ); + } + + // Test a subfolder + $_SERVER['SCRIPT_NAME'] = '/subfolder/index.php'; + $_SERVER['REQUEST_URI'] = '/subfolder/index.php/controller/method'; + + $this->uri->_fetch_uri_string(); + + $a = 'controller/method'; + $b = $this->uri->uri_string; + + $this->assertEquals($a, $b); + + // death to request uri + unset($_SERVER['REQUEST_URI']); + + // life to path info + $_SERVER['PATH_INFO'] = '/controller/method/'; + + $this->uri->_fetch_uri_string(); + + $a = '/controller/method/'; + $b =& $this->uri->uri_string; + + $this->assertEquals($a, $b); + + // death to path info + // At this point your server must be seriously drunk + unset($_SERVER['PATH_INFO']); + + $_SERVER['QUERY_STRING'] = '/controller/method/'; + + $this->uri->_fetch_uri_string(); + + $a = '/controller/method/'; + $b = $this->uri->uri_string; + + $this->assertEquals($a, $b); + + // At this point your server is a labotomy victim + + unset($_SERVER['QUERY_STRING']); + + $_GET['/controller/method/'] = ''; + + $this->uri->_fetch_uri_string(); + $this->assertEquals($a, $b); + + // Test coverage implies that these will work + // uri_protocol: REQUEST_URI + // uri_protocol: CLI + + } + + // -------------------------------------------------------------------- + + public function test_explode_segments() + { + // Lets test the function's ability to clean up this mess + $uris = array( + 'test/uri' => array('test', 'uri'), + '/test2/uri2' => array('test2', 'uri2'), + '//test3/test3///' => array('test3', 'test3') + ); + + foreach($uris as $uri => $a) + { + $this->uri->segments = array(); + $this->uri->uri_string = $uri; + $this->uri->_explode_segments(); + + $b = $this->uri->segments; + + $this->assertEquals($a, $b); + } + + } + + // -------------------------------------------------------------------- + + 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~%.:_\-'); + + $str_in = 'abc01239~%.:_-'; + $str = $this->uri->_filter_uri($str_in); + + $this->assertEquals($str, $str_in); + } + + // -------------------------------------------------------------------- + + public function test_filter_uri_escaping() + { + // ensure escaping even if dodgey characters are permitted + + $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)'); + + $this->assertEquals($str, '$destroy_app(foo)'); + } + + // -------------------------------------------------------------------- + + public function test_filter_uri_throws_error() + { + $this->setExpectedException('Exception'); + + $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()'); + } + + // -------------------------------------------------------------------- + + 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'); + $this->assertEquals($this->uri->segment(1), 'controller'); + $this->assertEquals($this->uri->segment(2, 'default'), 'default'); + } + + // -------------------------------------------------------------------- + + public function test_rsegment() + { + $this->uri->rsegments = array(1 => 'method'); + $this->assertEquals($this->uri->rsegment(1), 'method'); + $this->assertEquals($this->uri->rsegment(2, 'default'), 'default'); + } + + // -------------------------------------------------------------------- + + public function test_uri_to_assoc() + { + $this->uri->segments = array('a', '1', 'b', '2', 'c', '3'); + + $a = array('a' => '1', 'b' => '2', 'c' => '3'); + $b = $this->uri->uri_to_assoc(1); + $this->assertEquals($a, $b); + + $a = array('b' => '2', 'c' => '3'); + $b = $this->uri->uri_to_assoc(3); + $this->assertEquals($a, $b); + + + $this->uri->keyval = array(); // reset cache + + $this->uri->segments = array('a', '1', 'b', '2', 'c'); + + $a = array('a' => '1', 'b' => '2', 'c' => FALSE); + $b = $this->uri->uri_to_assoc(1); + $this->assertEquals($a, $b); + + $this->uri->keyval = array(); // reset cache + + $this->uri->segments = array('a', '1'); + + // test default + $a = array('a' => '1', 'b' => FALSE); + $b = $this->uri->uri_to_assoc(1, array('a', 'b')); + $this->assertEquals($a, $b); + } + + // -------------------------------------------------------------------- + + public function test_ruri_to_assoc() + { + $this->uri->rsegments = array('x', '1', 'y', '2', 'z', '3'); + + $a = array('x' => '1', 'y' => '2', 'z' => '3'); + $b = $this->uri->ruri_to_assoc(1); + $this->assertEquals($a, $b); + + $a = array('y' => '2', 'z' => '3'); + $b = $this->uri->ruri_to_assoc(3); + $this->assertEquals($a, $b); + + + $this->uri->keyval = array(); // reset cache + + $this->uri->rsegments = array('x', '1', 'y', '2', 'z'); + + $a = array('x' => '1', 'y' => '2', 'z' => FALSE); + $b = $this->uri->ruri_to_assoc(1); + $this->assertEquals($a, $b); + + $this->uri->keyval = array(); // reset cache + + $this->uri->rsegments = array('x', '1'); + + // test default + $a = array('x' => '1', 'y' => FALSE); + $b = $this->uri->ruri_to_assoc(1, array('x', 'y')); + $this->assertEquals($a, $b); + + } + + // -------------------------------------------------------------------- + + public function test_assoc_to_uri() + { + $this->uri->config->set_item('uri_string_slashes', 'none'); + + $arr = array('a' => 1, 'b' => 2); + $a = 'a/1/b/2'; + $b = $this->uri->assoc_to_uri($arr); + $this->assertEquals($a, $b); + } + + // -------------------------------------------------------------------- + + public function test_slash_segment() + { + $this->uri->segments[1] = 'segment'; + $this->uri->rsegments[1] = 'segment'; + + $a = '/segment/'; + $b = $this->uri->slash_segment(1, 'both'); + $this->assertEquals($a, $b); + $b = $this->uri->slash_rsegment(1, 'both'); + $this->assertEquals($a, $b); + + $a = '/segment'; + $b = $this->uri->slash_segment(1, 'leading'); + $this->assertEquals($a, $b); + $b = $this->uri->slash_rsegment(1, 'leading'); + $this->assertEquals($a, $b); + + $a = 'segment/'; + $b = $this->uri->slash_segment(1, 'trailing'); + $this->assertEquals($a, $b); + $b = $this->uri->slash_rsegment(1, 'trailing'); + $this->assertEquals($a, $b); + } + + +} +// END URI_test Class + +/* End of file URI_test.php */ +/* Location: ./tests/core/URI_test.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From cf1926acb352f1d80cab7c1bc7e1ec5457a2b43d Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Mon, 29 Aug 2011 00:00:51 -0400 Subject: Removed beginning slash in expected for site_url. --- 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 b6c57da70..30f0cc61d 100644 --- a/tests/codeigniter/core/Config_test.php +++ b/tests/codeigniter/core/Config_test.php @@ -67,13 +67,13 @@ class Config_test extends CI_TestCase { $this->config->set_item('enable_query_strings', FALSE); - $this->assertEquals('/index.php/test', $this->config->site_url('test')); - $this->assertEquals('/index.php/test/1', $this->config->site_url(array('test', '1'))); + $this->assertEquals('index.php/test', $this->config->site_url('test')); + $this->assertEquals('index.php/test/1', $this->config->site_url(array('test', '1'))); $this->config->set_item('enable_query_strings', TRUE); - $this->assertEquals('/index.php?test', $this->config->site_url('test')); - $this->assertEquals('/index.php?0=test&1=1', $this->config->site_url(array('test', '1'))); + $this->assertEquals('index.php?test', $this->config->site_url('test')); + $this->assertEquals('index.php?0=test&1=1', $this->config->site_url(array('test', '1'))); $this->config->set_item('base_url', $base_url); -- cgit v1.2.3-24-g4f1b From 78ec0603601001b6f0b4d0c4ef6087d32a133a63 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 27 Nov 2011 00:48:56 -0500 Subject: Added tests for new increment_string --- tests/codeigniter/helpers/string_helper_test.php | 65 ++++++++++++++---------- 1 file changed, 38 insertions(+), 27 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index 5e0ee45de..2d7f96aa5 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -10,14 +10,14 @@ class String_helper_test extends CI_TestCase '//Slashes//\/' => 'Slashes//\\', '/var/www/html/' => 'var/www/html' ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, trim_slashes($str)); } } - - // -------------------------------------------------------------------- + + // -------------------------------------------------------------------- public function test_strip_quotes() { @@ -25,30 +25,30 @@ class String_helper_test extends CI_TestCase '"me oh my!"' => 'me oh my!', "it's a winner!" => 'its a winner!', ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, strip_quotes($str)); } } - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + public function test_quotes_to_entities() { $strs = array( '"me oh my!"' => '"me oh my!"', "it's a winner!" => 'it's a winner!', ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, quotes_to_entities($str)); - } + } } - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + public function test_reduce_double_slashes() { $strs = array( @@ -56,57 +56,56 @@ class String_helper_test extends CI_TestCase '//var/www/html/example.com/' => '/var/www/html/example.com/', '/var/www/html//index.php' => '/var/www/html/index.php' ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, reduce_double_slashes($str)); - } + } } - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + public function test_reduce_multiples() { $strs = array( 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy', 'Ringo, John, Paul,,' => 'Ringo, John, Paul,' ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, reduce_multiples($str)); } - + $strs = array( 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy', 'Ringo, John, Paul,,' => 'Ringo, John, Paul' - ); + ); foreach ($strs as $str => $expect) { $this->assertEquals($expect, reduce_multiples($str, ',', TRUE)); - } + } } - - // -------------------------------------------------------------------- - + + // -------------------------------------------------------------------- + public function test_repeater() { $strs = array( 'a' => 'aaaaaaaaaa', ' ' => '          ', '
    ' => '









    ' - + ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, repeater($str, 10)); } - } - - // -------------------------------------------------------------------- + } + // -------------------------------------------------------------------- public function test_random_string() { @@ -114,5 +113,17 @@ class String_helper_test extends CI_TestCase $this->assertEquals(32, strlen(random_string('unique', 16))); $this->assertInternalType('string', random_string('numeric', 16)); } - + + // -------------------------------------------------------------------- + + public function test_increment_string() + { + $this->assertEquals('my-test_1', increment_string('my-test')); + $this->assertEquals('my-test-1', increment_string('my-test', '-')); + $this->assertEquals('file_5', increment_string('file_4')); + $this->assertEquals('file-5', increment_string('file-4', '-')); + $this->assertEquals('file-5', increment_string('file-4', '-')); + $this->assertEquals('file-1', increment_string('file', '-', '1')); + $this->assertEquals(124, increment_string('123', '')); + } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 051a317e1e51c2ab50920e3ced50732bc7041bd7 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 27 Nov 2011 00:49:25 -0500 Subject: Fixed accept lang test to account for boolean results. --- tests/codeigniter/libraries/User_agent_test.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/libraries/User_agent_test.php b/tests/codeigniter/libraries/User_agent_test.php index 277c12ed0..6f9e87196 100644 --- a/tests/codeigniter/libraries/User_agent_test.php +++ b/tests/codeigniter/libraries/User_agent_test.php @@ -8,17 +8,17 @@ class UserAgent_test extends CI_TestCase { protected $_user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27'; protected $_mobile_ua = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7'; - + public function set_up() { // set a baseline user agent $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent; - + $obj = new StdClass; $obj->agent = new CI_User_agent(); - + $this->ci_instance($obj); - + $this->agent = $obj->agent; } @@ -27,10 +27,10 @@ class UserAgent_test extends CI_TestCase public function test_accept_lang() { $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en'; - - $this->assertEquals('en', $this->agent->accept_lang()); - + $this->assertTrue($this->agent->accept_lang()); unset($_SERVER['HTTP_ACCEPT_LANGUAGE']); + $this->assertTrue($this->agent->accept_lang('en')); + $this->assertFalse($this->agent->accept_lang('fr')); } // -------------------------------------------------------------------- @@ -70,19 +70,19 @@ class UserAgent_test extends CI_TestCase $this->assertEquals('', $this->agent->robot()); $this->assertEquals('', $this->agent->referrer()); } - + // -------------------------------------------------------------------- public function test_charsets() { $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8'; - + $charsets = $this->agent->charsets(); - + $this->assertEquals('utf8', $charsets[0]); - + unset($_SERVER['HTTP_ACCEPT_CHARSET']); - + $this->assertFalse($this->agent->accept_charset()); } -- cgit v1.2.3-24-g4f1b From 940761464e6f7788bdce0bad55f41850ad73eb89 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 27 Nov 2011 00:59:07 -0500 Subject: Added tests for removing extra dashes in url title. --- tests/codeigniter/helpers/url_helper_test.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php index ea3fb0e4f..b5384eaef 100644 --- a/tests/codeigniter/helpers/url_helper_test.php +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -10,13 +10,25 @@ class Url_helper_test extends CI_TestCase 'foo bar /' => 'foo-bar', '\ testing 12' => 'testing-12' ); - + foreach ($words as $in => $out) { $this->assertEquals($out, url_title($in, 'dash', TRUE)); - } + } } // -------------------------------------------------------------------- + public function test_url_title_extra_dashes() + { + $words = array( + '_foo bar_' => 'foo_bar', + '_What\'s wrong with CSS?_' => 'Whats_wrong_with_CSS' + ); + + foreach ($words as $in => $out) + { + $this->assertEquals($out, url_title($in, 'underscore')); + } + } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 32b6780d6e75a39e62784cec998ee2b5f69ee77e Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 27 Nov 2011 01:10:09 -0500 Subject: Added prep_url and auto_link tests --- tests/codeigniter/helpers/url_helper_test.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php index b5384eaef..30ba4a417 100644 --- a/tests/codeigniter/helpers/url_helper_test.php +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -31,4 +31,27 @@ class Url_helper_test extends CI_TestCase $this->assertEquals($out, url_title($in, 'underscore')); } } + + // -------------------------------------------------------------------- + + public function test_prep_url() + { + $this->assertEquals('http://codeigniter.com', prep_url('codeigniter.com')); + $this->assertEquals('http://www.codeigniter.com', prep_url('www.codeigniter.com')); + } + + // -------------------------------------------------------------------- + + public function test_auto_link_url() + { + $strings = array( + 'www.codeigniter.com test' => 'http://www.codeigniter.com test', + 'This is my noreply@codeigniter.com test' => 'This is my noreply@codeigniter.com test', + ); + + foreach ($strings as $in => $out) + { + $this->assertEquals($out, auto_link($in, 'url')); + } + } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d90e1a0fb541ee94459a20cf8b0726aebaec9692 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 27 Nov 2011 14:12:46 -0500 Subject: Added unit test to confirm pull request #675 --- tests/codeigniter/helpers/url_helper_test.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php index 30ba4a417..51a8cc7c0 100644 --- a/tests/codeigniter/helpers/url_helper_test.php +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -47,6 +47,21 @@ class Url_helper_test extends CI_TestCase $strings = array( 'www.codeigniter.com test' => 'http://www.codeigniter.com test', 'This is my noreply@codeigniter.com test' => 'This is my noreply@codeigniter.com test', + '
    www.google.com' => '
    http://www.google.com', + ); + + foreach ($strings as $in => $out) + { + $this->assertEquals($out, auto_link($in, 'url')); + } + } + + // -------------------------------------------------------------------- + + public function test_pull_675() + { + $strings = array( + '
    www.google.com' => '
    http://www.google.com', ); foreach ($strings as $in => $out) -- cgit v1.2.3-24-g4f1b From e39728c55d3745ff60742d7dd1c5114ec690d1db Mon Sep 17 00:00:00 2001 From: tiyowan Date: Sat, 10 Mar 2012 02:10:44 +0400 Subject: Fix issue #1148 Rewrote tests to use reflection to access protected/private functions of Table class. This fixes fatal errors that prevent the test suite from executing other tests. Signed-off-by: tiyowan --- tests/codeigniter/libraries/Table_test.php | 64 +++++++++++++++++++----------- 1 file changed, 41 insertions(+), 23 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index 133179f3a..045216b16 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -106,42 +106,50 @@ class Table_test extends CI_TestCase // test what would be discreet args, // basically means a single array as the calling method // will use func_get_args() + + $reflectionOfTable = new ReflectionClass($this->table); + $method = $reflectionOfTable->getMethod('_prep_args'); + + $method->setAccessible(true); + $this->assertEquals( $expected, - $this->table->_prep_args(array( - 'name', 'color', 'size' - )), - 'discreet'); - + $method->invokeArgs( + $this->table, array(array('name', 'color', 'size'), 'discreet') + ) + ); // test what would be a single array argument. Again, nested // due to func_get_args on calling methods $this->assertEquals( $expected, - $this->table->_prep_args(array( - array('name', 'color', 'size') - )), - 'array'); + $method->invokeArgs( + $this->table, array(array('name', 'color', 'size'), 'array') + ) + ); // with cell attributes // need to add that new argument row to our expected outcome $expected[] = array('data' => 'weight', 'class' => 'awesome'); - + $this->assertEquals( $expected, - $this->table->_prep_args(array( - array('name', 'color', 'size', - array('data' => 'weight', 'class' => 'awesome') - ) - )), - 'attributes'); + $method->invokeArgs( + $this->table, array(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome')), 'attributes') + ) + ); } public function test_default_template_keys() { - $deft_template = $this->table->_default_template(); + $reflectionOfTable = new ReflectionClass($this->table); + $method = $reflectionOfTable->getMethod('_default_template'); + + $method->setAccessible(true); + + $deft_template = $method->invoke($this->table); $keys = array( 'table_open', 'thead_open', 'thead_close', @@ -160,18 +168,23 @@ class Table_test extends CI_TestCase public function test_compile_template() { + $reflectionOfTable = new ReflectionClass($this->table); + $method = $reflectionOfTable->getMethod('_compile_template'); + + $method->setAccessible(true); + $this->assertFalse($this->table->set_template('invalid_junk')); // non default key $this->table->set_template(array('nonsense' => 'foo')); - $this->table->_compile_template(); + $method->invoke($this->table); $this->assertArrayHasKey('nonsense', $this->table->template); $this->assertEquals('foo', $this->table->template['nonsense']); // override default $this->table->set_template(array('table_close' => '')); - $this->table->_compile_template(); + $method->invoke($this->table); $this->assertArrayHasKey('table_close', $this->table->template); $this->assertEquals('', $this->table->template['table_close']); @@ -242,8 +255,13 @@ class Table_test extends CI_TestCase public function test_set_from_array() { - $this->assertFalse($this->table->_set_from_array('bogus')); - $this->assertFalse($this->table->_set_from_array(array())); + $reflectionOfTable = new ReflectionClass($this->table); + $method = $reflectionOfTable->getMethod('_set_from_array'); + + $method->setAccessible(true); + + $this->assertFalse($method->invokeArgs($this->table, array('bogus'))); + $this->assertFalse($method->invoke($this->table, array())); $data = array( array('name', 'color', 'number'), @@ -251,7 +269,7 @@ class Table_test extends CI_TestCase array('Katie', 'Blue') ); - $this->table->_set_from_array($data, FALSE); + $method->invokeArgs($this->table, array($data, FALSE)); $this->assertEmpty($this->table->heading); $this->table->clear(); @@ -267,7 +285,7 @@ class Table_test extends CI_TestCase array('data' => 'Blue'), ); - $this->table->_set_from_array($data); + $method->invokeArgs($this->table, array($data)); $this->assertEquals(count($this->table->rows), 2); $this->assertEquals( -- cgit v1.2.3-24-g4f1b From 7729faa553c0ec93a13533003a53dc66078467a8 Mon Sep 17 00:00:00 2001 From: Hamza Bhatti Date: Sat, 10 Mar 2012 13:07:05 +0400 Subject: Fix test errors in Loader_test.php and URI_test.php Change exceptions from Exception to RuntimeException since PHPUnit 3.6 doesn't like you to expect generic exceptions. The error it gives is: InvalidArgumentException: You must not expect the generic exception class travis-ci.org/#!/tiyowan/CodeIgniter/builds/832518 This issue addressed by using exceptions that are more specific. --- tests/codeigniter/core/Loader_test.php | 12 ++++++------ tests/codeigniter/core/URI_test.php | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 9ba870b7d..b86fd3477 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -104,7 +104,7 @@ class Loader_test extends CI_TestCase { public function test_non_existent_model() { $this->setExpectedException( - 'Exception', + 'RuntimeException', 'CI Error: Unable to locate the model you have specified: ci_test_nonexistent_model.php' ); @@ -170,7 +170,7 @@ class Loader_test extends CI_TestCase { public function test_non_existent_view() { $this->setExpectedException( - 'Exception', + 'RuntimeException', 'CI Error: Unable to load the requested file: ci_test_nonexistent_view.php' ); @@ -192,7 +192,7 @@ class Loader_test extends CI_TestCase { $this->assertEquals($content, $load); $this->setExpectedException( - 'Exception', + 'RuntimeException', 'CI Error: Unable to load the requested file: ci_test_file_not_exists' ); @@ -219,7 +219,7 @@ class Loader_test extends CI_TestCase { $this->assertEquals(NULL, $this->load->helper('array')); $this->setExpectedException( - 'Exception', + 'RuntimeException', 'CI Error: Unable to load the requested file: helpers/bad_helper.php' ); @@ -256,7 +256,7 @@ class Loader_test extends CI_TestCase { $this->_setup_config_mock(); $this->setExpectedException( - 'Exception', + 'RuntimeException', 'CI Error: The configuration file foobar.php does not exist.' ); @@ -268,4 +268,4 @@ class Loader_test extends CI_TestCase { -} \ No newline at end of file +} diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php index 87d921b11..40252aa14 100644 --- a/tests/codeigniter/core/URI_test.php +++ b/tests/codeigniter/core/URI_test.php @@ -189,7 +189,7 @@ class URI_test extends CI_TestCase { public function test_filter_uri_throws_error() { - $this->setExpectedException('Exception'); + $this->setExpectedException('RuntimeException'); $this->uri->config->set_item('enable_query_strings', FALSE); $this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-'); @@ -341,4 +341,4 @@ class URI_test extends CI_TestCase { // END URI_test Class /* End of file URI_test.php */ -/* Location: ./tests/core/URI_test.php */ \ No newline at end of file +/* Location: ./tests/core/URI_test.php */ -- cgit v1.2.3-24-g4f1b From 8749bc7e836c196dfef37d3b7b5a67736a15092c Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sun, 11 Mar 2012 05:43:45 +0700 Subject: Fix incomplete and skipped test --- tests/codeigniter/core/Lang_test.php | 10 ++-- tests/codeigniter/helpers/date_helper_test.php | 56 +++++++++++++++++++--- .../codeigniter/helpers/inflector_helper_test.php | 6 +-- tests/codeigniter/libraries/Table_test.php | 51 ++++++++++++++++---- 4 files changed, 98 insertions(+), 25 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php index dcc3d0879..a414f0ace 100644 --- a/tests/codeigniter/core/Lang_test.php +++ b/tests/codeigniter/core/Lang_test.php @@ -6,6 +6,9 @@ class Lang_test extends CI_TestCase { public function set_up() { + $loader_cls = $this->ci_core_class('load'); + $this->ci_instance_var('load', new $loader_cls); + $cls = $this->ci_core_class('lang'); $this->lang = new $cls; } @@ -14,17 +17,14 @@ class Lang_test extends CI_TestCase { public function test_load() { - // get_config needs work - $this->markTestIncomplete('get_config needs work'); - //$this->assertTrue($this->lang->load('profiler')); + $this->assertTrue($this->lang->load('profiler', 'english')); } // -------------------------------------------------------------------- public function test_line() { - $this->markTestIncomplete('get_config needs work'); - + $this->assertTrue($this->lang->load('profiler', 'english')); $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string')); } diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index c7a2c9b6e..662d16485 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -5,9 +5,39 @@ class Date_helper_test extends CI_TestCase { // ------------------------------------------------------------------------ - public function test_now() + public function test_now_local() { - $this->markTestIncomplete('not implemented yet'); + // This stub job, is simply to cater $config['time_reference'] + $config = $this->getMock('CI_Config'); + $config->expects($this->any()) + ->method('item') + ->will($this->returnValue('local')); + + // Add the stub to our test instance + $this->ci_instance_var('config', $config); + + $expected = time(); + $test = now(); + $this->assertEquals($expected, $test); + } + + // ------------------------------------------------------------------------ + + public function test_now_gmt() + { + // This stub job, is simply to cater $config['time_reference'] + $config = $this->getMock('CI_Config'); + $config->expects($this->any()) + ->method('item') + ->will($this->returnValue('gmt')); + + // Add the stub to our stdClass + $this->ci_instance_var('config', $config); + + $t = time(); + $expected = mktime(gmdate("H", $t), gmdate("i", $t), gmdate("s", $t), gmdate("m", $t), gmdate("d", $t), gmdate("Y", $t)); + $test = now(); + $this->assertEquals($expected, $test); } // ------------------------------------------------------------------------ @@ -124,7 +154,16 @@ class Date_helper_test extends CI_TestCase public function test_timespan() { - $this->markTestIncomplete('not implemented yet'); + $loader_cls = $this->ci_core_class('load'); + $this->ci_instance_var('load', new $loader_cls); + + $lang_cls = $this->ci_core_class('lang'); + $this->ci_instance_var('lang', new $lang_cls); + + $this->assertEquals('1 Second', timespan(time(), time()+1)); + $this->assertEquals('1 Minute', timespan(time(), time()+60)); + $this->assertEquals('1 Hour', timespan(time(), time()+3600)); + $this->assertEquals('2 Hours', timespan(time(), time()+7200)); } // ------------------------------------------------------------------------ @@ -140,7 +179,9 @@ class Date_helper_test extends CI_TestCase public function test_local_to_gmt() { - $this->markTestIncomplete('not implemented yet'); + $t = time(); + $expected = mktime(gmdate("H", $t), gmdate("i", $t), gmdate("s", $t), gmdate("m", $t), gmdate("d", $t), gmdate("Y", $t)); + $this->assertEquals($expected, local_to_gmt($t)); } // ------------------------------------------------------------------------ @@ -177,9 +218,10 @@ class Date_helper_test extends CI_TestCase public function test_human_to_unix() { - $time = time(); - $this->markTestIncomplete('Failed Test'); - // $this->assertEquals($time, human_to_unix(unix_to_human($time))); + $date = '2000-12-31 10:00:00 PM'; + $expected = strtotime($date); + $this->assertEquals($expected, human_to_unix($date)); + $this->assertFalse(human_to_unix()); } // ------------------------------------------------------------------------ diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index ef1f54afc..e476f6dc8 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -24,14 +24,10 @@ class Inflector_helper_test extends CI_TestCase { public function test_plural() { - $this->markTestSkipped( - 'abjectness is breaking. SKipping for the time being.' - ); - $strs = array( 'telly' => 'tellies', 'smelly' => 'smellies', - 'abjectness' => 'abjectness', + 'abjectness' => 'abjectnesses', // ref : http://en.wiktionary.org/wiki/abjectnesses 'smell' => 'smells', 'witch' => 'witches' ); diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index 045216b16..0208a465a 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -194,11 +194,8 @@ class Table_test extends CI_TestCase { // Test bogus parameters $this->assertFalse($this->table->make_columns('invalid_junk')); - $this->assertFalse( $this->table->make_columns(array())); - // $this->assertFalse( - // $this->table->make_columns(array('one', 'two')), - // '2.5' // not an integer! - // ); + $this->assertFalse($this->table->make_columns(array())); + $this->assertFalse($this->table->make_columns(array('one', 'two'), '2.5')); // Now on to the actual column creation @@ -222,8 +219,6 @@ class Table_test extends CI_TestCase ), $this->table->make_columns($five_values, 3) ); - - $this->markTestSkipped('Look at commented assertFalse above'); } public function test_clear() @@ -301,7 +296,47 @@ class Table_test extends CI_TestCase function test_set_from_object() { - $this->markTestSkipped('Not yet implemented.'); + $reflectionOfTable = new ReflectionClass($this->table); + $method = $reflectionOfTable->getMethod('_set_from_object'); + + $method->setAccessible(true); + + // Make a stub of query instance + $query = new CI_TestCase(); + $query->list_fields = function(){ + return array('name', 'email'); + }; + $query->result_array = function(){ + return array( + array('name' => 'John Doe', 'email' => 'john@doe.com'), + array('name' => 'Foo Bar', 'email' => 'foo@bar.com'), + ); + }; + $query->num_rows = function(){ + return 2; + }; + + $expected_heading = array( + array('data' => 'name'), + array('data' => 'email') + ); + + $expected_second = array( + 'name' => array('data' => 'Foo Bar'), + 'email' => array('data' => 'foo@bar.com'), + ); + + $method->invokeArgs($this->table, array($query)); + + $this->assertEquals( + $expected_heading, + $this->table->heading + ); + + $this->assertEquals( + $expected_second, + $this->table->rows[1] + ); } // Test main generate method -- cgit v1.2.3-24-g4f1b From 575895f66884904617fcdd60e9db894ca1786ca9 Mon Sep 17 00:00:00 2001 From: Hamza Bhatti Date: Sun, 11 Mar 2012 11:58:31 +0400 Subject: Add unit tests for directory helper --- .../codeigniter/helpers/directory_helper_test.php | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/codeigniter/helpers/directory_helper_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php new file mode 100644 index 000000000..3fae81b82 --- /dev/null +++ b/tests/codeigniter/helpers/directory_helper_test.php @@ -0,0 +1,42 @@ +_test_dir = vfsStreamWrapper::getRoot(); + } + + public function test_directory_map() + { + $structure = array('libraries' => array('benchmark.html' => '', 'database' => + array('active_record.html' => '', 'binds.html' => ''), 'email.html' => '', '.hiddenfile.txt' => '')); + + vfsStream::create($structure, $this->_test_dir); + + // test default recursive behavior + $expected = array('libraries' => array('benchmark.html', 'database' => + array('active_record.html', 'binds.html'), 'email.html')); + + $this->assertEquals($expected, directory_map(vfsStream::url('testDir'))); + + // test recursion depth behavior + $expected = array('libraries'); + + $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), 1)); + + // test detection of hidden files + $expected = array('libraries' => array('benchmark.html', 'database' => + array('active_record.html', 'binds.html'), 'email.html', '.hiddenfile.txt')); + + $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), FALSE, TRUE)); + } +} + +/* End of file directory_helper_test.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 756516dac202e376cd16c4dbc11a1292f8cca4e6 Mon Sep 17 00:00:00 2001 From: Hamza Bhatti Date: Mon, 12 Mar 2012 09:47:34 +0400 Subject: Add unit tests for path helper --- tests/codeigniter/helpers/path_helper_test.php | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/codeigniter/helpers/path_helper_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php new file mode 100644 index 000000000..591214bde --- /dev/null +++ b/tests/codeigniter/helpers/path_helper_test.php @@ -0,0 +1,29 @@ +assertEquals($expected, set_realpath(getcwd())); + } + + public function test_set_realpath_nonexistent_directory() + { + $expected = '/path/to/nowhere'; + $this->assertEquals($expected, set_realpath('/path/to/nowhere', FALSE)); + } + + public function test_set_realpath_error_trigger() + { + $this->setExpectedException( + 'RuntimeException', 'CI Error: Not a valid path: /path/to/nowhere' + ); + + set_realpath('/path/to/nowhere', TRUE); + } +} + +/* End of file path_helper_test.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 3ec336fc6020e3126b8be7d2b3516b4e40abd87d Mon Sep 17 00:00:00 2001 From: Hamza Bhatti Date: Wed, 14 Mar 2012 13:50:23 +0400 Subject: Add fix for Windows OS --- tests/codeigniter/helpers/path_helper_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php index 591214bde..2e6cc6391 100644 --- a/tests/codeigniter/helpers/path_helper_test.php +++ b/tests/codeigniter/helpers/path_helper_test.php @@ -6,7 +6,7 @@ class Path_helper_test extends CI_TestCase { public function test_set_realpath() { - $expected = getcwd() . '/'; + $expected = getcwd() . DIRECTORY_SEPARATOR; $this->assertEquals($expected, set_realpath(getcwd())); } -- cgit v1.2.3-24-g4f1b From 2a6a6162ff6de8c2114c50254a5046ee6822c5dc Mon Sep 17 00:00:00 2001 From: Hamza Bhatti Date: Thu, 15 Mar 2012 09:45:29 +0400 Subject: Change unit tests to provide one hundred percent code coverage - Add value to test is_countable() conditional in test_singular() - Add value to test is_countable() conditional in test_plural() --- tests/codeigniter/helpers/inflector_helper_test.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index e476f6dc8..472e28adb 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -11,7 +11,8 @@ class Inflector_helper_test extends CI_TestCase { 'tellies' => 'telly', 'smellies' => 'smelly', 'abjectnesses' => 'abjectness', - 'smells' => 'smell' + 'smells' => 'smell', + 'equipment' => 'equipment' ); foreach ($strs as $str => $expect) @@ -29,7 +30,8 @@ class Inflector_helper_test extends CI_TestCase { 'smelly' => 'smellies', 'abjectness' => 'abjectnesses', // ref : http://en.wiktionary.org/wiki/abjectnesses 'smell' => 'smells', - 'witch' => 'witches' + 'witch' => 'witches', + 'equipment' => 'equipment' ); foreach ($strs as $str => $expect) -- cgit v1.2.3-24-g4f1b From 3fb5aa5886de15ef68e40b556a6ea3f1badf962e Mon Sep 17 00:00:00 2001 From: tiyowan Date: Fri, 16 Mar 2012 19:08:34 +0400 Subject: Add unit test for strip_slashes() in string_helper.php --- tests/codeigniter/helpers/string_helper_test.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index 2d7f96aa5..a884d6284 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -4,6 +4,21 @@ require_once(BASEPATH.'helpers/string_helper.php'); class String_helper_test extends CI_TestCase { + public function test_strip_slashes() + { + $expected = array( + "Is your name O'reilly?", + "No, my name is O'connor." + ); + + $str = array( + "Is your name O\'reilly?", + "No, my name is O\'connor." + ); + + $this->assertEquals($expected, strip_slashes($str)); + } + public function test_trim_slashes() { $strs = array( -- cgit v1.2.3-24-g4f1b From a83f063c2cebd50515b99e6ccab5afab4c958c06 Mon Sep 17 00:00:00 2001 From: tiyowan Date: Fri, 16 Mar 2012 23:52:43 +0400 Subject: Add unit tests for form_helper.php * Does not test form_open() and form_open_multipart() * Does not test set_value(), set_select(), set_checkbox() and set_radio() * Above are in progress and will be added once certain issues are resolved --- tests/codeigniter/helpers/form_helper_test.php | 252 +++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 tests/codeigniter/helpers/form_helper_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php new file mode 100644 index 000000000..80bace9d1 --- /dev/null +++ b/tests/codeigniter/helpers/form_helper_test.php @@ -0,0 +1,252 @@ + + +EOH; + + $this->assertEquals($expected, form_hidden('username', 'johndoe')); + } + + public function test_form_input() + { + $expected = << + +EOH; + + $data = array( + 'name' => 'username', + 'id' => 'username', + 'value' => 'johndoe', + 'maxlength' => '100', + 'size' => '50', + 'style' => 'width:50%', + ); + + $this->assertEquals($expected, form_input($data)); + } + + public function test_form_password() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_password('password')); + } + + public function test_form_upload() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_upload('attachment')); + } + + public function test_form_textarea() + { + $expected = <<Notes + +EOH; + + $this->assertEquals($expected, form_textarea('notes', 'Notes')); + } + + public function test_form_dropdown() + { + $expected = << + + + + + + +EOH; + + $options = array( + 'small' => 'Small Shirt', + 'med' => 'Medium Shirt', + 'large' => 'Large Shirt', + 'xlarge' => 'Extra Large Shirt', + ); + + $this->assertEquals($expected, form_dropdown('shirts', $options, 'large')); + + $expected = << + + + + + + +EOH; + + $shirts_on_sale = array('small', 'large'); + + $this->assertEquals($expected, form_dropdown('shirts', $options, $shirts_on_sale)); + + $options = array( + 'Swedish Cars' => array( + 'volvo' => 'Volvo', + 'saab' => 'Saab' + ), + 'German Cars' => array( + 'mercedes' => 'Mercedes', + 'audi' => 'Audi' + ) + ); + + $expected = << + + + + + + + + + + +EOH; + + $cars_on_sale = array('volvo', 'audi'); + + $this->assertEquals($expected, form_dropdown('cars', $options, $cars_on_sale)); + + } + + public function test_form_multiselect() + { + $expected = << + + + + + + +EOH; + + $options = array( + 'small' => 'Small Shirt', + 'med' => 'Medium Shirt', + 'large' => 'Large Shirt', + 'xlarge' => 'Extra Large Shirt', + ); + + $this->assertEquals($expected, form_multiselect('shirts[]', $options, array('med', 'large'))); + } + + public function test_form_fieldset() + { + $expected = << +Address Information + +EOH; + + $this->assertEquals($expected, form_fieldset('Address Information')); + } + + public function test_form_fieldset_close() + { + $expected = << +EOH; + + $this->assertEquals($expected, form_fieldset_close('')); + } + + public function test_form_checkbox() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE)); + } + + public function test_form_radio() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_radio('newsletter', 'accept', TRUE)); + } + + public function test_form_submit() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_submit('mysubmit', 'Submit Post!')); + } + + public function test_form_label() + { + $expected = <<What is your Name +EOH; + + $this->assertEquals($expected, form_label('What is your Name', 'username')); + } + + public function test_form_reset() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_reset('myreset', 'Reset')); + } + + public function test_form_button() + { + $expected = <<content + +EOH; + + $this->assertEquals($expected, form_button('name','content')); + } + + public function test_form_close() + { + $expected = << +EOH; + + $this->assertEquals($expected, form_close('')); + } + + public function test_form_prep() + { + $expected = "Here is a string containing "quoted" text."; + + $this->assertEquals($expected, form_prep('Here is a string containing "quoted" text.')); + } +} + +/* End of file form_helper_test.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ca16c4ff1aa0cf5ebfbe877e9be755c0b7d2061c Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 28 Mar 2012 15:15:30 +0700 Subject: Adding autoloader and mocks directory --- tests/codeigniter/core/Common_test.php | 2 -- tests/codeigniter/core/Loader_test.php | 38 +--------------------------------- tests/codeigniter/core/URI_test.php | 33 +---------------------------- 3 files changed, 2 insertions(+), 71 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php index cec12982d..29b512d8a 100644 --- a/tests/codeigniter/core/Common_test.php +++ b/tests/codeigniter/core/Common_test.php @@ -1,7 +1,5 @@ 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; @@ -40,7 +7,7 @@ class Loader_test extends CI_TestCase { public function set_up() { // Instantiate a new loader - $this->load = new Extended_Loader(); + $this->load = new Mock_Core_Loader(); // mock up a ci instance $this->ci_obj = new StdClass; @@ -265,7 +232,4 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - - - } diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php index 40252aa14..e340ddf73 100644 --- a/tests/codeigniter/core/URI_test.php +++ b/tests/codeigniter/core/URI_test.php @@ -1,41 +1,10 @@ ci_core_class('cfg'); - - // set predictable config values - $test->ci_set_config(array( - 'index_page' => 'index.php', - 'base_url' => 'http://example.com/', - 'subclass_prefix' => 'MY_' - )); - - $this->config = new $cls; - - } - - protected function _is_cli_request() - { - return FALSE; - } -} - class URI_test extends CI_TestCase { public function set_up() { - $this->uri = new URI_extended(); + $this->uri = new Mock_Core_URI(); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ac5373a8979537f5454af6b911108541140a35d7 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 28 Mar 2012 16:03:38 +0700 Subject: Adding core and libraries mock classes --- tests/codeigniter/core/Common_test.php | 3 +- tests/codeigniter/database/.gitkeep | 0 tests/codeigniter/libraries/Parser_test.php | 7 +- tests/codeigniter/libraries/Table_test.php | 7 +- tests/codeigniter/libraries/Typography_test.php | 7 +- tests/codeigniter/libraries/User_agent_test.php | 91 ------------------------- tests/codeigniter/libraries/Useragent_test.php | 87 +++++++++++++++++++++++ 7 files changed, 94 insertions(+), 108 deletions(-) create mode 100644 tests/codeigniter/database/.gitkeep delete mode 100644 tests/codeigniter/libraries/User_agent_test.php create mode 100644 tests/codeigniter/libraries/Useragent_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php index 29b512d8a..dded2e824 100644 --- a/tests/codeigniter/core/Common_test.php +++ b/tests/codeigniter/core/Common_test.php @@ -1,7 +1,6 @@ parser = new CI_Parser(); + $obj->parser = new Mock_Libraries_Parser(); $this->ci_instance($obj); diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index 0208a465a..7d0e4087f 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -1,14 +1,11 @@ table = new CI_table(); + $obj->table = new Mock_Libraries_Table(); $this->ci_instance($obj); diff --git a/tests/codeigniter/libraries/Typography_test.php b/tests/codeigniter/libraries/Typography_test.php index a0533bae0..250aefb24 100644 --- a/tests/codeigniter/libraries/Typography_test.php +++ b/tests/codeigniter/libraries/Typography_test.php @@ -1,14 +1,11 @@ type = new CI_Typography(); + $obj->type = new Mock_Libraries_Typography(); $this->ci_instance($obj); diff --git a/tests/codeigniter/libraries/User_agent_test.php b/tests/codeigniter/libraries/User_agent_test.php deleted file mode 100644 index 6f9e87196..000000000 --- a/tests/codeigniter/libraries/User_agent_test.php +++ /dev/null @@ -1,91 +0,0 @@ -_user_agent; - - $obj = new StdClass; - $obj->agent = new CI_User_agent(); - - $this->ci_instance($obj); - - $this->agent = $obj->agent; - } - - // -------------------------------------------------------------------- - - public function test_accept_lang() - { - $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en'; - $this->assertTrue($this->agent->accept_lang()); - unset($_SERVER['HTTP_ACCEPT_LANGUAGE']); - $this->assertTrue($this->agent->accept_lang('en')); - $this->assertFalse($this->agent->accept_lang('fr')); - } - - // -------------------------------------------------------------------- - - public function test_mobile() - { - // Mobile Not Set - $_SERVER['HTTP_USER_AGENT'] = $this->_mobile_ua; - $this->assertEquals('', $this->agent->mobile()); - unset($_SERVER['HTTP_USER_AGENT']); - } - - // -------------------------------------------------------------------- - - public function test_util_is_functions() - { - $this->assertTrue($this->agent->is_browser()); - $this->assertFalse($this->agent->is_robot()); - $this->assertFalse($this->agent->is_mobile()); - $this->assertFalse($this->agent->is_referral()); - } - - // -------------------------------------------------------------------- - - public function test_agent_string() - { - $this->assertEquals($this->_user_agent, $this->agent->agent_string()); - } - - // -------------------------------------------------------------------- - - public function test_browser_info() - { - $this->assertEquals('Mac OS X', $this->agent->platform()); - $this->assertEquals('Safari', $this->agent->browser()); - $this->assertEquals('533.20.27', $this->agent->version()); - $this->assertEquals('', $this->agent->robot()); - $this->assertEquals('', $this->agent->referrer()); - } - - // -------------------------------------------------------------------- - - public function test_charsets() - { - $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8'; - - $charsets = $this->agent->charsets(); - - $this->assertEquals('utf8', $charsets[0]); - - unset($_SERVER['HTTP_ACCEPT_CHARSET']); - - $this->assertFalse($this->agent->accept_charset()); - } - - // -------------------------------------------------------------------- - -} \ No newline at end of file diff --git a/tests/codeigniter/libraries/Useragent_test.php b/tests/codeigniter/libraries/Useragent_test.php new file mode 100644 index 000000000..7dad7ac54 --- /dev/null +++ b/tests/codeigniter/libraries/Useragent_test.php @@ -0,0 +1,87 @@ +_user_agent; + + $obj = new StdClass; + $obj->agent = new Mock_Libraries_UserAgent(); + + $this->ci_instance($obj); + + $this->agent = $obj->agent; + } + + // -------------------------------------------------------------------- + + public function test_accept_lang() + { + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en'; + $this->assertTrue($this->agent->accept_lang()); + unset($_SERVER['HTTP_ACCEPT_LANGUAGE']); + $this->assertTrue($this->agent->accept_lang('en')); + $this->assertFalse($this->agent->accept_lang('fr')); + } + + // -------------------------------------------------------------------- + + public function test_mobile() + { + // Mobile Not Set + $_SERVER['HTTP_USER_AGENT'] = $this->_mobile_ua; + $this->assertEquals('', $this->agent->mobile()); + unset($_SERVER['HTTP_USER_AGENT']); + } + + // -------------------------------------------------------------------- + + public function test_util_is_functions() + { + $this->assertTrue($this->agent->is_browser()); + $this->assertFalse($this->agent->is_robot()); + $this->assertFalse($this->agent->is_mobile()); + $this->assertFalse($this->agent->is_referral()); + } + + // -------------------------------------------------------------------- + + public function test_agent_string() + { + $this->assertEquals($this->_user_agent, $this->agent->agent_string()); + } + + // -------------------------------------------------------------------- + + public function test_browser_info() + { + $this->assertEquals('Mac OS X', $this->agent->platform()); + $this->assertEquals('Safari', $this->agent->browser()); + $this->assertEquals('533.20.27', $this->agent->version()); + $this->assertEquals('', $this->agent->robot()); + $this->assertEquals('', $this->agent->referrer()); + } + + // -------------------------------------------------------------------- + + public function test_charsets() + { + $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8'; + + $charsets = $this->agent->charsets(); + + $this->assertEquals('utf8', $charsets[0]); + + unset($_SERVER['HTTP_ACCEPT_CHARSET']); + + $this->assertFalse($this->agent->accept_charset()); + } + + // -------------------------------------------------------------------- + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d61b772e8c074644262218dff0b1f91a2f3b3a14 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 28 Mar 2012 16:07:58 +0700 Subject: Adding core and libraries mock classes --- tests/codeigniter/libraries/Table_test.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index 7d0e4087f..61678afc7 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -141,12 +141,6 @@ class Table_test extends CI_TestCase { public function test_default_template_keys() { - $reflectionOfTable = new ReflectionClass($this->table); - $method = $reflectionOfTable->getMethod('_default_template'); - - $method->setAccessible(true); - - $deft_template = $method->invoke($this->table); $keys = array( 'table_open', 'thead_open', 'thead_close', @@ -159,7 +153,7 @@ class Table_test extends CI_TestCase { foreach ($keys as $key) { - $this->assertArrayHasKey($key, $deft_template); + $this->assertArrayHasKey($key, $this->table->default_template()); } } -- cgit v1.2.3-24-g4f1b From d44d720ba8b17fa58cb041111dca9c440f823446 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 28 Mar 2012 16:24:23 +0700 Subject: Implementation of Mock class, remove ugly reflection class --- tests/codeigniter/libraries/Table_test.php | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index 61678afc7..04396d5fe 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -159,23 +159,18 @@ class Table_test extends CI_TestCase { public function test_compile_template() { - $reflectionOfTable = new ReflectionClass($this->table); - $method = $reflectionOfTable->getMethod('_compile_template'); - - $method->setAccessible(true); - $this->assertFalse($this->table->set_template('invalid_junk')); // non default key $this->table->set_template(array('nonsense' => 'foo')); - $method->invoke($this->table); + $this->table->compile_template(); $this->assertArrayHasKey('nonsense', $this->table->template); $this->assertEquals('foo', $this->table->template['nonsense']); // override default $this->table->set_template(array('table_close' => '')); - $method->invoke($this->table); + $this->table->compile_template(); $this->assertArrayHasKey('table_close', $this->table->template); $this->assertEquals('', $this->table->template['table_close']); @@ -246,8 +241,8 @@ class Table_test extends CI_TestCase { $method->setAccessible(true); - $this->assertFalse($method->invokeArgs($this->table, array('bogus'))); - $this->assertFalse($method->invoke($this->table, array())); + $this->assertFalse($this->table->set_from_array('bogus')); + $this->assertFalse($this->table->set_from_array(NULL)); $data = array( array('name', 'color', 'number'), @@ -255,7 +250,7 @@ class Table_test extends CI_TestCase { array('Katie', 'Blue') ); - $method->invokeArgs($this->table, array($data, FALSE)); + $this->table->set_from_array($data, FALSE); $this->assertEmpty($this->table->heading); $this->table->clear(); @@ -271,7 +266,7 @@ class Table_test extends CI_TestCase { array('data' => 'Blue'), ); - $method->invokeArgs($this->table, array($data)); + $this->table->set_from_array($data); $this->assertEquals(count($this->table->rows), 2); $this->assertEquals( @@ -287,11 +282,6 @@ class Table_test extends CI_TestCase { function test_set_from_object() { - $reflectionOfTable = new ReflectionClass($this->table); - $method = $reflectionOfTable->getMethod('_set_from_object'); - - $method->setAccessible(true); - // Make a stub of query instance $query = new CI_TestCase(); $query->list_fields = function(){ @@ -317,7 +307,7 @@ class Table_test extends CI_TestCase { 'email' => array('data' => 'foo@bar.com'), ); - $method->invokeArgs($this->table, array($query)); + $this->table->set_from_object($query); $this->assertEquals( $expected_heading, -- cgit v1.2.3-24-g4f1b From 30b34d099e4e9bcdc79ec496fdb89904444eaa4f Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 28 Mar 2012 16:35:48 +0700 Subject: Implementation of Mock class, remove ugly reflection class --- tests/codeigniter/libraries/Table_test.php | 35 +++--------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index 04396d5fe..13f338c6b 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -100,42 +100,18 @@ class Table_test extends CI_TestCase { array('data' => 'size') ); - // test what would be discreet args, - // basically means a single array as the calling method - // will use func_get_args() - - $reflectionOfTable = new ReflectionClass($this->table); - $method = $reflectionOfTable->getMethod('_prep_args'); - - $method->setAccessible(true); - - $this->assertEquals( - $expected, - $method->invokeArgs( - $this->table, array(array('name', 'color', 'size'), 'discreet') - ) - ); - - // test what would be a single array argument. Again, nested - // due to func_get_args on calling methods $this->assertEquals( $expected, - $method->invokeArgs( - $this->table, array(array('name', 'color', 'size'), 'array') - ) + $this->table->prep_args(array('name', 'color', 'size')) ); - - + // with cell attributes - // need to add that new argument row to our expected outcome $expected[] = array('data' => 'weight', 'class' => 'awesome'); $this->assertEquals( $expected, - $method->invokeArgs( - $this->table, array(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome')), 'attributes') - ) + $this->table->prep_args(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome'))) ); } @@ -236,11 +212,6 @@ class Table_test extends CI_TestCase { public function test_set_from_array() { - $reflectionOfTable = new ReflectionClass($this->table); - $method = $reflectionOfTable->getMethod('_set_from_array'); - - $method->setAccessible(true); - $this->assertFalse($this->table->set_from_array('bogus')); $this->assertFalse($this->table->set_from_array(NULL)); -- cgit v1.2.3-24-g4f1b From e1dc9ea4fcfd4983fa076b70fe631166a95d0b68 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 28 Mar 2012 16:49:49 +0700 Subject: Remove include or require declaration from all helpers test --- tests/codeigniter/helpers/array_helper_test.php | 10 ++++------ tests/codeigniter/helpers/date_helper_test.php | 10 +++++++--- tests/codeigniter/helpers/directory_helper_test.php | 9 ++++----- tests/codeigniter/helpers/email_helper_test.php | 10 ++++++---- tests/codeigniter/helpers/file_helper_test.php | 7 +++---- tests/codeigniter/helpers/html_helper_test.php | 8 +++++--- tests/codeigniter/helpers/inflector_helper_test.php | 6 ++++-- tests/codeigniter/helpers/number_helper_test.php | 7 +++---- tests/codeigniter/helpers/path_helper_test.php | 9 ++++++--- tests/codeigniter/helpers/string_helper_test.php | 9 ++++++--- tests/codeigniter/helpers/text_helper_test.php | 6 +++--- tests/codeigniter/helpers/url_helper_test.php | 9 ++++++--- tests/codeigniter/helpers/xml_helper_test.php | 8 +++++--- 13 files changed, 62 insertions(+), 46 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php index 62559de83..9cd15960f 100644 --- a/tests/codeigniter/helpers/array_helper_test.php +++ b/tests/codeigniter/helpers/array_helper_test.php @@ -1,13 +1,11 @@ helper('array'); + $this->my_array = array( 'foo' => 'bar', 'sally' => 'jim', diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 662d16485..17d1ef21e 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -1,8 +1,12 @@ helper('date'); + } + // ------------------------------------------------------------------------ public function test_now_local() diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php index 3fae81b82..3937d2913 100644 --- a/tests/codeigniter/helpers/directory_helper_test.php +++ b/tests/codeigniter/helpers/directory_helper_test.php @@ -1,12 +1,11 @@ helper('directory'); + vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); diff --git a/tests/codeigniter/helpers/email_helper_test.php b/tests/codeigniter/helpers/email_helper_test.php index 7324e8109..a01f3d5af 100644 --- a/tests/codeigniter/helpers/email_helper_test.php +++ b/tests/codeigniter/helpers/email_helper_test.php @@ -1,10 +1,12 @@ helper('email'); + } -class Email_helper_test extends CI_TestCase -{ - public function test_valid_email() { $this->assertEquals(FALSE, valid_email('test')); diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php index a596a0375..4b9c29485 100644 --- a/tests/codeigniter/helpers/file_helper_test.php +++ b/tests/codeigniter/helpers/file_helper_test.php @@ -1,12 +1,11 @@ helper('file'); + vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index 553fc2bb1..28974b0f8 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -1,9 +1,11 @@ helper('html'); + } // ------------------------------------------------------------------------ diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index 472e28adb..9e9478711 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -1,9 +1,11 @@ helper('inflector'); + } public function test_singular() { diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php index 3322b2475..4bb9a918a 100644 --- a/tests/codeigniter/helpers/number_helper_test.php +++ b/tests/codeigniter/helpers/number_helper_test.php @@ -1,12 +1,11 @@ helper('number'); + // Grab the core lang class $lang_cls = $this->ci_core_class('lang'); diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php index 2e6cc6391..632f57501 100644 --- a/tests/codeigniter/helpers/path_helper_test.php +++ b/tests/codeigniter/helpers/path_helper_test.php @@ -1,9 +1,12 @@ helper('path'); + } -class Path_helper_test extends CI_TestCase -{ public function test_set_realpath() { $expected = getcwd() . DIRECTORY_SEPARATOR; diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index a884d6284..29c3d6594 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -1,9 +1,12 @@ helper('string'); + } -class String_helper_test extends CI_TestCase -{ public function test_strip_slashes() { $expected = array( diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index a0866e638..584066b0c 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -1,13 +1,13 @@ helper('text'); + $this->_long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.'; } diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php index 51a8cc7c0..c561809ce 100644 --- a/tests/codeigniter/helpers/url_helper_test.php +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -1,9 +1,12 @@ helper('url'); + } -class Url_helper_test extends CI_TestCase -{ public function test_url_title() { $words = array( diff --git a/tests/codeigniter/helpers/xml_helper_test.php b/tests/codeigniter/helpers/xml_helper_test.php index 49f49e166..a83fef91e 100644 --- a/tests/codeigniter/helpers/xml_helper_test.php +++ b/tests/codeigniter/helpers/xml_helper_test.php @@ -1,9 +1,11 @@ helper('xml'); + } public function test_xml_convert() { -- cgit v1.2.3-24-g4f1b From 655a89f4059ebae017d1c4ec5f26aeb2cf4a3bae Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 29 Mar 2012 03:00:56 +0700 Subject: Preliminary Database Test --- tests/codeigniter/database/.gitkeep | 0 tests/codeigniter/database/DB_test.php | 44 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) delete mode 100644 tests/codeigniter/database/.gitkeep create mode 100644 tests/codeigniter/database/DB_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/.gitkeep b/tests/codeigniter/database/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/codeigniter/database/DB_test.php b/tests/codeigniter/database/DB_test.php new file mode 100644 index 000000000..c1930f5f2 --- /dev/null +++ b/tests/codeigniter/database/DB_test.php @@ -0,0 +1,44 @@ +db_config = new Mock_Database_DB(array( + 'mysql' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'travis', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'mysql', + 'dbprefix' => '', + 'pconnect' => FALSE, + 'db_debug' => TRUE, + 'cache_on' => FALSE, + 'cachedir' => '', + 'char_set' => 'utf8', + 'dbcollat' => 'utf8_general_ci', + 'swap_pre' => '', + 'autoinit' => TRUE, + 'stricton' => FALSE, + 'failover' => array(), + ), + )); + } + + // ------------------------------------------------------------------------ + + public function test_db_valid() + { + $db = DB($this->db_config->set_config('mysql'), TRUE); + + $this->assertTrue($db instanceof CI_DB); + $this->assertTrue($db instanceof CI_DB_Driver); + $this->assertTrue($db instanceof CI_DB_active_record); + $this->assertTrue($db instanceof CI_DB_mysql_driver); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a8a2e3325c128ccdc941daba3bba10b78bf2d098 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 29 Mar 2012 03:56:46 +0700 Subject: Travis setup and minor cleanup --- tests/codeigniter/database/DB_test.php | 45 ++++++++++++----------- tests/codeigniter/database/query_builder/.gitkeep | 0 2 files changed, 24 insertions(+), 21 deletions(-) create mode 100644 tests/codeigniter/database/query_builder/.gitkeep (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/DB_test.php b/tests/codeigniter/database/DB_test.php index c1930f5f2..10e8dec64 100644 --- a/tests/codeigniter/database/DB_test.php +++ b/tests/codeigniter/database/DB_test.php @@ -2,11 +2,31 @@ class DB_test extends CI_TestCase { - public $db_config; + // ------------------------------------------------------------------------ - public function set_up() + public function test_db_invalid() { - $this->db_config = new Mock_Database_DB(array( + $db_config = new Mock_Database_DB(array( + 'undefined' => array( + 'dsn' => '', + 'hostname' => 'undefined', + 'username' => 'undefined', + 'password' => 'undefined', + 'database' => 'undefined', + 'dbdriver' => 'undefined', + ), + )); + + $this->setExpectedException('InvalidArgumentException', 'CI Error: Invalid DB driver'); + + Mock_Database_DB::DB($db_config->set_dsn('undefined'), TRUE); + } + + // ------------------------------------------------------------------------ + + public function test_db_valid() + { + $db_config = new Mock_Database_DB(array( 'mysql' => array( 'dsn' => '', 'hostname' => 'localhost', @@ -14,30 +34,13 @@ class DB_test extends CI_TestCase { 'password' => '', 'database' => 'ci_test', 'dbdriver' => 'mysql', - 'dbprefix' => '', - 'pconnect' => FALSE, - 'db_debug' => TRUE, - 'cache_on' => FALSE, - 'cachedir' => '', - 'char_set' => 'utf8', - 'dbcollat' => 'utf8_general_ci', - 'swap_pre' => '', - 'autoinit' => TRUE, - 'stricton' => FALSE, - 'failover' => array(), ), )); - } - // ------------------------------------------------------------------------ - - public function test_db_valid() - { - $db = DB($this->db_config->set_config('mysql'), TRUE); + $db = Mock_Database_DB::DB($db_config->set_dsn('mysql'), TRUE); $this->assertTrue($db instanceof CI_DB); $this->assertTrue($db instanceof CI_DB_Driver); - $this->assertTrue($db instanceof CI_DB_active_record); $this->assertTrue($db instanceof CI_DB_mysql_driver); } diff --git a/tests/codeigniter/database/query_builder/.gitkeep b/tests/codeigniter/database/query_builder/.gitkeep new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3-24-g4f1b From ee2f5d08c64d96b7abc7195bcd1b6a3fd67b5b42 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 30 Mar 2012 06:29:11 +0700 Subject: Multi database setup --- tests/codeigniter/database/DB_test.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/DB_test.php b/tests/codeigniter/database/DB_test.php index 10e8dec64..9b93e223d 100644 --- a/tests/codeigniter/database/DB_test.php +++ b/tests/codeigniter/database/DB_test.php @@ -6,7 +6,7 @@ class DB_test extends CI_TestCase { public function test_db_invalid() { - $db_config = new Mock_Database_DB(array( + $connection = new Mock_Database_DB(array( 'undefined' => array( 'dsn' => '', 'hostname' => 'undefined', @@ -19,29 +19,31 @@ class DB_test extends CI_TestCase { $this->setExpectedException('InvalidArgumentException', 'CI Error: Invalid DB driver'); - Mock_Database_DB::DB($db_config->set_dsn('undefined'), TRUE); + Mock_Database_DB::DB($connection->set_dsn('undefined'), TRUE); } // ------------------------------------------------------------------------ public function test_db_valid() { - $db_config = new Mock_Database_DB(array( - 'mysql' => array( - 'dsn' => '', - 'hostname' => 'localhost', - 'username' => 'travis', - 'password' => '', - 'database' => 'ci_test', - 'dbdriver' => 'mysql', - ), - )); + $config = Mock_Database_DB::config(DB_DRIVER); + $connection = new Mock_Database_DB($config); + $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER), TRUE); + + $this->assertTrue($db instanceof CI_DB); + $this->assertTrue($db instanceof CI_DB_Driver); + } - $db = Mock_Database_DB::DB($db_config->set_dsn('mysql'), TRUE); + // ------------------------------------------------------------------------ + + public function test_db_failover() + { + $config = Mock_Database_DB::config(DB_DRIVER); + $connection = new Mock_Database_DB($config); + $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER.'_failover'), TRUE); $this->assertTrue($db instanceof CI_DB); $this->assertTrue($db instanceof CI_DB_Driver); - $this->assertTrue($db instanceof CI_DB_mysql_driver); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f4c6c9b3061b464c959b6409f962228959f35287 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 4 Apr 2012 23:24:09 +0700 Subject: DB Drivers test --- tests/codeigniter/database/DB_driver_test.php | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/codeigniter/database/DB_driver_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php new file mode 100644 index 000000000..fb40f0608 --- /dev/null +++ b/tests/codeigniter/database/DB_driver_test.php @@ -0,0 +1,36 @@ +$driver_name($config[DB_DRIVER]); + + $this->assertTrue($driver->initialize()); + } + + protected function pdo($config) + { + return new Mock_Database_Drivers_PDO($config); + } + + protected function mysql($config) + { + return new Mock_Database_Drivers_Mysql($config); + } + + protected function sqlite($config) + { + return new Mock_Database_Drivers_Sqlite($config); + } + + protected function pgsql($config) + { + return new Mock_Database_Drivers_Postgre($config); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 61ff054fb905f0514b942bf3e70a6c882bd64f7a Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 01:23:56 +0700 Subject: Adding schema and initial Query Builder code coverage --- tests/codeigniter/database/query_builder/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/codeigniter/database/query_builder/.gitkeep (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/.gitkeep b/tests/codeigniter/database/query_builder/.gitkeep deleted file mode 100644 index e69de29bb..000000000 -- cgit v1.2.3-24-g4f1b From 5b421665bac7609192917f7b0f34838534be099e Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 01:24:50 +0700 Subject: Simple query builder tests --- .../database/query_builder/get_test.php | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/get_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php new file mode 100644 index 000000000..6f98ded4f --- /dev/null +++ b/tests/codeigniter/database/query_builder/get_test.php @@ -0,0 +1,48 @@ +set_dsn(DB_DRIVER), TRUE); + + $this->ci_instance_var('db', $db); + + $loader = new Mock_Core_Loader(); + $loader->dbforge(); + + $forge = $this->ci_instance->dbforge; + + Mock_Database_Schema_Skeleton::create_tables($forge); + Mock_Database_Schema_Skeleton::create_data($db); + + $this->query_builder = $db; + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_get_simple() + { + $jobs = $this->query_builder->get('job')->result_array(); + + // Dummy jobs contain 4 rows + $this->assertCount(4, $jobs); + + // Check rows item + $this->assertEquals('Developer', $jobs[0]['name']); + $this->assertEquals('Politician', $jobs[1]['name']); + $this->assertEquals('Accountant', $jobs[2]['name']); + $this->assertEquals('Musician', $jobs[3]['name']); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 333ce0db32865d1e6d6a96207e5c9306bd40c676 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 02:34:06 +0700 Subject: Fixed schema --- tests/codeigniter/database/query_builder/get_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php index 6f98ded4f..e6fe319c5 100644 --- a/tests/codeigniter/database/query_builder/get_test.php +++ b/tests/codeigniter/database/query_builder/get_test.php @@ -20,7 +20,7 @@ class Get_test extends CI_TestCase { $forge = $this->ci_instance->dbforge; - Mock_Database_Schema_Skeleton::create_tables($forge); + Mock_Database_Schema_Skeleton::create_tables($forge, DB_DRIVER); Mock_Database_Schema_Skeleton::create_data($db); $this->query_builder = $db; -- cgit v1.2.3-24-g4f1b From 55f622f76371949ae615ccdff76ed1e4bab55170 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 19:01:34 +0700 Subject: Add select clause test --- .../database/query_builder/get_test.php | 31 +++++++++++------- .../database/query_builder/select_test.php | 37 ++++++++++++++++++++++ 2 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 tests/codeigniter/database/query_builder/select_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php index e6fe319c5..dd946a40c 100644 --- a/tests/codeigniter/database/query_builder/get_test.php +++ b/tests/codeigniter/database/query_builder/get_test.php @@ -9,19 +9,10 @@ class Get_test extends CI_TestCase { public function set_up() { - $config = Mock_Database_DB::config(DB_DRIVER); - $connection = new Mock_Database_DB($config); - $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER), TRUE); + $db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - $this->ci_instance_var('db', $db); - - $loader = new Mock_Core_Loader(); - $loader->dbforge(); - - $forge = $this->ci_instance->dbforge; - - Mock_Database_Schema_Skeleton::create_tables($forge, DB_DRIVER); - Mock_Database_Schema_Skeleton::create_data($db); + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); $this->query_builder = $db; } @@ -44,5 +35,21 @@ class Get_test extends CI_TestCase { $this->assertEquals('Accountant', $jobs[2]['name']); $this->assertEquals('Musician', $jobs[3]['name']); } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_get_where() + { + $job1 = $this->query_builder->get('job', array('id' => 1))->result_array(); + + // Dummy jobs contain 1 rows + $this->assertCount(1, $job1); + + // Check rows item + $this->assertEquals('Developer', $job1[0]['name']); + } } \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php new file mode 100644 index 000000000..ba2f21b64 --- /dev/null +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -0,0 +1,37 @@ +query_builder = $db; + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_select_only_one_collumn() + { + $jobs_name = $this->query_builder->select('name') + ->get('job') + ->result_array(); + + // Check rows item + $this->assertArrayHasKey('name',$jobs_name[0]); + $this->assertFalse(array_key_exists('id', $jobs_name[0])); + $this->assertFalse(array_key_exists('description', $jobs_name[0])); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From fdc0ea8802c48a5f74df97c013f683d4b264218a Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 19:08:00 +0700 Subject: Min, Max, Avg and Sum --- .../database/query_builder/select_test.php | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php index ba2f21b64..50a062c9f 100644 --- a/tests/codeigniter/database/query_builder/select_test.php +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -33,5 +33,65 @@ class Select_test extends CI_TestCase { $this->assertFalse(array_key_exists('id', $jobs_name[0])); $this->assertFalse(array_key_exists('description', $jobs_name[0])); } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_select_min() + { + $job_min = $this->query_builder->select_min('id') + ->get('job') + ->result_array(); + + // Minimum id was 1 + $this->assertEquals('1', $job_min[0]['id']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_select_max() + { + $job_max = $this->query_builder->select_max('id') + ->get('job') + ->result_array(); + + // Maximum id was 4 + $this->assertEquals('4', $job_max[0]['id']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_select_avg() + { + $job_avg = $this->query_builder->select_avg('id') + ->get('job') + ->result_array(); + + // Average should be 2.5 + $this->assertEquals('2.5', $job_avg[0]['id']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_select_sum() + { + $job_sum = $this->query_builder->select_sum('id') + ->get('job') + ->result_array(); + + // Sum of ids should be 10 + $this->assertEquals('10', $job_sum[0]['id']); + } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0793b1c918a0146920b1a03323f055521c4a9c66 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 21:47:53 +0700 Subject: Rename to db, for more familiar naming convention --- .../database/query_builder/get_test.php | 10 +++--- .../database/query_builder/select_test.php | 36 ++++++++++------------ 2 files changed, 21 insertions(+), 25 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php index dd946a40c..0751c9332 100644 --- a/tests/codeigniter/database/query_builder/get_test.php +++ b/tests/codeigniter/database/query_builder/get_test.php @@ -5,16 +5,14 @@ class Get_test extends CI_TestCase { /** * @var object Database/Query Builder holder */ - protected $query_builder; + protected $db; public function set_up() { - $db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); Mock_Database_Schema_Skeleton::create_tables(); Mock_Database_Schema_Skeleton::create_data(); - - $this->query_builder = $db; } // ------------------------------------------------------------------------ @@ -24,7 +22,7 @@ class Get_test extends CI_TestCase { */ public function test_get_simple() { - $jobs = $this->query_builder->get('job')->result_array(); + $jobs = $this->db->get('job')->result_array(); // Dummy jobs contain 4 rows $this->assertCount(4, $jobs); @@ -43,7 +41,7 @@ class Get_test extends CI_TestCase { */ public function test_get_where() { - $job1 = $this->query_builder->get('job', array('id' => 1))->result_array(); + $job1 = $this->db->get('job', array('id' => 1))->result_array(); // Dummy jobs contain 1 rows $this->assertCount(1, $job1); diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php index 50a062c9f..dbf432a7c 100644 --- a/tests/codeigniter/database/query_builder/select_test.php +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -5,16 +5,14 @@ class Select_test extends CI_TestCase { /** * @var object Database/Query Builder holder */ - protected $query_builder; + protected $db; public function set_up() { - $db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); Mock_Database_Schema_Skeleton::create_tables(); Mock_Database_Schema_Skeleton::create_data(); - - $this->query_builder = $db; } // ------------------------------------------------------------------------ @@ -24,9 +22,9 @@ class Select_test extends CI_TestCase { */ public function test_select_only_one_collumn() { - $jobs_name = $this->query_builder->select('name') - ->get('job') - ->result_array(); + $jobs_name = $this->db->select('name') + ->get('job') + ->result_array(); // Check rows item $this->assertArrayHasKey('name',$jobs_name[0]); @@ -41,9 +39,9 @@ class Select_test extends CI_TestCase { */ public function test_select_min() { - $job_min = $this->query_builder->select_min('id') - ->get('job') - ->result_array(); + $job_min = $this->db->select_min('id') + ->get('job') + ->result_array(); // Minimum id was 1 $this->assertEquals('1', $job_min[0]['id']); @@ -56,9 +54,9 @@ class Select_test extends CI_TestCase { */ public function test_select_max() { - $job_max = $this->query_builder->select_max('id') - ->get('job') - ->result_array(); + $job_max = $this->db->select_max('id') + ->get('job') + ->result_array(); // Maximum id was 4 $this->assertEquals('4', $job_max[0]['id']); @@ -71,9 +69,9 @@ class Select_test extends CI_TestCase { */ public function test_select_avg() { - $job_avg = $this->query_builder->select_avg('id') - ->get('job') - ->result_array(); + $job_avg = $this->db->select_avg('id') + ->get('job') + ->result_array(); // Average should be 2.5 $this->assertEquals('2.5', $job_avg[0]['id']); @@ -86,9 +84,9 @@ class Select_test extends CI_TestCase { */ public function test_select_sum() { - $job_sum = $this->query_builder->select_sum('id') - ->get('job') - ->result_array(); + $job_sum = $this->db->select_sum('id') + ->get('job') + ->result_array(); // Sum of ids should be 10 $this->assertEquals('10', $job_sum[0]['id']); -- cgit v1.2.3-24-g4f1b From c0df5a231a28c6038f0a8ab702e090ce0e12b5a5 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 6 Apr 2012 17:35:12 +0700 Subject: Include insert test --- .../database/query_builder/insert_test.php | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/insert_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php new file mode 100644 index 000000000..5607e8ce1 --- /dev/null +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -0,0 +1,47 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_insert() + { + $job_data = array('name' => 'Grocery Sales', 'description' => 'Discount!'); + + // Do normal insert + $this->assertTrue($this->db->insert('job', $job_data)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_insert_batch() + { + $job_datas = array( + array('name' => 'Commedian', 'description' => 'Theres something in your teeth'), + array('name' => 'Cab Driver', 'description' => 'Iam yellow'), + ); + + // Do insert batch + $this->assertTrue($this->db->insert_batch('job', $job_datas)); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 81b6b5d4ea2e63159c443bae19880a78f6ac2f9f Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 6 Apr 2012 17:58:22 +0700 Subject: Insert test --- tests/codeigniter/database/query_builder/insert_test.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 5607e8ce1..80073b9ba 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -12,7 +12,6 @@ class Insert_test extends CI_TestCase { $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); } // ------------------------------------------------------------------------ @@ -22,7 +21,7 @@ class Insert_test extends CI_TestCase { */ public function test_insert() { - $job_data = array('name' => 'Grocery Sales', 'description' => 'Discount!'); + $job_data = array('id' => 1, 'name' => 'Grocery Sales', 'description' => 'Discount!'); // Do normal insert $this->assertTrue($this->db->insert('job', $job_data)); @@ -36,8 +35,8 @@ class Insert_test extends CI_TestCase { public function test_insert_batch() { $job_datas = array( - array('name' => 'Commedian', 'description' => 'Theres something in your teeth'), - array('name' => 'Cab Driver', 'description' => 'Iam yellow'), + array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'), + array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'), ); // Do insert batch -- cgit v1.2.3-24-g4f1b From fc92fc2e4f262a3607898ca7cd8b361d95f09136 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 6 Apr 2012 18:00:55 +0700 Subject: Add truncate --- tests/codeigniter/database/query_builder/insert_test.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 80073b9ba..78587d2e9 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -4,6 +4,7 @@ class Insert_test extends CI_TestCase { /** * @var object Database/Query Builder holder + * @see ./mocks/schema/skeleton.php */ protected $db; @@ -12,6 +13,9 @@ class Insert_test extends CI_TestCase { $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); Mock_Database_Schema_Skeleton::create_tables(); + + // Truncate the current datas + $this->db->truncate('job'); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 80c0e3df5998a2a4b2376a6361f4690b783446df Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 7 Apr 2012 01:15:53 +0700 Subject: Check the insert result --- tests/codeigniter/database/query_builder/insert_test.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 78587d2e9..5dfccce82 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -29,6 +29,12 @@ class Insert_test extends CI_TestCase { // Do normal insert $this->assertTrue($this->db->insert('job', $job_data)); + + $job_1 = $this->db->get('job')->row(); + + // Check the result + $this->assertEquals('Grocery Sales', $job_1->name); + } // ------------------------------------------------------------------------ @@ -45,6 +51,11 @@ class Insert_test extends CI_TestCase { // Do insert batch $this->assertTrue($this->db->insert_batch('job', $job_datas)); + + $job_2 = $this->db->get_where('job', array('id' => 2))->row(); + + // Check the result + $this->assertEquals('Commedian', $job_2->name); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d489747059db6a91d5532f35437a812a81f2b98b Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 7 Apr 2012 03:16:25 +0700 Subject: Remove batch test from sqlite --- .../database/query_builder/insert_test.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 5dfccce82..b86feeb74 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -30,10 +30,11 @@ class Insert_test extends CI_TestCase { // Do normal insert $this->assertTrue($this->db->insert('job', $job_data)); - $job_1 = $this->db->get('job')->row(); + $jobs = $this->db->get('job')->result_array(); + $job1 = $jobs[0]; // Check the result - $this->assertEquals('Grocery Sales', $job_1->name); + $this->assertEquals('Grocery Sales', $job1['name']); } @@ -49,13 +50,18 @@ class Insert_test extends CI_TestCase { array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'), ); - // Do insert batch - $this->assertTrue($this->db->insert_batch('job', $job_datas)); + // Do insert batch except for sqlite driver + if (strpos(DB_DRIVER, 'sqlite') === FALSE) + { + $this->assertTrue($this->db->insert('job', $job_datas[0])); - $job_2 = $this->db->get_where('job', array('id' => 2))->row(); + $job_2 = $this->db->where('id', 2)->get('job')->row(); + $job_3 = $this->db->where('id', 3)->get('job')->row(); - // Check the result - $this->assertEquals('Commedian', $job_2->name); + // Check the result + $this->assertEquals('Commedian', $job_2->name); + $this->assertEquals('Cab Driver', $job_3->name); + } } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5ce26c912f11fb859e661a43a6667fba5a5a3ca2 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 7 Apr 2012 03:19:35 +0700 Subject: Typo --- tests/codeigniter/database/query_builder/insert_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index b86feeb74..53ce23c19 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -53,7 +53,7 @@ class Insert_test extends CI_TestCase { // Do insert batch except for sqlite driver if (strpos(DB_DRIVER, 'sqlite') === FALSE) { - $this->assertTrue($this->db->insert('job', $job_datas[0])); + $this->assertTrue($this->db->insert_batch('job', $job_datas)); $job_2 = $this->db->where('id', 2)->get('job')->row(); $job_3 = $this->db->where('id', 3)->get('job')->row(); -- cgit v1.2.3-24-g4f1b From 190c6bb125447f83793d9437f1bea28feada910a Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 3 May 2012 12:13:39 +0700 Subject: Cleaning up --- tests/codeigniter/database/query_builder/insert_test.php | 5 ++--- tests/codeigniter/database/query_builder/select_test.php | 16 ++++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 53ce23c19..8ba60e242 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -30,11 +30,10 @@ class Insert_test extends CI_TestCase { // Do normal insert $this->assertTrue($this->db->insert('job', $job_data)); - $jobs = $this->db->get('job')->result_array(); - $job1 = $jobs[0]; + $job1 = $this->db->get('job')->row(); // Check the result - $this->assertEquals('Grocery Sales', $job1['name']); + $this->assertEquals('Grocery Sales', $job1->name); } diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php index dbf432a7c..0d299ed16 100644 --- a/tests/codeigniter/database/query_builder/select_test.php +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -41,10 +41,10 @@ class Select_test extends CI_TestCase { { $job_min = $this->db->select_min('id') ->get('job') - ->result_array(); + ->row(); // Minimum id was 1 - $this->assertEquals('1', $job_min[0]['id']); + $this->assertEquals('1', $job_min->id); } // ------------------------------------------------------------------------ @@ -56,10 +56,10 @@ class Select_test extends CI_TestCase { { $job_max = $this->db->select_max('id') ->get('job') - ->result_array(); + ->row(); // Maximum id was 4 - $this->assertEquals('4', $job_max[0]['id']); + $this->assertEquals('4', $job_max->id); } // ------------------------------------------------------------------------ @@ -71,10 +71,10 @@ class Select_test extends CI_TestCase { { $job_avg = $this->db->select_avg('id') ->get('job') - ->result_array(); + ->row(); // Average should be 2.5 - $this->assertEquals('2.5', $job_avg[0]['id']); + $this->assertEquals('2.5', $job_avg->id); } // ------------------------------------------------------------------------ @@ -86,10 +86,10 @@ class Select_test extends CI_TestCase { { $job_sum = $this->db->select_sum('id') ->get('job') - ->result_array(); + ->row(); // Sum of ids should be 10 - $this->assertEquals('10', $job_sum[0]['id']); + $this->assertEquals('10', $job_sum->id); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6e131cbd0a5243f29a5ad9f56c80715e534e4267 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 3 May 2012 12:14:19 +0700 Subject: FROM clause API code-coverage --- .../database/query_builder/from_test.php | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/from_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/from_test.php b/tests/codeigniter/database/query_builder/from_test.php new file mode 100644 index 000000000..95ae4dfdb --- /dev/null +++ b/tests/codeigniter/database/query_builder/from_test.php @@ -0,0 +1,51 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_from_simple() + { + $jobs = $this->db->from('job') + ->get() + ->result_array(); + + // Check items + $this->assertEquals(4, count($jobs)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_from_with_where() + { + $job1 = $this->db->from('job') + ->where('id', 1) + ->get() + ->row(); + + // Check the result + $this->assertEquals('1', $job1->id); + $this->assertEquals('Developer', $job1->name); + $this->assertEquals('Awesome job, but sometimes makes you bored', $job1->description); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d6b41bb2659f959da01aee0ddb38bb4bce6cd4b6 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 15:05:22 +0700 Subject: JOIN clause API code-coverage --- .../database/query_builder/join_test.php | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/join_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php new file mode 100644 index 000000000..e05329d67 --- /dev/null +++ b/tests/codeigniter/database/query_builder/join_test.php @@ -0,0 +1,38 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_join_simple() + { + $job_user = $this->db->select('job.id as job_id, job.name as job_name, user.id as user_id, user.name as user_name') + ->from('job') + ->join('user', 'user.id = job.id') + ->get() + ->result_array(); + + // Check the result + $this->assertEquals('1', $job_user[0]['job_id']); + $this->assertEquals('1', $job_user[0]['user_id']); + $this->assertEquals('Derek Jones', $job_user[0]['user_name']); + $this->assertEquals('Developer', $job_user[0]['job_name']); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 12f5475e2b279d1c2361ad5fc85bc2ba0d0f9033 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 15:46:39 +0700 Subject: WHERE clause API code-coverage --- .../database/query_builder/where_test.php | 144 +++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/where_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php new file mode 100644 index 000000000..607eaa076 --- /dev/null +++ b/tests/codeigniter/database/query_builder/where_test.php @@ -0,0 +1,144 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_simple_key_value() + { + $job1 = $this->db->where('id', 1) + ->get('job') + ->row(); + + // Check the result + $this->assertEquals('1', $job1->id); + $this->assertEquals('Developer', $job1->name); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_custom_key_value() + { + $jobs = $this->db->where('id !=', 1) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_associative_array() + { + $where = array('id >' => 2, 'name !=' => 'Accountant'); + $jobs = $this->db->where($where) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(1, count($jobs)); + + // Should be Musician + $job = current($jobs); + + $this->assertEquals('Musician', $job['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_custom_string() + { + $where = "id > 2 AND name != 'Accountant'"; + $jobs = $this->db->where($where) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(1, count($jobs)); + + // Should be Musician + $job = current($jobs); + + $this->assertEquals('Musician', $job['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_or() + { + $jobs = $this->db->where('name !=', 'Accountant') + ->or_where('id >', 3) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + $this->assertEquals('Developer', $jobs[0]['name']); + $this->assertEquals('Politician', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_in() + { + $jobs = $this->db->where_in('name', array('Politician', 'Accountant')) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + $this->assertEquals('Politician', $jobs[0]['name']); + $this->assertEquals('Accountant', $jobs[1]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_not_in() + { + $jobs = $this->db->where_not_in('name', array('Politician', 'Accountant')) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + $this->assertEquals('Developer', $jobs[0]['name']); + $this->assertEquals('Musician', $jobs[1]['name']); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f78018ec6b081518e4be24934448862a31bda9f8 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 15:53:55 +0700 Subject: LIKE clause API code-coverage --- .../database/query_builder/like_test.php | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/like_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/like_test.php b/tests/codeigniter/database/query_builder/like_test.php new file mode 100644 index 000000000..df98c713f --- /dev/null +++ b/tests/codeigniter/database/query_builder/like_test.php @@ -0,0 +1,90 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_like() + { + $job1 = $this->db->like('name', 'veloper') + ->get('job') + ->row(); + + // Check the result + $this->assertEquals('1', $job1->id); + $this->assertEquals('Developer', $job1->name); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_or_like() + { + $jobs = $this->db->like('name', 'ian') + ->or_like('name', 'veloper') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + $this->assertEquals('Developer', $jobs[0]['name']); + $this->assertEquals('Politician', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_not_like() + { + $jobs = $this->db->not_like('name', 'veloper') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + $this->assertEquals('Politician', $jobs[0]['name']); + $this->assertEquals('Accountant', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_or_not_like() + { + $jobs = $this->db->like('name', 'an') + ->or_not_like('name', 'veloper') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + $this->assertEquals('Politician', $jobs[0]['name']); + $this->assertEquals('Accountant', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4e607b00b2c56b7fdcc5f1d1a290be2363c74a46 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 19:22:48 +0700 Subject: GROUP BY clause API code-coverage --- .../database/query_builder/group_test.php | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/group_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php new file mode 100644 index 000000000..ddb2d0d6a --- /dev/null +++ b/tests/codeigniter/database/query_builder/group_test.php @@ -0,0 +1,37 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_group_by() + { + $jobs = $this->db->select('name') + ->from('job') + ->group_by('name HAVING SUM(id) > 2') + ->get() + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + $this->assertEquals('Accountant', $jobs[0]['name']); + $this->assertEquals('Musician', $jobs[1]['name']); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f7377abee2ef1e165a362edc9a1c650373a002ca Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 19:42:24 +0700 Subject: Trace error --- tests/codeigniter/database/query_builder/group_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php index ddb2d0d6a..dd248ae9a 100644 --- a/tests/codeigniter/database/query_builder/group_test.php +++ b/tests/codeigniter/database/query_builder/group_test.php @@ -22,16 +22,16 @@ class Group_test extends CI_TestCase { */ public function test_group_by() { - $jobs = $this->db->select('name') + $jobs = $this->db->select('job.name as job_name, job.id as job_id') ->from('job') - ->group_by('name HAVING SUM(id) > 2') + ->group_by('job_name HAVING SUM(job_id) > 2') ->get() ->result_array(); // Check the result $this->assertEquals(2, count($jobs)); - $this->assertEquals('Accountant', $jobs[0]['name']); - $this->assertEquals('Musician', $jobs[1]['name']); + $this->assertEquals('Accountant', $jobs[0]['job_name']); + $this->assertEquals('Musician', $jobs[1]['job_name']); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1afd479059c3d6f7c46aa0c36aa56cfba7f94226 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 20:34:30 +0700 Subject: HAVING clause API code-coverage --- .../database/query_builder/group_test.php | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php index dd248ae9a..7d8abc33f 100644 --- a/tests/codeigniter/database/query_builder/group_test.php +++ b/tests/codeigniter/database/query_builder/group_test.php @@ -22,16 +22,32 @@ class Group_test extends CI_TestCase { */ public function test_group_by() { - $jobs = $this->db->select('job.name as job_name, job.id as job_id') + $jobs = $this->db->select('name') ->from('job') - ->group_by('job_name HAVING SUM(job_id) > 2') + ->group_by('name') + ->get() + ->result_array(); + + // Check the result + $this->assertEquals(4, count($jobs)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_having_by() + { + $jobs = $this->db->select('name') + ->from('job') + ->group_by('name') + ->having('SUM(id) > 2') ->get() ->result_array(); // Check the result $this->assertEquals(2, count($jobs)); - $this->assertEquals('Accountant', $jobs[0]['job_name']); - $this->assertEquals('Musician', $jobs[1]['job_name']); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 44d8d881b401238661d81fc9db10482604b4cf43 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 20:43:45 +0700 Subject: DISTINCT clause API code-coverage --- .../database/query_builder/distinct_test.php | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/distinct_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/distinct_test.php b/tests/codeigniter/database/query_builder/distinct_test.php new file mode 100644 index 000000000..925eadb19 --- /dev/null +++ b/tests/codeigniter/database/query_builder/distinct_test.php @@ -0,0 +1,34 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_distinct() + { + $users = $this->db->select('country') + ->distinct() + ->get('user') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($users)); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d2d329a99f60bebc36eebc1c7b3c1a94b9789b49 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 00:33:04 +0700 Subject: ORDER BY clause API code-coverage --- .../database/query_builder/order_test.php | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/order_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/order_test.php b/tests/codeigniter/database/query_builder/order_test.php new file mode 100644 index 000000000..01aa1c2b4 --- /dev/null +++ b/tests/codeigniter/database/query_builder/order_test.php @@ -0,0 +1,55 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_order_ascending() + { + $jobs = $this->db->order_by('name', 'asc') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(4, count($jobs)); + $this->assertEquals('Accountant', $jobs[0]['name']); + $this->assertEquals('Developer', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + $this->assertEquals('Politician', $jobs[3]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_order_descending() + { + $jobs = $this->db->order_by('name', 'desc') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(4, count($jobs)); + $this->assertEquals('Politician', $jobs[0]['name']); + $this->assertEquals('Musician', $jobs[1]['name']); + $this->assertEquals('Developer', $jobs[2]['name']); + $this->assertEquals('Accountant', $jobs[3]['name']); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From be6fb4271ce723376930507dbe534f91344f26c7 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 00:35:41 +0700 Subject: LIMIT clause API code-coverage --- .../database/query_builder/limit_test.php | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/limit_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/limit_test.php b/tests/codeigniter/database/query_builder/limit_test.php new file mode 100644 index 000000000..704f3b651 --- /dev/null +++ b/tests/codeigniter/database/query_builder/limit_test.php @@ -0,0 +1,49 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_limit() + { + $jobs = $this->db->limit(2) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_limit_and_offset() + { + $jobs = $this->db->limit(2, 2) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + $this->assertEquals('Accountant', $jobs[0]['name']); + $this->assertEquals('Musician', $jobs[1]['name']); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c386b2a363c289afcfa07eea081050e35c1e86d8 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 00:42:02 +0700 Subject: count code-coverage --- .../database/query_builder/count_test.php | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/count_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/count_test.php b/tests/codeigniter/database/query_builder/count_test.php new file mode 100644 index 000000000..5e691692d --- /dev/null +++ b/tests/codeigniter/database/query_builder/count_test.php @@ -0,0 +1,44 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_count_all() + { + $job_count = $this->db->count_all('job'); + + // Check the result + $this->assertEquals(4, $job_count); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_count_all_results() + { + $job_count = $this->db->like('name', 'ian') + ->count_all_results('job'); + + // Check the result + $this->assertEquals(2, $job_count); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9ec507badf60952750e76b5d83da54874dd19119 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 00:55:39 +0700 Subject: UPDATE and SET clause code-coverage --- .../database/query_builder/update_test.php | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/update_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/update_test.php b/tests/codeigniter/database/query_builder/update_test.php new file mode 100644 index 000000000..f5bbffd4f --- /dev/null +++ b/tests/codeigniter/database/query_builder/update_test.php @@ -0,0 +1,71 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_update() + { + // Check initial record + $job1 = $this->db->where('id', 1) + ->get('job') + ->row(); + + $this->assertEquals('Developer', $job1->name); + + // Do the update + $job_data = array('name' => 'Programmer'); + + $this->db->where('id', 1) + ->update('job', $job_data); + + // Check updated record + $job1 = $this->db->where('id', 1) + ->get('job') + ->row(); + + $this->assertEquals('Programmer', $job1->name); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_update_with_set() + { + // Check initial record + $job1 = $this->db->where('id', 4) + ->get('job') + ->row(); + + $this->assertEquals('Musician', $job1->name); + + // Do the update + $this->db->set('name', 'Vocalist'); + $this->db->update('job', NULL, 'id = 4'); + + // Check updated record + $job1 = $this->db->where('id', 4) + ->get('job') + ->row(); + + $this->assertEquals('Vocalist', $job1->name); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6657cc1672f3f466655b1e476028b9d46a16bd1c Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:06:41 +0700 Subject: DELETE code-coverage --- .../database/query_builder/delete_test.php | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/delete_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/delete_test.php b/tests/codeigniter/database/query_builder/delete_test.php new file mode 100644 index 000000000..84ea7616f --- /dev/null +++ b/tests/codeigniter/database/query_builder/delete_test.php @@ -0,0 +1,72 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_delete() + { + // Check initial record + $job1 = $this->db->where('id', 1) + ->get('job') + ->row(); + + $this->assertEquals('Developer', $job1->name); + + // Do the delete + $this->db->delete('job', array('id' => 1)); + + // Check the record + $job1 = $this->db->where('id', 1) + ->get('job'); + + $this->assertEmpty($job1->result_array()); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_delete_several_tables() + { + // Check initial record + $user4 = $this->db->where('id', 4) + ->get('user') + ->row(); + + $job4 = $this->db->where('id', 4) + ->get('job') + ->row(); + + $this->assertEquals('Musician', $job4->name); + $this->assertEquals('Chris Martin', $user4->name); + + // Do the delete + $this->db->delete(array('job', 'user'), array('id' => 4)); + + // Check the record + $job4 = $this->db->where('id', 4)->get('job'); + $user4 = $this->db->where('id', 4)->get('user'); + + $this->assertEmpty($job4->result_array()); + $this->assertEmpty($user4->result_array()); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 85859b212e480e2e1a59aae50c759367d6794ecd Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:26:51 +0700 Subject: empty table API code-coverage --- .../database/query_builder/empty_test.php | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/empty_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/empty_test.php b/tests/codeigniter/database/query_builder/empty_test.php new file mode 100644 index 000000000..d1f56285f --- /dev/null +++ b/tests/codeigniter/database/query_builder/empty_test.php @@ -0,0 +1,39 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_empty_table() + { + // Check initial record + $jobs = $this->db->get('job')->result_array(); + + $this->assertEquals(4, count($jobs)); + + // Do the empty + $this->db->empty_table('job'); + + // Check the record + $jobs = $this->db->get('job'); + + $this->assertEmpty($jobs->result_array()); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 39f35fde6d023433e98904105f55f305483b6b5e Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:29:13 +0700 Subject: TRUNCATE code-coverage --- .../database/query_builder/truncate_test.php | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/truncate_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/truncate_test.php b/tests/codeigniter/database/query_builder/truncate_test.php new file mode 100644 index 000000000..2a9c8a91e --- /dev/null +++ b/tests/codeigniter/database/query_builder/truncate_test.php @@ -0,0 +1,61 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_truncate() + { + // Check initial record + $jobs = $this->db->get('job')->result_array(); + + $this->assertEquals(4, count($jobs)); + + // Do the empty + $this->db->truncate('job'); + + // Check the record + $jobs = $this->db->get('job'); + + $this->assertEmpty($jobs->result_array()); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_truncate_with_from() + { + // Check initial record + $users = $this->db->get('user')->result_array(); + + $this->assertEquals(4, count($users)); + + // Do the empty + $this->db->from('user') + ->truncate(); + + // Check the record + $users = $this->db->get('user'); + + $this->assertEmpty($users->result_array()); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 51a7c0b98df29205d39bb404c2bcd12bfb4ed4cb Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:43:08 +0700 Subject: Clean up --- tests/codeigniter/Setup_test.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php index 550245f2f..b48e32bfb 100644 --- a/tests/codeigniter/Setup_test.php +++ b/tests/codeigniter/Setup_test.php @@ -2,12 +2,12 @@ class Setup_test extends PHPUnit_Framework_TestCase { - function test_nonsense() + function test_bootstrap_constants() { - $this->markTestIncomplete('not implemented'); - // ensure that our bootstrapped test environment - // is a good representation of an isolated CI install - //die('here'); + $this->assertTrue(defined('PROJECT_BASE')); + $this->assertTrue(defined('BASEPATH')); + $this->assertTrue(defined('APPPATH')); + $this->assertTrue(defined('VIEWPATH')); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 570e77cd78e0c704b032c3e7702372ca63d5ddaa Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Tue, 15 May 2012 18:47:24 +0700 Subject: Benchmark code-coverage --- tests/codeigniter/core/Benchmark_test.php | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/codeigniter/core/Benchmark_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php new file mode 100644 index 000000000..2790b582e --- /dev/null +++ b/tests/codeigniter/core/Benchmark_test.php @@ -0,0 +1,42 @@ +benchmark = new Mock_Core_Benchmark(); + } + + // -------------------------------------------------------------------- + + public function test_mark() + { + $this->assertEmpty($this->benchmark->marker); + + $this->benchmark->mark('code_start'); + + $this->assertEquals(1, count($this->benchmark->marker)); + $this->assertArrayHasKey('code_start', $this->benchmark->marker); + } + + // -------------------------------------------------------------------- + + public function test_elapsed_time() + { + $this->assertEquals('{elapsed_time}', $this->benchmark->elapsed_time()); + $this->assertEmpty($this->benchmark->elapsed_time('undefined_point')); + + $this->benchmark->mark('code_start'); + sleep(1); + $this->benchmark->mark('code_end'); + + $this->assertEquals('1.00', $this->benchmark->elapsed_time('code_start', 'code_end', 3)); + } + + // -------------------------------------------------------------------- + + public function test_memory_usage() + { + $this->assertEquals('{memory_usage}', $this->benchmark->memory_usage()); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 8af88f3f729b7bcfd2a106f858b5445deafe5ed0 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Tue, 15 May 2012 21:52:53 +0700 Subject: Security Code coverage --- tests/codeigniter/core/Security_test.php | 79 ++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tests/codeigniter/core/Security_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php new file mode 100644 index 000000000..c3b526965 --- /dev/null +++ b/tests/codeigniter/core/Security_test.php @@ -0,0 +1,79 @@ +ci_set_config('csrf_protection', TRUE); + $this->ci_set_config('csrf_token_name', 'ci_csrf_token'); + // @see : ./Bootstrap.php Line 16 + $this->ci_set_config('csrf_cookie_name', 'ci_csrf_cookie'); + $this->ci_set_config('csrf_expire', 7200); + $this->ci_set_config('csrf_regenerate', TRUE); + $this->ci_set_config('csrf_exclude_uris', array()); + + $this->ci_set_config('cookie_prefix', ""); + $this->ci_set_config('cookie_domain', ""); + $this->ci_set_config('cookie_path', "/"); + $this->ci_set_config('cookie_secure', FALSE); + $this->ci_set_config('cookie_httponly', FALSE); + + $this->security = new Mock_Core_Security(); + } + + // -------------------------------------------------------------------- + + public function test_csrf_verify() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + + $this->assertInstanceOf('CI_Security', $this->security->csrf_verify()); + } + + // -------------------------------------------------------------------- + + public function test_csrf_verify_invalid() + { + // Without issuing $_POST[csrf_token_name], this request will triggering CSRF error + $_SERVER['REQUEST_METHOD'] = 'POST'; + + $this->setExpectedException('RuntimeException', 'CI Error: The action you have requested is not allowed'); + + $this->security->csrf_verify(); + } + + // -------------------------------------------------------------------- + + public function test_csrf_verify_valid() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST[$this->security->csrf_token_name] = $this->security->csrf_hash; + + $this->assertInstanceOf('CI_Security', $this->security->csrf_verify()); + } + + // -------------------------------------------------------------------- + + public function test_get_csrf_hash() + { + $this->assertEquals($this->security->csrf_hash, $this->security->get_csrf_hash()); + } + + // -------------------------------------------------------------------- + + public function test_get_csrf_token_name() + { + $this->assertEquals('ci_csrf_token', $this->security->get_csrf_token_name()); + } + + // -------------------------------------------------------------------- + + public function test_xss_clean() + { + $harm_string = "Hello, i try to your site"; + + $harmless_string = $this->security->xss_clean($harm_string); + + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless_string); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 7756af5df0a53930019e9fd7b828504f0c2c5427 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Tue, 15 May 2012 23:57:05 +0700 Subject: Input class code-coverage --- tests/codeigniter/core/Input_test.php | 144 +++++++++++++++++++++++++++++++ tests/codeigniter/core/Security_test.php | 14 +-- 2 files changed, 148 insertions(+), 10 deletions(-) create mode 100644 tests/codeigniter/core/Input_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php new file mode 100644 index 000000000..fd0576e38 --- /dev/null +++ b/tests/codeigniter/core/Input_test.php @@ -0,0 +1,144 @@ +ci_set_config('allow_get_array', TRUE); + $this->ci_set_config('global_xss_filtering', FALSE); + $this->ci_set_config('csrf_protection', FALSE); + + $security = new Mock_Core_Security(); + $utf8 = new Mock_Core_Utf8(); + + $this->input = new Mock_Core_Input($security, $utf8); + } + + // -------------------------------------------------------------------- + + public function test_get_not_exists() + { + $this->assertEmpty($this->input->get()); + $this->assertEmpty($this->input->get('foo')); + + $this->assertTrue( ! $this->input->get()); + $this->assertTrue( ! $this->input->get('foo')); + + $this->assertTrue($this->input->get() == FALSE); + $this->assertTrue($this->input->get('foo') == FALSE); + + $this->assertTrue($this->input->get() === FALSE); + $this->assertTrue($this->input->get('foo') === FALSE); + } + + // -------------------------------------------------------------------- + + public function test_get_exist() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_GET['foo'] = 'bar'; + + $this->assertArrayHasKey('foo', $this->input->get()); + $this->assertEquals('bar', $this->input->get('foo')); + } + + // -------------------------------------------------------------------- + + public function test_get_exist_with_xss_clean() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_GET['harm'] = "Hello, i try to your site"; + + $this->assertArrayHasKey('harm', $this->input->get()); + $this->assertEquals("Hello, i try to your site", $this->input->get('harm')); + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $this->input->get('harm', TRUE)); + } + + // -------------------------------------------------------------------- + + public function test_post_not_exists() + { + $this->assertEmpty($this->input->post()); + $this->assertEmpty($this->input->post('foo')); + + $this->assertTrue( ! $this->input->post()); + $this->assertTrue( ! $this->input->post('foo')); + + $this->assertTrue($this->input->post() == FALSE); + $this->assertTrue($this->input->post('foo') == FALSE); + + $this->assertTrue($this->input->post() === FALSE); + $this->assertTrue($this->input->post('foo') === FALSE); + } + + // -------------------------------------------------------------------- + + public function test_post_exist() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST['foo'] = 'bar'; + + $this->assertArrayHasKey('foo', $this->input->post()); + $this->assertEquals('bar', $this->input->post('foo')); + } + + // -------------------------------------------------------------------- + + public function test_post_exist_with_xss_clean() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST['harm'] = "Hello, i try to your site"; + + $this->assertArrayHasKey('harm', $this->input->post()); + $this->assertEquals("Hello, i try to your site", $this->input->post('harm')); + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $this->input->post('harm', TRUE)); + } + + // -------------------------------------------------------------------- + + public function test_get_post() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST['foo'] = 'bar'; + + $this->assertEquals('bar', $this->input->get_post('foo')); + } + + // -------------------------------------------------------------------- + + public function test_cookie() + { + $_COOKIE['foo'] = 'bar'; + + $this->assertEquals('bar', $this->input->cookie('foo')); + } + + // -------------------------------------------------------------------- + + public function test_server() + { + $this->assertEquals('GET', $this->input->server('REQUEST_METHOD')); + } + + // -------------------------------------------------------------------- + + public function test_fetch_from_array() + { + $data = array( + 'foo' => 'bar', + 'harm' => 'Hello, i try to your site', + ); + + $foo = $this->input->fetch_from_array($data, 'foo'); + $harm = $this->input->fetch_from_array($data, 'harm'); + $harmless = $this->input->fetch_from_array($data, 'harm', TRUE); + + $this->assertEquals('bar', $foo); + $this->assertEquals("Hello, i try to your site", $harm); + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless); + } +} \ No newline at end of file diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index c3b526965..1796ba74d 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -4,19 +4,13 @@ class Security_test extends CI_TestCase { public function set_up() { + // Set cookie for security test + $_COOKIE['ci_csrf_cookie'] = md5(uniqid(rand(), TRUE)); + + // Set config for Security class $this->ci_set_config('csrf_protection', TRUE); $this->ci_set_config('csrf_token_name', 'ci_csrf_token'); - // @see : ./Bootstrap.php Line 16 $this->ci_set_config('csrf_cookie_name', 'ci_csrf_cookie'); - $this->ci_set_config('csrf_expire', 7200); - $this->ci_set_config('csrf_regenerate', TRUE); - $this->ci_set_config('csrf_exclude_uris', array()); - - $this->ci_set_config('cookie_prefix', ""); - $this->ci_set_config('cookie_domain', ""); - $this->ci_set_config('cookie_path', "/"); - $this->ci_set_config('cookie_secure', FALSE); - $this->ci_set_config('cookie_httponly', FALSE); $this->security = new Mock_Core_Security(); } -- cgit v1.2.3-24-g4f1b From 09a1b5e7fb3c930aa9a50e246236227a499b5d28 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 16 May 2012 22:18:00 +0700 Subject: Reduce decimal points, since there is a micro differencess on runtime and update travis status --- tests/codeigniter/core/Benchmark_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php index 2790b582e..109b38821 100644 --- a/tests/codeigniter/core/Benchmark_test.php +++ b/tests/codeigniter/core/Benchmark_test.php @@ -29,8 +29,8 @@ class Benchmark_test extends CI_TestCase { $this->benchmark->mark('code_start'); sleep(1); $this->benchmark->mark('code_end'); - - $this->assertEquals('1.00', $this->benchmark->elapsed_time('code_start', 'code_end', 3)); + + $this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1)); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 55a6ddb0c7bab1149bb1ddfa3a1aff46612c91d4 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 23 May 2012 18:37:24 +0100 Subject: Input, Session and Cookie get's will return NULL. Read more about this change here: http://codeigniter.com/forums/viewthread/215833 --- tests/codeigniter/core/Input_test.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index fd0576e38..a066d9960 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -28,11 +28,13 @@ class Input_test extends CI_TestCase { $this->assertTrue( ! $this->input->get()); $this->assertTrue( ! $this->input->get('foo')); - $this->assertTrue($this->input->get() == FALSE); - $this->assertTrue($this->input->get('foo') == FALSE); + // Test we're getting empty results + $this->assertTrue($this->input->get() == NULL); + $this->assertTrue($this->input->get('foo') == NULL); - $this->assertTrue($this->input->get() === FALSE); - $this->assertTrue($this->input->get('foo') === FALSE); + // Test new 3.0 behaviour for non existant results (used to be FALSE) + $this->assertTrue($this->input->get() === NULL); + $this->assertTrue($this->input->get('foo') === NULL); } // -------------------------------------------------------------------- @@ -68,11 +70,11 @@ class Input_test extends CI_TestCase { $this->assertTrue( ! $this->input->post()); $this->assertTrue( ! $this->input->post('foo')); - $this->assertTrue($this->input->post() == FALSE); - $this->assertTrue($this->input->post('foo') == FALSE); + $this->assertTrue($this->input->post() == NULL); + $this->assertTrue($this->input->post('foo') == NULL); - $this->assertTrue($this->input->post() === FALSE); - $this->assertTrue($this->input->post('foo') === FALSE); + $this->assertTrue($this->input->post() === NULL); + $this->assertTrue($this->input->post('foo') === NULL); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 2d57445ba66f8b6e5fef526b932d691b0e5690db Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 25 May 2012 04:03:56 +0700 Subject: Escape like tests, #136 verification --- .../database/query_builder/escape_test.php | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/escape_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php new file mode 100644 index 000000000..6d220d65d --- /dev/null +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -0,0 +1,47 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_escape_like_percent_sign() + { + $string = $this->db->escape_like_str('\%foo'); + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';"; + $res = $this->db->query($sql)->result_array(); + + // Check the result + $this->assertEquals(1, count($res)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_escape_like_backslash_sign() + { + $string = $this->db->escape_like_str('\\'); + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';"; + $res = $this->db->query($sql)->result_array(); + + // Check the result + $this->assertEquals(2, count($res)); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6a43244e1d739db17db266456221099232d120d6 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 25 May 2012 04:09:38 +0700 Subject: replace space with tab --- tests/codeigniter/database/query_builder/escape_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index 6d220d65d..f2d1b84ca 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -23,8 +23,8 @@ class Escape_test extends CI_TestCase { public function test_escape_like_percent_sign() { $string = $this->db->escape_like_str('\%foo'); - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';"; - $res = $this->db->query($sql)->result_array(); + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';"; + $res = $this->db->query($sql)->result_array(); // Check the result $this->assertEquals(1, count($res)); @@ -38,8 +38,8 @@ class Escape_test extends CI_TestCase { public function test_escape_like_backslash_sign() { $string = $this->db->escape_like_str('\\'); - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';"; - $res = $this->db->query($sql)->result_array(); + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';"; + $res = $this->db->query($sql)->result_array(); // Check the result $this->assertEquals(2, count($res)); -- cgit v1.2.3-24-g4f1b From 98dcac7ea5f82cc1d5cecedd030c5f242f1dc652 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 25 May 2012 05:07:51 +0700 Subject: Alter the escape like test, since it use raw SQL via query(), the sql statement would need to add ESCAPE clause for database(s) other than mysql --- tests/codeigniter/database/query_builder/escape_test.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index f2d1b84ca..5dd2da058 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -23,7 +23,9 @@ class Escape_test extends CI_TestCase { public function test_escape_like_percent_sign() { $string = $this->db->escape_like_str('\%foo'); - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';"; + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%'"; + $sql .= (strpos(DB_DRIVER, 'mysql') !== FALSE) ? ";" : "ESCAPE '!';"; + $res = $this->db->query($sql)->result_array(); // Check the result @@ -38,7 +40,8 @@ class Escape_test extends CI_TestCase { public function test_escape_like_backslash_sign() { $string = $this->db->escape_like_str('\\'); - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%';"; + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%'"; + $sql .= (strpos(DB_DRIVER, 'mysql') !== FALSE) ? ";" : "ESCAPE '!';"; $res = $this->db->query($sql)->result_array(); // Check the result -- cgit v1.2.3-24-g4f1b From 59d6b4fc4f4d7d5265b59cfd8c0f68f885083f69 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 25 May 2012 02:08:00 +0300 Subject: Alter LIKE escaping tests again --- tests/codeigniter/database/DB_driver_test.php | 4 +--- tests/codeigniter/database/DB_test.php | 4 +--- tests/codeigniter/database/query_builder/escape_test.php | 16 ++++++---------- 3 files changed, 8 insertions(+), 16 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php index fb40f0608..9e16e29b4 100644 --- a/tests/codeigniter/database/DB_driver_test.php +++ b/tests/codeigniter/database/DB_driver_test.php @@ -2,8 +2,6 @@ class DB_driver_test extends CI_TestCase { - // ------------------------------------------------------------------------ - public function test_initialize() { $config = Mock_Database_DB::config(DB_DRIVER); @@ -32,5 +30,5 @@ class DB_driver_test extends CI_TestCase { { return new Mock_Database_Drivers_Postgre($config); } - + } \ No newline at end of file diff --git a/tests/codeigniter/database/DB_test.php b/tests/codeigniter/database/DB_test.php index 9b93e223d..d5c0dea08 100644 --- a/tests/codeigniter/database/DB_test.php +++ b/tests/codeigniter/database/DB_test.php @@ -2,8 +2,6 @@ class DB_test extends CI_TestCase { - // ------------------------------------------------------------------------ - public function test_db_invalid() { $connection = new Mock_Database_DB(array( @@ -45,5 +43,5 @@ class DB_test extends CI_TestCase { $this->assertTrue($db instanceof CI_DB); $this->assertTrue($db instanceof CI_DB_Driver); } - + } \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index 5dd2da058..96fbd078b 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -23,13 +23,10 @@ class Escape_test extends CI_TestCase { public function test_escape_like_percent_sign() { $string = $this->db->escape_like_str('\%foo'); - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%'"; - $sql .= (strpos(DB_DRIVER, 'mysql') !== FALSE) ? ";" : "ESCAPE '!';"; + $res = $this->db->select('value')->from('misc')->like('key', $string, 'after')->get(); - $res = $this->db->query($sql)->result_array(); - // Check the result - $this->assertEquals(1, count($res)); + $this->assertEquals(1, count($res->result_array())); } // ------------------------------------------------------------------------ @@ -40,11 +37,10 @@ class Escape_test extends CI_TestCase { public function test_escape_like_backslash_sign() { $string = $this->db->escape_like_str('\\'); - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%'"; - $sql .= (strpos(DB_DRIVER, 'mysql') !== FALSE) ? ";" : "ESCAPE '!';"; - $res = $this->db->query($sql)->result_array(); - + $res = $this->db->select('value')->from('misc')->like('key', $string, 'after')->get(); + // Check the result - $this->assertEquals(2, count($res)); + $this->assertEquals(2, count($res->result_array())); } + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0174d84401b5c5996115a4a6193161f1dab96de2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 25 May 2012 02:17:49 +0300 Subject: Alter LIKE escaping tests again --- tests/codeigniter/database/query_builder/escape_test.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index 96fbd078b..9df82c2d0 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -23,7 +23,10 @@ class Escape_test extends CI_TestCase { public function test_escape_like_percent_sign() { $string = $this->db->escape_like_str('\%foo'); - $res = $this->db->select('value')->from('misc')->like('key', $string, 'after')->get(); + $this->db->select('value'); + $this->db->from('misc'); + $this->db->like('key', $string, 'after'); + $res = $this->db->get(); // Check the result $this->assertEquals(1, count($res->result_array())); @@ -38,6 +41,10 @@ class Escape_test extends CI_TestCase { { $string = $this->db->escape_like_str('\\'); $res = $this->db->select('value')->from('misc')->like('key', $string, 'after')->get(); + $this->db->select('value'); + $this->db->from('misc'); + $this->db->like('key', $string, 'after'); + $res = $this->db->get(); // Check the result $this->assertEquals(2, count($res->result_array())); -- cgit v1.2.3-24-g4f1b From f33e2ff30b0a9c54d6e8adbe88662838b9bd525e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 25 May 2012 02:24:17 +0300 Subject: Again ... escape_like_str() tests --- tests/codeigniter/database/query_builder/escape_test.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index 9df82c2d0..50685922a 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -22,7 +22,8 @@ class Escape_test extends CI_TestCase { */ public function test_escape_like_percent_sign() { - $string = $this->db->escape_like_str('\%foo'); + $string = '\%foo' +; $this->db->select('value'); $this->db->from('misc'); $this->db->like('key', $string, 'after'); @@ -39,8 +40,8 @@ class Escape_test extends CI_TestCase { */ public function test_escape_like_backslash_sign() { - $string = $this->db->escape_like_str('\\'); - $res = $this->db->select('value')->from('misc')->like('key', $string, 'after')->get(); + $string = '\\'; + $this->db->select('value'); $this->db->from('misc'); $this->db->like('key', $string, 'after'); -- cgit v1.2.3-24-g4f1b From 502942bd94fef292970df331b15652ef6e1385e7 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 25 May 2012 07:00:41 +0700 Subject: Explicitely testing escape_like_str API --- tests/codeigniter/database/query_builder/escape_test.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index 5dd2da058..ac1c8f659 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -13,6 +13,9 @@ class Escape_test extends CI_TestCase { Mock_Database_Schema_Skeleton::create_tables(); Mock_Database_Schema_Skeleton::create_data(); + + $this->pre = (strpos(DB_DRIVER, 'pgsql') === FALSE) ? '`' : '"'; + $this->esc = (strpos(DB_DRIVER, 'mysql') === FALSE) ? '!' : ''; } // ------------------------------------------------------------------------ @@ -23,8 +26,8 @@ class Escape_test extends CI_TestCase { public function test_escape_like_percent_sign() { $string = $this->db->escape_like_str('\%foo'); - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%'"; - $sql .= (strpos(DB_DRIVER, 'mysql') !== FALSE) ? ";" : "ESCAPE '!';"; + + $sql = "SELECT {$this->pre}value{$this->pre} FROM {$this->pre}misc{$this->pre} WHERE {$this->pre}key{$this->pre} LIKE '$string%' ESCAPE '$this->esc';"; $res = $this->db->query($sql)->result_array(); @@ -40,8 +43,9 @@ class Escape_test extends CI_TestCase { public function test_escape_like_backslash_sign() { $string = $this->db->escape_like_str('\\'); - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%'"; - $sql .= (strpos(DB_DRIVER, 'mysql') !== FALSE) ? ";" : "ESCAPE '!';"; + + $sql = "SELECT {$this->pre}value{$this->pre} FROM {$this->pre}misc{$this->pre} WHERE {$this->pre}key{$this->pre} LIKE '$string%' ESCAPE '$this->esc';"; + $res = $this->db->query($sql)->result_array(); // Check the result -- cgit v1.2.3-24-g4f1b From 3c5abf93d3031064c8181069cfee83ebfb54dcf0 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 25 May 2012 07:17:26 +0700 Subject: Clean up --- tests/codeigniter/database/query_builder/escape_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index fe225436a..5df812ca6 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -32,7 +32,7 @@ class Escape_test extends CI_TestCase { $res = $this->db->query($sql)->result_array(); // Check the result - $this->assertEquals(1, count($res->result_array())); + $this->assertEquals(1, count($res)); } // ------------------------------------------------------------------------ @@ -49,7 +49,7 @@ class Escape_test extends CI_TestCase { $res = $this->db->query($sql)->result_array(); // Check the result - $this->assertEquals(2, count($res->result_array())); + $this->assertEquals(2, count($res)); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1af5b47ad6f95f805d9f411ce020f2e2fa88b302 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 26 May 2012 16:04:39 +0700 Subject: Remove ternary --- .../database/query_builder/escape_test.php | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index 5df812ca6..5d575a37b 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -13,9 +13,6 @@ class Escape_test extends CI_TestCase { Mock_Database_Schema_Skeleton::create_tables(); Mock_Database_Schema_Skeleton::create_data(); - - $this->pre = (strpos(DB_DRIVER, 'pgsql') === FALSE) ? '`' : '"'; - $this->esc = (strpos(DB_DRIVER, 'mysql') === FALSE) ? '!' : ''; } // ------------------------------------------------------------------------ @@ -25,9 +22,17 @@ class Escape_test extends CI_TestCase { */ public function test_escape_like_percent_sign() { + // Escape the like string $string = $this->db->escape_like_str('\%foo'); - $sql = "SELECT {$this->pre}value{$this->pre} FROM {$this->pre}misc{$this->pre} WHERE {$this->pre}key{$this->pre} LIKE '$string%' ESCAPE '$this->esc';"; + if (strpos(DB_DRIVER, 'mysql') !== FALSE) + { + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '';"; + } + else + { + $sql = 'SELECT "value" FROM "misc" WHERE "key" LIKE \''.$string.'%\' ESCAPE \'!\';'; + } $res = $this->db->query($sql)->result_array(); @@ -42,14 +47,21 @@ class Escape_test extends CI_TestCase { */ public function test_escape_like_backslash_sign() { + // Escape the like string $string = $this->db->escape_like_str('\\'); - $sql = "SELECT {$this->pre}value{$this->pre} FROM {$this->pre}misc{$this->pre} WHERE {$this->pre}key{$this->pre} LIKE '$string%' ESCAPE '$this->esc';"; + if (strpos(DB_DRIVER, 'mysql') !== FALSE) + { + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '';"; + } + else + { + $sql = 'SELECT "value" FROM "misc" WHERE "key" LIKE \''.$string.'%\' ESCAPE \'!\';'; + } $res = $this->db->query($sql)->result_array(); // Check the result $this->assertEquals(2, count($res)); } - } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6c7526c95b3fbd502dc8105a67fd38da793caa4e Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sun, 27 May 2012 13:51:27 +0700 Subject: Continuation for Security and Table code-coverage, add coverage report to travis --- tests/codeigniter/core/Security_test.php | 32 ++++++++++++++++++++++++++++++ tests/codeigniter/libraries/Table_test.php | 24 ++++++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index 1796ba74d..b2f8c69d2 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -70,4 +70,36 @@ class Security_test extends CI_TestCase { $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless_string); } + + // -------------------------------------------------------------------- + + public function test_xss_hash() + { + $this->assertEmpty($this->security->xss_hash); + + // Perform hash + $this->security->xss_hash(); + + $this->assertTrue(preg_match('#^[0-9a-f]{32}$#iS', $this->security->xss_hash) === 1); + } + + // -------------------------------------------------------------------- + + public function test_entity_decode() + { + $encoded = '<div>Hello <b>Booya</b></div>'; + $decoded = $this->security->entity_decode($encoded); + + $this->assertEquals('
    Hello Booya
    ', $decoded); + } + + // -------------------------------------------------------------------- + + public function test_sanitize_filename() + { + $filename = './'; + $safe_filename = $this->security->sanitize_filename($filename); + + $this->assertEquals('foo', $safe_filename); + } } \ No newline at end of file diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index 13f338c6b..f5133de1e 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -291,6 +291,26 @@ class Table_test extends CI_TestCase { ); } - // Test main generate method - // -------------------------------------------------------------------- + function test_generate() + { + // Prepare the data + $data = array( + array('Name', 'Color', 'Size'), + array('Fred', 'Blue', 'Small'), + array('Mary', 'Red', 'Large'), + array('John', 'Green', 'Medium') + ); + + $table = $this->table->generate($data); + + // Test the table header + $this->assertTrue(strpos($table, 'Name') !== FALSE); + $this->assertTrue(strpos($table, 'Color') !== FALSE); + $this->assertTrue(strpos($table, 'Size') !== FALSE); + + // Test the first entry + $this->assertTrue(strpos($table, 'Fred') !== FALSE); + $this->assertTrue(strpos($table, 'Blue') !== FALSE); + $this->assertTrue(strpos($table, 'Small') !== FALSE); + } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d6d1150959c95e43d310d0bc45f8bd674ff6460c Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:12:55 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /tests --- tests/codeigniter/core/Input_test.php | 8 ++++---- tests/codeigniter/database/query_builder/where_test.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index a066d9960..cfc80c950 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -29,8 +29,8 @@ class Input_test extends CI_TestCase { $this->assertTrue( ! $this->input->get('foo')); // Test we're getting empty results - $this->assertTrue($this->input->get() == NULL); - $this->assertTrue($this->input->get('foo') == NULL); + $this->assertTrue($this->input->get() === NULL); + $this->assertTrue($this->input->get('foo') === NULL); // Test new 3.0 behaviour for non existant results (used to be FALSE) $this->assertTrue($this->input->get() === NULL); @@ -70,8 +70,8 @@ class Input_test extends CI_TestCase { $this->assertTrue( ! $this->input->post()); $this->assertTrue( ! $this->input->post('foo')); - $this->assertTrue($this->input->post() == NULL); - $this->assertTrue($this->input->post('foo') == NULL); + $this->assertTrue($this->input->post() === NULL); + $this->assertTrue($this->input->post('foo') === NULL); $this->assertTrue($this->input->post() === NULL); $this->assertTrue($this->input->post('foo') === NULL); diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php index 607eaa076..6a92c6fce 100644 --- a/tests/codeigniter/database/query_builder/where_test.php +++ b/tests/codeigniter/database/query_builder/where_test.php @@ -74,7 +74,7 @@ class Where_test extends CI_TestCase { */ public function test_where_custom_string() { - $where = "id > 2 AND name != 'Accountant'"; + $where = "id > 2 AND name !== 'Accountant'"; $jobs = $this->db->where($where) ->get('job') ->result_array(); -- cgit v1.2.3-24-g4f1b From 2be12da6a443e74fb3f5f64d12c4e0a7164503da Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 15:39:04 +0100 Subject: Fixed bug created in `test_where_custom_string()` in /tests/codeigniter/database/query_builder/where_test.php by d6d1150959c95e43d310d0bc45f8bd674ff6460c --- tests/codeigniter/database/query_builder/where_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php index 6a92c6fce..607eaa076 100644 --- a/tests/codeigniter/database/query_builder/where_test.php +++ b/tests/codeigniter/database/query_builder/where_test.php @@ -74,7 +74,7 @@ class Where_test extends CI_TestCase { */ public function test_where_custom_string() { - $where = "id > 2 AND name !== 'Accountant'"; + $where = "id > 2 AND name != 'Accountant'"; $jobs = $this->db->where($where) ->get('job') ->result_array(); -- cgit v1.2.3-24-g4f1b From 9d533aef135dff9dd3465f993283d6e49a9983a5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 4 Jun 2012 15:56:56 +0300 Subject: Fix an SQLite3 pconnect() bug + other minor changes --- tests/codeigniter/database/query_builder/insert_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 8ba60e242..a9aafb66e 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -26,7 +26,7 @@ class Insert_test extends CI_TestCase { public function test_insert() { $job_data = array('id' => 1, 'name' => 'Grocery Sales', 'description' => 'Discount!'); - + // Do normal insert $this->assertTrue($this->db->insert('job', $job_data)); @@ -45,10 +45,10 @@ class Insert_test extends CI_TestCase { public function test_insert_batch() { $job_datas = array( - array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'), + array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'), array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'), ); - + // Do insert batch except for sqlite driver if (strpos(DB_DRIVER, 'sqlite') === FALSE) { @@ -62,5 +62,5 @@ class Insert_test extends CI_TestCase { $this->assertEquals('Cab Driver', $job_3->name); } } - + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 06c22871943bee956522b893e8acbf206524a229 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Tue, 5 Jun 2012 13:36:13 +0200 Subject: Add test when loading language file and not using the second parameter (language) --- tests/codeigniter/core/Lang_test.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php index a414f0ace..92c71322e 100644 --- a/tests/codeigniter/core/Lang_test.php +++ b/tests/codeigniter/core/Lang_test.php @@ -18,13 +18,21 @@ class Lang_test extends CI_TestCase { public function test_load() { $this->assertTrue($this->lang->load('profiler', 'english')); + $this->_test_line(); + } + + // -------------------------------------------------------------------- + + public function test_load_with_unspecified_language() + { + $this->assertTrue($this->lang->load('profiler')); + $this->_test_line(); } // -------------------------------------------------------------------- - public function test_line() + private function _test_line() { - $this->assertTrue($this->lang->load('profiler', 'english')); $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string')); } -- cgit v1.2.3-24-g4f1b From d348cb0fd6f255074bc410f169072e2f613074fe Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Tue, 5 Jun 2012 15:32:55 +0200 Subject: remove _test_line() --- tests/codeigniter/core/Lang_test.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php index 92c71322e..874230feb 100644 --- a/tests/codeigniter/core/Lang_test.php +++ b/tests/codeigniter/core/Lang_test.php @@ -18,7 +18,7 @@ class Lang_test extends CI_TestCase { public function test_load() { $this->assertTrue($this->lang->load('profiler', 'english')); - $this->_test_line(); + $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string')); } // -------------------------------------------------------------------- @@ -26,13 +26,6 @@ class Lang_test extends CI_TestCase { public function test_load_with_unspecified_language() { $this->assertTrue($this->lang->load('profiler')); - $this->_test_line(); - } - - // -------------------------------------------------------------------- - - private function _test_line() - { $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string')); } -- cgit v1.2.3-24-g4f1b From 83c62ccf881847c5f4eef83822de0f7b09f98491 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 14:26:31 +0200 Subject: add tests for ipv6 and new method ip_version() --- tests/codeigniter/core/Input_test.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index cfc80c950..27e152d6a 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -143,4 +143,31 @@ class Input_test extends CI_TestCase { $this->assertEquals("Hello, i try to your site", $harm); $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless); } + + // -------------------------------------------------------------------- + + public function test_valid_ip() + { + $ip_v4 = '175.123.74.43'; + $this->assertTrue($this->input->valid_ip($ip_v4)); + + $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)); + } + } + + // -------------------------------------------------------------------- + + public function test_ip_version() + { + $ip_v4 = '175.123.74.43'; + $this->assertEquals('4', $this->input->ip_version($ip_v4)); + + $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->assertEquals('6', $this->input->ip_version($ip)); + } + } + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0723617703dda3660597d9cdef59e7cdded1c497 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 14:39:02 +0200 Subject: follow styling guide --- tests/codeigniter/core/Input_test.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 27e152d6a..2aa3a6246 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -152,7 +152,8 @@ class Input_test extends CI_TestCase { $this->assertTrue($this->input->valid_ip($ip_v4)); $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) { + foreach($ip_v6 as $ip) + { $this->assertTrue($this->input->valid_ip($ip)); } } @@ -165,7 +166,8 @@ class Input_test extends CI_TestCase { $this->assertEquals('4', $this->input->ip_version($ip_v4)); $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) { + foreach($ip_v6 as $ip) + { $this->assertEquals('6', $this->input->ip_version($ip)); } } -- cgit v1.2.3-24-g4f1b From 5ace440aa4dbd948191c37b67b01871b3a7593e9 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 14:52:15 +0200 Subject: change ellipsizing to ellipsize --- tests/codeigniter/helpers/text_helper_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 584066b0c..a83c7e74d 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -122,7 +122,7 @@ class Text_helper_test extends CI_TestCase { // ------------------------------------------------------------------------ - public function test_ellipsizing() + public function test_ellipsize() { $strs = array( '0' => array( -- cgit v1.2.3-24-g4f1b From 0ef92f6fa4a40d4a689eee3ebd7eb7d632fe29c0 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:12:37 +0200 Subject: test for word_wrap() --- tests/codeigniter/helpers/text_helper_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index a83c7e74d..974247c4f 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -156,4 +156,12 @@ class Text_helper_test extends CI_TestCase { // ------------------------------------------------------------------------ + public function test_word_wrap() + { + $string = "Here is a simple string of text that will help us demonstrate this function."; + $word_wraped = word_wrap($string, 25); + preg_match_all("/\r\n|\n/", $word_wraped, $matches); + $this->assertEquals(count($matches[0]), 4); + } + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4221b980b66bbaebc23a0f9cc5dee7d649948e15 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:38:35 +0200 Subject: add test for word_wrap default charlim --- tests/codeigniter/helpers/text_helper_test.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 974247c4f..d59b2743d 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -160,8 +160,17 @@ class Text_helper_test extends CI_TestCase { { $string = "Here is a simple string of text that will help us demonstrate this function."; $word_wraped = word_wrap($string, 25); - preg_match_all("/\r\n|\n/", $word_wraped, $matches); - $this->assertEquals(count($matches[0]), 4); + $this->assertEquals(substr_count($word_wraped, "\n"), 4); + } + + // ------------------------------------------------------------------------ + + public function test_default_word_wrap_charlim() + { + $string = "Here is a simple string of text that will help us demonstrate this function."; + $word_wraped = word_wrap($string); + $matches = preg_split("/\n/", $word_wraped, 1); + $this->assertEquals(strlen($matches[0]) - 1, 76); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From bfaf50258b6f33961210ecc3df4ade2e0a4512b4 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:39:45 +0200 Subject: typo word_wraped -> word_wrapped --- tests/codeigniter/helpers/text_helper_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index d59b2743d..3bc83f050 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -159,8 +159,8 @@ class Text_helper_test extends CI_TestCase { public function test_word_wrap() { $string = "Here is a simple string of text that will help us demonstrate this function."; - $word_wraped = word_wrap($string, 25); - $this->assertEquals(substr_count($word_wraped, "\n"), 4); + $word_wrapped = word_wrap($string, 25); + $this->assertEquals(substr_count($word_wrapped, "\n"), 4); } // ------------------------------------------------------------------------ @@ -168,8 +168,8 @@ class Text_helper_test extends CI_TestCase { public function test_default_word_wrap_charlim() { $string = "Here is a simple string of text that will help us demonstrate this function."; - $word_wraped = word_wrap($string); - $matches = preg_split("/\n/", $word_wraped, 1); + $word_wrapped = word_wrap($string); + $matches = preg_split("/\n/", $word_wrapped, 1); $this->assertEquals(strlen($matches[0]) - 1, 76); } -- cgit v1.2.3-24-g4f1b From 385452c2ca1f9ce00668ca6d77c6fd0ad1ea4771 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:43:18 +0200 Subject: correction of the test and longer test string --- tests/codeigniter/helpers/text_helper_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 3bc83f050..3c590538a 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -167,10 +167,10 @@ class Text_helper_test extends CI_TestCase { public function test_default_word_wrap_charlim() { - $string = "Here is a simple string of text that will help us demonstrate this function."; + $string = "Here is a longer string of text that will help us demonstrate the default charlim of this function."; $word_wrapped = word_wrap($string); - $matches = preg_split("/\n/", $word_wrapped, 1); - $this->assertEquals(strlen($matches[0]) - 1, 76); + $matches = preg_split("/\n/", $word_wrapped, 0); + $this->assertEquals(strlen($matches[0]), 73); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 908f36a583384b0314d04c4cfe71992746e35daa Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:47:22 +0200 Subject: ip_version() now returns int instead of string --- tests/codeigniter/core/Input_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 2aa3a6246..98d6299f8 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -163,12 +163,12 @@ class Input_test extends CI_TestCase { public function test_ip_version() { $ip_v4 = '175.123.74.43'; - $this->assertEquals('4', $this->input->ip_version($ip_v4)); + $this->assertEquals(4, $this->input->ip_version($ip_v4)); $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->assertEquals('6', $this->input->ip_version($ip)); + $this->assertEquals(6, $this->input->ip_version($ip)); } } -- cgit v1.2.3-24-g4f1b From 4215ddccd369ae8894c1031b97a344ae76eef5f6 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:58:28 +0200 Subject: remove regex in favor of strpos --- tests/codeigniter/helpers/text_helper_test.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 3c590538a..73e2b9429 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -169,8 +169,7 @@ class Text_helper_test extends CI_TestCase { { $string = "Here is a longer string of text that will help us demonstrate the default charlim of this function."; $word_wrapped = word_wrap($string); - $matches = preg_split("/\n/", $word_wrapped, 0); - $this->assertEquals(strlen($matches[0]), 73); + $this->assertEquals(strpos($word_wrapped, "\n"), 73); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 70b5d3b4eb74ad27da7eac29ef5d349be944ba15 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 18:22:36 +0200 Subject: use an ip of the range 192.18.0.0/15 --- tests/codeigniter/core/Input_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 98d6299f8..3682d308d 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -148,7 +148,7 @@ class Input_test extends CI_TestCase { public function test_valid_ip() { - $ip_v4 = '175.123.74.43'; + $ip_v4 = '192.18.0.1'; $this->assertTrue($this->input->valid_ip($ip_v4)); $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'); @@ -162,7 +162,7 @@ class Input_test extends CI_TestCase { public function test_ip_version() { - $ip_v4 = '175.123.74.43'; + $ip_v4 = '192.18.0.1'; $this->assertEquals(4, $this->input->ip_version($ip_v4)); $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'); -- cgit v1.2.3-24-g4f1b From 1ab6f6520ebfc016c49cfbe3a4d9d009be5da268 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 20:14:13 +0200 Subject: removed ip_version() --- tests/codeigniter/core/Input_test.php | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 3682d308d..c9322c027 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -158,18 +158,4 @@ class Input_test extends CI_TestCase { } } - // -------------------------------------------------------------------- - - public function test_ip_version() - { - $ip_v4 = '192.18.0.1'; - $this->assertEquals(4, $this->input->ip_version($ip_v4)); - - $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->assertEquals(6, $this->input->ip_version($ip)); - } - } - } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9d1407523ae585d45171b54123ba29c0ec831f79 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 01:40:18 +0200 Subject: tests for encryption class --- tests/codeigniter/libraries/Encrypt_test.php | 71 ++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/codeigniter/libraries/Encrypt_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php new file mode 100644 index 000000000..066990186 --- /dev/null +++ b/tests/codeigniter/libraries/Encrypt_test.php @@ -0,0 +1,71 @@ +encrypt = new Mock_Libraries_Encrypt(); + + $this->ci_instance($obj); + $this->encrypt = $obj->encrypt; + + $this->ci_set_config('encryption_key', "Encryptin'glike@boss!"); + $this->msg = 'My secret message'; + } + + // -------------------------------------------------------------------- + + public function test_encode() + { + $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg)); + } + + // -------------------------------------------------------------------- + + public function test_decode() + { + $encoded_msg = $this->encrypt->encode($this->msg); + $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg)); + } + + // -------------------------------------------------------------------- + + public function test_optional_key() + { + $key = 'Ohai!ù0129°03182%HD1892P0'; + $encoded_msg = $this->encrypt->encode($this->msg, $key); + $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg, $key)); + } + + // -------------------------------------------------------------------- + + public function test_default_cipher() + { + $this->assertEquals('rijndael-256', $this->encrypt->get_cipher()); + } + + // -------------------------------------------------------------------- + + public function test_set_cipher() + { + $this->encrypt->set_cipher(MCRYPT_BLOWFISH); + $this->assertEquals('blowfish', $this->encrypt->get_cipher()); + } + + // -------------------------------------------------------------------- + + public function test_default_mode() + { + $this->assertEquals('cbc', $this->encrypt->get_mode()); + } + + // -------------------------------------------------------------------- + + public function test_set_mode() + { + $this->encrypt->set_mode(MCRYPT_MODE_CFB); + $this->assertEquals('cfb', $this->encrypt->get_mode()); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1b60fda70ff1e1801c133575c530ef0a5a450029 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 9 Jun 2012 21:07:40 +0300 Subject: Modified date helper tests for better accuracy --- tests/codeigniter/helpers/date_helper_test.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 17d1ef21e..df03fe32c 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -16,13 +16,11 @@ class Date_helper_test extends CI_TestCase { $config->expects($this->any()) ->method('item') ->will($this->returnValue('local')); - + // Add the stub to our test instance $this->ci_instance_var('config', $config); - $expected = time(); - $test = now(); - $this->assertEquals($expected, $test); + $this->assertEquals(time(), now()); } // ------------------------------------------------------------------------ @@ -34,7 +32,7 @@ class Date_helper_test extends CI_TestCase { $config->expects($this->any()) ->method('item') ->will($this->returnValue('gmt')); - + // Add the stub to our stdClass $this->ci_instance_var('config', $config); @@ -204,8 +202,7 @@ class Date_helper_test extends CI_TestCase { public function test_mysql_to_unix() { $time = time(); - $this->assertEquals($time, - mysql_to_unix(date("Y-m-d H:i:s", $time))); + $this->assertEquals($time, mysql_to_unix(date("Y-m-d H:i:s", $time))); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 99b782d8a3d92c4703a059cbd62e2f1e6fea689c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 9 Jun 2012 22:24:46 +0300 Subject: Cleanup and optimize helper tests for speed --- tests/codeigniter/helpers/array_helper_test.php | 22 ++-- tests/codeigniter/helpers/date_helper_test.php | 127 +++++++++--------- .../codeigniter/helpers/directory_helper_test.php | 47 ++++--- tests/codeigniter/helpers/email_helper_test.php | 2 +- tests/codeigniter/helpers/file_helper_test.php | 143 ++++++++++----------- tests/codeigniter/helpers/form_helper_test.php | 112 ++++++++-------- tests/codeigniter/helpers/html_helper_test.php | 28 ++-- .../codeigniter/helpers/inflector_helper_test.php | 31 ++--- tests/codeigniter/helpers/number_helper_test.php | 35 +++-- tests/codeigniter/helpers/path_helper_test.php | 5 +- tests/codeigniter/helpers/string_helper_test.php | 9 +- tests/codeigniter/helpers/text_helper_test.php | 70 +++++----- tests/codeigniter/helpers/url_helper_test.php | 1 + tests/codeigniter/helpers/xml_helper_test.php | 4 +- 14 files changed, 317 insertions(+), 319 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php index 9cd15960f..ba46e86f9 100644 --- a/tests/codeigniter/helpers/array_helper_test.php +++ b/tests/codeigniter/helpers/array_helper_test.php @@ -1,7 +1,7 @@ helper('array'); @@ -13,31 +13,31 @@ class Array_helper_test extends CI_TestCase { 'herb' => 'cook' ); } - + // ------------------------------------------------------------------------ - + public function test_element_with_existing_item() - { + { $this->assertEquals(FALSE, element('testing', $this->my_array)); - + $this->assertEquals('not set', element('testing', $this->my_array, 'not set')); - + $this->assertEquals('bar', element('foo', $this->my_array)); } - - // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ public function test_random_element() { // Send a string, not an array to random_element $this->assertEquals('my string', random_element('my string')); - + // Test sending an array $this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array)); } - // ------------------------------------------------------------------------ - + // ------------------------------------------------------------------------ + public function test_elements() { $this->assertEquals(TRUE, is_array(elements('test', $this->my_array))); diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index df03fe32c..4b747b864 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -5,6 +5,8 @@ class Date_helper_test extends CI_TestCase { public function set_up() { $this->helper('date'); + + $this->time = time(); } // ------------------------------------------------------------------------ @@ -37,119 +39,120 @@ class Date_helper_test extends CI_TestCase { $this->ci_instance_var('config', $config); $t = time(); - $expected = mktime(gmdate("H", $t), gmdate("i", $t), gmdate("s", $t), gmdate("m", $t), gmdate("d", $t), gmdate("Y", $t)); - $test = now(); - $this->assertEquals($expected, $test); + $this->assertEquals( + mktime(gmdate('H', $t), gmdate('i', $t), gmdate('s', $t), gmdate('m', $t), gmdate('d', $t), gmdate('Y', $t)), + now() + ); } // ------------------------------------------------------------------------ public function test_mdate() { - $time = time(); - $expected = date("Y-m-d - h:i a", $time); - $test = mdate("%Y-%m-%d - %h:%i %a", $time); - $this->assertEquals($expected, $test); + $this->assertEquals( + date('Y-m-d - h:i a', $this->time), + mdate('%Y-%m-%d - %h:%i %a', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_rfc822() { - $time = time(); - $format = 'DATE_RFC822'; - $expected = date("D, d M y H:i:s O", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date('D, d M y H:i:s O', $this->time), + standard_date('DATE_RFC822', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_atom() { - $time = time(); - $format = 'DATE_ATOM'; - $expected = date("Y-m-d\TH:i:sO", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date("Y-m-d\TH:i:sO", $this->time), + standard_date('DATE_ATOM', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_cookie() { - $time = time(); - $format = 'DATE_COOKIE'; - $expected = date("l, d-M-y H:i:s \U\T\C", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date("l, d-M-y H:i:s \U\T\C", $this->time), + standard_date('DATE_COOKIE', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_iso8601() { - $time = time(); - $format = 'DATE_ISO8601'; - $expected = date("Y-m-d\TH:i:sO", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date("Y-m-d\TH:i:sO", $this->time), + standard_date('DATE_ISO8601', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_rfc850() { - $time = time(); - $format = 'DATE_RFC850'; - $expected = date("l, d-M-y H:i:s \U\T\C", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date("l, d-M-y H:i:s \U\T\C", $this->time), + standard_date('DATE_RFC850', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_rfc1036() { - $time = time(); - $format = 'DATE_RFC1036'; - $expected = date("D, d M y H:i:s O", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date('D, d M y H:i:s O', $this->time), + standard_date('DATE_RFC1036', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_rfc1123() { - $time = time(); - $format = 'DATE_RFC1123'; - $expected = date("D, d M Y H:i:s O", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date('D, d M Y H:i:s O', $this->time), + standard_date('DATE_RFC1123', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_rfc2822() { - $time = time(); - $format = 'DATE_RFC2822'; - $expected = date("D, d M Y H:i:s O", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date('D, d M Y H:i:s O', $this->time), + standard_date('DATE_RFC2822', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_rss() { - $time = time(); - $format = 'DATE_RSS'; - $expected = date("D, d M Y H:i:s O", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date('D, d M Y H:i:s O', $this->time), + standard_date('DATE_RSS', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_w3c() { - $time = time(); - $format = 'DATE_W3C'; - $expected = date("Y-m-d\TH:i:sO", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date("Y-m-d\TH:i:sO", $this->time), + standard_date('DATE_W3C', $this->time) + ); } // ------------------------------------------------------------------------ @@ -181,38 +184,36 @@ class Date_helper_test extends CI_TestCase { public function test_local_to_gmt() { - $t = time(); - $expected = mktime(gmdate("H", $t), gmdate("i", $t), gmdate("s", $t), gmdate("m", $t), gmdate("d", $t), gmdate("Y", $t)); - $this->assertEquals($expected, local_to_gmt($t)); + $this->assertEquals( + mktime( + gmdate('H', $this->time), gmdate('i', $this->time), gmdate('s', $this->time), + gmdate('m', $this->time), gmdate('d', $this->time), gmdate('Y', $this->time) + ), + local_to_gmt($this->time) + ); } // ------------------------------------------------------------------------ public function test_gmt_to_local() { - $timestamp = '1140153693'; - $timezone = 'UM8'; - $daylight_saving = TRUE; - - $this->assertEquals(1140128493, gmt_to_local($timestamp, $timezone, $daylight_saving)); + $this->assertEquals(1140128493, gmt_to_local('1140153693', 'UM8', TRUE)); } // ------------------------------------------------------------------------ public function test_mysql_to_unix() { - $time = time(); - $this->assertEquals($time, mysql_to_unix(date("Y-m-d H:i:s", $time))); + $this->assertEquals($this->time, mysql_to_unix(date('Y-m-d H:i:s', $this->time))); } // ------------------------------------------------------------------------ public function test_unix_to_human() { - $time = time(); - $this->assertEquals(date("Y-m-d h:i A", $time), unix_to_human($time)); - $this->assertEquals(date("Y-m-d h:i:s A", $time), unix_to_human($time, TRUE, 'us')); - $this->assertEquals(date("Y-m-d H:i:s", $time), unix_to_human($time, TRUE, 'eu')); + $this->assertEquals(date('Y-m-d h:i A', $this->time), unix_to_human($this->time)); + $this->assertEquals(date('Y-m-d h:i:s A', $this->time), unix_to_human($this->time, TRUE, 'us')); + $this->assertEquals(date('Y-m-d H:i:s', $this->time), unix_to_human($this->time, TRUE, 'eu')); } // ------------------------------------------------------------------------ @@ -220,8 +221,7 @@ class Date_helper_test extends CI_TestCase { public function test_human_to_unix() { $date = '2000-12-31 10:00:00 PM'; - $expected = strtotime($date); - $this->assertEquals($expected, human_to_unix($date)); + $this->assertEquals(strtotime($date), human_to_unix($date)); $this->assertFalse(human_to_unix()); } @@ -280,6 +280,7 @@ class Date_helper_test extends CI_TestCase { $this->assertArrayHasKey('UP3', timezones()); $this->assertEquals(0, timezones('non_existant')); } + } /* End of file date_helper_test.php */ \ No newline at end of file diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php index 3937d2913..176ff1d78 100644 --- a/tests/codeigniter/helpers/directory_helper_test.php +++ b/tests/codeigniter/helpers/directory_helper_test.php @@ -1,41 +1,50 @@ helper('directory'); vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); - + $this->_test_dir = vfsStreamWrapper::getRoot(); - } - + } + public function test_directory_map() { - $structure = array('libraries' => array('benchmark.html' => '', 'database' => - array('active_record.html' => '', 'binds.html' => ''), 'email.html' => '', '.hiddenfile.txt' => '')); - + $structure = array( + 'libraries' => array( + 'benchmark.html' => '', + 'database' => array('active_record.html' => '', 'binds.html' => ''), + 'email.html' => '', + '.hiddenfile.txt' => '' + ) + ); + vfsStream::create($structure, $this->_test_dir); // test default recursive behavior - $expected = array('libraries' => array('benchmark.html', 'database' => - array('active_record.html', 'binds.html'), 'email.html')); - - $this->assertEquals($expected, directory_map(vfsStream::url('testDir'))); + $expected = array( + 'libraries' => array( + 'benchmark.html', + 'database' => array('active_record.html', 'binds.html'), + 'email.html' + ) + ); - // test recursion depth behavior - $expected = array('libraries'); - - $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), 1)); + $this->assertEquals($expected, directory_map(vfsStream::url('testDir'))); // test detection of hidden files - $expected = array('libraries' => array('benchmark.html', 'database' => - array('active_record.html', 'binds.html'), 'email.html', '.hiddenfile.txt')); - + $expected['libraries'][] = '.hiddenfile.txt'; + $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), FALSE, TRUE)); - } + + // test recursion depth behavior + $this->assertEquals(array('libraries'), directory_map(vfsStream::url('testDir'), 1)); + } + } /* End of file directory_helper_test.php */ \ No newline at end of file diff --git a/tests/codeigniter/helpers/email_helper_test.php b/tests/codeigniter/helpers/email_helper_test.php index a01f3d5af..fea452f5f 100644 --- a/tests/codeigniter/helpers/email_helper_test.php +++ b/tests/codeigniter/helpers/email_helper_test.php @@ -14,5 +14,5 @@ class Email_helper_test extends CI_TestCase { $this->assertEquals(TRUE, valid_email('test@test.com')); $this->assertEquals(TRUE, valid_email('my.test@test.com')); } - + } \ No newline at end of file diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php index 4b9c29485..9b03da9d7 100644 --- a/tests/codeigniter/helpers/file_helper_test.php +++ b/tests/codeigniter/helpers/file_helper_test.php @@ -5,24 +5,23 @@ class File_helper_Test extends CI_TestCase { public function set_up() { $this->helper('file'); - + vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); - + $this->_test_dir = vfsStreamWrapper::getRoot(); } - + // -------------------------------------------------------------------- - + public function test_read_file() { $this->assertFalse(read_file('does_not_exist')); - + $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - - $file = vfsStream::newFile('my_file.txt')->withContent($content) - ->at($this->_test_dir); - + + $file = vfsStream::newFile('my_file.txt')->withContent($content)->at($this->_test_dir); + $this->assertEquals($content, read_file(vfsStream::url('my_file.txt'))); } @@ -31,126 +30,124 @@ class File_helper_Test extends CI_TestCase { public function test_octal_permissions() { $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - + $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) - ->lastModified(time() - 86400) - ->at($this->_test_dir); - - $this->assertEquals('777', octal_permissions($file->getPermissions())); + ->lastModified(time() - 86400) + ->at($this->_test_dir); + + $this->assertEquals('777', octal_permissions($file->getPermissions())); } - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + /** * More tests should happen here, since I'm not hitting the whole function. */ public function test_symbolic_permissions() { $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - + $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) - ->lastModified(time() - 86400) - ->at($this->_test_dir); - - $this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions())); + ->lastModified(time() - 86400) + ->at($this->_test_dir); + + $this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions())); } - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + public function test_get_mime_by_extension() { $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - + $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) - ->lastModified(time() - 86400) - ->at($this->_test_dir); - - $this->assertEquals('text/plain', - get_mime_by_extension(vfsStream::url('my_file.txt'))); - - // Test a mime with an array, such as png + ->lastModified(time() - 86400) + ->at($this->_test_dir); + + $this->assertEquals('text/plain', get_mime_by_extension(vfsStream::url('my_file.txt'))); + + // Test a mime with an array, such as png $file = vfsStream::newFile('foo.png')->at($this->_test_dir); - - $this->assertEquals('image/png', get_mime_by_extension(vfsStream::url('foo.png'))); - + + $this->assertEquals('image/png', get_mime_by_extension(vfsStream::url('foo.png'))); + // Test a file not in the mimes array $file = vfsStream::newFile('foo.blarfengar')->at($this->_test_dir); - + $this->assertFalse(get_mime_by_extension(vfsStream::url('foo.blarfengar'))); } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- public function test_get_file_info() { // Test Bad File $this->assertFalse(get_file_info('i_am_bad_boo')); - + // Test the rest - + // First pass in an array $vals = array( 'name', 'server_path', 'size', 'date', - 'readable', 'writable', 'executable', 'fileperms' + 'readable', 'writable', 'executable', 'fileperms' ); - + $this->_test_get_file_info($vals); // Test passing in vals as a string. - $vals = 'name, server_path, size, date, readable, writable, executable, fileperms'; - $this->_test_get_file_info($vals); + $this->_test_get_file_info(implode(', ', $vals)); } - + private function _test_get_file_info($vals) { $content = 'Jack and Jill went up the mountain to fight a billy goat.'; $last_modified = time() - 86400; - + $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) - ->lastModified($last_modified) - ->at($this->_test_dir); - + ->lastModified($last_modified) + ->at($this->_test_dir); + $ret_values = array( - 'name' => 'my_file.txt', - 'server_path' => 'vfs://my_file.txt', - 'size' => 57, - 'date' => $last_modified, + 'name' => 'my_file.txt', + 'server_path' => 'vfs://my_file.txt', + 'size' => 57, + 'date' => $last_modified, 'readable' => TRUE, - 'writable' => TRUE, - 'executable' => TRUE, + 'writable' => TRUE, + 'executable' => TRUE, 'fileperms' => 33279 ); - + $info = get_file_info(vfsStream::url('my_file.txt'), $vals); - + foreach ($info as $k => $v) { $this->assertEquals($ret_values[$k], $v); } } - - // -------------------------------------------------------------------- + + // -------------------------------------------------------------------- // Skipping for now, as it's not implemented in vfsStreamWrapper // flock(): vfsStreamWrapper::stream_lock is not implemented! - + // public function test_write_file() // { - // if ( ! defined('FOPEN_WRITE_CREATE_DESTRUCTIVE')) - // { - // define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); - // } - // - // $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - // - // $file = vfsStream::newFile('write.txt', 0777)->withContent('') - // ->lastModified(time() - 86400) - // ->at($this->_test_dir); - // - // $this->assertTrue(write_file(vfsStream::url('write.txt'), $content)); - // + // if ( ! defined('FOPEN_WRITE_CREATE_DESTRUCTIVE')) + // { + // define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); + // } + // + // $content = 'Jack and Jill went up the mountain to fight a billy goat.'; + // + // $file = vfsStream::newFile('write.txt', 0777)->withContent('') + // ->lastModified(time() - 86400) + // ->at($this->_test_dir); + // + // $this->assertTrue(write_file(vfsStream::url('write.txt'), $content)); + // // } - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + } \ No newline at end of file diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php index 80bace9d1..1a30ed993 100644 --- a/tests/codeigniter/helpers/form_helper_test.php +++ b/tests/codeigniter/helpers/form_helper_test.php @@ -3,26 +3,26 @@ require BASEPATH . 'core/Common.php'; require BASEPATH . 'helpers/form_helper.php'; -class Form_helper_test extends CI_TestCase +class Form_helper_test extends CI_TestCase { public function test_form_hidden() - { + { $expected = << EOH; - + $this->assertEquals($expected, form_hidden('username', 'johndoe')); } - + public function test_form_input() { $expected = << EOH; - + $data = array( 'name' => 'username', 'id' => 'username', @@ -34,37 +34,37 @@ EOH; $this->assertEquals($expected, form_input($data)); } - + public function test_form_password() - { + { $expected = << EOH; - + $this->assertEquals($expected, form_password('password')); } - + public function test_form_upload() - { + { $expected = << EOH; - + $this->assertEquals($expected, form_upload('attachment')); } - + public function test_form_textarea() - { + { $expected = <<Notes EOH; - + $this->assertEquals($expected, form_textarea('notes', 'Notes')); } - + public function test_form_dropdown() { $expected = << EOH; - + $options = array( - 'small' => 'Small Shirt', - 'med' => 'Medium Shirt', - 'large' => 'Large Shirt', - 'xlarge' => 'Extra Large Shirt', + 'small' => 'Small Shirt', + 'med' => 'Medium Shirt', + 'large' => 'Large Shirt', + 'xlarge' => 'Extra Large Shirt', ); - + $this->assertEquals($expected, form_dropdown('shirts', $options, 'large')); - + $expected = << @@ -95,22 +95,22 @@ EOH; EOH; - + $shirts_on_sale = array('small', 'large'); - + $this->assertEquals($expected, form_dropdown('shirts', $options, $shirts_on_sale)); - + $options = array( 'Swedish Cars' => array( - 'volvo' => 'Volvo', - 'saab' => 'Saab' + 'volvo' => 'Volvo', + 'saab' => 'Saab' ), 'German Cars' => array( - 'mercedes' => 'Mercedes', - 'audi' => 'Audi' + 'mercedes' => 'Mercedes', + 'audi' => 'Audi' ) ); - + $expected = << @@ -124,13 +124,10 @@ EOH; EOH; - - $cars_on_sale = array('volvo', 'audi'); - - $this->assertEquals($expected, form_dropdown('cars', $options, $cars_on_sale)); - + + $this->assertEquals($expected, form_dropdown('cars', $options, array('volvo', 'audi'))); } - + public function test_form_multiselect() { $expected = << EOH; - + $options = array( - 'small' => 'Small Shirt', - 'med' => 'Medium Shirt', - 'large' => 'Large Shirt', - 'xlarge' => 'Extra Large Shirt', - ); - + 'small' => 'Small Shirt', + 'med' => 'Medium Shirt', + 'large' => 'Large Shirt', + 'xlarge' => 'Extra Large Shirt', + ); + $this->assertEquals($expected, form_multiselect('shirts[]', $options, array('med', 'large'))); } - + public function test_form_fieldset() { $expected = <<Address Information EOH; - + $this->assertEquals($expected, form_fieldset('Address Information')); } @@ -169,10 +166,10 @@ EOH; $expected = << EOH; - + $this->assertEquals($expected, form_fieldset_close('')); } - + public function test_form_checkbox() { $expected = <<assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE)); } - + public function test_form_radio() { $expected = <<assertEquals($expected, form_radio('newsletter', 'accept', TRUE)); } - + public function test_form_submit() { $expected = <<assertEquals($expected, form_submit('mysubmit', 'Submit Post!')); } - + public function test_form_label() { $expected = <<assertEquals($expected, form_label('What is your Name', 'username')); } - + public function test_form_reset() { $expected = <<assertEquals($expected, form_reset('myreset', 'Reset')); } - + public function test_form_button() { $expected = <<assertEquals($expected, form_button('name','content')); + $this->assertEquals($expected, form_button('name', 'content')); } - + public function test_form_close() { $expected = <<assertEquals($expected, form_close('')); } - + public function test_form_prep() { - $expected = "Here is a string containing "quoted" text."; - + $expected = 'Here is a string containing "quoted" text.'; + $this->assertEquals($expected, form_prep('Here is a string containing "quoted" text.')); } + } /* End of file form_helper_test.php */ \ No newline at end of file diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index 28974b0f8..9a7bb48bf 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -6,16 +6,16 @@ class Html_helper_test extends CI_TestCase { { $this->helper('html'); } - + // ------------------------------------------------------------------------ - + public function test_br() { $this->assertEquals('

    ', br(2)); } - + // ------------------------------------------------------------------------ - + public function test_heading() { $this->assertEquals('

    foobar

    ', heading('foobar')); @@ -23,7 +23,7 @@ class Html_helper_test extends CI_TestCase { } // ------------------------------------------------------------------------ - + public function test_Ul() { $expect = <<assertEquals($expect, ul($list)); + $this->assertEquals(ltrim($expect), ul($list)); $expect = << @@ -51,13 +49,11 @@ EOH; $expect = ltrim($expect); - $list = array('foo', 'bar'); - $this->assertEquals($expect, ul($list, 'class="test"')); $this->assertEquals($expect, ul($list, array('class' => 'test'))); } - + // ------------------------------------------------------------------------ public function test_NBS() @@ -66,15 +62,15 @@ EOH; } // ------------------------------------------------------------------------ - + public function test_meta() { $this->assertEquals("\n", meta('test', 'foo')); - + $expect = "\n"; - + $this->assertEquals($expect, meta(array('name' => 'foo'))); - + } - + } \ No newline at end of file diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index 9e9478711..f3b0ebbe8 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -1,12 +1,12 @@ helper('inflector'); } - + public function test_singular() { $strs = array( @@ -16,15 +16,15 @@ class Inflector_helper_test extends CI_TestCase { 'smells' => 'smell', 'equipment' => 'equipment' ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, singular($str)); } } - + // -------------------------------------------------------------------- - + public function test_plural() { $strs = array( @@ -35,15 +35,15 @@ class Inflector_helper_test extends CI_TestCase { 'witch' => 'witches', 'equipment' => 'equipment' ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, plural($str)); - } - } + } + } // -------------------------------------------------------------------- - + public function test_camelize() { $strs = array( @@ -52,15 +52,15 @@ class Inflector_helper_test extends CI_TestCase { 'i-am-playing-a-trick' => 'i-am-playing-a-trick', 'what_do_you_think-yo?' => 'whatDoYouThink-yo?', ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, camelize($str)); } - } + } // -------------------------------------------------------------------- - + public function test_underscore() { $strs = array( @@ -69,7 +69,7 @@ class Inflector_helper_test extends CI_TestCase { 'i-am-playing-a-trick' => 'i-am-playing-a-trick', 'what_do_you_think-yo?' => 'what_do_you_think-yo?', ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, underscore($str)); @@ -77,7 +77,7 @@ class Inflector_helper_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_humanize() { $strs = array( @@ -86,10 +86,11 @@ class Inflector_helper_test extends CI_TestCase { 'i-am-playing-a-trick' => 'I-am-playing-a-trick', 'what_do_you_think-yo?' => 'What Do You Think-yo?', ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, humanize($str)); } } + } \ No newline at end of file diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php index 4bb9a918a..23d5c5c1a 100644 --- a/tests/codeigniter/helpers/number_helper_test.php +++ b/tests/codeigniter/helpers/number_helper_test.php @@ -1,35 +1,35 @@ helper('number'); - + // Grab the core lang class $lang_cls = $this->ci_core_class('lang'); - + // Mock away load, too much going on in there, // we'll just check for the expected parameter - + $lang = $this->getMock($lang_cls, array('load')); $lang->expects($this->once()) ->method('load') ->with($this->equalTo('number')); - + // Assign the proper language array - + $lang->language = $this->_get_lang('number'); - + // We don't have a controller, so just create // a cheap class to act as our super object. // Make sure it has a lang attribute. - + $obj = new StdClass; $obj->lang = $lang; $this->ci_instance($obj); } - + // Quick helper to actually grab the language // file. Consider moving this to ci_testcase? public function _get_lang($name) @@ -37,41 +37,40 @@ class Number_helper_test extends CI_TestCase { require BASEPATH.'language/english/'.$name.'_lang.php'; return $lang; } - + public function test_byte_format() { $this->assertEquals('456 Bytes', byte_format(456)); } - + public function test_kb_format() { $this->assertEquals('4.5 KB', byte_format(4567)); } - + public function test_kb_format_medium() { $this->assertEquals('44.6 KB', byte_format(45678)); } - + public function test_kb_format_large() { $this->assertEquals('446.1 KB', byte_format(456789)); } - + public function test_mb_format() { $this->assertEquals('3.3 MB', byte_format(3456789)); } - + public function test_gb_format() { $this->assertEquals('1.8 GB', byte_format(1932735283.2)); } - + public function test_tb_format() { $this->assertEquals('112,283.3 TB', byte_format(123456789123456789)); } -} -// EOF \ No newline at end of file +} \ No newline at end of file diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php index 632f57501..0faf6f383 100644 --- a/tests/codeigniter/helpers/path_helper_test.php +++ b/tests/codeigniter/helpers/path_helper_test.php @@ -8,9 +8,8 @@ class Path_helper_test extends CI_TestCase { } public function test_set_realpath() - { - $expected = getcwd() . DIRECTORY_SEPARATOR; - $this->assertEquals($expected, set_realpath(getcwd())); + { + $this->assertEquals(getcwd().DIRECTORY_SEPARATOR, set_realpath(getcwd())); } public function test_set_realpath_nonexistent_directory() diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index 29c3d6594..75701ec13 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -10,18 +10,18 @@ class String_helper_test extends CI_TestCase { public function test_strip_slashes() { $expected = array( - "Is your name O'reilly?", + "Is your name O'reilly?", "No, my name is O'connor." ); - + $str = array( "Is your name O\'reilly?", "No, my name is O\'connor." ); - + $this->assertEquals($expected, strip_slashes($str)); } - + public function test_trim_slashes() { $strs = array( @@ -144,4 +144,5 @@ class String_helper_test extends CI_TestCase { $this->assertEquals('file-1', increment_string('file', '-', '1')); $this->assertEquals(124, increment_string('123', '')); } + } \ No newline at end of file diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 73e2b9429..f131469cb 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -3,16 +3,16 @@ class Text_helper_test extends CI_TestCase { private $_long_string; - + public function set_up() { $this->helper('text'); - + $this->_long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.'; } - + // ------------------------------------------------------------------------ - + public function test_word_limiter() { $this->assertEquals('Once upon a time,…', word_limiter($this->_long_string, 4)); @@ -20,8 +20,8 @@ class Text_helper_test extends CI_TestCase { $this->assertEquals('', word_limiter('', 4)); } - // ------------------------------------------------------------------------ - + // ------------------------------------------------------------------------ + public function test_character_limiter() { $this->assertEquals('Once upon a time, a…', character_limiter($this->_long_string, 20)); @@ -30,22 +30,22 @@ class Text_helper_test extends CI_TestCase { $this->assertEquals('Short', character_limiter('Short', 5)); } - // ------------------------------------------------------------------------ - + // ------------------------------------------------------------------------ + public function test_ascii_to_entities() { $strs = array( '“‘ “test”' => '“‘ “test”', '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '†¥¨ˆøåß∂ƒ©˙∆˚¬' ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, ascii_to_entities($str)); } } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ public function test_entities_to_ascii() { @@ -53,27 +53,27 @@ class Text_helper_test extends CI_TestCase { '“‘ “test”' => '“‘ “test”', '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '†¥¨ˆøåß∂ƒ©˙∆˚¬' ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, entities_to_ascii($str)); - } + } } - - // ------------------------------------------------------------------------ - - function test_convert_accented_characters() + + // ------------------------------------------------------------------------ + + public function test_convert_accented_characters() { $this->assertEquals('AAAeEEEIIOOEUUUeY', convert_accented_characters('ÀÂÄÈÊËÎÏÔŒÙÛÜŸ')); $this->assertEquals('a e i o u n ue', convert_accented_characters('á é í ó ú ñ ü')); } - // ------------------------------------------------------------------------ - + // ------------------------------------------------------------------------ + public function test_censored_words() { $censored = array('boob', 'nerd', 'ass', 'fart'); - + $strs = array( 'Ted bobbled the ball' => 'Ted bobbled the ball', 'Jake is a nerdo' => 'Jake is a nerdo', @@ -81,28 +81,26 @@ class Text_helper_test extends CI_TestCase { 'Did Mary Fart?' => 'Did Mary $*#?', 'Jake is really a boob' => 'Jake is really a $*#' ); - - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, word_censor($str, $censored, '$*#')); } - + // test censored words being sent as a string $this->assertEquals('test', word_censor('test', 'test')); } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ public function test_highlight_code() { - $code = ''; $expect = "\n<?php var_dump(\$this); ?> \n\n"; - $this->assertEquals($expect, highlight_code($code)); + $this->assertEquals($expect, highlight_code('')); } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ public function test_highlight_phrase() { @@ -113,14 +111,14 @@ class Text_helper_test extends CI_TestCase { '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')); } } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ public function test_ellipsize() { @@ -144,32 +142,30 @@ class Text_helper_test extends CI_TestCase { 'short' => 'short' ), ); - + foreach ($strs as $pos => $s) { foreach ($s as $str => $expect) { - $this->assertEquals($expect, ellipsize($str, 10, $pos)); + $this->assertEquals($expect, ellipsize($str, 10, $pos)); } } } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ public function test_word_wrap() { - $string = "Here is a simple string of text that will help us demonstrate this function."; - $word_wrapped = word_wrap($string, 25); - $this->assertEquals(substr_count($word_wrapped, "\n"), 4); + $string = 'Here is a simple string of text that will help us demonstrate this function.'; + $this->assertEquals(substr_count(word_wrap($string, 25), "\n"), 4); } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ public function test_default_word_wrap_charlim() { $string = "Here is a longer string of text that will help us demonstrate the default charlim of this function."; - $word_wrapped = word_wrap($string); - $this->assertEquals(strpos($word_wrapped, "\n"), 73); + $this->assertEquals(strpos(word_wrap($string), "\n"), 73); } } \ No newline at end of file diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php index c561809ce..c81c5f1b8 100644 --- a/tests/codeigniter/helpers/url_helper_test.php +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -72,4 +72,5 @@ class Url_helper_test extends CI_TestCase { $this->assertEquals($out, auto_link($in, 'url')); } } + } \ No newline at end of file diff --git a/tests/codeigniter/helpers/xml_helper_test.php b/tests/codeigniter/helpers/xml_helper_test.php index a83fef91e..e8cf411da 100644 --- a/tests/codeigniter/helpers/xml_helper_test.php +++ b/tests/codeigniter/helpers/xml_helper_test.php @@ -6,10 +6,10 @@ class Xml_helper_test extends CI_TestCase { { $this->helper('xml'); } - + public function test_xml_convert() { $this->assertEquals('<tag>my & test - </tag>', xml_convert('my & test - ')); } - + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c186288755aba46a2b6f0c3f104d9a6ce6b11a7f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 9 Jun 2012 23:16:58 +0300 Subject: Cleanup/optimize tests/codeigniter/ --- tests/codeigniter/Setup_test.php | 6 +- tests/codeigniter/core/Benchmark_test.php | 11 +- tests/codeigniter/core/Common_test.php | 6 +- tests/codeigniter/core/Config_test.php | 38 ++-- tests/codeigniter/core/Input_test.php | 28 +-- tests/codeigniter/core/Lang_test.php | 12 +- tests/codeigniter/core/Loader_test.php | 132 ++++++------ tests/codeigniter/core/Security_test.php | 23 ++- tests/codeigniter/core/URI_test.php | 225 +++++++++------------ .../database/query_builder/count_test.php | 12 +- .../database/query_builder/delete_test.php | 16 +- .../database/query_builder/distinct_test.php | 9 +- .../database/query_builder/escape_test.php | 5 +- .../database/query_builder/from_test.php | 18 +- .../database/query_builder/get_test.php | 6 +- .../database/query_builder/group_test.php | 26 ++- .../database/query_builder/join_test.php | 2 +- .../database/query_builder/like_test.php | 2 +- .../database/query_builder/limit_test.php | 7 +- .../database/query_builder/order_test.php | 6 +- .../database/query_builder/select_test.php | 12 +- .../database/query_builder/truncate_test.php | 7 +- .../database/query_builder/update_test.php | 26 +-- .../database/query_builder/where_test.php | 28 +-- tests/codeigniter/helpers/number_helper_test.php | 2 +- tests/codeigniter/libraries/Encrypt_test.php | 131 ++++++------ tests/codeigniter/libraries/Parser_test.php | 61 +++--- tests/codeigniter/libraries/Table_test.php | 153 ++++++-------- tests/codeigniter/libraries/Typography_test.php | 40 ++-- tests/codeigniter/libraries/Useragent_test.php | 6 +- 30 files changed, 463 insertions(+), 593 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php index b48e32bfb..5317c56c7 100644 --- a/tests/codeigniter/Setup_test.php +++ b/tests/codeigniter/Setup_test.php @@ -1,13 +1,13 @@ assertTrue(defined('PROJECT_BASE')); $this->assertTrue(defined('BASEPATH')); $this->assertTrue(defined('APPPATH')); $this->assertTrue(defined('VIEWPATH')); } - + } \ No newline at end of file diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php index 109b38821..a239ba51d 100644 --- a/tests/codeigniter/core/Benchmark_test.php +++ b/tests/codeigniter/core/Benchmark_test.php @@ -1,14 +1,14 @@ benchmark = new Mock_Core_Benchmark(); } - + // -------------------------------------------------------------------- - + public function test_mark() { $this->assertEmpty($this->benchmark->marker); @@ -18,7 +18,7 @@ class Benchmark_test extends CI_TestCase { $this->assertEquals(1, count($this->benchmark->marker)); $this->assertArrayHasKey('code_start', $this->benchmark->marker); } - + // -------------------------------------------------------------------- public function test_elapsed_time() @@ -29,7 +29,7 @@ class Benchmark_test extends CI_TestCase { $this->benchmark->mark('code_start'); sleep(1); $this->benchmark->mark('code_end'); - + $this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1)); } @@ -39,4 +39,5 @@ class Benchmark_test extends CI_TestCase { { $this->assertEquals('{memory_usage}', $this->benchmark->memory_usage()); } + } \ No newline at end of file diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php index dded2e824..f9bf6c27f 100644 --- a/tests/codeigniter/core/Common_test.php +++ b/tests/codeigniter/core/Common_test.php @@ -1,13 +1,13 @@ assertEquals(TRUE, is_php('1.2.0')); $this->assertEquals(FALSE, is_php('9999.9.9')); } - + } \ No newline at end of file diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php index 30f0cc61d..30cb90a28 100644 --- a/tests/codeigniter/core/Config_test.php +++ b/tests/codeigniter/core/Config_test.php @@ -5,7 +5,7 @@ class Config_test extends CI_TestCase { public function set_up() { $cls =& $this->ci_core_class('cfg'); - + // set predictable config values $this->ci_set_config(array( 'index_page' => 'index.php', @@ -13,9 +13,9 @@ class Config_test extends CI_TestCase { 'subclass_prefix' => 'MY_' )); - $this->config = new $cls; + $this->config = new $cls; } - + // -------------------------------------------------------------------- public function test_item() @@ -24,30 +24,30 @@ class Config_test extends CI_TestCase { // Bad Config value $this->assertFalse($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')); } - + // -------------------------------------------------------------------- - + public function test_set_item() { $this->assertFalse($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')); } // -------------------------------------------------------------------- - + public function test_slash_item() { // Bad Config value $this->assertFalse($this->config->slash_item('no_good_item')); - + $this->assertEquals('http://example.com/', $this->config->slash_item('base_url')); $this->assertEquals('MY_/', $this->config->slash_item('subclass_prefix')); @@ -58,33 +58,33 @@ class Config_test extends CI_TestCase { public function test_site_url() { $this->assertEquals('http://example.com/index.php', $this->config->site_url()); - + $base_url = $this->config->item('base_url'); - + $this->config->set_item('base_url', ''); - + $q_string = $this->config->item('enable_query_strings'); - + $this->config->set_item('enable_query_strings', FALSE); $this->assertEquals('index.php/test', $this->config->site_url('test')); $this->assertEquals('index.php/test/1', $this->config->site_url(array('test', '1'))); - + $this->config->set_item('enable_query_strings', TRUE); $this->assertEquals('index.php?test', $this->config->site_url('test')); $this->assertEquals('index.php?0=test&1=1', $this->config->site_url(array('test', '1'))); - + $this->config->set_item('base_url', $base_url); $this->assertEquals('http://example.com/index.php?test', $this->config->site_url('test')); - + // back to home base - $this->config->set_item('enable_query_strings', $q_string); + $this->config->set_item('enable_query_strings', $q_string); } // -------------------------------------------------------------------- - + public function test_system_url() { $this->assertEquals('http://example.com/system/', $this->config->system_url()); diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index c9322c027..fe8738832 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -1,7 +1,7 @@ input = new Mock_Core_Input($security, $utf8); } - + // -------------------------------------------------------------------- - + public function test_get_not_exists() { $this->assertEmpty($this->input->get()); @@ -38,7 +38,7 @@ class Input_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_get_exist() { $_SERVER['REQUEST_METHOD'] = 'GET'; @@ -49,7 +49,7 @@ class Input_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_get_exist_with_xss_clean() { $_SERVER['REQUEST_METHOD'] = 'GET'; @@ -61,7 +61,7 @@ class Input_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_post_not_exists() { $this->assertEmpty($this->input->post()); @@ -78,7 +78,7 @@ class Input_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_post_exist() { $_SERVER['REQUEST_METHOD'] = 'POST'; @@ -89,7 +89,7 @@ class Input_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_post_exist_with_xss_clean() { $_SERVER['REQUEST_METHOD'] = 'POST'; @@ -101,7 +101,7 @@ class Input_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_get_post() { $_SERVER['REQUEST_METHOD'] = 'POST'; @@ -111,7 +111,7 @@ class Input_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_cookie() { $_COOKIE['foo'] = 'bar'; @@ -120,14 +120,14 @@ class Input_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_server() { $this->assertEquals('GET', $this->input->server('REQUEST_METHOD')); } // -------------------------------------------------------------------- - + public function test_fetch_from_array() { $data = array( @@ -145,14 +145,14 @@ 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)); $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) + foreach ($ip_v6 as $ip) { $this->assertTrue($this->input->valid_ip($ip)); } diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php index 874230feb..a410dabfa 100644 --- a/tests/codeigniter/core/Lang_test.php +++ b/tests/codeigniter/core/Lang_test.php @@ -1,9 +1,9 @@ ci_core_class('load'); @@ -12,9 +12,9 @@ class Lang_test extends CI_TestCase { $cls = $this->ci_core_class('lang'); $this->lang = new $cls; } - + // -------------------------------------------------------------------- - + public function test_load() { $this->assertTrue($this->lang->load('profiler', 'english')); @@ -22,11 +22,11 @@ class Lang_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_load_with_unspecified_language() { $this->assertTrue($this->lang->load('profiler')); $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string')); } - + } \ No newline at end of file diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 43008651e..fdea962b7 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -1,35 +1,35 @@ load = new Mock_Core_Loader(); - + // mock up a ci instance - $this->ci_obj = new StdClass; - + $this->ci_obj = new stdClass; + // Fix get_instance() $this->ci_instance($this->ci_obj); } // -------------------------------------------------------------------- - + public function test_library() { $this->_setup_config_mock(); - + // Test loading as an array. $this->assertNull($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->load->library()); - + // Test a string given to params $this->assertEquals(NULL, $this->load->library('table', ' ')); } @@ -39,20 +39,18 @@ class Loader_test extends CI_TestCase { public function test_load_library_in_application_dir() { $this->_setup_config_mock(); - + $content = 'withContent($content) - ->at($this->load->libs_dir); - + + $model = vfsStream::newFile('Super_test_library.php')->withContent($content)->at($this->load->libs_dir); $this->assertNull($this->load->library('super_test_library')); - + // Was the model class instantiated. - $this->assertTrue(class_exists('Super_test_library')); + $this->assertTrue(class_exists('Super_test_library')); } - + // -------------------------------------------------------------------- - + private function _setup_config_mock() { // Mock up a config object until we @@ -61,7 +59,7 @@ class Loader_test extends CI_TestCase { $config->expects($this->any()) ->method('load') ->will($this->returnValue(TRUE)); - + // Add the mock to our stdClass $this->ci_instance_var('config', $config); } @@ -73,64 +71,62 @@ class Loader_test extends CI_TestCase { $this->setExpectedException( 'RuntimeException', 'CI Error: Unable to locate the model you have specified: ci_test_nonexistent_model.php' - ); - + ); + $this->load->model('ci_test_nonexistent_model.php'); } // -------------------------------------------------------------------- - + /** * @coverts CI_Loader::model */ public function test_models() { $this->ci_set_core_class('model', 'CI_Model'); - + $content = 'withContent($content) - ->at($this->load->models_dir); - + + $model = vfsStream::newFile('unit_test_model.php')->withContent($content)->at($this->load->models_dir); + $this->assertNull($this->load->model('unit_test_model')); - + // Was the model class instantiated. $this->assertTrue(class_exists('Unit_test_model')); - + // Test no model given - $this->assertNull($this->load->model('')); + $this->assertNull($this->load->model('')); } // -------------------------------------------------------------------- - + // public function testDatabase() // { // $this->assertEquals(NULL, $this->load->database()); - // $this->assertEquals(NULL, $this->load->dbutil()); + // $this->assertEquals(NULL, $this->load->dbutil()); // } // -------------------------------------------------------------------- - + /** * @coverts CI_Loader::view */ public function test_load_view() { $this->ci_set_core_class('output', 'CI_Output'); - + $content = 'This is my test page. '; - $view = vfsStream::newFile('unit_test_view.php')->withContent($content) - ->at($this->load->views_dir); - + $view = vfsStream::newFile('unit_test_view.php')->withContent($content)->at($this->load->views_dir); + // Use the optional return parameter in this test, so the view is not // run through the output class. $this->assertEquals('This is my test page. World!', $this->load->view('unit_test_view', array('hello' => "World!"), TRUE)); - + } // -------------------------------------------------------------------- - + /** * @coverts CI_Loader::view */ @@ -139,8 +135,8 @@ class Loader_test extends CI_TestCase { $this->setExpectedException( 'RuntimeException', 'CI Error: Unable to load the requested file: ci_test_nonexistent_view.php' - ); - + ); + $this->load->view('ci_test_nonexistent_view', array('foo' => 'bar')); } @@ -149,87 +145,77 @@ class Loader_test extends CI_TestCase { public function test_file() { $content = 'Here is a test file, which we will load now.'; - $file = vfsStream::newFile('ci_test_mock_file.php')->withContent($content) - ->at($this->load->views_dir); - + $file = vfsStream::newFile('ci_test_mock_file.php')->withContent($content)->at($this->load->views_dir); + // Just like load->view(), take the output class out of the mix here. - $load = $this->load->file(vfsStream::url('application').'/views/ci_test_mock_file.php', - TRUE); - + $load = $this->load->file(vfsStream::url('application').'/views/ci_test_mock_file.php', TRUE); + $this->assertEquals($content, $load); - + $this->setExpectedException( 'RuntimeException', 'CI Error: Unable to load the requested file: ci_test_file_not_exists' - ); - + ); + $this->load->file('ci_test_file_not_exists', TRUE); - } // -------------------------------------------------------------------- - + public function test_vars() { - $vars = array( - 'foo' => 'bar' - ); - - $this->assertNull($this->load->vars($vars)); + $this->assertNull($this->load->vars(array('foo' => 'bar'))); $this->assertNull($this->load->vars('foo', 'bar')); } // -------------------------------------------------------------------- - + public function test_helper() { $this->assertEquals(NULL, $this->load->helper('array')); - + $this->setExpectedException( 'RuntimeException', 'CI Error: Unable to load the requested file: helpers/bad_helper.php' - ); - + ); + $this->load->helper('bad'); } - + // -------------------------------------------------------------------- public function test_loading_multiple_helpers() { $this->assertEquals(NULL, $this->load->helpers(array('file', 'array', 'string'))); } - + // -------------------------------------------------------------------- - + // public function testLanguage() // { // $this->assertEquals(NULL, $this->load->language('test')); - // } + // } // -------------------------------------------------------------------- public function test_load_config() { $this->_setup_config_mock(); - $this->assertNull($this->load->config('config', FALSE)); } - + // -------------------------------------------------------------------- public function test_load_bad_config() { $this->_setup_config_mock(); - + $this->setExpectedException( 'RuntimeException', 'CI Error: The configuration file foobar.php does not exist.' - ); - + ); + $this->load->config('foobar', FALSE); } - // -------------------------------------------------------------------- - -} +} \ No newline at end of file diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index b2f8c69d2..3f6e3b07a 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -1,7 +1,7 @@ security = new Mock_Core_Security(); } - + // -------------------------------------------------------------------- - + public function test_csrf_verify() { $_SERVER['REQUEST_METHOD'] = 'GET'; @@ -25,7 +25,7 @@ class Security_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_csrf_verify_invalid() { // Without issuing $_POST[csrf_token_name], this request will triggering CSRF error @@ -37,7 +37,7 @@ class Security_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_csrf_verify_valid() { $_SERVER['REQUEST_METHOD'] = 'POST'; @@ -47,21 +47,21 @@ class Security_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_get_csrf_hash() { $this->assertEquals($this->security->csrf_hash, $this->security->get_csrf_hash()); } // -------------------------------------------------------------------- - + public function test_get_csrf_token_name() { $this->assertEquals('ci_csrf_token', $this->security->get_csrf_token_name()); } // -------------------------------------------------------------------- - + public function test_xss_clean() { $harm_string = "Hello, i try to your site"; @@ -72,7 +72,7 @@ class Security_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_xss_hash() { $this->assertEmpty($this->security->xss_hash); @@ -84,7 +84,7 @@ class Security_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_entity_decode() { $encoded = '<div>Hello <b>Booya</b></div>'; @@ -94,7 +94,7 @@ class Security_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_sanitize_filename() { $filename = './'; @@ -102,4 +102,5 @@ class Security_test extends CI_TestCase { $this->assertEquals('foo', $safe_filename); } + } \ No newline at end of file diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php index e340ddf73..0ba694b46 100644 --- a/tests/codeigniter/core/URI_test.php +++ b/tests/codeigniter/core/URI_test.php @@ -1,7 +1,7 @@ uri = new Mock_Core_URI(); @@ -13,19 +13,12 @@ class URI_test extends CI_TestCase { { // Slashes get killed $this->uri->_set_uri_string('/'); - - $a = ''; - $b =& $this->uri->uri_string; - - $this->assertEquals($a, $b); - + $this->assertEquals('', $this->uri->uri_string); + $this->uri->_set_uri_string('nice/uri'); - - $a = 'nice/uri'; - - $this->assertEquals($a, $b); + $this->assertEquals('nice/uri', $this->uri->uri_string); } - + // -------------------------------------------------------------------- public function test_fetch_uri_string() @@ -34,75 +27,61 @@ class URI_test extends CI_TestCase { // uri_protocol: AUTO $this->uri->config->set_item('uri_protocol', 'AUTO'); - + // Test a variety of request uris $requests = array( '/index.php/controller/method' => 'controller/method', '/index.php?/controller/method' => 'controller/method', '/index.php?/controller/method/?var=foo' => 'controller/method' ); - + foreach($requests as $request => $expected) { $_SERVER['SCRIPT_NAME'] = '/index.php'; $_SERVER['REQUEST_URI'] = $request; - + $this->uri->_fetch_uri_string(); $this->assertEquals($expected, $this->uri->uri_string ); } - + // Test a subfolder $_SERVER['SCRIPT_NAME'] = '/subfolder/index.php'; $_SERVER['REQUEST_URI'] = '/subfolder/index.php/controller/method'; - + $this->uri->_fetch_uri_string(); - - $a = 'controller/method'; - $b = $this->uri->uri_string; - - $this->assertEquals($a, $b); - + $this->assertEquals('controller/method', $this->uri->uri_string); + // death to request uri unset($_SERVER['REQUEST_URI']); - + // life to path info - $_SERVER['PATH_INFO'] = '/controller/method/'; - + $_SERVER['PATH_INFO'] = $a = '/controller/method/'; + $this->uri->_fetch_uri_string(); - - $a = '/controller/method/'; - $b =& $this->uri->uri_string; + $this->assertEquals($a, $this->uri->uri_string); - $this->assertEquals($a, $b); - // death to path info // At this point your server must be seriously drunk unset($_SERVER['PATH_INFO']); - + $_SERVER['QUERY_STRING'] = '/controller/method/'; - + $this->uri->_fetch_uri_string(); + $this->assertEquals($a, $this->uri->uri_string); - $a = '/controller/method/'; - $b = $this->uri->uri_string; - - $this->assertEquals($a, $b); - // At this point your server is a labotomy victim - unset($_SERVER['QUERY_STRING']); - + $_GET['/controller/method/'] = ''; - + $this->uri->_fetch_uri_string(); - $this->assertEquals($a, $b); + $this->assertEquals($a, $this->uri->uri_string); // Test coverage implies that these will work // uri_protocol: REQUEST_URI // uri_protocol: CLI - } - + // -------------------------------------------------------------------- public function test_explode_segments() @@ -113,18 +92,15 @@ class URI_test extends CI_TestCase { '/test2/uri2' => array('test2', 'uri2'), '//test3/test3///' => array('test3', 'test3') ); - - foreach($uris as $uri => $a) + + foreach ($uris as $uri => $a) { $this->uri->segments = array(); $this->uri->uri_string = $uri; $this->uri->_explode_segments(); - - $b = $this->uri->segments; - - $this->assertEquals($a, $b); + + $this->assertEquals($a, $this->uri->segments); } - } // -------------------------------------------------------------------- @@ -133,7 +109,7 @@ class URI_test extends CI_TestCase { { $this->uri->config->set_item('enable_query_strings', FALSE); $this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-'); - + $str_in = 'abc01239~%.:_-'; $str = $this->uri->_filter_uri($str_in); @@ -145,52 +121,52 @@ class URI_test extends CI_TestCase { public function test_filter_uri_escaping() { // ensure escaping even if dodgey characters are permitted - + $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)'); - + $this->assertEquals($str, '$destroy_app(foo)'); } // -------------------------------------------------------------------- - public function test_filter_uri_throws_error() - { + public function test_filter_uri_throws_error() + { $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()'); - } + } // -------------------------------------------------------------------- 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'); $this->assertEquals($this->uri->segment(1), 'controller'); $this->assertEquals($this->uri->segment(2, 'default'), 'default'); } - + // -------------------------------------------------------------------- public function test_rsegment() @@ -205,32 +181,33 @@ class URI_test extends CI_TestCase { public function test_uri_to_assoc() { $this->uri->segments = array('a', '1', 'b', '2', 'c', '3'); - - $a = array('a' => '1', 'b' => '2', 'c' => '3'); - $b = $this->uri->uri_to_assoc(1); - $this->assertEquals($a, $b); - - $a = array('b' => '2', 'c' => '3'); - $b = $this->uri->uri_to_assoc(3); - $this->assertEquals($a, $b); - - + + $this->assertEquals( + array('a' => '1', 'b' => '2', 'c' => '3'), + $this->uri->uri_to_assoc(1) + ); + + $this->assertEquals( + array('b' => '2', 'c' => '3'), + $this->uri->uri_to_assoc(3) + ); + $this->uri->keyval = array(); // reset cache - $this->uri->segments = array('a', '1', 'b', '2', 'c'); - - $a = array('a' => '1', 'b' => '2', 'c' => FALSE); - $b = $this->uri->uri_to_assoc(1); - $this->assertEquals($a, $b); - + + $this->assertEquals( + array('a' => '1', 'b' => '2', 'c' => FALSE), + $this->uri->uri_to_assoc(1) + ); + $this->uri->keyval = array(); // reset cache - $this->uri->segments = array('a', '1'); - + // test default - $a = array('a' => '1', 'b' => FALSE); - $b = $this->uri->uri_to_assoc(1, array('a', 'b')); - $this->assertEquals($a, $b); + $this->assertEquals( + array('a' => '1', 'b' => FALSE), + $this->uri->uri_to_assoc(1, array('a', 'b')) + ); } // -------------------------------------------------------------------- @@ -238,33 +215,33 @@ class URI_test extends CI_TestCase { public function test_ruri_to_assoc() { $this->uri->rsegments = array('x', '1', 'y', '2', 'z', '3'); - - $a = array('x' => '1', 'y' => '2', 'z' => '3'); - $b = $this->uri->ruri_to_assoc(1); - $this->assertEquals($a, $b); - - $a = array('y' => '2', 'z' => '3'); - $b = $this->uri->ruri_to_assoc(3); - $this->assertEquals($a, $b); - - + + $this->assertEquals( + array('x' => '1', 'y' => '2', 'z' => '3'), + $this->uri->ruri_to_assoc(1) + ); + + $this->assertEquals( + array('y' => '2', 'z' => '3'), + $this->uri->ruri_to_assoc(3) + ); + $this->uri->keyval = array(); // reset cache - $this->uri->rsegments = array('x', '1', 'y', '2', 'z'); - - $a = array('x' => '1', 'y' => '2', 'z' => FALSE); - $b = $this->uri->ruri_to_assoc(1); - $this->assertEquals($a, $b); - + + $this->assertEquals( + array('x' => '1', 'y' => '2', 'z' => FALSE), + $this->uri->ruri_to_assoc(1) + ); + $this->uri->keyval = array(); // reset cache - $this->uri->rsegments = array('x', '1'); - - // test default - $a = array('x' => '1', 'y' => FALSE); - $b = $this->uri->ruri_to_assoc(1, array('x', 'y')); - $this->assertEquals($a, $b); + // test default + $this->assertEquals( + array('x' => '1', 'y' => FALSE), + $this->uri->ruri_to_assoc(1, array('x', 'y')) + ); } // -------------------------------------------------------------------- @@ -272,11 +249,7 @@ class URI_test extends CI_TestCase { public function test_assoc_to_uri() { $this->uri->config->set_item('uri_string_slashes', 'none'); - - $arr = array('a' => 1, 'b' => 2); - $a = 'a/1/b/2'; - $b = $this->uri->assoc_to_uri($arr); - $this->assertEquals($a, $b); + $this->assertEquals('a/1/b/2', $this->uri->assoc_to_uri(array('a' => '1', 'b' => '2'))); } // -------------------------------------------------------------------- @@ -286,28 +259,18 @@ class URI_test extends CI_TestCase { $this->uri->segments[1] = 'segment'; $this->uri->rsegments[1] = 'segment'; - $a = '/segment/'; - $b = $this->uri->slash_segment(1, 'both'); - $this->assertEquals($a, $b); - $b = $this->uri->slash_rsegment(1, 'both'); - $this->assertEquals($a, $b); - + $this->assertEquals('/segment/', $this->uri->slash_segment(1, 'both')); + $this->assertEquals('/segment/', $this->uri->slash_rsegment(1, 'both')); + $a = '/segment'; - $b = $this->uri->slash_segment(1, 'leading'); - $this->assertEquals($a, $b); - $b = $this->uri->slash_rsegment(1, 'leading'); - $this->assertEquals($a, $b); - - $a = 'segment/'; - $b = $this->uri->slash_segment(1, 'trailing'); - $this->assertEquals($a, $b); - $b = $this->uri->slash_rsegment(1, 'trailing'); - $this->assertEquals($a, $b); - } + $this->assertEquals('/segment', $this->uri->slash_segment(1, 'leading')); + $this->assertEquals('/segment', $this->uri->slash_rsegment(1, 'leading')); + $this->assertEquals('segment/', $this->uri->slash_segment(1, 'trailing')); + $this->assertEquals('segment/', $this->uri->slash_rsegment(1, 'trailing')); + } } -// END URI_test Class /* End of file URI_test.php */ -/* Location: ./tests/core/URI_test.php */ +/* Location: ./tests/core/URI_test.php */ \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/count_test.php b/tests/codeigniter/database/query_builder/count_test.php index 5e691692d..90ac5283e 100644 --- a/tests/codeigniter/database/query_builder/count_test.php +++ b/tests/codeigniter/database/query_builder/count_test.php @@ -22,10 +22,7 @@ class Count_test extends CI_TestCase { */ public function test_count_all() { - $job_count = $this->db->count_all('job'); - - // Check the result - $this->assertEquals(4, $job_count); + $this->assertEquals(4, $this->db->count_all('job')); } // ------------------------------------------------------------------------ @@ -35,10 +32,7 @@ class Count_test extends CI_TestCase { */ public function test_count_all_results() { - $job_count = $this->db->like('name', 'ian') - ->count_all_results('job'); - - // Check the result - $this->assertEquals(2, $job_count); + $this->assertEquals(2, $this->db->like('name', 'ian')->count_all_results('job')); } + } \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/delete_test.php b/tests/codeigniter/database/query_builder/delete_test.php index 84ea7616f..ab9d97f56 100644 --- a/tests/codeigniter/database/query_builder/delete_test.php +++ b/tests/codeigniter/database/query_builder/delete_test.php @@ -23,9 +23,7 @@ class Delete_test extends CI_TestCase { public function test_delete() { // Check initial record - $job1 = $this->db->where('id', 1) - ->get('job') - ->row(); + $job1 = $this->db->where('id', 1)->get('job')->row(); $this->assertEquals('Developer', $job1->name); @@ -33,8 +31,7 @@ class Delete_test extends CI_TestCase { $this->db->delete('job', array('id' => 1)); // Check the record - $job1 = $this->db->where('id', 1) - ->get('job'); + $job1 = $this->db->where('id', 1)->get('job'); $this->assertEmpty($job1->result_array()); } @@ -47,13 +44,8 @@ class Delete_test extends CI_TestCase { public function test_delete_several_tables() { // Check initial record - $user4 = $this->db->where('id', 4) - ->get('user') - ->row(); - - $job4 = $this->db->where('id', 4) - ->get('job') - ->row(); + $user4 = $this->db->where('id', 4)->get('user')->row(); + $job4 = $this->db->where('id', 4)->get('job')->row(); $this->assertEquals('Musician', $job4->name); $this->assertEquals('Chris Martin', $user4->name); diff --git a/tests/codeigniter/database/query_builder/distinct_test.php b/tests/codeigniter/database/query_builder/distinct_test.php index 925eadb19..cc98009ce 100644 --- a/tests/codeigniter/database/query_builder/distinct_test.php +++ b/tests/codeigniter/database/query_builder/distinct_test.php @@ -23,11 +23,10 @@ class Distinct_test extends CI_TestCase { public function test_distinct() { $users = $this->db->select('country') - ->distinct() - ->get('user') - ->result_array(); - - // Check the result + ->distinct() + ->get('user') + ->result_array(); + $this->assertEquals(3, count($users)); } diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index 5d575a37b..c6380ddf1 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -35,7 +35,7 @@ class Escape_test extends CI_TestCase { } $res = $this->db->query($sql)->result_array(); - + // Check the result $this->assertEquals(1, count($res)); } @@ -60,8 +60,9 @@ class Escape_test extends CI_TestCase { } $res = $this->db->query($sql)->result_array(); - + // Check the result $this->assertEquals(2, count($res)); } + } \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/from_test.php b/tests/codeigniter/database/query_builder/from_test.php index 95ae4dfdb..7aaae348d 100644 --- a/tests/codeigniter/database/query_builder/from_test.php +++ b/tests/codeigniter/database/query_builder/from_test.php @@ -23,10 +23,9 @@ class From_test extends CI_TestCase { public function test_from_simple() { $jobs = $this->db->from('job') - ->get() - ->result_array(); - - // Check items + ->get() + ->result_array(); + $this->assertEquals(4, count($jobs)); } @@ -38,14 +37,13 @@ class From_test extends CI_TestCase { public function test_from_with_where() { $job1 = $this->db->from('job') - ->where('id', 1) - ->get() - ->row(); - - // Check the result + ->where('id', 1) + ->get() + ->row(); + $this->assertEquals('1', $job1->id); $this->assertEquals('Developer', $job1->name); $this->assertEquals('Awesome job, but sometimes makes you bored', $job1->description); } - + } \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php index 0751c9332..699d2906a 100644 --- a/tests/codeigniter/database/query_builder/get_test.php +++ b/tests/codeigniter/database/query_builder/get_test.php @@ -23,7 +23,7 @@ class Get_test extends CI_TestCase { public function test_get_simple() { $jobs = $this->db->get('job')->result_array(); - + // Dummy jobs contain 4 rows $this->assertCount(4, $jobs); @@ -42,12 +42,12 @@ class Get_test extends CI_TestCase { public function test_get_where() { $job1 = $this->db->get('job', array('id' => 1))->result_array(); - + // Dummy jobs contain 1 rows $this->assertCount(1, $job1); // Check rows item $this->assertEquals('Developer', $job1[0]['name']); } - + } \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php index 7d8abc33f..5249f7c87 100644 --- a/tests/codeigniter/database/query_builder/group_test.php +++ b/tests/codeigniter/database/query_builder/group_test.php @@ -23,12 +23,11 @@ class Group_test extends CI_TestCase { public function test_group_by() { $jobs = $this->db->select('name') - ->from('job') - ->group_by('name') - ->get() - ->result_array(); - - // Check the result + ->from('job') + ->group_by('name') + ->get() + ->result_array(); + $this->assertEquals(4, count($jobs)); } @@ -40,14 +39,13 @@ class Group_test extends CI_TestCase { public function test_having_by() { $jobs = $this->db->select('name') - ->from('job') - ->group_by('name') - ->having('SUM(id) > 2') - ->get() - ->result_array(); - - // Check the result + ->from('job') + ->group_by('name') + ->having('SUM(id) > 2') + ->get() + ->result_array(); + $this->assertEquals(2, count($jobs)); } - + } \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php index e05329d67..b8cf2a822 100644 --- a/tests/codeigniter/database/query_builder/join_test.php +++ b/tests/codeigniter/database/query_builder/join_test.php @@ -34,5 +34,5 @@ class Join_test extends CI_TestCase { $this->assertEquals('Derek Jones', $job_user[0]['user_name']); $this->assertEquals('Developer', $job_user[0]['job_name']); } - + } \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/like_test.php b/tests/codeigniter/database/query_builder/like_test.php index df98c713f..5f3e52228 100644 --- a/tests/codeigniter/database/query_builder/like_test.php +++ b/tests/codeigniter/database/query_builder/like_test.php @@ -86,5 +86,5 @@ class Like_test extends CI_TestCase { $this->assertEquals('Accountant', $jobs[1]['name']); $this->assertEquals('Musician', $jobs[2]['name']); } - + } \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/limit_test.php b/tests/codeigniter/database/query_builder/limit_test.php index 704f3b651..a0954c7ab 100644 --- a/tests/codeigniter/database/query_builder/limit_test.php +++ b/tests/codeigniter/database/query_builder/limit_test.php @@ -25,8 +25,7 @@ class Limit_test extends CI_TestCase { $jobs = $this->db->limit(2) ->get('job') ->result_array(); - - // Check the result + $this->assertEquals(2, count($jobs)); } @@ -40,10 +39,10 @@ class Limit_test extends CI_TestCase { $jobs = $this->db->limit(2, 2) ->get('job') ->result_array(); - - // Check the result + $this->assertEquals(2, count($jobs)); $this->assertEquals('Accountant', $jobs[0]['name']); $this->assertEquals('Musician', $jobs[1]['name']); } + } \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/order_test.php b/tests/codeigniter/database/query_builder/order_test.php index 01aa1c2b4..46f452bae 100644 --- a/tests/codeigniter/database/query_builder/order_test.php +++ b/tests/codeigniter/database/query_builder/order_test.php @@ -25,7 +25,7 @@ class Order_test extends CI_TestCase { $jobs = $this->db->order_by('name', 'asc') ->get('job') ->result_array(); - + // Check the result $this->assertEquals(4, count($jobs)); $this->assertEquals('Accountant', $jobs[0]['name']); @@ -44,12 +44,12 @@ class Order_test extends CI_TestCase { $jobs = $this->db->order_by('name', 'desc') ->get('job') ->result_array(); - - // Check the result + $this->assertEquals(4, count($jobs)); $this->assertEquals('Politician', $jobs[0]['name']); $this->assertEquals('Musician', $jobs[1]['name']); $this->assertEquals('Developer', $jobs[2]['name']); $this->assertEquals('Accountant', $jobs[3]['name']); } + } \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php index 0d299ed16..877b5d8c0 100644 --- a/tests/codeigniter/database/query_builder/select_test.php +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -25,7 +25,7 @@ class Select_test extends CI_TestCase { $jobs_name = $this->db->select('name') ->get('job') ->result_array(); - + // Check rows item $this->assertArrayHasKey('name',$jobs_name[0]); $this->assertFalse(array_key_exists('id', $jobs_name[0])); @@ -42,7 +42,7 @@ class Select_test extends CI_TestCase { $job_min = $this->db->select_min('id') ->get('job') ->row(); - + // Minimum id was 1 $this->assertEquals('1', $job_min->id); } @@ -57,7 +57,7 @@ class Select_test extends CI_TestCase { $job_max = $this->db->select_max('id') ->get('job') ->row(); - + // Maximum id was 4 $this->assertEquals('4', $job_max->id); } @@ -72,7 +72,7 @@ class Select_test extends CI_TestCase { $job_avg = $this->db->select_avg('id') ->get('job') ->row(); - + // Average should be 2.5 $this->assertEquals('2.5', $job_avg->id); } @@ -87,9 +87,9 @@ class Select_test extends CI_TestCase { $job_sum = $this->db->select_sum('id') ->get('job') ->row(); - + // Sum of ids should be 10 $this->assertEquals('10', $job_sum->id); } - + } \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/truncate_test.php b/tests/codeigniter/database/query_builder/truncate_test.php index 2a9c8a91e..09923c7f1 100644 --- a/tests/codeigniter/database/query_builder/truncate_test.php +++ b/tests/codeigniter/database/query_builder/truncate_test.php @@ -24,7 +24,6 @@ class Truncate_test extends CI_TestCase { { // Check initial record $jobs = $this->db->get('job')->result_array(); - $this->assertEquals(4, count($jobs)); // Do the empty @@ -32,7 +31,6 @@ class Truncate_test extends CI_TestCase { // Check the record $jobs = $this->db->get('job'); - $this->assertEmpty($jobs->result_array()); } @@ -45,16 +43,13 @@ class Truncate_test extends CI_TestCase { { // Check initial record $users = $this->db->get('user')->result_array(); - $this->assertEquals(4, count($users)); // Do the empty - $this->db->from('user') - ->truncate(); + $this->db->from('user')->truncate(); // Check the record $users = $this->db->get('user'); - $this->assertEmpty($users->result_array()); } diff --git a/tests/codeigniter/database/query_builder/update_test.php b/tests/codeigniter/database/query_builder/update_test.php index f5bbffd4f..27a647c45 100644 --- a/tests/codeigniter/database/query_builder/update_test.php +++ b/tests/codeigniter/database/query_builder/update_test.php @@ -23,23 +23,14 @@ class Update_test extends CI_TestCase { public function test_update() { // Check initial record - $job1 = $this->db->where('id', 1) - ->get('job') - ->row(); - + $job1 = $this->db->where('id', 1)->get('job')->row(); $this->assertEquals('Developer', $job1->name); // Do the update - $job_data = array('name' => 'Programmer'); - - $this->db->where('id', 1) - ->update('job', $job_data); + $this->db->where('id', 1)->update('job', array('name' => 'Programmer')); // Check updated record - $job1 = $this->db->where('id', 1) - ->get('job') - ->row(); - + $job1 = $this->db->where('id', 1)->get('job')->row(); $this->assertEquals('Programmer', $job1->name); } @@ -51,10 +42,7 @@ class Update_test extends CI_TestCase { public function test_update_with_set() { // Check initial record - $job1 = $this->db->where('id', 4) - ->get('job') - ->row(); - + $job1 = $this->db->where('id', 4)->get('job')->row(); $this->assertEquals('Musician', $job1->name); // Do the update @@ -62,10 +50,8 @@ class Update_test extends CI_TestCase { $this->db->update('job', NULL, 'id = 4'); // Check updated record - $job1 = $this->db->where('id', 4) - ->get('job') - ->row(); - + $job1 = $this->db->where('id', 4)->get('job')->row(); $this->assertEquals('Vocalist', $job1->name); } + } \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php index 607eaa076..20b7a567c 100644 --- a/tests/codeigniter/database/query_builder/where_test.php +++ b/tests/codeigniter/database/query_builder/where_test.php @@ -22,11 +22,8 @@ class Where_test extends CI_TestCase { */ public function test_where_simple_key_value() { - $job1 = $this->db->where('id', 1) - ->get('job') - ->row(); + $job1 = $this->db->where('id', 1)->get('job')->row(); - // Check the result $this->assertEquals('1', $job1->id); $this->assertEquals('Developer', $job1->name); } @@ -38,11 +35,7 @@ class Where_test extends CI_TestCase { */ public function test_where_custom_key_value() { - $jobs = $this->db->where('id !=', 1) - ->get('job') - ->result_array(); - - // Check the result + $jobs = $this->db->where('id !=', 1)->get('job')->result_array(); $this->assertEquals(3, count($jobs)); } @@ -54,16 +47,12 @@ class Where_test extends CI_TestCase { public function test_where_associative_array() { $where = array('id >' => 2, 'name !=' => 'Accountant'); - $jobs = $this->db->where($where) - ->get('job') - ->result_array(); + $jobs = $this->db->where($where)->get('job')->result_array(); - // Check the result $this->assertEquals(1, count($jobs)); // Should be Musician $job = current($jobs); - $this->assertEquals('Musician', $job['name']); } @@ -75,16 +64,12 @@ class Where_test extends CI_TestCase { public function test_where_custom_string() { $where = "id > 2 AND name != 'Accountant'"; - $jobs = $this->db->where($where) - ->get('job') - ->result_array(); + $jobs = $this->db->where($where)->get('job')->result_array(); - // Check the result $this->assertEquals(1, count($jobs)); // Should be Musician $job = current($jobs); - $this->assertEquals('Musician', $job['name']); } @@ -100,7 +85,6 @@ class Where_test extends CI_TestCase { ->get('job') ->result_array(); - // Check the result $this->assertEquals(3, count($jobs)); $this->assertEquals('Developer', $jobs[0]['name']); $this->assertEquals('Politician', $jobs[1]['name']); @@ -118,7 +102,6 @@ class Where_test extends CI_TestCase { ->get('job') ->result_array(); - // Check the result $this->assertEquals(2, count($jobs)); $this->assertEquals('Politician', $jobs[0]['name']); $this->assertEquals('Accountant', $jobs[1]['name']); @@ -135,10 +118,9 @@ class Where_test extends CI_TestCase { ->get('job') ->result_array(); - // Check the result $this->assertEquals(2, count($jobs)); $this->assertEquals('Developer', $jobs[0]['name']); $this->assertEquals('Musician', $jobs[1]['name']); } - + } \ No newline at end of file diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php index 23d5c5c1a..ef6aae138 100644 --- a/tests/codeigniter/helpers/number_helper_test.php +++ b/tests/codeigniter/helpers/number_helper_test.php @@ -25,7 +25,7 @@ class Number_helper_test extends CI_TestCase { // a cheap class to act as our super object. // Make sure it has a lang attribute. - $obj = new StdClass; + $obj = new stdClass; $obj->lang = $lang; $this->ci_instance($obj); } diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php index 066990186..153a25e1d 100644 --- a/tests/codeigniter/libraries/Encrypt_test.php +++ b/tests/codeigniter/libraries/Encrypt_test.php @@ -2,70 +2,71 @@ class Encrypt_test extends CI_TestCase { - public function set_up() - { - $obj = new StdClass; - $obj->encrypt = new Mock_Libraries_Encrypt(); - - $this->ci_instance($obj); - $this->encrypt = $obj->encrypt; - - $this->ci_set_config('encryption_key', "Encryptin'glike@boss!"); - $this->msg = 'My secret message'; - } - - // -------------------------------------------------------------------- - - public function test_encode() - { - $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg)); - } - - // -------------------------------------------------------------------- - - public function test_decode() - { - $encoded_msg = $this->encrypt->encode($this->msg); - $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg)); - } - - // -------------------------------------------------------------------- - - public function test_optional_key() - { - $key = 'Ohai!ù0129°03182%HD1892P0'; - $encoded_msg = $this->encrypt->encode($this->msg, $key); - $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg, $key)); - } - - // -------------------------------------------------------------------- - - public function test_default_cipher() - { - $this->assertEquals('rijndael-256', $this->encrypt->get_cipher()); - } - - // -------------------------------------------------------------------- - - public function test_set_cipher() - { - $this->encrypt->set_cipher(MCRYPT_BLOWFISH); - $this->assertEquals('blowfish', $this->encrypt->get_cipher()); - } - - // -------------------------------------------------------------------- - - public function test_default_mode() - { - $this->assertEquals('cbc', $this->encrypt->get_mode()); - } - - // -------------------------------------------------------------------- - - public function test_set_mode() - { - $this->encrypt->set_mode(MCRYPT_MODE_CFB); - $this->assertEquals('cfb', $this->encrypt->get_mode()); - } + public function set_up() + { + $obj = new stdClass; + $obj->encrypt = new Mock_Libraries_Encrypt(); + + $this->ci_instance($obj); + $this->encrypt = $obj->encrypt; + + $this->ci_set_config('encryption_key', "Encryptin'glike@boss!"); + $this->msg = 'My secret message'; + } + + // -------------------------------------------------------------------- + + public function test_encode() + { + $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg)); + } + + // -------------------------------------------------------------------- + + public function test_decode() + { + $encoded_msg = $this->encrypt->encode($this->msg); + $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg)); + } + + // -------------------------------------------------------------------- + + public function test_optional_key() + { + $key = 'Ohai!ù0129°03182%HD1892P0'; + $encoded_msg = $this->encrypt->encode($this->msg, $key); + $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg, $key)); + } + + // -------------------------------------------------------------------- + + public function test_default_cipher() + { + $this->assertEquals('rijndael-256', $this->encrypt->get_cipher()); + } + + // -------------------------------------------------------------------- + + + public function test_set_cipher() + { + $this->encrypt->set_cipher(MCRYPT_BLOWFISH); + $this->assertEquals('blowfish', $this->encrypt->get_cipher()); + } + + // -------------------------------------------------------------------- + + public function test_default_mode() + { + $this->assertEquals('cbc', $this->encrypt->get_mode()); + } + + // -------------------------------------------------------------------- + + public function test_set_mode() + { + $this->encrypt->set_mode(MCRYPT_MODE_CFB); + $this->assertEquals('cfb', $this->encrypt->get_mode()); + } } \ No newline at end of file diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php index c3d88fa85..b68f44a33 100644 --- a/tests/codeigniter/libraries/Parser_test.php +++ b/tests/codeigniter/libraries/Parser_test.php @@ -1,73 +1,74 @@ parser = new Mock_Libraries_Parser(); - + $this->ci_instance($obj); - + $this->parser = $obj->parser; } + // -------------------------------------------------------------------- - + public function test_set_delimiters() { // Make sure default delimiters are there $this->assertEquals('{', $this->parser->l_delim); $this->assertEquals('}', $this->parser->r_delim); - + // Change them to square brackets $this->parser->set_delimiters('[', ']'); - + // Make sure they changed $this->assertEquals('[', $this->parser->l_delim); $this->assertEquals(']', $this->parser->r_delim); - + // Reset them $this->parser->set_delimiters(); - + // Make sure default delimiters are there $this->assertEquals('{', $this->parser->l_delim); $this->assertEquals('}', $this->parser->r_delim); } - + // -------------------------------------------------------------------- - + public function test_parse_simple_string() { $data = array( 'title' => 'Page Title', 'body' => 'Lorem ipsum dolor sit amet.' ); - + $template = "{title}\n{body}"; - + $result = implode("\n", $data); - + $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE)); } - + // -------------------------------------------------------------------- - + public function test_parse() { $this->_parse_no_template(); $this->_parse_var_pair(); $this->_mismatched_var_pair(); } - + // -------------------------------------------------------------------- - + private function _parse_no_template() { $this->assertFalse($this->parser->parse_string('', '', TRUE)); } - + // -------------------------------------------------------------------- - + private function _parse_var_pair() { $data = array( @@ -78,16 +79,14 @@ class Parser_test extends CI_TestCase { 'flying' => 'no'), ) ); - + $template = "{title}\n{powers}{invisibility}\n{flying}{/powers}"; - - $result = "Super Heroes\nyes\nno"; - - $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE)); + + $this->assertEquals("Super Heroes\nyes\nno", $this->parser->parse_string($template, $data, TRUE)); } - + // -------------------------------------------------------------------- - + private function _mismatched_var_pair() { $data = array( @@ -98,13 +97,11 @@ class Parser_test extends CI_TestCase { 'flying' => 'no'), ) ); - + $template = "{title}\n{powers}{invisibility}\n{flying}"; - $result = "Super Heroes\n{powers}{invisibility}\n{flying}"; - - $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE)); + + $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE)); } - // -------------------------------------------------------------------- } \ No newline at end of file diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index f5133de1e..edfc83dd0 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -4,43 +4,39 @@ class Table_test extends CI_TestCase { public function set_up() { - $obj = new StdClass; + $obj = new stdClass; $obj->table = new Mock_Libraries_Table(); - + $this->ci_instance($obj); - + $this->table = $obj->table; } - // Setter Methods // -------------------------------------------------------------------- - + public function test_set_template() { $this->assertFalse($this->table->set_template('not an array')); - - $template = array( - 'a' => 'b' - ); - + + $template = array('a' => 'b'); + $this->table->set_template($template); $this->assertEquals($template, $this->table->template); } - + public function test_set_empty() { $this->table->set_empty('nada'); $this->assertEquals('nada', $this->table->empty_cells); } - + public function test_set_caption() { $this->table->set_caption('awesome cap'); $this->assertEquals('awesome cap', $this->table->caption); } - - + /* * @depends testPrepArgs */ @@ -49,9 +45,9 @@ class Table_test extends CI_TestCase { // uses _prep_args internally, so we'll just do a quick // check to verify that func_get_args and prep_args are // being called. - + $this->table->set_heading('name', 'color', 'size'); - + $this->assertEquals( array( array('data' => 'name'), @@ -61,8 +57,7 @@ class Table_test extends CI_TestCase { $this->table->heading ); } - - + /* * @depends testPrepArgs */ @@ -71,13 +66,13 @@ class Table_test extends CI_TestCase { // uses _prep_args internally, so we'll just do a quick // check to verify that func_get_args and prep_args are // being called. - + $this->table->add_row('my', 'pony', 'sings'); $this->table->add_row('your', 'pony', 'stinks'); $this->table->add_row('my pony', '>', 'your pony'); - + $this->assertEquals(count($this->table->rows), 3); - + $this->assertEquals( array( array('data' => 'your'), @@ -87,11 +82,10 @@ class Table_test extends CI_TestCase { $this->table->rows[1] ); } - - + // Uility Methods // -------------------------------------------------------------------- - + public function test_prep_args() { $expected = array( @@ -99,7 +93,7 @@ class Table_test extends CI_TestCase { array('data' => 'color'), array('data' => 'size') ); - + $this->assertEquals( $expected, $this->table->prep_args(array('name', 'color', 'size')) @@ -114,7 +108,7 @@ class Table_test extends CI_TestCase { $this->table->prep_args(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome'))) ); } - + public function test_default_template_keys() { $keys = array( @@ -126,132 +120,124 @@ class Table_test extends CI_TestCase { 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', 'table_close' ); - + foreach ($keys as $key) { $this->assertArrayHasKey($key, $this->table->default_template()); } } - + public function test_compile_template() { $this->assertFalse($this->table->set_template('invalid_junk')); - + // non default key $this->table->set_template(array('nonsense' => 'foo')); $this->table->compile_template(); - + $this->assertArrayHasKey('nonsense', $this->table->template); $this->assertEquals('foo', $this->table->template['nonsense']); - + // override default $this->table->set_template(array('table_close' => '')); $this->table->compile_template(); - + $this->assertArrayHasKey('table_close', $this->table->template); $this->assertEquals('', $this->table->template['table_close']); } - + public function test_make_columns() { // Test bogus parameters $this->assertFalse($this->table->make_columns('invalid_junk')); $this->assertFalse($this->table->make_columns(array())); $this->assertFalse($this->table->make_columns(array('one', 'two'), '2.5')); - - + // Now on to the actual column creation - + $five_values = array( 'Laura', 'Red', '15', 'Katie', 'Blue' ); - + // No column count - no changes to the array $this->assertEquals( $five_values, $this->table->make_columns($five_values) ); - + // Column count of 3 leaves us with one   $this->assertEquals( array( array('Laura', 'Red', '15'), - array('Katie', 'Blue', ' ') + array('Katie', 'Blue', ' ') ), $this->table->make_columns($five_values, 3) ); } - + public function test_clear() { $this->table->set_heading('Name', 'Color', 'Size'); - + // Make columns changes auto_heading $rows = $this->table->make_columns(array( 'Laura', 'Red', '15', 'Katie', 'Blue' ), 3); - + foreach ($rows as $row) { $this->table->add_row($row); } - + $this->assertFalse($this->table->auto_heading); $this->assertEquals(count($this->table->heading), 3); $this->assertEquals(count($this->table->rows), 2); - + $this->table->clear(); - + $this->assertTrue($this->table->auto_heading); $this->assertEmpty($this->table->heading); $this->assertEmpty($this->table->rows); } - - + public function test_set_from_array() { $this->assertFalse($this->table->set_from_array('bogus')); $this->assertFalse($this->table->set_from_array(NULL)); - + $data = array( array('name', 'color', 'number'), array('Laura', 'Red', '22'), - array('Katie', 'Blue') + array('Katie', 'Blue') ); - + $this->table->set_from_array($data, FALSE); $this->assertEmpty($this->table->heading); - + $this->table->clear(); - - $expected_heading = array( + + $this->table->set_from_array($data); + $this->assertEquals(count($this->table->rows), 2); + + $expected = array( array('data' => 'name'), array('data' => 'color'), array('data' => 'number') ); - - $expected_second = array( + + $this->assertEquals($expected, $this->table->heading); + + $expected = array( array('data' => 'Katie'), array('data' => 'Blue'), ); - - $this->table->set_from_array($data); - $this->assertEquals(count($this->table->rows), 2); - - $this->assertEquals( - $expected_heading, - $this->table->heading - ); - - $this->assertEquals( - $expected_second, - $this->table->rows[1] - ); + + $this->assertEquals($expected, $this->table->rows[1]); } - - function test_set_from_object() + + public function test_set_from_object() { // Make a stub of query instance $query = new CI_TestCase(); @@ -268,37 +254,31 @@ class Table_test extends CI_TestCase { return 2; }; - $expected_heading = array( + $this->table->set_from_object($query); + + $expected = array( array('data' => 'name'), array('data' => 'email') ); - $expected_second = array( + $this->assertEquals($expected, $this->table->heading); + + $expected = array( 'name' => array('data' => 'Foo Bar'), 'email' => array('data' => 'foo@bar.com'), ); - $this->table->set_from_object($query); - - $this->assertEquals( - $expected_heading, - $this->table->heading - ); - - $this->assertEquals( - $expected_second, - $this->table->rows[1] - ); + $this->assertEquals($expected, $this->table->rows[1]); } - - function test_generate() + + public function test_generate() { // Prepare the data $data = array( array('Name', 'Color', 'Size'), array('Fred', 'Blue', 'Small'), array('Mary', 'Red', 'Large'), - array('John', 'Green', 'Medium') + array('John', 'Green', 'Medium') ); $table = $this->table->generate($data); @@ -313,4 +293,5 @@ class Table_test extends CI_TestCase { $this->assertTrue(strpos($table, 'Blue') !== FALSE); $this->assertTrue(strpos($table, 'Small') !== FALSE); } + } \ No newline at end of file diff --git a/tests/codeigniter/libraries/Typography_test.php b/tests/codeigniter/libraries/Typography_test.php index 250aefb24..eb6dacb73 100644 --- a/tests/codeigniter/libraries/Typography_test.php +++ b/tests/codeigniter/libraries/Typography_test.php @@ -4,11 +4,11 @@ class Typography_test extends CI_TestCase { public function set_up() { - $obj = new StdClass; + $obj = new stdClass; $obj->type = new Mock_Libraries_Typography(); - + $this->ci_instance($obj); - + $this->type = $obj->type; } @@ -33,18 +33,18 @@ class Typography_test extends CI_TestCase { 'foo..' => 'foo..', 'foo...bar.' => 'foo…bar.', 'test. new' => 'test.  new', - ); - + ); + foreach ($strs as $str => $expected) { - $this->assertEquals($expected, $this->type->format_characters($str)); + $this->assertEquals($expected, $this->type->format_characters($str)); } } // -------------------------------------------------------------------- public function test_nl2br_except_pre() - { + { $str = << The End. EOH; - $this->assertEquals($expected, - $this->type->nl2br_except_pre($str)); + $this->assertEquals($expected, $this->type->nl2br_except_pre($str)); } // -------------------------------------------------------------------- - + public function test_auto_typography() { $this->_blank_string(); @@ -103,7 +102,7 @@ EOH; } // -------------------------------------------------------------------- - + private function _blank_string() { // Test blank string @@ -131,7 +130,7 @@ EOH; { $str = "This has way too many linebreaks.\n\n\n\nSee?"; $expect = "

    This has way too many linebreaks.

    \n\n

    See?

    "; - + $this->assertEquals($expect, $this->type->auto_typography($str, TRUE)); } @@ -141,7 +140,7 @@ EOH; { $str = ' But no!'; $expect = '

      But no!

    '; - + $this->assertEquals($expect, $this->type->auto_typography($str)); } @@ -151,7 +150,7 @@ EOH; { $str = '

    My Sentence

    var_dump($this);
    '; $expect = '

    My Sentence

    var_dump($this);
    '; - + $this->assertEquals($expect, $this->type->auto_typography($str)); } @@ -161,7 +160,7 @@ EOH; { $str = 'My Sentence
    var_dump($this);
    '; $expect = '

    My Sentence

    var_dump($this);
    '; - + $this->assertEquals($expect, $this->type->auto_typography($str)); } @@ -170,19 +169,18 @@ EOH; public function _protect_braced_quotes() { $this->type->protect_braced_quotes = TRUE; - + $str = 'Test {parse="foobar"}'; $expect = '

    Test {parse="foobar"}

    '; - + $this->assertEquals($expect, $this->type->auto_typography($str)); $this->type->protect_braced_quotes = FALSE; - + $str = 'Test {parse="foobar"}'; $expect = '

    Test {parse=“foobar”}

    '; - - $this->assertEquals($expect, $this->type->auto_typography($str)); - + $this->assertEquals($expect, $this->type->auto_typography($str)); } + } \ No newline at end of file diff --git a/tests/codeigniter/libraries/Useragent_test.php b/tests/codeigniter/libraries/Useragent_test.php index 7dad7ac54..89383f807 100644 --- a/tests/codeigniter/libraries/Useragent_test.php +++ b/tests/codeigniter/libraries/Useragent_test.php @@ -1,7 +1,7 @@ _user_agent; - $obj = new StdClass; + $obj = new stdClass; $obj->agent = new Mock_Libraries_UserAgent(); $this->ci_instance($obj); @@ -82,6 +82,4 @@ class UserAgent_test extends CI_TestCase { $this->assertFalse($this->agent->accept_charset()); } - // -------------------------------------------------------------------- - } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 43cfd0c37ca241618f33eae87fec720a5bcf13d6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 11:18:26 +0300 Subject: Comment out _set_uri_string() test as it is no longer callable from outside the class --- tests/codeigniter/core/URI_test.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php index 0ba694b46..60ed1a4e9 100644 --- a/tests/codeigniter/core/URI_test.php +++ b/tests/codeigniter/core/URI_test.php @@ -9,6 +9,10 @@ class URI_test extends CI_TestCase { // -------------------------------------------------------------------- + /* As of the following commit, _set_uri_string() is a protected method: + + https://github.com/EllisLab/CodeIgniter/commit/d461934184d95b0cfb2feec93f27b621ef72a5c2 + public function test_set_uri_string() { // Slashes get killed @@ -18,6 +22,7 @@ class URI_test extends CI_TestCase { $this->uri->_set_uri_string('nice/uri'); $this->assertEquals('nice/uri', $this->uri->uri_string); } + */ // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e1c8ee76f4756442094106320d9577c2c7595959 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 11:35:11 +0300 Subject: Alter now() tests --- tests/codeigniter/helpers/date_helper_test.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 4b747b864..bcb1477bc 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -13,6 +13,8 @@ class Date_helper_test extends CI_TestCase { public function test_now_local() { + /* + // This stub job, is simply to cater $config['time_reference'] $config = $this->getMock('CI_Config'); $config->expects($this->any()) @@ -22,6 +24,10 @@ class Date_helper_test extends CI_TestCase { // Add the stub to our test instance $this->ci_instance_var('config', $config); + */ + + $this->ci_set_config('time_reference', 'local'); + $this->assertEquals(time(), now()); } @@ -29,6 +35,8 @@ class Date_helper_test extends CI_TestCase { public function test_now_gmt() { + /* + // This stub job, is simply to cater $config['time_reference'] $config = $this->getMock('CI_Config'); $config->expects($this->any()) @@ -38,6 +46,10 @@ class Date_helper_test extends CI_TestCase { // Add the stub to our stdClass $this->ci_instance_var('config', $config); + */ + + $this->ci_set_config('time_reference', 'gmt'); + $t = time(); $this->assertEquals( mktime(gmdate('H', $t), gmdate('i', $t), gmdate('s', $t), gmdate('m', $t), gmdate('d', $t), gmdate('Y', $t)), -- cgit v1.2.3-24-g4f1b From 0ddff314d619e5d24bdf07f3da33c779f5b6e2c0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 13:18:07 +0300 Subject: test_now_gmt() -> test_now_utc() --- tests/codeigniter/helpers/date_helper_test.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index bcb1477bc..242935116 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -33,7 +33,7 @@ class Date_helper_test extends CI_TestCase { // ------------------------------------------------------------------------ - public function test_now_gmt() + public function test_now_utc() { /* @@ -41,18 +41,17 @@ class Date_helper_test extends CI_TestCase { $config = $this->getMock('CI_Config'); $config->expects($this->any()) ->method('item') - ->will($this->returnValue('gmt')); + ->will($this->returnValue('UTC')); // Add the stub to our stdClass $this->ci_instance_var('config', $config); */ - $this->ci_set_config('time_reference', 'gmt'); + $this->ci_set_config('time_reference', 'UTC'); - $t = time(); $this->assertEquals( - mktime(gmdate('H', $t), gmdate('i', $t), gmdate('s', $t), gmdate('m', $t), gmdate('d', $t), gmdate('Y', $t)), + gmmktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y')), now() ); } -- cgit v1.2.3-24-g4f1b From 3ed533109309326a858c778dfea5cb9186f965b4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 13:21:07 +0300 Subject: Some optimizations to the date helper tests --- tests/codeigniter/helpers/date_helper_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 242935116..1d397ac81 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -51,7 +51,7 @@ class Date_helper_test extends CI_TestCase { $this->ci_set_config('time_reference', 'UTC'); $this->assertEquals( - gmmktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y')), + gmmktime(date('G'), date('i'), date('s'), date('n'), date('j'), date('Y')), now() ); } @@ -196,9 +196,9 @@ class Date_helper_test extends CI_TestCase { public function test_local_to_gmt() { $this->assertEquals( - mktime( - gmdate('H', $this->time), gmdate('i', $this->time), gmdate('s', $this->time), - gmdate('m', $this->time), gmdate('d', $this->time), gmdate('Y', $this->time) + gmmktime( + date('G', $this->time), date('i', $this->time), date('s', $this->time), + date('n', $this->time), date('j', $this->time), date('Y', $this->time) ), local_to_gmt($this->time) ); -- cgit v1.2.3-24-g4f1b From b089e15b1510de6b6a034631c80d3d5e830ff9f3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 16 Jun 2012 19:11:40 +0300 Subject: Fix local_to_gmt() --- tests/codeigniter/helpers/date_helper_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 1d397ac81..8258c9248 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -196,9 +196,9 @@ class Date_helper_test extends CI_TestCase { public function test_local_to_gmt() { $this->assertEquals( - gmmktime( - date('G', $this->time), date('i', $this->time), date('s', $this->time), - date('n', $this->time), date('j', $this->time), date('Y', $this->time) + mktime( + gmdate('G', $this->time), gmdate('i', $this->time), gmdate('s', $this->time), + gmdate('n', $this->time), gmdate('j', $this->time), gmdate('Y', $this->time) ), local_to_gmt($this->time) ); -- cgit v1.2.3-24-g4f1b From a84055b49539da1faa2893618b2475d1888a9fea Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 20 Jun 2012 14:37:59 +0300 Subject: Fix issue #1510 --- tests/codeigniter/helpers/date_helper_test.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 8258c9248..4e01b1aa3 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -48,11 +48,9 @@ class Date_helper_test extends CI_TestCase { */ - $this->ci_set_config('time_reference', 'UTC'); - $this->assertEquals( - gmmktime(date('G'), date('i'), date('s'), date('n'), date('j'), date('Y')), - now() + mktime(gmdate('G'), gmdate('i'), gmdate('s'), gmdate('n'), gmdate('j'), gmdate('Y')), + now('UTC') ); } -- cgit v1.2.3-24-g4f1b From eb22d544c4ea1993fcbdad0404ce9ec65d0410be Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 26 Jun 2012 23:16:35 +0300 Subject: Fix get_where() test --- tests/codeigniter/database/query_builder/get_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php index 699d2906a..156027537 100644 --- a/tests/codeigniter/database/query_builder/get_test.php +++ b/tests/codeigniter/database/query_builder/get_test.php @@ -41,7 +41,7 @@ class Get_test extends CI_TestCase { */ public function test_get_where() { - $job1 = $this->db->get('job', array('id' => 1))->result_array(); + $job1 = $this->db->get_where('job', array('id' => 1))->result_array(); // Dummy jobs contain 1 rows $this->assertCount(1, $job1); -- cgit v1.2.3-24-g4f1b From 5211c094c930d69d52539591b306c293c99689ad Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 2 Jul 2012 16:47:12 +0300 Subject: Fix standard_date() tests --- tests/codeigniter/helpers/date_helper_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 4e01b1aa3..eaf4cf8a5 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -79,7 +79,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_atom() { $this->assertEquals( - date("Y-m-d\TH:i:sO", $this->time), + date('Y-m-d\TH:i:sP', $this->time), standard_date('DATE_ATOM', $this->time) ); } @@ -99,7 +99,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_iso8601() { $this->assertEquals( - date("Y-m-d\TH:i:sO", $this->time), + date('Y-m-d\TH:i:sP', $this->time), standard_date('DATE_ISO8601', $this->time) ); } @@ -139,7 +139,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc2822() { $this->assertEquals( - date('D, d M Y H:i:s O', $this->time), + date('r', $this->time), standard_date('DATE_RFC2822', $this->time) ); } @@ -159,7 +159,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_w3c() { $this->assertEquals( - date("Y-m-d\TH:i:sO", $this->time), + date('Y-m-d\TH:i:sP', $this->time), standard_date('DATE_W3C', $this->time) ); } -- cgit v1.2.3-24-g4f1b From dd6f32b3b506d29da38f41d307e5ea217c21cb51 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 4 Jul 2012 10:08:54 +0300 Subject: Optimize standard_date() --- tests/codeigniter/helpers/date_helper_test.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index eaf4cf8a5..1b79b9480 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -69,7 +69,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc822() { $this->assertEquals( - date('D, d M y H:i:s O', $this->time), + date(DATE_RFC822, $this->time), standard_date('DATE_RFC822', $this->time) ); } @@ -79,7 +79,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_atom() { $this->assertEquals( - date('Y-m-d\TH:i:sP', $this->time), + date(DATE_ATOM, $this->time), standard_date('DATE_ATOM', $this->time) ); } @@ -89,7 +89,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_cookie() { $this->assertEquals( - date("l, d-M-y H:i:s \U\T\C", $this->time), + date(DATE_COOKIE, $this->time), standard_date('DATE_COOKIE', $this->time) ); } @@ -99,7 +99,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_iso8601() { $this->assertEquals( - date('Y-m-d\TH:i:sP', $this->time), + date(DATE_ISO8601, $this->time), standard_date('DATE_ISO8601', $this->time) ); } @@ -109,7 +109,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc850() { $this->assertEquals( - date("l, d-M-y H:i:s \U\T\C", $this->time), + date(DATE_RFC850, $this->time), standard_date('DATE_RFC850', $this->time) ); } @@ -119,7 +119,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc1036() { $this->assertEquals( - date('D, d M y H:i:s O', $this->time), + date(DATE_RFC1036, $this->time), standard_date('DATE_RFC1036', $this->time) ); } @@ -129,7 +129,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc1123() { $this->assertEquals( - date('D, d M Y H:i:s O', $this->time), + date(DATE_RFC1123, $this->time), standard_date('DATE_RFC1123', $this->time) ); } @@ -139,7 +139,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc2822() { $this->assertEquals( - date('r', $this->time), + date(DATE_RFC2822, $this->time), standard_date('DATE_RFC2822', $this->time) ); } @@ -149,7 +149,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rss() { $this->assertEquals( - date('D, d M Y H:i:s O', $this->time), + date(DATE_RSS, $this->time), standard_date('DATE_RSS', $this->time) ); } @@ -159,7 +159,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_w3c() { $this->assertEquals( - date('Y-m-d\TH:i:sP', $this->time), + date(DATE_W3C, $this->time), standard_date('DATE_W3C', $this->time) ); } -- cgit v1.2.3-24-g4f1b From 49aa45b45e1cc83cb61d1524ba32d6c188dac2e1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 6 Jul 2012 16:22:21 +0300 Subject: Fix a few join() bugs --- .../codeigniter/database/query_builder/join_test.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php index b8cf2a822..6d5fc64af 100644 --- a/tests/codeigniter/database/query_builder/join_test.php +++ b/tests/codeigniter/database/query_builder/join_test.php @@ -35,4 +35,24 @@ class Join_test extends CI_TestCase { $this->assertEquals('Developer', $job_user[0]['job_name']); } + // ------------------------------------------------------------------------ + + public function test_join_escape_multiple_conditions() + { + // We just need a valid query produced, not one that makes sense + $fields = array($this->db->protect_identifiers('table1.field1'), $this->db->protect_identifiers('table2.field2')); + + $expected = 'SELECT '.implode(', ', $fields) + ."\nFROM ".$this->db->escape_identifiers('table1') + ."\nLEFT JOIN ".$this->db->escape_identifiers('table2').' ON '.implode(' = ', $fields) + .' AND '.$fields[0]." = 'foo' AND ".$fields[1].' = 0'; + + $result = $this->db->select('table1.field1, table2.field2') + ->from('table1') + ->join('table2', "table1.field1 = table2.field2 AND table1.field1 = 'foo' AND table2.field2 = 0", 'LEFT') + ->get_compiled_select(); + + $this->assertEquals($sql, $result); + } + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b6490f507e6c0c470b91d50eb550cda96199d591 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 6 Jul 2012 16:32:16 +0300 Subject: Fix a join() test ... doh --- tests/codeigniter/database/query_builder/join_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php index 6d5fc64af..25bd4accb 100644 --- a/tests/codeigniter/database/query_builder/join_test.php +++ b/tests/codeigniter/database/query_builder/join_test.php @@ -52,7 +52,7 @@ class Join_test extends CI_TestCase { ->join('table2', "table1.field1 = table2.field2 AND table1.field1 = 'foo' AND table2.field2 = 0", 'LEFT') ->get_compiled_select(); - $this->assertEquals($sql, $result); + $this->assertEquals($expected, $result); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b