summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Bootstrap.php21
-rw-r--r--tests/README.md164
-rw-r--r--tests/codeigniter/Setup_test.php13
-rw-r--r--tests/codeigniter/core/Common_test.php13
-rw-r--r--tests/codeigniter/core/Config_test.php93
-rw-r--r--tests/codeigniter/core/Lang_test.php31
-rw-r--r--tests/codeigniter/core/Loader_test.php235
-rw-r--r--tests/codeigniter/core/URI_test.php313
-rw-r--r--tests/codeigniter/database/DB_test.php49
-rw-r--r--tests/codeigniter/database/query_builder/.gitkeep0
-rw-r--r--tests/codeigniter/helpers/array_helper_test.php47
-rw-r--r--tests/codeigniter/helpers/date_helper_test.php288
-rw-r--r--tests/codeigniter/helpers/directory_helper_test.php41
-rw-r--r--tests/codeigniter/helpers/email_helper_test.php18
-rw-r--r--tests/codeigniter/helpers/file_helper_test.php156
-rw-r--r--tests/codeigniter/helpers/form_helper_test.php252
-rw-r--r--tests/codeigniter/helpers/html_helper_test.php80
-rw-r--r--tests/codeigniter/helpers/inflector_helper_test.php95
-rw-r--r--tests/codeigniter/helpers/number_helper_test.php77
-rw-r--r--tests/codeigniter/helpers/path_helper_test.php32
-rw-r--r--tests/codeigniter/helpers/string_helper_test.php147
-rw-r--r--tests/codeigniter/helpers/text_helper_test.php159
-rw-r--r--tests/codeigniter/helpers/url_helper_test.php75
-rw-r--r--tests/codeigniter/helpers/xml_helper_test.php15
-rw-r--r--tests/codeigniter/libraries/Parser_test.php110
-rw-r--r--tests/codeigniter/libraries/Table_test.php296
-rw-r--r--tests/codeigniter/libraries/Typography_test.php188
-rw-r--r--tests/codeigniter/libraries/Useragent_test.php87
-rw-r--r--tests/mocks/autoloader.php79
-rw-r--r--tests/mocks/ci_testcase.php196
-rw-r--r--tests/mocks/core/common.php132
-rw-r--r--tests/mocks/core/loader.php30
-rw-r--r--tests/mocks/core/uri.php25
-rwxr-xr-xtests/mocks/database/ci_test.sqlitebin0 -> 17408 bytes
-rw-r--r--tests/mocks/database/config/mysql.php34
-rw-r--r--tests/mocks/database/config/pgsql.php34
-rw-r--r--tests/mocks/database/config/sqlite.php35
-rw-r--r--tests/mocks/database/db.php101
-rw-r--r--tests/mocks/database/schema/.gitkeep0
-rw-r--r--tests/mocks/libraries/parser.php3
-rw-r--r--tests/mocks/libraries/table.php15
-rw-r--r--tests/mocks/libraries/typography.php3
-rw-r--r--tests/mocks/libraries/useragent.php3
-rw-r--r--tests/travis/mysql.phpunit.xml37
-rw-r--r--tests/travis/pgsql.phpunit.xml37
-rw-r--r--tests/travis/sqlite.phpunit.xml37
46 files changed, 3896 insertions, 0 deletions
diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php
new file mode 100644
index 000000000..9f89d1be8
--- /dev/null
+++ b/tests/Bootstrap.php
@@ -0,0 +1,21 @@
+<?php
+
+// Errors on full!
+ini_set('display_errors', 1);
+error_reporting(E_ALL | E_STRICT);
+
+$dir = realpath(dirname(__FILE__));
+
+// Path constants
+define('PROJECT_BASE', realpath($dir.'/../').'/');
+define('BASEPATH', PROJECT_BASE.'system/');
+define('APPPATH', PROJECT_BASE.'application/');
+define('VIEWPATH', PROJECT_BASE.'');
+
+// Prep our test environment
+require_once 'vfsStream/vfsStream.php';
+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..6d83c34d8
--- /dev/null
+++ b/tests/README.md
@@ -0,0 +1,164 @@
+# CodeIgniter Unit Tests #
+
+Status : [![Build Status](https://secure.travis-ci.org/EllisLab/CodeIgniter.png?branch=feature/unit-tests)](http://travis-ci.org/EllisLab/CodeIgniter)
+
+*Do not merge to default until these issues have been addressed*
+
+- Clean up naming conventions
+- Figure out config stuff
+- Figure out database testing
+
+### 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.php-tools.net
+ pear install pat/vfsStream-alpha
+
+#### 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.php-tools.net
+
+ # Finally install PHPUnit and vfsStream (including dependencies)
+ pear install --alldeps phpunit/PHPUnit
+ pear install --alldeps pat/vfsStream-alpha
+
+ # 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..550245f2f
--- /dev/null
+++ b/tests/codeigniter/Setup_test.php
@@ -0,0 +1,13 @@
+<?php
+
+class Setup_test extends PHPUnit_Framework_TestCase {
+
+ function test_nonsense()
+ {
+ $this->markTestIncomplete('not implemented');
+ // ensure that our bootstrapped test environment
+ // is a good representation of an isolated CI install
+ //die('here');
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php
new file mode 100644
index 000000000..dded2e824
--- /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..30f0cc61d
--- /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/Lang_test.php b/tests/codeigniter/core/Lang_test.php
new file mode 100644
index 000000000..a414f0ace
--- /dev/null
+++ b/tests/codeigniter/core/Lang_test.php
@@ -0,0 +1,31 @@
+<?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'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_line()
+ {
+ $this->assertTrue($this->lang->load('profiler', 'english'));
+ $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..43008651e
--- /dev/null
+++ b/tests/codeigniter/core/Loader_test.php
@@ -0,0 +1,235 @@
+<?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()
+ {
+ $vars = array(
+ 'foo' => 'bar'
+ );
+
+ $this->assertNull($this->load->vars($vars));
+ $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);
+ }
+
+ // --------------------------------------------------------------------
+
+}
diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php
new file mode 100644
index 000000000..e340ddf73
--- /dev/null
+++ b/tests/codeigniter/core/URI_test.php
@@ -0,0 +1,313 @@
+<?php
+
+class URI_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->uri = new Mock_Core_URI();
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_set_uri_string()
+ {
+ // Slashes get killed
+ $this->uri->_set_uri_string('/');
+
+ $a = '';
+ $b =& $this->uri->uri_string;
+
+ $this->assertEquals($a, $b);
+
+ $this->uri->_set_uri_string('nice/uri');
+
+ $a = 'nice/uri';
+
+ $this->assertEquals($a, $b);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_fetch_uri_string()
+ {
+ define('SELF', 'index.php');
+
+ // uri_protocol: AUTO
+ $this->uri->config->set_item('uri_protocol', 'AUTO');
+
+ // Test a variety of request uris
+ $requests = array(
+ '/index.php/controller/method' => 'controller/method',
+ '/index.php?/controller/method' => 'controller/method',
+ '/index.php?/controller/method/?var=foo' => 'controller/method'
+ );
+
+ foreach($requests as $request => $expected)
+ {
+ $_SERVER['SCRIPT_NAME'] = '/index.php';
+ $_SERVER['REQUEST_URI'] = $request;
+
+ $this->uri->_fetch_uri_string();
+ $this->assertEquals($expected, $this->uri->uri_string );
+ }
+
+ // Test a subfolder
+ $_SERVER['SCRIPT_NAME'] = '/subfolder/index.php';
+ $_SERVER['REQUEST_URI'] = '/subfolder/index.php/controller/method';
+
+ $this->uri->_fetch_uri_string();
+
+ $a = 'controller/method';
+ $b = $this->uri->uri_string;
+
+ $this->assertEquals($a, $b);
+
+ // death to request uri
+ unset($_SERVER['REQUEST_URI']);
+
+ // life to path info
+ $_SERVER['PATH_INFO'] = '/controller/method/';
+
+ $this->uri->_fetch_uri_string();
+
+ $a = '/controller/method/';
+ $b =& $this->uri->uri_string;
+
+ $this->assertEquals($a, $b);
+
+ // death to path info
+ // At this point your server must be seriously drunk
+ unset($_SERVER['PATH_INFO']);
+
+ $_SERVER['QUERY_STRING'] = '/controller/method/';
+
+ $this->uri->_fetch_uri_string();
+
+ $a = '/controller/method/';
+ $b = $this->uri->uri_string;
+
+ $this->assertEquals($a, $b);
+
+ // At this point your server is a labotomy victim
+
+ unset($_SERVER['QUERY_STRING']);
+
+ $_GET['/controller/method/'] = '';
+
+ $this->uri->_fetch_uri_string();
+ $this->assertEquals($a, $b);
+
+ // Test coverage implies that these will work
+ // uri_protocol: REQUEST_URI
+ // uri_protocol: CLI
+
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_explode_segments()
+ {
+ // Lets test the function's ability to clean up this mess
+ $uris = array(
+ 'test/uri' => array('test', 'uri'),
+ '/test2/uri2' => array('test2', 'uri2'),
+ '//test3/test3///' => array('test3', 'test3')
+ );
+
+ foreach($uris as $uri => $a)
+ {
+ $this->uri->segments = array();
+ $this->uri->uri_string = $uri;
+ $this->uri->_explode_segments();
+
+ $b = $this->uri->segments;
+
+ $this->assertEquals($a, $b);
+ }
+
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_filter_uri()
+ {
+ $this->uri->config->set_item('enable_query_strings', FALSE);
+ $this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-');
+
+ $str_in = 'abc01239~%.:_-';
+ $str = $this->uri->_filter_uri($str_in);
+
+ $this->assertEquals($str, $str_in);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_filter_uri_escaping()
+ {
+ // ensure escaping even if dodgey characters are permitted
+
+ $this->uri->config->set_item('enable_query_strings', FALSE);
+ $this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-()$');
+
+ $str = $this->uri->_filter_uri('$destroy_app(foo)');
+
+ $this->assertEquals($str, '&#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');
+
+ $a = array('a' => '1', 'b' => '2', 'c' => '3');
+ $b = $this->uri->uri_to_assoc(1);
+ $this->assertEquals($a, $b);
+
+ $a = array('b' => '2', 'c' => '3');
+ $b = $this->uri->uri_to_assoc(3);
+ $this->assertEquals($a, $b);
+
+
+ $this->uri->keyval = array(); // reset cache
+
+ $this->uri->segments = array('a', '1', 'b', '2', 'c');
+
+ $a = array('a' => '1', 'b' => '2', 'c' => FALSE);
+ $b = $this->uri->uri_to_assoc(1);
+ $this->assertEquals($a, $b);
+
+ $this->uri->keyval = array(); // reset cache
+
+ $this->uri->segments = array('a', '1');
+
+ // test default
+ $a = array('a' => '1', 'b' => FALSE);
+ $b = $this->uri->uri_to_assoc(1, array('a', 'b'));
+ $this->assertEquals($a, $b);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_ruri_to_assoc()
+ {
+ $this->uri->rsegments = array('x', '1', 'y', '2', 'z', '3');
+
+ $a = array('x' => '1', 'y' => '2', 'z' => '3');
+ $b = $this->uri->ruri_to_assoc(1);
+ $this->assertEquals($a, $b);
+
+ $a = array('y' => '2', 'z' => '3');
+ $b = $this->uri->ruri_to_assoc(3);
+ $this->assertEquals($a, $b);
+
+
+ $this->uri->keyval = array(); // reset cache
+
+ $this->uri->rsegments = array('x', '1', 'y', '2', 'z');
+
+ $a = array('x' => '1', 'y' => '2', 'z' => FALSE);
+ $b = $this->uri->ruri_to_assoc(1);
+ $this->assertEquals($a, $b);
+
+ $this->uri->keyval = array(); // reset cache
+
+ $this->uri->rsegments = array('x', '1');
+
+ // test default
+ $a = array('x' => '1', 'y' => FALSE);
+ $b = $this->uri->ruri_to_assoc(1, array('x', 'y'));
+ $this->assertEquals($a, $b);
+
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_assoc_to_uri()
+ {
+ $this->uri->config->set_item('uri_string_slashes', 'none');
+
+ $arr = array('a' => 1, 'b' => 2);
+ $a = 'a/1/b/2';
+ $b = $this->uri->assoc_to_uri($arr);
+ $this->assertEquals($a, $b);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_slash_segment()
+ {
+ $this->uri->segments[1] = 'segment';
+ $this->uri->rsegments[1] = 'segment';
+
+ $a = '/segment/';
+ $b = $this->uri->slash_segment(1, 'both');
+ $this->assertEquals($a, $b);
+ $b = $this->uri->slash_rsegment(1, 'both');
+ $this->assertEquals($a, $b);
+
+ $a = '/segment';
+ $b = $this->uri->slash_segment(1, 'leading');
+ $this->assertEquals($a, $b);
+ $b = $this->uri->slash_rsegment(1, 'leading');
+ $this->assertEquals($a, $b);
+
+ $a = 'segment/';
+ $b = $this->uri->slash_segment(1, 'trailing');
+ $this->assertEquals($a, $b);
+ $b = $this->uri->slash_rsegment(1, 'trailing');
+ $this->assertEquals($a, $b);
+ }
+
+
+}
+// END URI_test Class
+
+/* End of file URI_test.php */
+/* Location: ./tests/core/URI_test.php */
diff --git a/tests/codeigniter/database/DB_test.php b/tests/codeigniter/database/DB_test.php
new file mode 100644
index 000000000..9b93e223d
--- /dev/null
+++ b/tests/codeigniter/database/DB_test.php
@@ -0,0 +1,49 @@
+<?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/.gitkeep b/tests/codeigniter/database/query_builder/.gitkeep
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/.gitkeep
diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php
new file mode 100644
index 000000000..9cd15960f
--- /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..17d1ef21e
--- /dev/null
+++ b/tests/codeigniter/helpers/date_helper_test.php
@@ -0,0 +1,288 @@
+<?php
+
+class Date_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->helper('date');
+ }
+
+ // ------------------------------------------------------------------------
+
+ 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);
+
+ $expected = time();
+ $test = now();
+ $this->assertEquals($expected, $test);
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_now_gmt()
+ {
+ // This stub job, is simply to cater $config['time_reference']
+ $config = $this->getMock('CI_Config');
+ $config->expects($this->any())
+ ->method('item')
+ ->will($this->returnValue('gmt'));
+
+ // Add the stub to our stdClass
+ $this->ci_instance_var('config', $config);
+
+ $t = time();
+ $expected = mktime(gmdate("H", $t), gmdate("i", $t), gmdate("s", $t), gmdate("m", $t), gmdate("d", $t), gmdate("Y", $t));
+ $test = now();
+ $this->assertEquals($expected, $test);
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_mdate()
+ {
+ $time = time();
+ $expected = date("Y-m-d - h:i a", $time);
+ $test = mdate("%Y-%m-%d - %h:%i %a", $time);
+ $this->assertEquals($expected, $test);
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rfc822()
+ {
+ $time = time();
+ $format = 'DATE_RFC822';
+ $expected = date("D, d M y H:i:s O", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_atom()
+ {
+ $time = time();
+ $format = 'DATE_ATOM';
+ $expected = date("Y-m-d\TH:i:sO", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_cookie()
+ {
+ $time = time();
+ $format = 'DATE_COOKIE';
+ $expected = date("l, d-M-y H:i:s \U\T\C", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_iso8601()
+ {
+ $time = time();
+ $format = 'DATE_ISO8601';
+ $expected = date("Y-m-d\TH:i:sO", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rfc850()
+ {
+ $time = time();
+ $format = 'DATE_RFC850';
+ $expected = date("l, d-M-y H:i:s \U\T\C", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rfc1036()
+ {
+ $time = time();
+ $format = 'DATE_RFC1036';
+ $expected = date("D, d M y H:i:s O", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rfc1123()
+ {
+ $time = time();
+ $format = 'DATE_RFC1123';
+ $expected = date("D, d M Y H:i:s O", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rfc2822()
+ {
+ $time = time();
+ $format = 'DATE_RFC2822';
+ $expected = date("D, d M Y H:i:s O", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_rss()
+ {
+ $time = time();
+ $format = 'DATE_RSS';
+ $expected = date("D, d M Y H:i:s O", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_standard_date_w3c()
+ {
+ $time = time();
+ $format = 'DATE_W3C';
+ $expected = date("Y-m-d\TH:i:sO", $time);
+ $this->assertEquals($expected, standard_date($format, $time));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_timespan()
+ {
+ $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()
+ {
+ $t = time();
+ $expected = mktime(gmdate("H", $t), gmdate("i", $t), gmdate("s", $t), gmdate("m", $t), gmdate("d", $t), gmdate("Y", $t));
+ $this->assertEquals($expected, local_to_gmt($t));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_gmt_to_local()
+ {
+ $timestamp = '1140153693';
+ $timezone = 'UM8';
+ $daylight_saving = TRUE;
+
+ $this->assertEquals(1140128493, gmt_to_local($timestamp, $timezone, $daylight_saving));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_mysql_to_unix()
+ {
+ $time = time();
+ $this->assertEquals($time,
+ mysql_to_unix(date("Y-m-d H:i:s", $time)));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_unix_to_human()
+ {
+ $time = time();
+ $this->assertEquals(date("Y-m-d h:i A", $time), unix_to_human($time));
+ $this->assertEquals(date("Y-m-d h:i:s A", $time), unix_to_human($time, TRUE, 'us'));
+ $this->assertEquals(date("Y-m-d H:i:s", $time), unix_to_human($time, TRUE, 'eu'));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_human_to_unix()
+ {
+ $date = '2000-12-31 10:00:00 PM';
+ $expected = strtotime($date);
+ $this->assertEquals($expected, human_to_unix($date));
+ $this->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..3937d2913
--- /dev/null
+++ b/tests/codeigniter/helpers/directory_helper_test.php
@@ -0,0 +1,41 @@
+<?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 recursion depth behavior
+ $expected = array('libraries');
+
+ $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), 1));
+
+ // test detection of hidden files
+ $expected = array('libraries' => array('benchmark.html', 'database' =>
+ array('active_record.html', 'binds.html'), 'email.html', '.hiddenfile.txt'));
+
+ $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), FALSE, TRUE));
+ }
+}
+
+/* End of file directory_helper_test.php */ \ No newline at end of file
diff --git a/tests/codeigniter/helpers/email_helper_test.php b/tests/codeigniter/helpers/email_helper_test.php
new file mode 100644
index 000000000..a01f3d5af
--- /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..4b9c29485
--- /dev/null
+++ b/tests/codeigniter/helpers/file_helper_test.php
@@ -0,0 +1,156 @@
+<?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.
+ $vals = 'name, server_path, size, date, readable, writable, executable, fileperms';
+ $this->_test_get_file_info($vals);
+ }
+
+ private function _test_get_file_info($vals)
+ {
+ $content = 'Jack and Jill went up the mountain to fight a billy goat.';
+ $last_modified = time() - 86400;
+
+ $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
+ ->lastModified($last_modified)
+ ->at($this->_test_dir);
+
+ $ret_values = array(
+ 'name' => 'my_file.txt',
+ 'server_path' => 'vfs://my_file.txt',
+ 'size' => 57,
+ 'date' => $last_modified,
+ 'readable' => TRUE,
+ 'writable' => TRUE,
+ 'executable' => TRUE,
+ 'fileperms' => 33279
+ );
+
+ $info = get_file_info(vfsStream::url('my_file.txt'), $vals);
+
+ foreach ($info as $k => $v)
+ {
+ $this->assertEquals($ret_values[$k], $v);
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ // Skipping for now, as it's not implemented in vfsStreamWrapper
+ // flock(): vfsStreamWrapper::stream_lock is not implemented!
+
+ // public function test_write_file()
+ // {
+ // if ( ! defined('FOPEN_WRITE_CREATE_DESTRUCTIVE'))
+ // {
+ // define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb');
+ // }
+ //
+ // $content = 'Jack and Jill went up the mountain to fight a billy goat.';
+ //
+ // $file = vfsStream::newFile('write.txt', 0777)->withContent('')
+ // ->lastModified(time() - 86400)
+ // ->at($this->_test_dir);
+ //
+ // $this->assertTrue(write_file(vfsStream::url('write.txt'), $content));
+ //
+ // }
+
+ // --------------------------------------------------------------------
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php
new file mode 100644
index 000000000..80bace9d1
--- /dev/null
+++ b/tests/codeigniter/helpers/form_helper_test.php
@@ -0,0 +1,252 @@
+<?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;
+
+ $cars_on_sale = array('volvo', 'audi');
+
+ $this->assertEquals($expected, form_dropdown('cars', $options, $cars_on_sale));
+
+ }
+
+ 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..28974b0f8
--- /dev/null
+++ b/tests/codeigniter/helpers/html_helper_test.php
@@ -0,0 +1,80 @@
+<?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($expect, ul($list));
+
+
+ $expect = <<<EOH
+<ul class="test">
+ <li>foo</li>
+ <li>bar</li>
+</ul>
+
+EOH;
+
+ $expect = ltrim($expect);
+
+ $list = array('foo', 'bar');
+
+ $this->assertEquals($expect, ul($list, 'class="test"'));
+
+ $this->assertEquals($expect, ul($list, array('class' => 'test')));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_NBS()
+ {
+ $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..9e9478711
--- /dev/null
+++ b/tests/codeigniter/helpers/inflector_helper_test.php
@@ -0,0 +1,95 @@
+<?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..4bb9a918a
--- /dev/null
+++ b/tests/codeigniter/helpers/number_helper_test.php
@@ -0,0 +1,77 @@
+<?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));
+ }
+}
+
+// EOF \ 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..632f57501
--- /dev/null
+++ b/tests/codeigniter/helpers/path_helper_test.php
@@ -0,0 +1,32 @@
+<?php
+
+class Path_helper_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $this->helper('path');
+ }
+
+ public function test_set_realpath()
+ {
+ $expected = getcwd() . DIRECTORY_SEPARATOR;
+ $this->assertEquals($expected, set_realpath(getcwd()));
+ }
+
+ public function test_set_realpath_nonexistent_directory()
+ {
+ $expected = '/path/to/nowhere';
+ $this->assertEquals($expected, set_realpath('/path/to/nowhere', FALSE));
+ }
+
+ public function test_set_realpath_error_trigger()
+ {
+ $this->setExpectedException(
+ 'RuntimeException', 'CI Error: Not a valid path: /path/to/nowhere'
+ );
+
+ set_realpath('/path/to/nowhere', TRUE);
+ }
+}
+
+/* End of file path_helper_test.php */ \ No newline at end of file
diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php
new file mode 100644
index 000000000..29c3d6594
--- /dev/null
+++ b/tests/codeigniter/helpers/string_helper_test.php
@@ -0,0 +1,147 @@
+<?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..584066b0c
--- /dev/null
+++ b/tests/codeigniter/helpers/text_helper_test.php
@@ -0,0 +1,159 @@
+<?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));
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ 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()
+ {
+ $code = '<?php var_dump($this); ?>';
+ $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($code));
+ }
+
+ // ------------------------------------------------------------------------
+
+ 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_ellipsizing()
+ {
+ $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));
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+} \ 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..c561809ce
--- /dev/null
+++ b/tests/codeigniter/helpers/url_helper_test.php
@@ -0,0 +1,75 @@
+<?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..a83fef91e
--- /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/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php
new file mode 100644
index 000000000..c3d88fa85
--- /dev/null
+++ b/tests/codeigniter/libraries/Parser_test.php
@@ -0,0 +1,110 @@
+<?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}";
+
+ $result = "Super Heroes\nyes\nno";
+
+ $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
+ }
+
+ // --------------------------------------------------------------------
+
+ private function _mismatched_var_pair()
+ {
+ $data = array(
+ 'title' => 'Super Heroes',
+ 'powers' => array(
+ array(
+ 'invisibility' => 'yes',
+ 'flying' => 'no'),
+ )
+ );
+
+ $template = "{title}\n{powers}{invisibility}\n{flying}";
+
+ $result = "Super Heroes\n{powers}{invisibility}\n{flying}";
+
+ $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
+ }
+
+ // --------------------------------------------------------------------
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php
new file mode 100644
index 000000000..13f338c6b
--- /dev/null
+++ b/tests/codeigniter/libraries/Table_test.php
@@ -0,0 +1,296 @@
+<?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();
+
+ $expected_heading = array(
+ array('data' => 'name'),
+ array('data' => 'color'),
+ array('data' => 'number')
+ );
+
+ $expected_second = array(
+ array('data' => 'Katie'),
+ array('data' => 'Blue'),
+ );
+
+ $this->table->set_from_array($data);
+ $this->assertEquals(count($this->table->rows), 2);
+
+ $this->assertEquals(
+ $expected_heading,
+ $this->table->heading
+ );
+
+ $this->assertEquals(
+ $expected_second,
+ $this->table->rows[1]
+ );
+ }
+
+ function 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;
+ };
+
+ $expected_heading = array(
+ array('data' => 'name'),
+ array('data' => 'email')
+ );
+
+ $expected_second = array(
+ 'name' => array('data' => 'Foo Bar'),
+ 'email' => array('data' => 'foo@bar.com'),
+ );
+
+ $this->table->set_from_object($query);
+
+ $this->assertEquals(
+ $expected_heading,
+ $this->table->heading
+ );
+
+ $this->assertEquals(
+ $expected_second,
+ $this->table->rows[1]
+ );
+ }
+
+ // Test main generate method
+ // --------------------------------------------------------------------
+} \ 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..250aefb24
--- /dev/null
+++ b/tests/codeigniter/libraries/Typography_test.php
@@ -0,0 +1,188 @@
+<?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..7dad7ac54
--- /dev/null
+++ b/tests/codeigniter/libraries/Useragent_test.php
@@ -0,0 +1,87 @@
+<?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..dd5929206
--- /dev/null
+++ b/tests/mocks/autoloader.php
@@ -0,0 +1,79 @@
+<?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 :
+//
+// include_once('Mock_Core_Loader') // Will load ./mocks/core/loader.php
+// $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',
+ '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;
+ }
+ else
+ {
+ $class = strtolower($class);
+ }
+ }
+
+ $file = $dir.$class.'.php';
+
+ if ( ! file_exists($file))
+ {
+ $trace = debug_backtrace();
+
+ // If the autoload call came from `class_exists` or `file_exists`,
+ // we skipped and return FALSE
+ if ($trace[2]['function'] == 'class_exists' OR $trace[2]['function'] == 'file_exists')
+ {
+ 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..f327e6b07
--- /dev/null
+++ b/tests/mocks/ci_testcase.php
@@ -0,0 +1,196 @@
+<?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;
+ }
+
+ // --------------------------------------------------------------------
+
+ function ci_set_config($key, $val = '')
+ {
+ if (is_array($key))
+ {
+ $this->ci_config = $key;
+ }
+ else
+ {
+ $this->ci_config[$key] = $val;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ function ci_get_config()
+ {
+ return $this->ci_config;
+ }
+
+ // --------------------------------------------------------------------
+
+ function ci_instance($obj = FALSE)
+ {
+ if ( ! is_object($obj))
+ {
+ return $this->ci_instance;
+ }
+
+ $this->ci_instance = $obj;
+ }
+
+ // --------------------------------------------------------------------
+
+ 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.
+ */
+ 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
+ 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();
+ }
+
+ // --------------------------------------------------------------------
+
+ 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.
+ */
+ function __call($method, $args)
+ {
+ if ($this->{$method} instanceof Closure)
+ {
+ return call_user_func_array($this->{$method},$args);
+ }
+ else
+ {
+ return parent::__call($method, $args);
+ }
+ }
+}
+
+// EOF \ 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..fc94d7fff
--- /dev/null
+++ b/tests/mocks/core/common.php
@@ -0,0 +1,132 @@
+<?php
+
+// Set up the global CI functions in their most minimal core representation
+
+function &get_instance()
+{
+ $test = CI_TestCase::instance();
+ $instance = $test->ci_instance();
+ return $instance;
+}
+
+// --------------------------------------------------------------------
+
+function &get_config() {
+ $test = CI_TestCase::instance();
+ $config = $test->ci_get_config();
+
+ return $config;
+}
+
+function config_item($item)
+{
+ $config =& get_config();
+
+ if ( ! isset($config[$item]))
+ {
+ return FALSE;
+ }
+
+ return $config[$item];
+}
+
+// --------------------------------------------------------------------
+
+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.
+// --------------------------------------------------------------------
+
+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
+// --------------------------------------------------------------------
+
+function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
+{
+ throw new RuntimeException('CI Error: '.$message);
+}
+
+function show_404($page = '', $log_error = TRUE)
+{
+ throw new RuntimeException('CI Error: 404');
+}
+
+function _exception_handler($severity, $message, $filepath, $line)
+{
+ throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line);
+}
+
+
+// We assume a few things about our environment ...
+// --------------------------------------------------------------------
+
+function is_php($version = '5.0.0')
+{
+ return ! (version_compare(PHP_VERSION, $version) < 0);
+}
+
+function is_really_writable($file)
+{
+ return is_writable($file);
+}
+
+function is_loaded()
+{
+ throw new Exception('Bad Isolation: mock up environment');
+}
+
+function log_message($level = 'error', $message, $php_error = FALSE)
+{
+ return TRUE;
+}
+
+function set_status_header($code = 200, $text = '')
+{
+ return TRUE;
+}
+
+// EOF \ 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..d4b29bb3d
--- /dev/null
+++ b/tests/mocks/core/loader.php
@@ -0,0 +1,30 @@
+<?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/uri.php b/tests/mocks/core/uri.php
new file mode 100644
index 000000000..b6946091e
--- /dev/null
+++ b/tests/mocks/core/uri.php
@@ -0,0 +1,25 @@
+<?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/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite
new file mode 100755
index 000000000..37ce4f870
--- /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..ace0a31b1
--- /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/pgsql.php b/tests/mocks/database/config/pgsql.php
new file mode 100644
index 000000000..c06af8ce0
--- /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..8665e208d
--- /dev/null
+++ b/tests/mocks/database/config/sqlite.php
@@ -0,0 +1,35 @@
+<?php
+$dbdriver = is_php('5.4') ? 'sqlite3' : 'sqlite';
+
+return array(
+
+ // Typical Database configuration
+ 'sqlite' => array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'sqlite',
+ 'password' => 'sqlite',
+ 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite',
+ 'dbdriver' => $dbdriver,
+ ),
+
+ // Database configuration with failover
+ 'sqlite_failover' => array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'sqlite',
+ 'password' => 'sqlite',
+ 'database' => '../not_exists.sqlite',
+ 'dbdriver' => $dbdriver,
+ 'failover' => array(
+ array(
+ 'dsn' => '',
+ 'hostname' => 'localhost',
+ 'username' => 'sqlite',
+ 'password' => 'sqlite',
+ 'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite',
+ 'dbdriver' => $dbdriver,
+ ),
+ ),
+ ),
+); \ 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..43a0d391f
--- /dev/null
+++ b/tests/mocks/database/db.php
@@ -0,0 +1,101 @@
+<?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);
+
+ if ( ! empty($config['dsn']))
+ {
+ $dsn = $config['dsn'];
+ }
+ else
+ {
+ $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password']
+ .'@'.$config['hostname'].'/'.$config['database'];
+
+ }
+
+ $other_params = array_slice($config, 6);
+
+ 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/schema/.gitkeep b/tests/mocks/database/schema/.gitkeep
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/mocks/database/schema/.gitkeep
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..1a6ff8d35
--- /dev/null
+++ b/tests/mocks/libraries/table.php
@@ -0,0 +1,15 @@
+<?php
+
+class Mock_Libraries_Table extends CI_Table {
+
+ // Overide inaccesible private or 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/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml
new file mode 100644
index 000000000..44d6d6ed9
--- /dev/null
+++ b/tests/travis/mysql.phpunit.xml
@@ -0,0 +1,37 @@
+<?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">
+ <file>../codeigniter/Setup_test.php</file>
+ <directory suffix="test.php">../codeigniter/core</directory>
+ <directory suffix="test.php">../codeigniter/helpers</directory>
+ <directory suffix="test.php">../codeigniter/libraries</directory>
+ <directory suffix="test.php">../codeigniter/database</directory>
+ </testsuite>
+ </testsuites>
+ <filters>
+ <blacklist>
+ <directory suffix=".php">PEAR_INSTALL_DIR</directory>
+ <directory suffix=".php">PHP_LIBDIR</directory>
+ <directory suffix=".php">PROJECT_BASE.'tests'</directory>
+ <directory suffix=".php">'../../system/core/CodeIgniter.php'</directory>
+ </blacklist>
+ <whitelist>
+ <!--
+ <directory suffix=".php">'../system/core'</directory>
+ -->
+ </whitelist>
+ </filters>
+</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..9f52b40ae
--- /dev/null
+++ b/tests/travis/pgsql.phpunit.xml
@@ -0,0 +1,37 @@
+<?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">
+ <file>../codeigniter/Setup_test.php</file>
+ <directory suffix="test.php">../codeigniter/core</directory>
+ <directory suffix="test.php">../codeigniter/helpers</directory>
+ <directory suffix="test.php">../codeigniter/libraries</directory>
+ <directory suffix="test.php">../codeigniter/database</directory>
+ </testsuite>
+ </testsuites>
+ <filters>
+ <blacklist>
+ <directory suffix=".php">PEAR_INSTALL_DIR</directory>
+ <directory suffix=".php">PHP_LIBDIR</directory>
+ <directory suffix=".php">PROJECT_BASE.'tests'</directory>
+ <directory suffix=".php">'../../system/core/CodeIgniter.php'</directory>
+ </blacklist>
+ <whitelist>
+ <!--
+ <directory suffix=".php">'../system/core'</directory>
+ -->
+ </whitelist>
+ </filters>
+</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..74ebb482b
--- /dev/null
+++ b/tests/travis/sqlite.phpunit.xml
@@ -0,0 +1,37 @@
+<?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">
+ <file>../codeigniter/Setup_test.php</file>
+ <directory suffix="test.php">../codeigniter/core</directory>
+ <directory suffix="test.php">../codeigniter/helpers</directory>
+ <directory suffix="test.php">../codeigniter/libraries</directory>
+ <directory suffix="test.php">../codeigniter/database</directory>
+ </testsuite>
+ </testsuites>
+ <filters>
+ <blacklist>
+ <directory suffix=".php">PEAR_INSTALL_DIR</directory>
+ <directory suffix=".php">PHP_LIBDIR</directory>
+ <directory suffix=".php">PROJECT_BASE.'tests'</directory>
+ <directory suffix=".php">'../../system/core/CodeIgniter.php'</directory>
+ </blacklist>
+ <whitelist>
+ <!--
+ <directory suffix=".php">'../system/core'</directory>
+ -->
+ </whitelist>
+ </filters>
+</phpunit> \ No newline at end of file