summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authordchill42 <dchill42@gmail.com>2012-07-23 16:53:47 +0200
committerdchill42 <dchill42@gmail.com>2012-07-23 16:53:47 +0200
commitc5079de78e5141330c07e990811ef15e998e95aa (patch)
tree0f39d8c4fc7614246fc185810bfeaa7fad88a33a /tests
parent00fcb545109d4e61bc14e403ec828749c34a54b3 (diff)
parentede49ba66b127535f3430e20aac72ceed2c4611a (diff)
Merge branch develop of github.com:/EllisLab/CodeIgniter into session
Diffstat (limited to 'tests')
-rw-r--r--tests/Bootstrap.php38
-rw-r--r--tests/README.md158
-rw-r--r--tests/codeigniter/Setup_test.php13
-rw-r--r--tests/codeigniter/core/Benchmark_test.php43
-rw-r--r--tests/codeigniter/core/Common_test.php13
-rw-r--r--tests/codeigniter/core/Config_test.php93
-rw-r--r--tests/codeigniter/core/Input_test.php161
-rw-r--r--tests/codeigniter/core/Lang_test.php32
-rw-r--r--tests/codeigniter/core/Loader_test.php221
-rw-r--r--tests/codeigniter/core/Security_test.php106
-rw-r--r--tests/codeigniter/core/URI_test.php281
-rw-r--r--tests/codeigniter/database/DB_driver_test.php34
-rw-r--r--tests/codeigniter/database/DB_test.php47
-rw-r--r--tests/codeigniter/database/query_builder/count_test.php38
-rw-r--r--tests/codeigniter/database/query_builder/delete_test.php64
-rw-r--r--tests/codeigniter/database/query_builder/distinct_test.php33
-rw-r--r--tests/codeigniter/database/query_builder/empty_test.php39
-rw-r--r--tests/codeigniter/database/query_builder/escape_test.php68
-rw-r--r--tests/codeigniter/database/query_builder/from_test.php49
-rw-r--r--tests/codeigniter/database/query_builder/get_test.php53
-rw-r--r--tests/codeigniter/database/query_builder/group_test.php51
-rw-r--r--tests/codeigniter/database/query_builder/insert_test.php66
-rw-r--r--tests/codeigniter/database/query_builder/join_test.php58
-rw-r--r--tests/codeigniter/database/query_builder/like_test.php90
-rw-r--r--tests/codeigniter/database/query_builder/limit_test.php48
-rw-r--r--tests/codeigniter/database/query_builder/order_test.php55
-rw-r--r--tests/codeigniter/database/query_builder/select_test.php95
-rw-r--r--tests/codeigniter/database/query_builder/truncate_test.php56
-rw-r--r--tests/codeigniter/database/query_builder/update_test.php57
-rw-r--r--tests/codeigniter/database/query_builder/where_test.php126
-rw-r--r--tests/codeigniter/helpers/array_helper_test.php47
-rw-r--r--tests/codeigniter/helpers/date_helper_test.php295
-rw-r--r--tests/codeigniter/helpers/directory_helper_test.php50
-rw-r--r--tests/codeigniter/helpers/email_helper_test.php18
-rw-r--r--tests/codeigniter/helpers/file_helper_test.php153
-rw-r--r--tests/codeigniter/helpers/form_helper_test.php250
-rw-r--r--tests/codeigniter/helpers/html_helper_test.php76
-rw-r--r--tests/codeigniter/helpers/inflector_helper_test.php96
-rw-r--r--tests/codeigniter/helpers/number_helper_test.php76
-rw-r--r--tests/codeigniter/helpers/path_helper_test.php31
-rw-r--r--tests/codeigniter/helpers/string_helper_test.php148
-rw-r--r--tests/codeigniter/helpers/text_helper_test.php171
-rw-r--r--tests/codeigniter/helpers/url_helper_test.php76
-rw-r--r--tests/codeigniter/helpers/xml_helper_test.php15
-rw-r--r--tests/codeigniter/libraries/Encrypt_test.php72
-rw-r--r--tests/codeigniter/libraries/Parser_test.php107
-rw-r--r--tests/codeigniter/libraries/Table_test.php297
-rw-r--r--tests/codeigniter/libraries/Typography_test.php186
-rw-r--r--tests/codeigniter/libraries/Useragent_test.php85
-rw-r--r--tests/mocks/autoloader.php94
-rw-r--r--tests/mocks/ci_testcase.php194
-rw-r--r--tests/mocks/core/benchmark.php3
-rw-r--r--tests/mocks/core/common.php169
-rw-r--r--tests/mocks/core/input.php31
-rw-r--r--tests/mocks/core/loader.php31
-rw-r--r--tests/mocks/core/security.php30
-rw-r--r--tests/mocks/core/uri.php26
-rw-r--r--tests/mocks/core/utf8.php26
-rwxr-xr-xtests/mocks/database/ci_test.sqlitebin0 -> 19456 bytes
-rw-r--r--tests/mocks/database/config/mysql.php34
-rw-r--r--tests/mocks/database/config/pdo/mysql.php37
-rw-r--r--tests/mocks/database/config/pdo/pgsql.php37
-rw-r--r--tests/mocks/database/config/pdo/sqlite.php37
-rw-r--r--tests/mocks/database/config/pgsql.php34
-rw-r--r--tests/mocks/database/config/sqlite.php34
-rw-r--r--tests/mocks/database/db.php100
-rw-r--r--tests/mocks/database/db/driver.php39
-rw-r--r--tests/mocks/database/db/querybuilder.php3
-rw-r--r--tests/mocks/database/drivers/mysql.php17
-rw-r--r--tests/mocks/database/drivers/pdo.php16
-rw-r--r--tests/mocks/database/drivers/postgre.php17
-rw-r--r--tests/mocks/database/drivers/sqlite.php17
-rw-r--r--tests/mocks/database/schema/skeleton.php147
-rw-r--r--tests/mocks/libraries/encrypt.php16
-rw-r--r--tests/mocks/libraries/parser.php3
-rw-r--r--tests/mocks/libraries/table.php16
-rw-r--r--tests/mocks/libraries/typography.php3
-rw-r--r--tests/mocks/libraries/useragent.php3
-rw-r--r--tests/phpunit.xml25
-rw-r--r--tests/travis/mysql.phpunit.xml25
-rw-r--r--tests/travis/pdo/mysql.phpunit.xml25
-rw-r--r--tests/travis/pdo/pgsql.phpunit.xml25
-rw-r--r--tests/travis/pdo/sqlite.phpunit.xml25
-rw-r--r--tests/travis/pgsql.phpunit.xml25
-rw-r--r--tests/travis/sqlite.phpunit.xml25
85 files changed, 5924 insertions, 0 deletions
diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php
new file mode 100644
index 000000000..5216038c6
--- /dev/null
+++ b/tests/Bootstrap.php
@@ -0,0 +1,38 @@
+<?php
+
+// Errors on full!
+ini_set('display_errors', 1);
+error_reporting(E_ALL | E_STRICT);
+
+$dir = realpath(dirname(__FILE__));
+
+// Path constants
+defined('PROJECT_BASE') OR define('PROJECT_BASE', realpath($dir.'/../').'/');
+defined('BASEPATH') OR define('BASEPATH', PROJECT_BASE.'system/');
+defined('APPPATH') OR define('APPPATH', PROJECT_BASE.'application/');
+defined('VIEWPATH') OR define('VIEWPATH', PROJECT_BASE.'');
+
+// Get vfsStream either via PEAR or composer
+foreach (explode(PATH_SEPARATOR, get_include_path()) as $path)
+{
+ if (file_exists($path.DIRECTORY_SEPARATOR.'vfsStream/vfsStream.php'))
+ {
+ require_once 'vfsStream/vfsStream.php';
+ break;
+ }
+}
+
+if ( ! class_exists('vfsStream') && file_exists(PROJECT_BASE.'vendor/autoload.php'))
+{
+ include_once PROJECT_BASE.'vendor/autoload.php';
+ class_alias('org\bovigo\vfs\vfsStream', 'vfsStream');
+ class_alias('org\bovigo\vfs\vfsStreamDirectory', 'vfsStreamDirectory');
+ class_alias('org\bovigo\vfs\vfsStreamWrapper', 'vfsStreamWrapper');
+}
+
+// Prep our test environment
+include_once $dir.'/mocks/core/common.php';
+include_once $dir.'/mocks/autoloader.php';
+spl_autoload_register('autoload');
+
+unset($dir); \ No newline at end of file
diff --git a/tests/README.md b/tests/README.md
new file mode 100644
index 000000000..d600951ee
--- /dev/null
+++ b/tests/README.md
@@ -0,0 +1,158 @@
+# CodeIgniter Unit Tests #
+
+Status : [![Build Status](https://secure.travis-ci.org/EllisLab/CodeIgniter.png?branch=develop)](http://travis-ci.org/EllisLab/CodeIgniter)
+
+### Introduction:
+
+This is the preliminary CodeIgniter testing documentation. It
+will cover both internal as well as external APIs and the reasoning
+behind their implemenation, where appropriate. As with all CodeIgniter
+documentation, this file should maintain a mostly human readable
+format to facilitate clean api design. [see http://arrenbrecht.ch/testing/]
+
+*First public draft: everything is subject to change*
+
+### Requirements
+
+PHP Unit >= 3.5.6
+
+ pear channel-discover pear.phpunit.de
+ pear install phpunit/PHPUnit
+
+vfsStream
+
+ pear channel-discover pear.bovigo.org
+ pear install bovigo/vfsStream-beta
+
+#### Installation of PEAR and PHPUnit on Ubuntu
+
+ Installation on Ubuntu requires a few steps. Depending on your setup you may
+ need to use 'sudo' to install these. Mileage may vary but these steps are a
+ good start.
+
+ # Install the PEAR package
+ sudo apt-get install php-pear
+
+ # Add a few sources to PEAR
+ pear channel-discover pear.phpunit.de
+ pear channel-discover pear.symfony-project.com
+ pear channel-discover components.ez.no
+ pear channel-discover pear.bovigo.org
+
+ # Finally install PHPUnit and vfsStream (including dependencies)
+ pear install --alldeps phpunit/PHPUnit
+ pear install --alldeps bovigo/vfsStream-beta
+
+ # Finally, run 'phpunit' from within the ./tests directory
+ # and you should be on your way!
+
+## Test Suites:
+
+CodeIgniter bootstraps a request very directly, with very flat class
+hierarchy. As a result, there is no main CodeIgniter class until the
+controller is instantiated.
+
+This has forced the core classes to be relatively decoupled, which is
+a good thing. However, it makes that portion of code relatively hard
+to test.
+
+Right now that means we'll probably have two core test suites, along
+with a base for application and package tests. That gives us:
+
+1. Bootstrap Test - test common.php and sanity check codeigniter.php [in planning]
+2. System Test - test core components in relative isolation [in development]
+3. Application Test - bootstrapping for application/tests [not started]
+4. Package Test - bootstrapping for <package>/tests [not started]
+
+### CI_TestCase Documentation
+
+Test cases should extend CI_TestCase. This internally extends
+PHPUnit\_Framework\_TestCase, so you have access to all of your
+usual PHPUnit methods.
+
+We need to provide a simple way to modify the globals and the
+common function output. We also need to be able to mock up
+the super object as we please.
+
+Current API is *not stable*. Names and implementations will change.
+
+ $this->ci_set_config($key, $val)
+
+Set the global config variables. If key is an array, it will
+replace the entire config array. They are _not_ merged.
+
+ $this->ci_instance($obj)
+
+Set the object to use as the "super object", in a lot
+of cases this will be a simple stdClass with the attributes
+you need it to have. If no parameter, will return the instance.
+
+ $this->ci_instance_var($name, $val)
+
+Add an attribute to the super object. This is useful if you
+set up a simple instance in setUp and then need to add different
+class mockups to your super object.
+
+ $this->ci_core_class($name)
+
+Get the _class name_ of a core class, so that you can instantiate
+it. The variable is returned by reference and is tied to the correct
+$GLOBALS key. For example:
+
+ $cfg =& $this->ci_core_class('cfg'); // returns 'CI_Config'
+ $cfg = new $cfg; // instantiates config and overwrites the CFG global
+
+ $this->ci_set_core_class($name, $obj)
+
+An alternative way to set one of the core globals.
+
+ $this->ci_get_config() __internal__
+
+Returns the global config array. Internal as you shouldn't need to
+call this (you're setting it, after all). Used internally to make
+CI's get_config() work.
+
+ CI_TestCase::instance() __internal__
+
+Returns an instance of the current test case. We force phpunit to
+run with backup-globals enabled, so this will always be the instance
+of the currently running test class.
+
+### Going forward
+
+#### 1. Bootstrap Test
+
+Testing common.php should be pretty simple. Include the file, and test the
+functions. May require some tweaking so that we can grab the statics from all
+methods (see is_loaded()). Testing the actual CodeIgniter.php file will most
+likely be an output test for the default view, with some object checking after
+the file runs. Needs consideration.
+
+#### 2. System Test
+
+Testing the core system relies on being able to isolate the core components
+as much as possible. A few of them access other core classes as globals. These
+should be mocked up and easy to manipulate.
+
+All functions in common.php should be a minimal implementation, or and mapped
+to a method in the test's parent class to gives us full control of their output.
+
+#### 3. Application Test:
+
+Not sure yet, needs to handle:
+
+- Libraries
+- Helpers
+- Models
+- MY_* files
+- Controllers (uh...?)
+- Views? (watir, selenium, cucumber?)
+- Database Testing
+
+#### 4. Package Test:
+
+I don't have a clue how this will work.
+
+Needs to be able to handle packages
+that are used multiple times within the application (i.e. EE/Pyro modules)
+as well as packages that are used by multiple applications (library distributions)
diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php
new file mode 100644
index 000000000..5317c56c7
--- /dev/null
+++ b/tests/codeigniter/Setup_test.php
@@ -0,0 +1,13 @@
+<?php
+
+class Setup_test extends PHPUnit_Framework_TestCase {
+
+ public function test_bootstrap_constants()
+ {
+ $this->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
new file mode 100644
index 000000000..a239ba51d
--- /dev/null
+++ b/tests/codeigniter/core/Benchmark_test.php
@@ -0,0 +1,43 @@
+<?php
+
+class Benchmark_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->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.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_memory_usage()
+ {
+ $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
new file mode 100644
index 000000000..f9bf6c27f
--- /dev/null
+++ b/tests/codeigniter/core/Common_test.php
@@ -0,0 +1,13 @@
+<?php
+
+class Common_test extends CI_TestCase {
+
+ // ------------------------------------------------------------------------
+
+ public function test_is_php()
+ {
+ $this->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
new file mode 100644
index 000000000..30cb90a28
--- /dev/null
+++ b/tests/codeigniter/core/Config_test.php
@@ -0,0 +1,93 @@
+<?php
+
+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',
+ 'base_url' => 'http://example.com/',
+ 'subclass_prefix' => 'MY_'
+ ));
+
+ $this->config = new $cls;
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_item()
+ {
+ $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 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'));
+ }
+
+ // --------------------------------------------------------------------
+
+ 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);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_system_url()
+ {
+ $this->assertEquals('http://example.com/system/', $this->config->system_url());
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php
new file mode 100644
index 000000000..fe8738832
--- /dev/null
+++ b/tests/codeigniter/core/Input_test.php
@@ -0,0 +1,161 @@
+<?php
+
+class Input_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ // Set server variable to GET as default, since this will leave unset in STDIN env
+ $_SERVER['REQUEST_METHOD'] = 'GET';
+
+ // Set config for Input class
+ $this->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'));
+
+ // Test we're getting empty results
+ $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);
+ $this->assertTrue($this->input->get('foo') === NULL);
+ }
+
+ // --------------------------------------------------------------------
+
+ 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 <script>alert('Hack');</script> your site";
+
+ $this->assertArrayHasKey('harm', $this->input->get());
+ $this->assertEquals("Hello, i try to <script>alert('Hack');</script> your site", $this->input->get('harm'));
+ $this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[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() === NULL);
+ $this->assertTrue($this->input->post('foo') === NULL);
+
+ $this->assertTrue($this->input->post() === NULL);
+ $this->assertTrue($this->input->post('foo') === NULL);
+ }
+
+ // --------------------------------------------------------------------
+
+ 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 <script>alert('Hack');</script> your site";
+
+ $this->assertArrayHasKey('harm', $this->input->post());
+ $this->assertEquals("Hello, i try to <script>alert('Hack');</script> your site", $this->input->post('harm'));
+ $this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[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 <script>alert(\'Hack\');</script> 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 <script>alert('Hack');</script> your site", $harm);
+ $this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", $harmless);
+ }
+
+ // --------------------------------------------------------------------
+
+ 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)
+ {
+ $this->assertTrue($this->input->valid_ip($ip));
+ }
+ }
+
+} \ 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..a410dabfa
--- /dev/null
+++ b/tests/codeigniter/core/Lang_test.php
@@ -0,0 +1,32 @@
+<?php
+
+class Lang_test extends CI_TestCase {
+
+ protected $lang;
+
+ 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;
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_load()
+ {
+ $this->assertTrue($this->lang->load('profiler', 'english'));
+ $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string'));
+ }
+
+ // --------------------------------------------------------------------
+
+ 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
new file mode 100644
index 000000000..fdea962b7
--- /dev/null
+++ b/tests/codeigniter/core/Loader_test.php
@@ -0,0 +1,221 @@
+<?php
+
+class Loader_test extends CI_TestCase {
+
+ private $ci_obj;
+
+ public function set_up()
+ {
+ // Instantiate a new loader
+ $this->load = new Mock_Core_Loader();
+
+ // mock up a ci instance
+ $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', ' '));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_load_library_in_application_dir()
+ {
+ $this->_setup_config_mock();
+
+ $content = '<?php class Super_test_library {} ';
+
+ $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'));
+ }
+
+ // --------------------------------------------------------------------
+
+ 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 test_non_existent_model()
+ {
+ $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 = '<?php class Unit_test_model extends CI_Model {} ';
+
+ $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(''));
+ }
+
+ // --------------------------------------------------------------------
+
+ // public function testDatabase()
+ // {
+ // $this->assertEquals(NULL, $this->load->database());
+ // $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. <?php echo $hello; ?>';
+ $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
+ */
+ public function test_non_existent_view()
+ {
+ $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'));
+ }
+
+ // --------------------------------------------------------------------
+
+ 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);
+
+ // 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(
+ '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()
+ {
+ $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
new file mode 100644
index 000000000..3f6e3b07a
--- /dev/null
+++ b/tests/codeigniter/core/Security_test.php
@@ -0,0 +1,106 @@
+<?php
+
+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');
+ $this->ci_set_config('csrf_cookie_name', 'ci_csrf_cookie');
+
+ $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 <script>alert('Hack');</script> your site";
+
+ $harmless_string = $this->security->xss_clean($harm_string);
+
+ $this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[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 = '&lt;div&gt;Hello &lt;b&gt;Booya&lt;/b&gt;&lt;/div&gt;';
+ $decoded = $this->security->entity_decode($encoded);
+
+ $this->assertEquals('<div>Hello <b>Booya</b></div>', $decoded);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_sanitize_filename()
+ {
+ $filename = './<!--foo-->';
+ $safe_filename = $this->security->sanitize_filename($filename);
+
+ $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
new file mode 100644
index 000000000..60ed1a4e9
--- /dev/null
+++ b/tests/codeigniter/core/URI_test.php
@@ -0,0 +1,281 @@
+<?php
+
+class URI_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->uri = new Mock_Core_URI();
+ }
+
+ // --------------------------------------------------------------------
+
+ /* 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
+ $this->uri->_set_uri_string('/');
+ $this->assertEquals('', $this->uri->uri_string);
+
+ $this->uri->_set_uri_string('nice/uri');
+ $this->assertEquals('nice/uri', $this->uri->uri_string);
+ }
+ */
+
+ // --------------------------------------------------------------------
+
+ 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();
+ $this->assertEquals('controller/method', $this->uri->uri_string);
+
+ // death to request uri
+ unset($_SERVER['REQUEST_URI']);
+
+ // life to path info
+ $_SERVER['PATH_INFO'] = $a = '/controller/method/';
+
+ $this->uri->_fetch_uri_string();
+ $this->assertEquals($a, $this->uri->uri_string);
+
+ // 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);
+
+ // At this point your server is a labotomy victim
+ unset($_SERVER['QUERY_STRING']);
+
+ $_GET['/controller/method/'] = '';
+
+ $this->uri->_fetch_uri_string();
+ $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()
+ {
+ // 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();
+
+ $this->assertEquals($a, $this->uri->segments);
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ 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, '&#36;destroy_app&#40;foo&#41;');
+ }
+
+ // --------------------------------------------------------------------
+
+ 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()
+ {
+ $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');
+
+ $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');
+
+ $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
+ $this->assertEquals(
+ array('a' => '1', 'b' => FALSE),
+ $this->uri->uri_to_assoc(1, array('a', 'b'))
+ );
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_ruri_to_assoc()
+ {
+ $this->uri->rsegments = array('x', '1', 'y', '2', 'z', '3');
+
+ $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');
+
+ $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
+ $this->assertEquals(
+ array('x' => '1', 'y' => FALSE),
+ $this->uri->ruri_to_assoc(1, array('x', 'y'))
+ );
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_assoc_to_uri()
+ {
+ $this->uri->config->set_item('uri_string_slashes', 'none');
+ $this->assertEquals('a/1/b/2', $this->uri->assoc_to_uri(array('a' => '1', 'b' => '2')));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_slash_segment()
+ {
+ $this->uri->segments[1] = 'segment';
+ $this->uri->rsegments[1] = 'segment';
+
+ $this->assertEquals('/segment/', $this->uri->slash_segment(1, 'both'));
+ $this->assertEquals('/segment/', $this->uri->slash_rsegment(1, 'both'));
+
+ $a = '/segment';
+ $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 of file URI_test.php */
+/* Location: ./tests/core/URI_test.php */ \ No newline at end of file
diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php
new file mode 100644
index 000000000..9e16e29b4
--- /dev/null
+++ b/tests/codeigniter/database/DB_driver_test.php
@@ -0,0 +1,34 @@
+<?php
+
+class DB_driver_test extends CI_TestCase {
+
+ public function test_initialize()
+ {
+ $config = Mock_Database_DB::config(DB_DRIVER);
+ $driver_name = current(explode('/', DB_DRIVER));
+ $driver = $this->$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
diff --git a/tests/codeigniter/database/DB_test.php b/tests/codeigniter/database/DB_test.php
new file mode 100644
index 000000000..d5c0dea08
--- /dev/null
+++ b/tests/codeigniter/database/DB_test.php
@@ -0,0 +1,47 @@
+<?php
+
+class DB_test extends CI_TestCase {
+
+ public function test_db_invalid()
+ {
+ $connection = 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($connection->set_dsn('undefined'), TRUE);
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_db_valid()
+ {
+ $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);
+ }
+
+ // ------------------------------------------------------------------------
+
+ 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);
+ }
+
+} \ 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
new file mode 100644
index 000000000..90ac5283e
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/count_test.php
@@ -0,0 +1,38 @@
+<?php
+
+class Count_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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()
+ {
+ $this->assertEquals(4, $this->db->count_all('job'));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_count_all_results()
+ {
+ $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
new file mode 100644
index 000000000..ab9d97f56
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/delete_test.php
@@ -0,0 +1,64 @@
+<?php
+
+class Delete_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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
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..cc98009ce
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/distinct_test.php
@@ -0,0 +1,33 @@
+<?php
+
+class Distinct_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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();
+
+ $this->assertEquals(3, count($users));
+ }
+
+} \ No newline at end of file
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 @@
+<?php
+
+class Empty_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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
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..c6380ddf1
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/escape_test.php
@@ -0,0 +1,68 @@
+<?php
+
+class Escape_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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()
+ {
+ // Escape the like string
+ $string = $this->db->escape_like_str('\%foo');
+
+ 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(1, count($res));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_escape_like_backslash_sign()
+ {
+ // Escape the like string
+ $string = $this->db->escape_like_str('\\');
+
+ 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
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..7aaae348d
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/from_test.php
@@ -0,0 +1,49 @@
+<?php
+
+class From_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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();
+
+ $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();
+
+ $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
new file mode 100644
index 000000000..156027537
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/get_test.php
@@ -0,0 +1,53 @@
+<?php
+
+class Get_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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_get_simple()
+ {
+ $jobs = $this->db->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']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_get_where()
+ {
+ $job1 = $this->db->get_where('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
new file mode 100644
index 000000000..5249f7c87
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/group_test.php
@@ -0,0 +1,51 @@
+<?php
+
+class Group_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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')
+ ->get()
+ ->result_array();
+
+ $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();
+
+ $this->assertEquals(2, count($jobs));
+ }
+
+} \ No newline at end of file
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..a9aafb66e
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/insert_test.php
@@ -0,0 +1,66 @@
+<?php
+
+class Insert_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ * @see ./mocks/schema/skeleton.php
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+
+ // Truncate the current datas
+ $this->db->truncate('job');
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ 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));
+
+ $job1 = $this->db->get('job')->row();
+
+ // Check the result
+ $this->assertEquals('Grocery Sales', $job1->name);
+
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_insert_batch()
+ {
+ $job_datas = array(
+ 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)
+ {
+ $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();
+
+ // Check the result
+ $this->assertEquals('Commedian', $job_2->name);
+ $this->assertEquals('Cab Driver', $job_3->name);
+ }
+ }
+
+} \ 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
new file mode 100644
index 000000000..25bd4accb
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/join_test.php
@@ -0,0 +1,58 @@
+<?php
+
+class Join_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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']);
+ }
+
+ // ------------------------------------------------------------------------
+
+ 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($expected, $result);
+ }
+
+} \ 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
new file mode 100644
index 000000000..5f3e52228
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/like_test.php
@@ -0,0 +1,90 @@
+<?php
+
+class Like_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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
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..a0954c7ab
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/limit_test.php
@@ -0,0 +1,48 @@
+<?php
+
+class Limit_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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();
+
+ $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();
+
+ $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
new file mode 100644
index 000000000..46f452bae
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/order_test.php
@@ -0,0 +1,55 @@
+<?php
+
+class Order_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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();
+
+ $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
new file mode 100644
index 000000000..877b5d8c0
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/select_test.php
@@ -0,0 +1,95 @@
+<?php
+
+class Select_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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_select_only_one_collumn()
+ {
+ $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]));
+ $this->assertFalse(array_key_exists('description', $jobs_name[0]));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_select_min()
+ {
+ $job_min = $this->db->select_min('id')
+ ->get('job')
+ ->row();
+
+ // Minimum id was 1
+ $this->assertEquals('1', $job_min->id);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_select_max()
+ {
+ $job_max = $this->db->select_max('id')
+ ->get('job')
+ ->row();
+
+ // Maximum id was 4
+ $this->assertEquals('4', $job_max->id);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_select_avg()
+ {
+ $job_avg = $this->db->select_avg('id')
+ ->get('job')
+ ->row();
+
+ // Average should be 2.5
+ $this->assertEquals('2.5', $job_avg->id);
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_select_sum()
+ {
+ $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
new file mode 100644
index 000000000..09923c7f1
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/truncate_test.php
@@ -0,0 +1,56 @@
+<?php
+
+class Truncate_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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
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..27a647c45
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/update_test.php
@@ -0,0 +1,57 @@
+<?php
+
+class Update_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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
+ $this->db->where('id', 1)->update('job', array('name' => 'Programmer'));
+
+ // 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
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..20b7a567c
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/where_test.php
@@ -0,0 +1,126 @@
+<?php
+
+class Where_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->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();
+
+ $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();
+ $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();
+
+ $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();
+
+ $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();
+
+ $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();
+
+ $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();
+
+ $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/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php
new file mode 100644
index 000000000..ba46e86f9
--- /dev/null
+++ b/tests/codeigniter/helpers/array_helper_test.php
@@ -0,0 +1,47 @@
+<?php
+
+class Array_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->helper('array');
+
+ $this->my_array = array(
+ 'foo' => 'bar',
+ 'sally' => 'jim',
+ 'maggie' => 'bessie',
+ '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)));
+ $this->assertEquals(TRUE, is_array(elements('foo', $this->my_array)));
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php
new file mode 100644
index 000000000..1b79b9480
--- /dev/null
+++ b/tests/codeigniter/helpers/date_helper_test.php
@@ -0,0 +1,295 @@
+<?php
+
+class Date_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->helper('date');
+
+ $this->time = time();
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_now_local()
+ {
+ /*
+
+ // 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);
+
+ */
+
+ $this->ci_set_config('time_reference', 'local');
+
+ $this->assertEquals(time(), now());
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_now_utc()
+ {
+ /*
+
+ // This stub job, is simply to cater $config['time_reference']
+ $config = $this->getMock('CI_Config');
+ $config->expects($this->any())
+ ->method('item')
+ ->will($this->returnValue('UTC'));
+
+ // Add the stub to our stdClass
+ $this->ci_instance_var('config', $config);
+
+ */
+
+ $this->assertEquals(
+ mktime(gmdate('G'), gmdate('i'), gmdate('s'), gmdate('n'), gmdate('j'), gmdate('Y')),
+ now('UTC')
+ );
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_mdate()
+ {
+ $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()
+ {
+ $this->assertEquals(
+ date(DATE_RFC822, $this->time),
+ standard_date('DATE_RFC822', $this->time)
+ );
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_atom()
+ {
+ $this->assertEquals(
+ date(DATE_ATOM, $this->time),
+ standard_date('DATE_ATOM', $this->time)
+ );
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_cookie()
+ {
+ $this->assertEquals(
+ date(DATE_COOKIE, $this->time),
+ standard_date('DATE_COOKIE', $this->time)
+ );
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_iso8601()
+ {
+ $this->assertEquals(
+ date(DATE_ISO8601, $this->time),
+ standard_date('DATE_ISO8601', $this->time)
+ );
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rfc850()
+ {
+ $this->assertEquals(
+ date(DATE_RFC850, $this->time),
+ standard_date('DATE_RFC850', $this->time)
+ );
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rfc1036()
+ {
+ $this->assertEquals(
+ date(DATE_RFC1036, $this->time),
+ standard_date('DATE_RFC1036', $this->time)
+ );
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rfc1123()
+ {
+ $this->assertEquals(
+ date(DATE_RFC1123, $this->time),
+ standard_date('DATE_RFC1123', $this->time)
+ );
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rfc2822()
+ {
+ $this->assertEquals(
+ date(DATE_RFC2822, $this->time),
+ standard_date('DATE_RFC2822', $this->time)
+ );
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rss()
+ {
+ $this->assertEquals(
+ date(DATE_RSS, $this->time),
+ standard_date('DATE_RSS', $this->time)
+ );
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_w3c()
+ {
+ $this->assertEquals(
+ date(DATE_W3C, $this->time),
+ standard_date('DATE_W3C', $this->time)
+ );
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_timespan()
+ {
+ $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));
+ }
+
+ // ------------------------------------------------------------------------
+
+ 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->assertEquals(
+ 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)
+ );
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_gmt_to_local()
+ {
+ $this->assertEquals(1140128493, gmt_to_local('1140153693', 'UM8', TRUE));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_mysql_to_unix()
+ {
+ $this->assertEquals($this->time, mysql_to_unix(date('Y-m-d H:i:s', $this->time)));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_unix_to_human()
+ {
+ $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'));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_human_to_unix()
+ {
+ $date = '2000-12-31 10:00:00 PM';
+ $this->assertEquals(strtotime($date), human_to_unix($date));
+ $this->assertFalse(human_to_unix());
+ }
+
+ // ------------------------------------------------------------------------
+
+ 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
diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php
new file mode 100644
index 000000000..176ff1d78
--- /dev/null
+++ b/tests/codeigniter/helpers/directory_helper_test.php
@@ -0,0 +1,50 @@
+<?php
+
+class Directory_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->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' => ''
+ )
+ );
+
+ 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 detection of hidden files
+ $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
new file mode 100644
index 000000000..fea452f5f
--- /dev/null
+++ b/tests/codeigniter/helpers/email_helper_test.php
@@ -0,0 +1,18 @@
+<?php
+
+class Email_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->helper('email');
+ }
+
+ public function test_valid_email()
+ {
+ $this->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/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php
new file mode 100644
index 000000000..9b03da9d7
--- /dev/null
+++ b/tests/codeigniter/helpers/file_helper_test.php
@@ -0,0 +1,153 @@
+<?php
+
+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);
+
+ $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.
+ $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);
+
+ $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
diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php
new file mode 100644
index 000000000..1a30ed993
--- /dev/null
+++ b/tests/codeigniter/helpers/form_helper_test.php
@@ -0,0 +1,250 @@
+<?php
+
+require BASEPATH . 'core/Common.php';
+require BASEPATH . 'helpers/form_helper.php';
+
+class Form_helper_test extends CI_TestCase
+{
+ public function test_form_hidden()
+ {
+ $expected = <<<EOH
+
+<input type="hidden" name="username" value="johndoe" />
+
+EOH;
+
+ $this->assertEquals($expected, form_hidden('username', 'johndoe'));
+ }
+
+ public function test_form_input()
+ {
+ $expected = <<<EOH
+<input type="text" name="username" value="johndoe" id="username" maxlength="100" size="50" style="width:50%" />
+
+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
+<input type="password" name="password" value="" />
+
+EOH;
+
+ $this->assertEquals($expected, form_password('password'));
+ }
+
+ public function test_form_upload()
+ {
+ $expected = <<<EOH
+<input type="file" name="attachment" value="" />
+
+EOH;
+
+ $this->assertEquals($expected, form_upload('attachment'));
+ }
+
+ public function test_form_textarea()
+ {
+ $expected = <<<EOH
+<textarea name="notes" cols="40" rows="10" >Notes</textarea>
+
+EOH;
+
+ $this->assertEquals($expected, form_textarea('notes', 'Notes'));
+ }
+
+ public function test_form_dropdown()
+ {
+ $expected = <<<EOH
+<select name="shirts">
+<option value="small">Small Shirt</option>
+<option value="med">Medium Shirt</option>
+<option value="large" selected="selected">Large Shirt</option>
+<option value="xlarge">Extra Large Shirt</option>
+</select>
+
+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
+<select name="shirts" multiple="multiple">
+<option value="small" selected="selected">Small Shirt</option>
+<option value="med">Medium Shirt</option>
+<option value="large" selected="selected">Large Shirt</option>
+<option value="xlarge">Extra Large Shirt</option>
+</select>
+
+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
+<select name="cars" multiple="multiple">
+<optgroup label="Swedish Cars">
+<option value="volvo" selected="selected">Volvo</option>
+<option value="saab">Saab</option>
+</optgroup>
+<optgroup label="German Cars">
+<option value="mercedes">Mercedes</option>
+<option value="audi" selected="selected">Audi</option>
+</optgroup>
+</select>
+
+EOH;
+
+ $this->assertEquals($expected, form_dropdown('cars', $options, array('volvo', 'audi')));
+ }
+
+ public function test_form_multiselect()
+ {
+ $expected = <<<EOH
+<select name="shirts[]" multiple="multiple">
+<option value="small">Small Shirt</option>
+<option value="med" selected="selected">Medium Shirt</option>
+<option value="large" selected="selected">Large Shirt</option>
+<option value="xlarge">Extra Large Shirt</option>
+</select>
+
+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 = <<<EOH
+<fieldset>
+<legend>Address Information</legend>
+
+EOH;
+
+ $this->assertEquals($expected, form_fieldset('Address Information'));
+ }
+
+ public function test_form_fieldset_close()
+ {
+ $expected = <<<EOH
+</fieldset></div></div>
+EOH;
+
+ $this->assertEquals($expected, form_fieldset_close('</div></div>'));
+ }
+
+ public function test_form_checkbox()
+ {
+ $expected = <<<EOH
+<input type="checkbox" name="newsletter" value="accept" checked="checked" />
+
+EOH;
+
+ $this->assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE));
+ }
+
+ public function test_form_radio()
+ {
+ $expected = <<<EOH
+<input type="radio" name="newsletter" value="accept" checked="checked" />
+
+EOH;
+
+ $this->assertEquals($expected, form_radio('newsletter', 'accept', TRUE));
+ }
+
+ public function test_form_submit()
+ {
+ $expected = <<<EOH
+<input type="submit" name="mysubmit" value="Submit Post!" />
+
+EOH;
+
+ $this->assertEquals($expected, form_submit('mysubmit', 'Submit Post!'));
+ }
+
+ public function test_form_label()
+ {
+ $expected = <<<EOH
+<label for="username">What is your Name</label>
+EOH;
+
+ $this->assertEquals($expected, form_label('What is your Name', 'username'));
+ }
+
+ public function test_form_reset()
+ {
+ $expected = <<<EOH
+<input type="reset" name="myreset" value="Reset" />
+
+EOH;
+
+ $this->assertEquals($expected, form_reset('myreset', 'Reset'));
+ }
+
+ public function test_form_button()
+ {
+ $expected = <<<EOH
+<button name="name" type="button" >content</button>
+
+EOH;
+
+ $this->assertEquals($expected, form_button('name', 'content'));
+ }
+
+ public function test_form_close()
+ {
+ $expected = <<<EOH
+</form></div></div>
+EOH;
+
+ $this->assertEquals($expected, form_close('</div></div>'));
+ }
+
+ public function test_form_prep()
+ {
+ $expected = 'Here is a string containing &quot;quoted&quot; 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
new file mode 100644
index 000000000..9a7bb48bf
--- /dev/null
+++ b/tests/codeigniter/helpers/html_helper_test.php
@@ -0,0 +1,76 @@
+<?php
+
+class Html_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->helper('html');
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_br()
+ {
+ $this->assertEquals('<br /><br />', br(2));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_heading()
+ {
+ $this->assertEquals('<h1>foobar</h1>', heading('foobar'));
+ $this->assertEquals('<h2 class="bar">foobar</h2>', heading('foobar', 2, 'class="bar"'));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_Ul()
+ {
+ $expect = <<<EOH
+<ul>
+ <li>foo</li>
+ <li>bar</li>
+</ul>
+
+EOH;
+
+ $expect = ltrim($expect);
+ $list = array('foo', 'bar');
+
+ $this->assertEquals(ltrim($expect), ul($list));
+
+ $expect = <<<EOH
+<ul class="test">
+ <li>foo</li>
+ <li>bar</li>
+</ul>
+
+EOH;
+
+ $expect = ltrim($expect);
+
+ $this->assertEquals($expect, ul($list, 'class="test"'));
+
+ $this->assertEquals($expect, ul($list, array('class' => 'test')));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_NBS()
+ {
+ $this->assertEquals('&nbsp;&nbsp;&nbsp;', nbs(3));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_meta()
+ {
+ $this->assertEquals("<meta name=\"test\" content=\"foo\" />\n", meta('test', 'foo'));
+
+ $expect = "<meta name=\"foo\" content=\"\" />\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
new file mode 100644
index 000000000..f3b0ebbe8
--- /dev/null
+++ b/tests/codeigniter/helpers/inflector_helper_test.php
@@ -0,0 +1,96 @@
+<?php
+
+class Inflector_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->helper('inflector');
+ }
+
+ public function test_singular()
+ {
+ $strs = array(
+ 'tellies' => 'telly',
+ 'smellies' => 'smelly',
+ 'abjectnesses' => 'abjectness',
+ 'smells' => 'smell',
+ 'equipment' => 'equipment'
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, singular($str));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_plural()
+ {
+ $strs = array(
+ 'telly' => 'tellies',
+ 'smelly' => 'smellies',
+ 'abjectness' => 'abjectnesses', // ref : http://en.wiktionary.org/wiki/abjectnesses
+ 'smell' => 'smells',
+ 'witch' => 'witches',
+ 'equipment' => 'equipment'
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, plural($str));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_camelize()
+ {
+ $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 test_underscore()
+ {
+ $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 test_humanize()
+ {
+ $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/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php
new file mode 100644
index 000000000..ef6aae138
--- /dev/null
+++ b/tests/codeigniter/helpers/number_helper_test.php
@@ -0,0 +1,76 @@
+<?php
+
+class Number_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->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)
+ {
+ 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));
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php
new file mode 100644
index 000000000..0faf6f383
--- /dev/null
+++ b/tests/codeigniter/helpers/path_helper_test.php
@@ -0,0 +1,31 @@
+<?php
+
+class Path_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->helper('path');
+ }
+
+ public function test_set_realpath()
+ {
+ $this->assertEquals(getcwd().DIRECTORY_SEPARATOR, 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
diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php
new file mode 100644
index 000000000..75701ec13
--- /dev/null
+++ b/tests/codeigniter/helpers/string_helper_test.php
@@ -0,0 +1,148 @@
+<?php
+
+class String_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->helper('string');
+ }
+
+ 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(
+ '//Slashes//\/' => 'Slashes//\\',
+ '/var/www/html/' => 'var/www/html'
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, trim_slashes($str));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_strip_quotes()
+ {
+ $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 test_quotes_to_entities()
+ {
+ $strs = array(
+ '"me oh my!"' => '&quot;me oh my!&quot;',
+ "it's a winner!" => 'it&#39;s a winner!',
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, quotes_to_entities($str));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_reduce_double_slashes()
+ {
+ $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 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',
+ '&nbsp;' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
+ '<br>' => '<br><br><br><br><br><br><br><br><br><br>'
+
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, repeater($str, 10));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ 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));
+ }
+
+ // --------------------------------------------------------------------
+
+ 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
diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php
new file mode 100644
index 000000000..f131469cb
--- /dev/null
+++ b/tests/codeigniter/helpers/text_helper_test.php
@@ -0,0 +1,171 @@
+<?php
+
+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,&#8230;', word_limiter($this->_long_string, 4));
+ $this->assertEquals('Once upon a time,&hellip;', word_limiter($this->_long_string, 4, '&hellip;'));
+ $this->assertEquals('', word_limiter('', 4));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_character_limiter()
+ {
+ $this->assertEquals('Once upon a time, a&#8230;', character_limiter($this->_long_string, 20));
+ $this->assertEquals('Once upon a time, a&hellip;', character_limiter($this->_long_string, 20, '&hellip;'));
+ $this->assertEquals('Short', character_limiter('Short', 20));
+ $this->assertEquals('Short', character_limiter('Short', 5));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_ascii_to_entities()
+ {
+ $strs = array(
+ '“‘ “test”' => '&#8220;&#8216; &#8220;test&#8221;',
+ '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '&#8224;&#165;&#168;&#710;&#248;&#229;&#223;&#8706;&#402;&#169;&#729;&#8710;&#730;&#172;'
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, ascii_to_entities($str));
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_entities_to_ascii()
+ {
+ $strs = array(
+ '&#8220;&#8216; &#8220;test&#8221;' => '“‘ “test”',
+ '&#8224;&#165;&#168;&#710;&#248;&#229;&#223;&#8706;&#402;&#169;&#729;&#8710;&#730;&#172;' => '†¥¨ˆøåß∂ƒ©˙∆˚¬'
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, entities_to_ascii($str));
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ 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',
+ '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 test_highlight_code()
+ {
+ $expect = "<code><span style=\"color: #000000\">\n<span style=\"color: #0000BB\">&lt;?php&nbsp;var_dump</span><span style=\"color: #007700\">(</span><span style=\"color: #0000BB\">\$this</span><span style=\"color: #007700\">);&nbsp;</span><span style=\"color: #0000BB\">?&gt;&nbsp;</span>\n</span>\n</code>";
+
+ $this->assertEquals($expect, highlight_code('<?php var_dump($this); ?>'));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_highlight_phrase()
+ {
+ $strs = array(
+ 'this is a phrase' => '<strong>this is</strong> a phrase',
+ 'this is another' => '<strong>this is</strong> another',
+ 'Gimme a test, Sally' => 'Gimme a test, Sally',
+ 'Or tell me what this is' => 'Or tell me what <strong>this is</strong>',
+ '' => ''
+ );
+
+ foreach ($strs as $str => $expect)
+ {
+ $this->assertEquals($expect, highlight_phrase($str, 'this is'));
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_ellipsize()
+ {
+ $strs = array(
+ '0' => array(
+ 'this is my string' => '&hellip; my string',
+ "here's another one" => '&hellip;nother one',
+ 'this one is just a bit longer' => '&hellip;bit longer',
+ 'short' => 'short'
+ ),
+ '.5' => array(
+ 'this is my string' => 'this &hellip;tring',
+ "here's another one" => "here'&hellip;r one",
+ 'this one is just a bit longer' => 'this &hellip;onger',
+ 'short' => 'short'
+ ),
+ '1' => array(
+ 'this is my string' => 'this is my&hellip;',
+ "here's another one" => "here's ano&hellip;",
+ 'this one is just a bit longer' => 'this one i&hellip;',
+ 'short' => 'short'
+ ),
+ );
+
+ foreach ($strs as $pos => $s)
+ {
+ foreach ($s as $str => $expect)
+ {
+ $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.';
+ $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.";
+ $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
new file mode 100644
index 000000000..c81c5f1b8
--- /dev/null
+++ b/tests/codeigniter/helpers/url_helper_test.php
@@ -0,0 +1,76 @@
+<?php
+
+class Url_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->helper('url');
+ }
+
+ public function test_url_title()
+ {
+ $words = array(
+ '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'));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ 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' => '<a href="http://www.codeigniter.com">http://www.codeigniter.com</a> test',
+ 'This is my noreply@codeigniter.com test' => 'This is my noreply@codeigniter.com test',
+ '<br />www.google.com' => '<br /><a href="http://www.google.com">http://www.google.com</a>',
+ );
+
+ foreach ($strings as $in => $out)
+ {
+ $this->assertEquals($out, auto_link($in, 'url'));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_pull_675()
+ {
+ $strings = array(
+ '<br />www.google.com' => '<br /><a href="http://www.google.com">http://www.google.com</a>',
+ );
+
+ foreach ($strings as $in => $out)
+ {
+ $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
new file mode 100644
index 000000000..e8cf411da
--- /dev/null
+++ b/tests/codeigniter/helpers/xml_helper_test.php
@@ -0,0 +1,15 @@
+<?php
+
+class Xml_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->helper('xml');
+ }
+
+ public function test_xml_convert()
+ {
+ $this->assertEquals('&lt;tag&gt;my &amp; test &#45; &lt;/tag&gt;', xml_convert('<tag>my & test - </tag>'));
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php
new file mode 100644
index 000000000..153a25e1d
--- /dev/null
+++ b/tests/codeigniter/libraries/Encrypt_test.php
@@ -0,0 +1,72 @@
+<?php
+
+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());
+ }
+
+} \ 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..b68f44a33
--- /dev/null
+++ b/tests/codeigniter/libraries/Parser_test.php
@@ -0,0 +1,107 @@
+<?php
+
+class Parser_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $obj = new stdClass;
+ $obj->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(
+ 'title' => 'Super Heroes',
+ 'powers' => array(
+ array(
+ 'invisibility' => 'yes',
+ 'flying' => 'no'),
+ )
+ );
+
+ $template = "{title}\n{powers}{invisibility}\n{flying}{/powers}";
+
+ $this->assertEquals("Super Heroes\nyes\nno", $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
diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php
new file mode 100644
index 000000000..edfc83dd0
--- /dev/null
+++ b/tests/codeigniter/libraries/Table_test.php
@@ -0,0 +1,297 @@
+<?php
+
+class Table_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $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');
+
+ $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
+ */
+ 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
+ // 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 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
+ // 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 test_prep_args()
+ {
+ $expected = array(
+ array('data' => 'name'),
+ array('data' => 'color'),
+ array('data' => 'size')
+ );
+
+ $this->assertEquals(
+ $expected,
+ $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,
+ $this->table->prep_args(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome')))
+ );
+ }
+
+ public function test_default_template_keys()
+ {
+ $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, $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' => '</table junk>'));
+ $this->table->compile_template();
+
+ $this->assertArrayHasKey('table_close', $this->table->template);
+ $this->assertEquals('</table junk>', $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 &nbsp;
+ $this->assertEquals(
+ array(
+ array('Laura', 'Red', '15'),
+ array('Katie', 'Blue', '&nbsp;')
+ ),
+ $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')
+ );
+
+ $this->table->set_from_array($data, FALSE);
+ $this->assertEmpty($this->table->heading);
+
+ $this->table->clear();
+
+ $this->table->set_from_array($data);
+ $this->assertEquals(count($this->table->rows), 2);
+
+ $expected = array(
+ array('data' => 'name'),
+ array('data' => 'color'),
+ array('data' => 'number')
+ );
+
+ $this->assertEquals($expected, $this->table->heading);
+
+ $expected = array(
+ array('data' => 'Katie'),
+ array('data' => 'Blue'),
+ );
+
+ $this->assertEquals($expected, $this->table->rows[1]);
+ }
+
+ public function test_set_from_object()
+ {
+ // 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;
+ };
+
+ $this->table->set_from_object($query);
+
+ $expected = array(
+ array('data' => 'name'),
+ array('data' => 'email')
+ );
+
+ $this->assertEquals($expected, $this->table->heading);
+
+ $expected = array(
+ 'name' => array('data' => 'Foo Bar'),
+ 'email' => array('data' => 'foo@bar.com'),
+ );
+
+ $this->assertEquals($expected, $this->table->rows[1]);
+ }
+
+ 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')
+ );
+
+ $table = $this->table->generate($data);
+
+ // Test the table header
+ $this->assertTrue(strpos($table, '<th>Name</th>') !== FALSE);
+ $this->assertTrue(strpos($table, '<th>Color</th>') !== FALSE);
+ $this->assertTrue(strpos($table, '<th>Size</th>') !== FALSE);
+
+ // Test the first entry
+ $this->assertTrue(strpos($table, '<td>Fred</td>') !== FALSE);
+ $this->assertTrue(strpos($table, '<td>Blue</td>') !== FALSE);
+ $this->assertTrue(strpos($table, '<td>Small</td>') !== FALSE);
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Typography_test.php b/tests/codeigniter/libraries/Typography_test.php
new file mode 100644
index 000000000..eb6dacb73
--- /dev/null
+++ b/tests/codeigniter/libraries/Typography_test.php
@@ -0,0 +1,186 @@
+<?php
+
+class Typography_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $obj = new stdClass;
+ $obj->type = new Mock_Libraries_Typography();
+
+ $this->ci_instance($obj);
+
+ $this->type = $obj->type;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Tests the format_characters() function.
+ *
+ * this can and should grow.
+ */
+ public function test_format_characters()
+ {
+ $strs = array(
+ '"double quotes"' => '&#8220;double quotes&#8221;',
+ '"testing" in "theory" that is' => '&#8220;testing&#8221; in &#8220;theory&#8221; that is',
+ "Here's what I'm" => 'Here&#8217;s what I&#8217;m',
+ '&' => '&amp;',
+ '&amp;' => '&amp;',
+ '&nbsp;' => '&nbsp;',
+ '--' => '&#8212;',
+ 'foo...' => 'foo&#8230;',
+ 'foo..' => 'foo..',
+ 'foo...bar.' => 'foo&#8230;bar.',
+ 'test. new' => 'test.&nbsp; new',
+ );
+
+ foreach ($strs as $str => $expected)
+ {
+ $this->assertEquals($expected, $this->type->format_characters($str));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_nl2br_except_pre()
+ {
+ $str = <<<EOH
+Hello, I'm a happy string with some new lines.
+
+I like to skip.
+
+Jump
+
+and sing.
+
+<pre>
+I am inside a pre tag. Please don't mess with me.
+
+k?
+</pre>
+
+That's my story and I'm sticking to it.
+
+The End.
+EOH;
+
+ $expected = <<<EOH
+Hello, I'm a happy string with some new lines. <br />
+<br />
+I like to skip.<br />
+<br />
+Jump<br />
+<br />
+and sing.<br />
+<br />
+<pre>
+I am inside a pre tag. Please don't mess with me.
+
+k?
+</pre><br />
+<br />
+That's my story and I'm sticking to it.<br />
+<br />
+The End.
+EOH;
+
+ $this->assertEquals($expected, $this->type->nl2br_except_pre($str));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_auto_typography()
+ {
+ $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" => "<p>My string<br />\nhas return characters</p>",
+ 'This one does not!' => '<p>This one does not!</p>'
+ );
+
+ 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 = "<p>This has way too many linebreaks.</p>\n\n<p>See?</p>";
+
+ $this->assertEquals($expect, $this->type->auto_typography($str, TRUE));
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _remove_comments()
+ {
+ $str = '<!-- I can haz comments? --> But no!';
+ $expect = '<p><!-- I can haz comments? -->&nbsp; But no!</p>';
+
+ $this->assertEquals($expect, $this->type->auto_typography($str));
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _protect_pre()
+ {
+ $str = '<p>My Sentence</p><pre>var_dump($this);</pre>';
+ $expect = '<p>My Sentence</p><pre>var_dump($this);</pre>';
+
+ $this->assertEquals($expect, $this->type->auto_typography($str));
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _no_opening_block()
+ {
+ $str = 'My Sentence<pre>var_dump($this);</pre>';
+ $expect = '<p>My Sentence</p><pre>var_dump($this);</pre>';
+
+ $this->assertEquals($expect, $this->type->auto_typography($str));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function _protect_braced_quotes()
+ {
+ $this->type->protect_braced_quotes = TRUE;
+
+ $str = 'Test {parse="foobar"}';
+ $expect = '<p>Test {parse="foobar"}</p>';
+
+ $this->assertEquals($expect, $this->type->auto_typography($str));
+
+ $this->type->protect_braced_quotes = FALSE;
+
+ $str = 'Test {parse="foobar"}';
+ $expect = '<p>Test {parse=&#8220;foobar&#8221;}</p>';
+
+ $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
new file mode 100644
index 000000000..89383f807
--- /dev/null
+++ b/tests/codeigniter/libraries/Useragent_test.php
@@ -0,0 +1,85 @@
+<?php
+
+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 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
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
new file mode 100644
index 000000000..be1c2220c
--- /dev/null
+++ b/tests/mocks/autoloader.php
@@ -0,0 +1,94 @@
+<?php
+
+// This autoloader provide convinient way to working with mock object
+// make the test looks natural. This autoloader support cascade file loading as well
+// within mocks directory.
+//
+// Prototype :
+//
+// $mock_table = new Mock_Libraries_Table(); // Will load ./mocks/libraries/table.php
+// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php
+// and so on...
+function autoload($class)
+{
+ $dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR;
+
+ $ci_core = array(
+ 'Benchmark', 'Config', 'Controller',
+ 'Exceptions', 'Hooks', 'Input',
+ 'Lang', 'Loader', 'Model',
+ 'Output', 'Router', 'Security',
+ 'URI', 'Utf8',
+ );
+
+ $ci_libraries = array(
+ 'Calendar', 'Cart', 'Driver_Library',
+ 'Email', 'Encrypt', 'Form_validation',
+ 'Ftp', 'Image_lib', 'Javascript',
+ 'Log', 'Migration', 'Pagination',
+ 'Parser', 'Profiler', 'Session',
+ 'Table', 'Trackback', 'Typography',
+ 'Unit_test', 'Upload', 'User_agent',
+ 'Xmlrpc', 'Zip',
+ );
+
+ if (strpos($class, 'Mock_') === 0)
+ {
+ $class = str_replace(array('Mock_', '_'), array('', DIRECTORY_SEPARATOR), $class);
+ $class = strtolower($class);
+ }
+ elseif (strpos($class, 'CI_') === 0)
+ {
+ $fragments = explode('_', $class, 2);
+ $subclass = next($fragments);
+
+ if (in_array($subclass, $ci_core))
+ {
+ $dir = BASEPATH.'core'.DIRECTORY_SEPARATOR;
+ $class = $subclass;
+ }
+ elseif (in_array($subclass, $ci_libraries))
+ {
+ $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR;
+ $class = ($subclass === 'Driver_Library') ? 'Driver' : $subclass;
+ }
+ elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) === 3)
+ {
+ $driver_path = BASEPATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
+ $dir = $driver_path.$m[1].DIRECTORY_SEPARATOR;
+ $file = $dir.$m[1].'_'.$m[2].'.php';
+ }
+ elseif (strpos($class, 'CI_DB') === 0)
+ {
+ $dir = BASEPATH.'database'.DIRECTORY_SEPARATOR;
+ $file = $dir.str_replace(array('CI_DB','active_record'), array('DB', 'active_rec'), $subclass).'.php';
+ }
+ else
+ {
+ $class = strtolower($class);
+ }
+ }
+
+ $file = (isset($file)) ? $file : $dir.$class.'.php';
+
+ if ( ! file_exists($file))
+ {
+ $trace = debug_backtrace();
+
+ if ($trace[2]['function'] === 'class_exists' OR $trace[2]['function'] === 'file_exists')
+ {
+ // If the autoload call came from `class_exists` or `file_exists`,
+ // we skipped and return FALSE
+ return FALSE;
+ }
+ elseif (($autoloader = spl_autoload_functions()) && end($autoloader) !== __FUNCTION__)
+ {
+ // If there was other custom autoloader, passed away
+ return FALSE;
+ }
+
+ throw new InvalidArgumentException("Unable to load {$class}.");
+ }
+
+ include_once($file);
+} \ No newline at end of file
diff --git a/tests/mocks/ci_testcase.php b/tests/mocks/ci_testcase.php
new file mode 100644
index 000000000..eda9e1b60
--- /dev/null
+++ b/tests/mocks/ci_testcase.php
@@ -0,0 +1,194 @@
+<?php
+
+class CI_TestCase extends PHPUnit_Framework_TestCase {
+
+ protected $ci_config;
+ protected $ci_instance;
+ protected static $ci_test_instance;
+
+ private $global_map = array(
+ 'benchmark' => 'bm',
+ 'config' => 'cfg',
+ 'hooks' => 'ext',
+ 'utf8' => 'uni',
+ 'router' => 'rtr',
+ 'output' => 'out',
+ 'security' => 'sec',
+ 'input' => 'in',
+ 'lang' => 'lang',
+ 'loader' => 'load',
+ 'model' => 'model'
+ );
+
+ // --------------------------------------------------------------------
+
+ public function __construct()
+ {
+ parent::__construct();
+ $this->ci_config = array();
+ }
+
+ // --------------------------------------------------------------------
+
+ public function setUp()
+ {
+ if (method_exists($this, 'set_up'))
+ {
+ $this->set_up();
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function tearDown()
+ {
+ if (method_exists($this, 'tear_down'))
+ {
+ $this->tear_down();
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public static function instance()
+ {
+ return self::$ci_test_instance;
+ }
+
+ // --------------------------------------------------------------------
+
+ public function ci_set_config($key, $val = '')
+ {
+ if (is_array($key))
+ {
+ $this->ci_config = $key;
+ }
+ else
+ {
+ $this->ci_config[$key] = $val;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ public function ci_get_config()
+ {
+ return $this->ci_config;
+ }
+
+ // --------------------------------------------------------------------
+
+ public function ci_instance($obj = FALSE)
+ {
+ if ( ! is_object($obj))
+ {
+ return $this->ci_instance;
+ }
+
+ $this->ci_instance = $obj;
+ }
+
+ // --------------------------------------------------------------------
+
+ public function ci_instance_var($name, $obj = FALSE)
+ {
+ if ( ! is_object($obj))
+ {
+ return $this->ci_instance->$name;
+ }
+
+ $this->ci_instance->$name =& $obj;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Grab a core class
+ *
+ * Loads the correct core class without extensions
+ * and returns a reference to the class name in the
+ * globals array with the correct key. This way the
+ * test can modify the variable it assigns to and
+ * still maintain the global.
+ */
+ public function &ci_core_class($name)
+ {
+ $name = strtolower($name);
+
+ if (isset($this->global_map[$name]))
+ {
+ $class_name = ucfirst($name);
+ $global_name = $this->global_map[$name];
+ }
+ elseif (in_array($name, $this->global_map))
+ {
+ $class_name = ucfirst(array_search($name, $this->global_map));
+ $global_name = $name;
+ }
+ else
+ {
+ throw new Exception('Not a valid core class.');
+ }
+
+ if ( ! class_exists('CI_'.$class_name))
+ {
+ require_once BASEPATH.'core/'.$class_name.'.php';
+ }
+
+ $GLOBALS[strtoupper($global_name)] = 'CI_'.$class_name;
+ return $GLOBALS[strtoupper($global_name)];
+ }
+
+ // --------------------------------------------------------------------
+
+ // convenience function for global mocks
+ public function ci_set_core_class($name, $obj)
+ {
+ $orig =& $this->ci_core_class($name);
+ $orig = $obj;
+ }
+
+ // --------------------------------------------------------------------
+ // Internals
+ // --------------------------------------------------------------------
+
+ /**
+ * Overwrite runBare
+ *
+ * PHPUnit instantiates the test classes before
+ * running them individually. So right before a test
+ * runs we set our instance. Normally this step would
+ * happen in setUp, but someone is bound to forget to
+ * call the parent method and debugging this is no fun.
+ */
+ public function runBare()
+ {
+ self::$ci_test_instance = $this;
+ parent::runBare();
+ }
+
+ // --------------------------------------------------------------------
+
+ public function helper($name)
+ {
+ require_once(BASEPATH.'helpers/'.$name.'_helper.php');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * This overload is useful to create a stub, that need to have a specific method.
+ */
+ public function __call($method, $args)
+ {
+ if ($this->{$method} instanceof Closure)
+ {
+ return call_user_func_array($this->{$method},$args);
+ }
+ else
+ {
+ return parent::__call($method, $args);
+ }
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/core/benchmark.php b/tests/mocks/core/benchmark.php
new file mode 100644
index 000000000..d92be21db
--- /dev/null
+++ b/tests/mocks/core/benchmark.php
@@ -0,0 +1,3 @@
+<?php
+
+class Mock_Core_Benchmark extends CI_Benchmark {} \ No newline at end of file
diff --git a/tests/mocks/core/common.php b/tests/mocks/core/common.php
new file mode 100644
index 000000000..a655ee1db
--- /dev/null
+++ b/tests/mocks/core/common.php
@@ -0,0 +1,169 @@
+<?php
+
+// Set up the global CI functions in their most minimal core representation
+
+if ( ! function_exists('get_instance'))
+{
+ function &get_instance()
+ {
+ $test = CI_TestCase::instance();
+ $test = $test->ci_instance();
+ return $test;
+ }
+}
+
+// --------------------------------------------------------------------
+
+if ( ! function_exists('get_config'))
+{
+ function &get_config()
+ {
+ $test = CI_TestCase::instance();
+ $config = $test->ci_get_config();
+ return $config;
+ }
+}
+
+if ( ! function_exists('config_item'))
+{
+ function config_item($item)
+ {
+ $config =& get_config();
+
+ if ( ! isset($config[$item]))
+ {
+ return FALSE;
+ }
+
+ return $config[$item];
+ }
+}
+
+// --------------------------------------------------------------------
+
+if ( ! function_exists('load_class'))
+{
+ function load_class($class, $directory = 'libraries', $prefix = 'CI_')
+ {
+ if ($directory !== 'core' OR $prefix !== 'CI_')
+ {
+ throw new Exception('Not Implemented: Non-core load_class()');
+ }
+
+ $test = CI_TestCase::instance();
+
+ $obj =& $test->ci_core_class($class);
+
+ if (is_string($obj))
+ {
+ throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class);
+ }
+
+ return $obj;
+ }
+}
+
+// This is sort of meh. Should probably be mocked up with
+// controllable output, so that we can test some of our
+// security code. The function itself will be tested in the
+// bootstrap testsuite.
+// --------------------------------------------------------------------
+
+if ( ! function_exists('remove_invisible_characters'))
+{
+ function remove_invisible_characters($str, $url_encoded = TRUE)
+ {
+ $non_displayables = array();
+
+ // every control character except newline (dec 10)
+ // carriage return (dec 13), and horizontal tab (dec 09)
+
+ if ($url_encoded)
+ {
+ $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15
+ $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31
+ }
+
+ $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127
+
+ do
+ {
+ $str = preg_replace($non_displayables, '', $str, -1, $count);
+ }
+ while ($count);
+
+ return $str;
+ }
+}
+
+
+// Clean up error messages
+// --------------------------------------------------------------------
+
+if ( ! function_exists('show_error'))
+{
+ function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
+ {
+ throw new RuntimeException('CI Error: '.$message);
+ }
+}
+
+if ( ! function_exists('show_404'))
+{
+ function show_404($page = '', $log_error = TRUE)
+ {
+ throw new RuntimeException('CI Error: 404');
+ }
+}
+
+if ( ! function_exists('_exception_handler'))
+{
+ function _exception_handler($severity, $message, $filepath, $line)
+ {
+ throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line);
+ }
+}
+
+
+// We assume a few things about our environment ...
+// --------------------------------------------------------------------
+
+if ( ! function_exists('is_php'))
+{
+ function is_php($version = '5.0.0')
+ {
+ return ! (version_compare(PHP_VERSION, $version) < 0);
+ }
+}
+
+if ( ! function_exists('is_really_writable'))
+{
+ function is_really_writable($file)
+ {
+ return is_writable($file);
+ }
+}
+
+if ( ! function_exists('is_loaded'))
+{
+ function is_loaded()
+ {
+ throw new Exception('Bad Isolation: mock up environment');
+ }
+}
+
+if ( ! function_exists('log_message'))
+{
+ function log_message($level = 'error', $message, $php_error = FALSE)
+ {
+ return TRUE;
+ }
+}
+
+if ( ! function_exists('set_status_header'))
+{
+ function set_status_header($code = 200, $text = '')
+ {
+ return TRUE;
+ }
+} \ No newline at end of file
diff --git a/tests/mocks/core/input.php b/tests/mocks/core/input.php
new file mode 100644
index 000000000..2a4aa4997
--- /dev/null
+++ b/tests/mocks/core/input.php
@@ -0,0 +1,31 @@
+<?php
+
+class Mock_Core_Input extends CI_Input {
+
+ /**
+ * Since we use GLOBAL to fetch Security and Utf8 classes,
+ * we need to use inversion of control to mock up
+ * the same process within CI_Input class constructor.
+ *
+ * @covers CI_Input::__construct()
+ */
+ public function __construct($security, $utf8)
+ {
+ $this->_allow_get_array = (config_item('allow_get_array') === TRUE);
+ $this->_enable_xss = (config_item('global_xss_filtering') === TRUE);
+ $this->_enable_csrf = (config_item('csrf_protection') === TRUE);
+
+ // Assign Security and Utf8 classes
+ $this->security = $security;
+ $this->uni = $utf8;
+
+ // Sanitize global arrays
+ $this->_sanitize_globals();
+ }
+
+ public function fetch_from_array($array, $index = '', $xss_clean = FALSE)
+ {
+ return parent::_fetch_from_array($array, $index, $xss_clean);
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php
new file mode 100644
index 000000000..53d88d55b
--- /dev/null
+++ b/tests/mocks/core/loader.php
@@ -0,0 +1,31 @@
+<?php
+
+class Mock_Core_Loader extends CI_Loader {
+
+ /**
+ * Since we use paths to load up models, views, etc, we need the ability to
+ * mock up the file system so when core tests are run, we aren't mucking
+ * in the application directory. this will give finer grained control over
+ * these tests. So yeah, while this looks odd, I need to overwrite protected
+ * class vars in the loader. So here we go...
+ *
+ * @covers CI_Loader::__construct()
+ */
+ public function __construct()
+ {
+ vfsStreamWrapper::register();
+ vfsStreamWrapper::setRoot(new vfsStreamDirectory('application'));
+
+ $this->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);
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/core/security.php b/tests/mocks/core/security.php
new file mode 100644
index 000000000..e19a8b20b
--- /dev/null
+++ b/tests/mocks/core/security.php
@@ -0,0 +1,30 @@
+<?php
+
+class Mock_Core_Security extends CI_Security {
+
+ public function csrf_set_cookie()
+ {
+ // We cannot set cookie in CLI mode, so for csrf test, who rely on $_COOKIE,
+ // we superseded set_cookie with directly set the cookie variable,
+ // @see : ./tests/codeigniter/core/Security_test.php, line 8
+ return $this;
+ }
+
+ // Overide inaccesible protected properties
+ public function __get($property)
+ {
+ return isset($this->{'_'.$property}) ? $this->{'_'.$property} : NULL;
+ }
+
+ // Overide inaccesible protected method
+ public function __call($method, $params)
+ {
+ if (is_callable(array($this, '_'.$method)))
+ {
+ return call_user_func_array(array($this, '_'.$method), $params);
+ }
+
+ throw new BadMethodCallException('Method '.$method.' was not found');
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/core/uri.php b/tests/mocks/core/uri.php
new file mode 100644
index 000000000..94f75df64
--- /dev/null
+++ b/tests/mocks/core/uri.php
@@ -0,0 +1,26 @@
+<?php
+
+class Mock_Core_URI extends CI_URI {
+
+ public function __construct()
+ {
+ $test = CI_TestCase::instance();
+ $cls =& $test->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;
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/core/utf8.php b/tests/mocks/core/utf8.php
new file mode 100644
index 000000000..068e74ac1
--- /dev/null
+++ b/tests/mocks/core/utf8.php
@@ -0,0 +1,26 @@
+<?php
+
+class Mock_Core_Utf8 extends CI_Utf8 {
+
+ /**
+ * We need to define several constants as
+ * the same process within CI_Utf8 class constructor.
+ *
+ * @covers CI_Utf8::__construct()
+ */
+ public function __construct()
+ {
+ defined('UTF8_ENABLED') OR define('UTF8_ENABLED', TRUE);
+
+ if (extension_loaded('mbstring'))
+ {
+ defined('MB_ENABLED') OR define('MB_ENABLED', TRUE);
+ mb_internal_encoding('UTF-8');
+ }
+ else
+ {
+ defined('MB_ENABLED') OR define('MB_ENABLED', FALSE);
+ }
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite
new file mode 100755
index 000000000..44dcef9ec
--- /dev/null
+++ b/tests/mocks/database/ci_test.sqlite
Binary files differ
diff --git a/tests/mocks/database/config/mysql.php b/tests/mocks/database/config/mysql.php
new file mode 100644
index 000000000..a590b9f53
--- /dev/null
+++ b/tests/mocks/database/config/mysql.php
@@ -0,0 +1,34 @@
+<?php
+
+return array(
+
+ // Typical Database configuration
+ 'mysql' => array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'travis',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'mysql'
+ ),
+
+ // Database configuration with failover
+ 'mysql_failover' => array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'not_travis',
+ 'password' => 'wrong password',
+ 'database' => 'not_ci_test',
+ 'dbdriver' => 'mysql',
+ 'failover' => array(
+ array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'travis',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'mysql',
+ )
+ )
+ )
+); \ No newline at end of file
diff --git a/tests/mocks/database/config/pdo/mysql.php b/tests/mocks/database/config/pdo/mysql.php
new file mode 100644
index 000000000..96608f787
--- /dev/null
+++ b/tests/mocks/database/config/pdo/mysql.php
@@ -0,0 +1,37 @@
+<?php
+
+return array(
+
+ // Typical Database configuration
+ 'pdo/mysql' => array(
+ 'dsn' => 'mysql:host=localhost;dbname=ci_test',
+ 'hostname' => 'localhost',
+ 'username' => 'travis',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'mysql'
+ ),
+
+ // Database configuration with failover
+ 'pdo/mysql_failover' => array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'not_travis',
+ 'password' => 'wrong password',
+ 'database' => 'not_ci_test',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'mysql',
+ 'failover' => array(
+ array(
+ 'dsn' => 'mysql:host=localhost;dbname=ci_test',
+ 'hostname' => 'localhost',
+ 'username' => 'travis',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'mysql'
+ )
+ )
+ )
+); \ No newline at end of file
diff --git a/tests/mocks/database/config/pdo/pgsql.php b/tests/mocks/database/config/pdo/pgsql.php
new file mode 100644
index 000000000..e55e3ea77
--- /dev/null
+++ b/tests/mocks/database/config/pdo/pgsql.php
@@ -0,0 +1,37 @@
+<?php
+
+return array(
+
+ // Typical Database configuration
+ 'pdo/pgsql' => array(
+ 'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;',
+ 'hostname' => 'localhost',
+ 'username' => 'postgres',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'pgsql'
+ ),
+
+ // Database configuration with failover
+ 'pdo/pgsql_failover' => array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'not_travis',
+ 'password' => 'wrong password',
+ 'database' => 'not_ci_test',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'pgsql',
+ 'failover' => array(
+ array(
+ 'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;',
+ 'hostname' => 'localhost',
+ 'username' => 'postgres',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'pgsql'
+ )
+ )
+ )
+); \ No newline at end of file
diff --git a/tests/mocks/database/config/pdo/sqlite.php b/tests/mocks/database/config/pdo/sqlite.php
new file mode 100644
index 000000000..1bf56b3ac
--- /dev/null
+++ b/tests/mocks/database/config/pdo/sqlite.php
@@ -0,0 +1,37 @@
+<?php
+
+return array(
+
+ // Typical Database configuration
+ 'pdo/sqlite' => array(
+ 'dsn' => 'sqlite:/'.realpath(__DIR__.'/../..').'/ci_test.sqlite',
+ 'hostname' => 'localhost',
+ 'username' => 'sqlite',
+ 'password' => 'sqlite',
+ 'database' => 'sqlite',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'sqlite'
+ ),
+
+ // Database configuration with failover
+ 'pdo/sqlite_failover' => array(
+ 'dsn' => 'sqlite:not_exists.sqlite',
+ 'hostname' => 'localhost',
+ 'username' => 'sqlite',
+ 'password' => 'sqlite',
+ 'database' => 'sqlite',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'sqlite',
+ 'failover' => array(
+ array(
+ 'dsn' => 'sqlite:/'.realpath(__DIR__.'/../..').'/ci_test.sqlite',
+ 'hostname' => 'localhost',
+ 'username' => 'sqlite',
+ 'password' => 'sqlite',
+ 'database' => 'sqlite',
+ 'dbdriver' => 'pdo',
+ 'subdriver' => 'sqlite'
+ )
+ )
+ )
+); \ No newline at end of file
diff --git a/tests/mocks/database/config/pgsql.php b/tests/mocks/database/config/pgsql.php
new file mode 100644
index 000000000..1444b0066
--- /dev/null
+++ b/tests/mocks/database/config/pgsql.php
@@ -0,0 +1,34 @@
+<?php
+
+return array(
+
+ // Typical Database configuration
+ 'pgsql' => array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'postgres',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'postgre'
+ ),
+
+ // Database configuration with failover
+ 'pgsql_failover' => array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'not_travis',
+ 'password' => 'wrong password',
+ 'database' => 'not_ci_test',
+ 'dbdriver' => 'postgre',
+ 'failover' => array(
+ array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'postgres',
+ 'password' => '',
+ 'database' => 'ci_test',
+ 'dbdriver' => 'postgre',
+ )
+ )
+ )
+); \ No newline at end of file
diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php
new file mode 100644
index 000000000..d37ee4871
--- /dev/null
+++ b/tests/mocks/database/config/sqlite.php
@@ -0,0 +1,34 @@
+<?php
+
+return array(
+
+ // Typical Database configuration
+ 'sqlite' => array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'sqlite',
+ 'password' => 'sqlite',
+ 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite',
+ 'dbdriver' => 'sqlite3'
+ ),
+
+ // Database configuration with failover
+ 'sqlite_failover' => array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'sqlite',
+ 'password' => 'sqlite',
+ 'database' => '../not_exists.sqlite',
+ 'dbdriver' => 'sqlite3',
+ 'failover' => array(
+ array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'sqlite',
+ 'password' => 'sqlite',
+ 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite',
+ 'dbdriver' => 'sqlite3'
+ )
+ )
+ )
+); \ No newline at end of file
diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php
new file mode 100644
index 000000000..75658530b
--- /dev/null
+++ b/tests/mocks/database/db.php
@@ -0,0 +1,100 @@
+<?php
+
+class Mock_Database_DB {
+
+ /**
+ * @var array DB configuration
+ */
+ private $config = array();
+
+ /**
+ * Prepare database configuration skeleton
+ *
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($config = array())
+ {
+ $this->config = $config;
+ }
+
+ /**
+ * Build DSN connection string for DB driver instantiate process
+ *
+ * @param string Group name
+ * @return string DSN Connection string
+ */
+ public function set_dsn($group = 'default')
+ {
+ if ( ! isset($this->config[$group]))
+ {
+ throw new InvalidArgumentException('Group '.$group.' not exists');
+ }
+
+ $params = array(
+ 'dbprefix' => '',
+ 'pconnect' => FALSE,
+ 'db_debug' => FALSE,
+ 'cache_on' => FALSE,
+ 'cachedir' => '',
+ 'char_set' => 'utf8',
+ 'dbcollat' => 'utf8_general_ci',
+ 'swap_pre' => '',
+ 'autoinit' => TRUE,
+ 'stricton' => FALSE,
+ );
+
+ $config = array_merge($this->config[$group], $params);
+ $dsnstring = empty($config['dsn']) ? FALSE : $config['dsn'];
+ $subdriver = empty($config['subdriver']) ? FALSE: $config['subdriver'];
+ $failover = empty($config['failover']) ? FALSE : $config['failover'];
+
+ $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password']
+ .'@'.$config['hostname'].'/'.$config['database'];
+
+ // Build the parameter
+ $other_params = array_slice($config, 6);
+ if ($dsnstring) $other_params['dsn'] = $dsnstring;
+ if ($subdriver) $other_params['subdriver'] = $subdriver;
+ if ($failover) $other_params['failover'] = $failover;
+
+ return $dsn.'?'.http_build_query($other_params);
+ }
+
+ /**
+ * Return a database config array
+ *
+ * @see ./config
+ * @param string Driver based configuration
+ * @return array
+ */
+ public static function config($driver)
+ {
+ $dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR;
+ return include($dir.'config'.DIRECTORY_SEPARATOR.$driver.'.php');
+ }
+
+ /**
+ * Main DB method wrapper
+ *
+ * @param string Group or DSN string
+ * @param bool
+ * @return object
+ */
+ public static function DB($group, $query_builder = FALSE)
+ {
+ include_once(BASEPATH.'database/DB.php');
+
+ try
+ {
+ $db = DB($group, $query_builder);
+ }
+ catch (Exception $e)
+ {
+ throw new InvalidArgumentException($e->getMessage());
+ }
+
+ return $db;
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/database/db/driver.php b/tests/mocks/database/db/driver.php
new file mode 100644
index 000000000..65ac2c4cc
--- /dev/null
+++ b/tests/mocks/database/db/driver.php
@@ -0,0 +1,39 @@
+<?php
+
+class Mock_Database_DB_Driver extends CI_DB_driver {
+
+ /**
+ * @var object The actual Driver
+ */
+ protected $ci_db_driver;
+
+ /**
+ * Instantiate the database driver
+ *
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($driver_class, $config = array())
+ {
+ if (is_string($driver_class))
+ {
+ $this->ci_db_driver = new $driver_class($config);
+ }
+ }
+
+ /**
+ * Overloading method, emulate the actual driver method (multiple inheritance workaround)
+ */
+ public function __call($method, $arguments)
+ {
+ if ( ! is_callable(array($this->ci_db_driver, $method)))
+ {
+ throw new BadMethodCallException($method. ' not exists or not implemented');
+ }
+
+ return call_user_func_array(array($this->ci_db_driver, $method), $arguments);
+ }
+}
+
+class CI_DB extends Mock_Database_DB_QueryBuilder {} \ No newline at end of file
diff --git a/tests/mocks/database/db/querybuilder.php b/tests/mocks/database/db/querybuilder.php
new file mode 100644
index 000000000..3f2252622
--- /dev/null
+++ b/tests/mocks/database/db/querybuilder.php
@@ -0,0 +1,3 @@
+<?php
+
+class Mock_Database_DB_QueryBuilder extends CI_DB_query_builder {} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/mysql.php b/tests/mocks/database/drivers/mysql.php
new file mode 100644
index 000000000..e0c1fb06c
--- /dev/null
+++ b/tests/mocks/database/drivers/mysql.php
@@ -0,0 +1,17 @@
+<?php
+
+class Mock_Database_Drivers_Mysql extends Mock_Database_DB_Driver {
+
+ /**
+ * Instantiate the database driver
+ *
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($config = array())
+ {
+ parent::__construct('CI_DB_mysql_driver', $config);
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/pdo.php b/tests/mocks/database/drivers/pdo.php
new file mode 100644
index 000000000..17768eed7
--- /dev/null
+++ b/tests/mocks/database/drivers/pdo.php
@@ -0,0 +1,16 @@
+<?php
+
+class Mock_Database_Drivers_PDO extends Mock_Database_DB_Driver {
+
+ /**
+ * Instantiate the database driver
+ *
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($config = array())
+ {
+ parent::__construct('CI_DB_pdo_driver', $config);
+ }
+} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/postgre.php b/tests/mocks/database/drivers/postgre.php
new file mode 100644
index 000000000..5a45115fa
--- /dev/null
+++ b/tests/mocks/database/drivers/postgre.php
@@ -0,0 +1,17 @@
+<?php
+
+class Mock_Database_Drivers_Postgre extends Mock_Database_DB_Driver {
+
+ /**
+ * Instantiate the database driver
+ *
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($config = array())
+ {
+ parent::__construct('CI_DB_postgre_driver', $config);
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/database/drivers/sqlite.php b/tests/mocks/database/drivers/sqlite.php
new file mode 100644
index 000000000..512467520
--- /dev/null
+++ b/tests/mocks/database/drivers/sqlite.php
@@ -0,0 +1,17 @@
+<?php
+
+class Mock_Database_Drivers_Sqlite extends Mock_Database_DB_Driver {
+
+ /**
+ * Instantiate the database driver
+ *
+ * @param string DB Driver class name
+ * @param array DB configuration to set
+ * @return void
+ */
+ public function __construct($config = array())
+ {
+ parent::__construct('CI_DB_sqlite3_driver', $config);
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
new file mode 100644
index 000000000..18e1ddd4d
--- /dev/null
+++ b/tests/mocks/database/schema/skeleton.php
@@ -0,0 +1,147 @@
+<?php
+
+class Mock_Database_Schema_Skeleton {
+
+ /**
+ * @var object Database Holder
+ */
+ public static $db;
+
+ /**
+ * @var object Forge Holder
+ */
+ public static $forge;
+
+ /**
+ * @var object Driver Holder
+ */
+ public static $driver;
+
+ /**
+ * Initialize both database and forge components
+ */
+ public static function init($driver)
+ {
+ if (empty(static::$db) && empty(static::$forge))
+ {
+ $config = Mock_Database_DB::config($driver);
+ $connection = new Mock_Database_DB($config);
+ $db = Mock_Database_DB::DB($connection->set_dsn($driver), TRUE);
+
+ CI_TestCase::instance()->ci_instance_var('db', $db);
+
+ $loader = new Mock_Core_Loader();
+ $loader->dbforge();
+ $forge = CI_TestCase::instance()->ci_instance_var('dbforge');
+
+ static::$db = $db;
+ static::$forge = $forge;
+ static::$driver = $driver;
+ }
+
+ return static::$db;
+ }
+
+ /**
+ * Create the dummy tables
+ *
+ * @return void
+ */
+ public static function create_tables()
+ {
+ // User Table
+ static::$forge->add_field(array(
+ 'id' => array(
+ 'type' => 'INTEGER',
+ 'constraint' => 3
+ ),
+ 'name' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40
+ ),
+ 'email' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 100
+ ),
+ 'country' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40
+ )
+ ));
+ static::$forge->add_key('id', TRUE);
+ static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE));
+
+ // Job Table
+ static::$forge->add_field(array(
+ 'id' => array(
+ 'type' => 'INTEGER',
+ 'constraint' => 3
+ ),
+ 'name' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40
+ ),
+ 'description' => array(
+ 'type' => 'TEXT'
+ )
+ ));
+ static::$forge->add_key('id', TRUE);
+ static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE));
+
+ // Misc Table
+ static::$forge->add_field(array(
+ 'id' => array(
+ 'type' => 'INTEGER',
+ 'constraint' => 3
+ ),
+ 'key' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40
+ ),
+ 'value' => array(
+ 'type' => 'TEXT'
+ )
+ ));
+ static::$forge->add_key('id', TRUE);
+ static::$forge->create_table('misc', (strpos(static::$driver, 'pgsql') === FALSE));
+ }
+
+ /**
+ * Create the dummy datas
+ *
+ * @return void
+ */
+ public static function create_data()
+ {
+ // Job Data
+ $data = array(
+ 'user' => array(
+ array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com', 'country' => 'US'),
+ array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com', 'country' => 'Iran'),
+ array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com', 'country' => 'US'),
+ array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com', 'country' => 'UK')
+ ),
+ 'job' => array(
+ array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'),
+ array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'),
+ array('id' => 3, 'name' => 'Accountant', 'description' => 'Boring job, but you will get free snack at lunch'),
+ array('id' => 4, 'name' => 'Musician', 'description' => 'Only Coldplay can actually called Musician')
+ ),
+ 'misc' => array(
+ array('id' => 1, 'key' => '\\xxxfoo456', 'value' => 'Entry with \\xxx'),
+ array('id' => 2, 'key' => '\\%foo456', 'value' => 'Entry with \\%')
+ )
+ );
+
+ foreach ($data as $table => $dummy_data)
+ {
+ static::$db->truncate($table);
+
+ foreach ($dummy_data as $single_dummy_data)
+ {
+ static::$db->insert($table, $single_dummy_data);
+ }
+ }
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/libraries/encrypt.php b/tests/mocks/libraries/encrypt.php
new file mode 100644
index 000000000..f1859398f
--- /dev/null
+++ b/tests/mocks/libraries/encrypt.php
@@ -0,0 +1,16 @@
+<?php
+
+class Mock_Libraries_Encrypt extends CI_Encrypt {
+
+ // Overide inaccesible protected method
+ public function __call($method, $params)
+ {
+ if (is_callable(array($this, '_'.$method)))
+ {
+ return call_user_func_array(array($this, '_'.$method), $params);
+ }
+
+ throw new BadMethodCallException('Method '.$method.' was not found');
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/libraries/parser.php b/tests/mocks/libraries/parser.php
new file mode 100644
index 000000000..81dcfb37e
--- /dev/null
+++ b/tests/mocks/libraries/parser.php
@@ -0,0 +1,3 @@
+<?php
+
+class Mock_Libraries_Parser extends CI_Parser {} \ No newline at end of file
diff --git a/tests/mocks/libraries/table.php b/tests/mocks/libraries/table.php
new file mode 100644
index 000000000..87c278bce
--- /dev/null
+++ b/tests/mocks/libraries/table.php
@@ -0,0 +1,16 @@
+<?php
+
+class Mock_Libraries_Table extends CI_Table {
+
+ // Overide inaccesible protected method
+ public function __call($method, $params)
+ {
+ if (is_callable(array($this, '_'.$method)))
+ {
+ return call_user_func_array(array($this, '_'.$method), $params);
+ }
+
+ throw new BadMethodCallException('Method '.$method.' was not found');
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/libraries/typography.php b/tests/mocks/libraries/typography.php
new file mode 100644
index 000000000..0f76c5745
--- /dev/null
+++ b/tests/mocks/libraries/typography.php
@@ -0,0 +1,3 @@
+<?php
+
+class Mock_Libraries_Typography extends CI_Typography {} \ No newline at end of file
diff --git a/tests/mocks/libraries/useragent.php b/tests/mocks/libraries/useragent.php
new file mode 100644
index 000000000..c957cde5b
--- /dev/null
+++ b/tests/mocks/libraries/useragent.php
@@ -0,0 +1,3 @@
+<?php
+
+class Mock_Libraries_UserAgent extends CI_User_agent {} \ No newline at end of file
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
new file mode 100644
index 000000000..56cb8841c
--- /dev/null
+++ b/tests/phpunit.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit
+ bootstrap="./Bootstrap.php"
+ colors="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnError="false"
+ stopOnFailure="false"
+ stopOnIncomplete="false"
+ stopOnSkipped="false">
+ <testsuites>
+ <testsuite name="CodeIgniter Core Test Suite">
+ <directory suffix="test.php">./codeigniter/core</directory>
+ <directory suffix="test.php">./codeigniter/helpers</directory>
+ <directory suffix="test.php">./codeigniter/libraries</directory>
+ </testsuite>
+ </testsuites>
+ <filters>
+ <blacklist>
+ <directory suffix=".php">PEAR_INSTALL_DIR</directory>
+ <directory suffix=".php">PHP_LIBDIR</directory>
+ </blacklist>
+ </filters>
+</phpunit> \ No newline at end of file
diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml
new file mode 100644
index 000000000..38c8eba48
--- /dev/null
+++ b/tests/travis/mysql.phpunit.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit
+ bootstrap="../Bootstrap.php"
+ colors="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnError="false"
+ stopOnFailure="false"
+ stopOnIncomplete="false"
+ stopOnSkipped="false">
+ <php>
+ <const name="DB_DRIVER" value="mysql"/>
+ </php>
+ <testsuites>
+ <testsuite name="CodeIgniter Core Test Suite">
+ <directory suffix="test.php">../codeigniter</directory>
+ </testsuite>
+ </testsuites>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">../../system</directory>
+ </whitelist>
+ </filter>
+</phpunit> \ No newline at end of file
diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml
new file mode 100644
index 000000000..c3113a66f
--- /dev/null
+++ b/tests/travis/pdo/mysql.phpunit.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit
+ bootstrap="../../Bootstrap.php"
+ colors="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnError="false"
+ stopOnFailure="false"
+ stopOnIncomplete="false"
+ stopOnSkipped="false">
+ <php>
+ <const name="DB_DRIVER" value="pdo/mysql"/>
+ </php>
+ <testsuites>
+ <testsuite name="CodeIgniter Core Test Suite">
+ <directory suffix="test.php">../../codeigniter</directory>
+ </testsuite>
+ </testsuites>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">../../../system</directory>
+ </whitelist>
+ </filter>
+</phpunit> \ No newline at end of file
diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml
new file mode 100644
index 000000000..232025523
--- /dev/null
+++ b/tests/travis/pdo/pgsql.phpunit.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit
+ bootstrap="../../Bootstrap.php"
+ colors="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnError="false"
+ stopOnFailure="false"
+ stopOnIncomplete="false"
+ stopOnSkipped="false">
+ <php>
+ <const name="DB_DRIVER" value="pdo/pgsql"/>
+ </php>
+ <testsuites>
+ <testsuite name="CodeIgniter Core Test Suite">
+ <directory suffix="test.php">../../codeigniter</directory>
+ </testsuite>
+ </testsuites>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">../../../system</directory>
+ </whitelist>
+ </filter>
+</phpunit> \ No newline at end of file
diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml
new file mode 100644
index 000000000..3d1256721
--- /dev/null
+++ b/tests/travis/pdo/sqlite.phpunit.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit
+ bootstrap="../../Bootstrap.php"
+ colors="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnError="false"
+ stopOnFailure="false"
+ stopOnIncomplete="false"
+ stopOnSkipped="false">
+ <php>
+ <const name="DB_DRIVER" value="pdo/sqlite"/>
+ </php>
+ <testsuites>
+ <testsuite name="CodeIgniter Core Test Suite">
+ <directory suffix="test.php">../../codeigniter</directory>
+ </testsuite>
+ </testsuites>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">../../../system</directory>
+ </whitelist>
+ </filter>
+</phpunit> \ No newline at end of file
diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml
new file mode 100644
index 000000000..51e433d76
--- /dev/null
+++ b/tests/travis/pgsql.phpunit.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit
+ bootstrap="../Bootstrap.php"
+ colors="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnError="false"
+ stopOnFailure="false"
+ stopOnIncomplete="false"
+ stopOnSkipped="false">
+ <php>
+ <const name="DB_DRIVER" value="pgsql"/>
+ </php>
+ <testsuites>
+ <testsuite name="CodeIgniter Core Test Suite">
+ <directory suffix="test.php">../codeigniter</directory>
+ </testsuite>
+ </testsuites>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">../../system</directory>
+ </whitelist>
+ </filter>
+</phpunit> \ No newline at end of file
diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml
new file mode 100644
index 000000000..701165734
--- /dev/null
+++ b/tests/travis/sqlite.phpunit.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit
+ bootstrap="../Bootstrap.php"
+ colors="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnError="false"
+ stopOnFailure="false"
+ stopOnIncomplete="false"
+ stopOnSkipped="false">
+ <php>
+ <const name="DB_DRIVER" value="sqlite"/>
+ </php>
+ <testsuites>
+ <testsuite name="CodeIgniter Core Test Suite">
+ <directory suffix="test.php">../codeigniter</directory>
+ </testsuite>
+ </testsuites>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">../../system</directory>
+ </whitelist>
+ </filter>
+</phpunit> \ No newline at end of file