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