summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter
diff options
context:
space:
mode:
Diffstat (limited to 'tests/codeigniter')
-rw-r--r--tests/codeigniter/Setup_test.php6
-rw-r--r--tests/codeigniter/core/Benchmark_test.php11
-rw-r--r--tests/codeigniter/core/Common_test.php37
-rw-r--r--tests/codeigniter/core/Config_test.php38
-rw-r--r--tests/codeigniter/core/Input_test.php57
-rw-r--r--tests/codeigniter/core/Lang_test.php17
-rw-r--r--tests/codeigniter/core/Loader_test.php132
-rw-r--r--tests/codeigniter/core/Security_test.php49
-rw-r--r--tests/codeigniter/core/URI_test.php230
-rw-r--r--tests/codeigniter/database/DB_driver_test.php4
-rw-r--r--tests/codeigniter/database/DB_test.php4
-rw-r--r--tests/codeigniter/database/query_builder/count_test.php12
-rw-r--r--tests/codeigniter/database/query_builder/delete_test.php16
-rw-r--r--tests/codeigniter/database/query_builder/distinct_test.php9
-rw-r--r--tests/codeigniter/database/query_builder/escape_test.php68
-rw-r--r--tests/codeigniter/database/query_builder/from_test.php18
-rw-r--r--tests/codeigniter/database/query_builder/get_test.php8
-rw-r--r--tests/codeigniter/database/query_builder/group_test.php26
-rw-r--r--tests/codeigniter/database/query_builder/insert_test.php8
-rw-r--r--tests/codeigniter/database/query_builder/join_test.php22
-rw-r--r--tests/codeigniter/database/query_builder/like_test.php2
-rw-r--r--tests/codeigniter/database/query_builder/limit_test.php7
-rw-r--r--tests/codeigniter/database/query_builder/order_test.php6
-rw-r--r--tests/codeigniter/database/query_builder/select_test.php12
-rw-r--r--tests/codeigniter/database/query_builder/truncate_test.php7
-rw-r--r--tests/codeigniter/database/query_builder/update_test.php26
-rw-r--r--tests/codeigniter/database/query_builder/where_test.php28
-rw-r--r--tests/codeigniter/helpers/array_helper_test.php22
-rw-r--r--tests/codeigniter/helpers/date_helper_test.php151
-rw-r--r--tests/codeigniter/helpers/directory_helper_test.php49
-rw-r--r--tests/codeigniter/helpers/email_helper_test.php2
-rw-r--r--tests/codeigniter/helpers/file_helper_test.php143
-rw-r--r--tests/codeigniter/helpers/form_helper_test.php112
-rw-r--r--tests/codeigniter/helpers/html_helper_test.php43
-rw-r--r--tests/codeigniter/helpers/inflector_helper_test.php31
-rw-r--r--tests/codeigniter/helpers/number_helper_test.php37
-rw-r--r--tests/codeigniter/helpers/path_helper_test.php5
-rw-r--r--tests/codeigniter/helpers/string_helper_test.php9
-rw-r--r--tests/codeigniter/helpers/text_helper_test.php76
-rw-r--r--tests/codeigniter/helpers/url_helper_test.php1
-rw-r--r--tests/codeigniter/helpers/xml_helper_test.php4
-rw-r--r--tests/codeigniter/libraries/Calendar_test.php204
-rw-r--r--tests/codeigniter/libraries/Encrypt_test.php72
-rw-r--r--tests/codeigniter/libraries/Parser_test.php61
-rw-r--r--tests/codeigniter/libraries/Session_test.php405
-rw-r--r--tests/codeigniter/libraries/Table_test.php169
-rw-r--r--tests/codeigniter/libraries/Typography_test.php40
-rw-r--r--tests/codeigniter/libraries/Upload_test.php270
-rw-r--r--tests/codeigniter/libraries/Useragent_test.php6
49 files changed, 1909 insertions, 863 deletions
diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php
index b48e32bfb..5317c56c7 100644
--- a/tests/codeigniter/Setup_test.php
+++ b/tests/codeigniter/Setup_test.php
@@ -1,13 +1,13 @@
<?php
class Setup_test extends PHPUnit_Framework_TestCase {
-
- function test_bootstrap_constants()
+
+ public function test_bootstrap_constants()
{
$this->assertTrue(defined('PROJECT_BASE'));
$this->assertTrue(defined('BASEPATH'));
$this->assertTrue(defined('APPPATH'));
$this->assertTrue(defined('VIEWPATH'));
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php
index 109b38821..a239ba51d 100644
--- a/tests/codeigniter/core/Benchmark_test.php
+++ b/tests/codeigniter/core/Benchmark_test.php
@@ -1,14 +1,14 @@
<?php
class Benchmark_test extends CI_TestCase {
-
+
public function set_up()
{
$this->benchmark = new Mock_Core_Benchmark();
}
-
+
// --------------------------------------------------------------------
-
+
public function test_mark()
{
$this->assertEmpty($this->benchmark->marker);
@@ -18,7 +18,7 @@ class Benchmark_test extends CI_TestCase {
$this->assertEquals(1, count($this->benchmark->marker));
$this->assertArrayHasKey('code_start', $this->benchmark->marker);
}
-
+
// --------------------------------------------------------------------
public function test_elapsed_time()
@@ -29,7 +29,7 @@ class Benchmark_test extends CI_TestCase {
$this->benchmark->mark('code_start');
sleep(1);
$this->benchmark->mark('code_end');
-
+
$this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1));
}
@@ -39,4 +39,5 @@ class Benchmark_test extends CI_TestCase {
{
$this->assertEquals('{memory_usage}', $this->benchmark->memory_usage());
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php
index dded2e824..27d48efc2 100644
--- a/tests/codeigniter/core/Common_test.php
+++ b/tests/codeigniter/core/Common_test.php
@@ -1,13 +1,44 @@
<?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'));
}
-
+
+ // ------------------------------------------------------------------------
+
+ public function test_stringify_attributes()
+ {
+ $this->assertEquals(' class="foo" id="bar"', _stringify_attributes(array('class' => 'foo', 'id' => 'bar')));
+
+ $atts = new Stdclass;
+ $atts->class = 'foo';
+ $atts->id = 'bar';
+ $this->assertEquals(' class="foo" id="bar"', _stringify_attributes($atts));
+
+ $atts = new Stdclass;
+ $this->assertEquals('', _stringify_attributes($atts));
+
+ $this->assertEquals(' class="foo" id="bar"', _stringify_attributes('class="foo" id="bar"'));
+
+ $this->assertEquals('', _stringify_attributes(array()));
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_stringify_js_attributes()
+ {
+ $this->assertEquals('width=800,height=600', _stringify_attributes(array('width' => '800', 'height' => '600'), TRUE));
+
+ $atts = new Stdclass;
+ $atts->width = 800;
+ $atts->height = 600;
+ $this->assertEquals('width=800,height=600', _stringify_attributes($atts, TRUE));
+ }
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php
index 30f0cc61d..30cb90a28 100644
--- a/tests/codeigniter/core/Config_test.php
+++ b/tests/codeigniter/core/Config_test.php
@@ -5,7 +5,7 @@ class Config_test extends CI_TestCase {
public function set_up()
{
$cls =& $this->ci_core_class('cfg');
-
+
// set predictable config values
$this->ci_set_config(array(
'index_page' => 'index.php',
@@ -13,9 +13,9 @@ class Config_test extends CI_TestCase {
'subclass_prefix' => 'MY_'
));
- $this->config = new $cls;
+ $this->config = new $cls;
}
-
+
// --------------------------------------------------------------------
public function test_item()
@@ -24,30 +24,30 @@ class Config_test extends CI_TestCase {
// Bad Config value
$this->assertFalse($this->config->item('no_good_item'));
-
+
// Index
$this->assertFalse($this->config->item('no_good_item', 'bad_index'));
$this->assertFalse($this->config->item('no_good_item', 'default'));
}
-
+
// --------------------------------------------------------------------
-
+
public function test_set_item()
{
$this->assertFalse($this->config->item('not_yet_set'));
-
+
$this->config->set_item('not_yet_set', 'is set');
-
+
$this->assertEquals('is set', $this->config->item('not_yet_set'));
}
// --------------------------------------------------------------------
-
+
public function test_slash_item()
{
// Bad Config value
$this->assertFalse($this->config->slash_item('no_good_item'));
-
+
$this->assertEquals('http://example.com/', $this->config->slash_item('base_url'));
$this->assertEquals('MY_/', $this->config->slash_item('subclass_prefix'));
@@ -58,33 +58,33 @@ class Config_test extends CI_TestCase {
public function test_site_url()
{
$this->assertEquals('http://example.com/index.php', $this->config->site_url());
-
+
$base_url = $this->config->item('base_url');
-
+
$this->config->set_item('base_url', '');
-
+
$q_string = $this->config->item('enable_query_strings');
-
+
$this->config->set_item('enable_query_strings', FALSE);
$this->assertEquals('index.php/test', $this->config->site_url('test'));
$this->assertEquals('index.php/test/1', $this->config->site_url(array('test', '1')));
-
+
$this->config->set_item('enable_query_strings', TRUE);
$this->assertEquals('index.php?test', $this->config->site_url('test'));
$this->assertEquals('index.php?0=test&1=1', $this->config->site_url(array('test', '1')));
-
+
$this->config->set_item('base_url', $base_url);
$this->assertEquals('http://example.com/index.php?test', $this->config->site_url('test'));
-
+
// back to home base
- $this->config->set_item('enable_query_strings', $q_string);
+ $this->config->set_item('enable_query_strings', $q_string);
}
// --------------------------------------------------------------------
-
+
public function test_system_url()
{
$this->assertEquals('http://example.com/system/', $this->config->system_url());
diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php
index fd0576e38..fe8738832 100644
--- a/tests/codeigniter/core/Input_test.php
+++ b/tests/codeigniter/core/Input_test.php
@@ -1,7 +1,7 @@
<?php
class Input_test extends CI_TestCase {
-
+
public function set_up()
{
// Set server variable to GET as default, since this will leave unset in STDIN env
@@ -17,9 +17,9 @@ class Input_test extends CI_TestCase {
$this->input = new Mock_Core_Input($security, $utf8);
}
-
+
// --------------------------------------------------------------------
-
+
public function test_get_not_exists()
{
$this->assertEmpty($this->input->get());
@@ -28,15 +28,17 @@ class Input_test extends CI_TestCase {
$this->assertTrue( ! $this->input->get());
$this->assertTrue( ! $this->input->get('foo'));
- $this->assertTrue($this->input->get() == FALSE);
- $this->assertTrue($this->input->get('foo') == FALSE);
+ // Test we're getting empty results
+ $this->assertTrue($this->input->get() === NULL);
+ $this->assertTrue($this->input->get('foo') === NULL);
- $this->assertTrue($this->input->get() === FALSE);
- $this->assertTrue($this->input->get('foo') === FALSE);
+ // Test new 3.0 behaviour for non existant results (used to be FALSE)
+ $this->assertTrue($this->input->get() === NULL);
+ $this->assertTrue($this->input->get('foo') === NULL);
}
// --------------------------------------------------------------------
-
+
public function test_get_exist()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
@@ -47,7 +49,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_get_exist_with_xss_clean()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
@@ -59,7 +61,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_post_not_exists()
{
$this->assertEmpty($this->input->post());
@@ -68,15 +70,15 @@ class Input_test extends CI_TestCase {
$this->assertTrue( ! $this->input->post());
$this->assertTrue( ! $this->input->post('foo'));
- $this->assertTrue($this->input->post() == FALSE);
- $this->assertTrue($this->input->post('foo') == FALSE);
+ $this->assertTrue($this->input->post() === NULL);
+ $this->assertTrue($this->input->post('foo') === NULL);
- $this->assertTrue($this->input->post() === FALSE);
- $this->assertTrue($this->input->post('foo') === FALSE);
+ $this->assertTrue($this->input->post() === NULL);
+ $this->assertTrue($this->input->post('foo') === NULL);
}
// --------------------------------------------------------------------
-
+
public function test_post_exist()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
@@ -87,7 +89,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_post_exist_with_xss_clean()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
@@ -99,7 +101,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_get_post()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
@@ -109,7 +111,7 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_cookie()
{
$_COOKIE['foo'] = 'bar';
@@ -118,14 +120,14 @@ class Input_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_server()
{
$this->assertEquals('GET', $this->input->server('REQUEST_METHOD'));
}
// --------------------------------------------------------------------
-
+
public function test_fetch_from_array()
{
$data = array(
@@ -141,4 +143,19 @@ class Input_test extends CI_TestCase {
$this->assertEquals("Hello, i try to <script>alert('Hack');</script> your site", $harm);
$this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", $harmless);
}
+
+ // --------------------------------------------------------------------
+
+ public function test_valid_ip()
+ {
+ $ip_v4 = '192.18.0.1';
+ $this->assertTrue($this->input->valid_ip($ip_v4));
+
+ $ip_v6 = array('2001:0db8:0000:85a3:0000:0000:ac1f:8001', '2001:db8:0:85a3:0:0:ac1f:8001', '2001:db8:0:85a3::ac1f:8001');
+ foreach ($ip_v6 as $ip)
+ {
+ $this->assertTrue($this->input->valid_ip($ip));
+ }
+ }
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php
index a414f0ace..a410dabfa 100644
--- a/tests/codeigniter/core/Lang_test.php
+++ b/tests/codeigniter/core/Lang_test.php
@@ -1,9 +1,9 @@
<?php
class Lang_test extends CI_TestCase {
-
+
protected $lang;
-
+
public function set_up()
{
$loader_cls = $this->ci_core_class('load');
@@ -12,20 +12,21 @@ class Lang_test extends CI_TestCase {
$cls = $this->ci_core_class('lang');
$this->lang = new $cls;
}
-
+
// --------------------------------------------------------------------
-
+
public function test_load()
{
$this->assertTrue($this->lang->load('profiler', 'english'));
+ $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string'));
}
-
+
// --------------------------------------------------------------------
- public function test_line()
+ public function test_load_with_unspecified_language()
{
- $this->assertTrue($this->lang->load('profiler', 'english'));
+ $this->assertTrue($this->lang->load('profiler'));
$this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string'));
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php
index 43008651e..fdea962b7 100644
--- a/tests/codeigniter/core/Loader_test.php
+++ b/tests/codeigniter/core/Loader_test.php
@@ -1,35 +1,35 @@
<?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;
-
+ $this->ci_obj = new stdClass;
+
// Fix get_instance()
$this->ci_instance($this->ci_obj);
}
// --------------------------------------------------------------------
-
+
public function test_library()
{
$this->_setup_config_mock();
-
+
// Test loading as an array.
$this->assertNull($this->load->library(array('table')));
$this->assertTrue(class_exists('CI_Table'), 'Table class exists');
$this->assertAttributeInstanceOf('CI_Table', 'table', $this->ci_obj);
-
+
// Test no lib given
$this->assertEquals(FALSE, $this->load->library());
-
+
// Test a string given to params
$this->assertEquals(NULL, $this->load->library('table', ' '));
}
@@ -39,20 +39,18 @@ class Loader_test extends CI_TestCase {
public function test_load_library_in_application_dir()
{
$this->_setup_config_mock();
-
+
$content = '<?php class Super_test_library {} ';
-
- $model = vfsStream::newFile('Super_test_library.php')->withContent($content)
- ->at($this->load->libs_dir);
-
+
+ $model = vfsStream::newFile('Super_test_library.php')->withContent($content)->at($this->load->libs_dir);
$this->assertNull($this->load->library('super_test_library'));
-
+
// Was the model class instantiated.
- $this->assertTrue(class_exists('Super_test_library'));
+ $this->assertTrue(class_exists('Super_test_library'));
}
-
+
// --------------------------------------------------------------------
-
+
private function _setup_config_mock()
{
// Mock up a config object until we
@@ -61,7 +59,7 @@ class Loader_test extends CI_TestCase {
$config->expects($this->any())
->method('load')
->will($this->returnValue(TRUE));
-
+
// Add the mock to our stdClass
$this->ci_instance_var('config', $config);
}
@@ -73,64 +71,62 @@ class Loader_test extends CI_TestCase {
$this->setExpectedException(
'RuntimeException',
'CI Error: Unable to locate the model you have specified: ci_test_nonexistent_model.php'
- );
-
+ );
+
$this->load->model('ci_test_nonexistent_model.php');
}
// --------------------------------------------------------------------
-
+
/**
* @coverts CI_Loader::model
*/
public function test_models()
{
$this->ci_set_core_class('model', 'CI_Model');
-
+
$content = '<?php class Unit_test_model extends CI_Model {} ';
-
- $model = vfsStream::newFile('unit_test_model.php')->withContent($content)
- ->at($this->load->models_dir);
-
+
+ $model = vfsStream::newFile('unit_test_model.php')->withContent($content)->at($this->load->models_dir);
+
$this->assertNull($this->load->model('unit_test_model'));
-
+
// Was the model class instantiated.
$this->assertTrue(class_exists('Unit_test_model'));
-
+
// Test no model given
- $this->assertNull($this->load->model(''));
+ $this->assertNull($this->load->model(''));
}
// --------------------------------------------------------------------
-
+
// public function testDatabase()
// {
// $this->assertEquals(NULL, $this->load->database());
- // $this->assertEquals(NULL, $this->load->dbutil());
+ // $this->assertEquals(NULL, $this->load->dbutil());
// }
// --------------------------------------------------------------------
-
+
/**
* @coverts CI_Loader::view
*/
public function test_load_view()
{
$this->ci_set_core_class('output', 'CI_Output');
-
+
$content = 'This is my test page. <?php echo $hello; ?>';
- $view = vfsStream::newFile('unit_test_view.php')->withContent($content)
- ->at($this->load->views_dir);
-
+ $view = vfsStream::newFile('unit_test_view.php')->withContent($content)->at($this->load->views_dir);
+
// Use the optional return parameter in this test, so the view is not
// run through the output class.
$this->assertEquals('This is my test page. World!',
$this->load->view('unit_test_view', array('hello' => "World!"), TRUE));
-
+
}
// --------------------------------------------------------------------
-
+
/**
* @coverts CI_Loader::view
*/
@@ -139,8 +135,8 @@ class Loader_test extends CI_TestCase {
$this->setExpectedException(
'RuntimeException',
'CI Error: Unable to load the requested file: ci_test_nonexistent_view.php'
- );
-
+ );
+
$this->load->view('ci_test_nonexistent_view', array('foo' => 'bar'));
}
@@ -149,87 +145,77 @@ class Loader_test extends CI_TestCase {
public function test_file()
{
$content = 'Here is a test file, which we will load now.';
- $file = vfsStream::newFile('ci_test_mock_file.php')->withContent($content)
- ->at($this->load->views_dir);
-
+ $file = vfsStream::newFile('ci_test_mock_file.php')->withContent($content)->at($this->load->views_dir);
+
// Just like load->view(), take the output class out of the mix here.
- $load = $this->load->file(vfsStream::url('application').'/views/ci_test_mock_file.php',
- TRUE);
-
+ $load = $this->load->file(vfsStream::url('application').'/views/ci_test_mock_file.php', TRUE);
+
$this->assertEquals($content, $load);
-
+
$this->setExpectedException(
'RuntimeException',
'CI Error: Unable to load the requested file: ci_test_file_not_exists'
- );
-
+ );
+
$this->load->file('ci_test_file_not_exists', TRUE);
-
}
// --------------------------------------------------------------------
-
+
public function test_vars()
{
- $vars = array(
- 'foo' => 'bar'
- );
-
- $this->assertNull($this->load->vars($vars));
+ $this->assertNull($this->load->vars(array('foo' => 'bar')));
$this->assertNull($this->load->vars('foo', 'bar'));
}
// --------------------------------------------------------------------
-
+
public function test_helper()
{
$this->assertEquals(NULL, $this->load->helper('array'));
-
+
$this->setExpectedException(
'RuntimeException',
'CI Error: Unable to load the requested file: helpers/bad_helper.php'
- );
-
+ );
+
$this->load->helper('bad');
}
-
+
// --------------------------------------------------------------------
public function test_loading_multiple_helpers()
{
$this->assertEquals(NULL, $this->load->helpers(array('file', 'array', 'string')));
}
-
+
// --------------------------------------------------------------------
-
+
// public function testLanguage()
// {
// $this->assertEquals(NULL, $this->load->language('test'));
- // }
+ // }
// --------------------------------------------------------------------
public function test_load_config()
{
$this->_setup_config_mock();
-
$this->assertNull($this->load->config('config', FALSE));
}
-
+
// --------------------------------------------------------------------
public function test_load_bad_config()
{
$this->_setup_config_mock();
-
+
$this->setExpectedException(
'RuntimeException',
'CI Error: The configuration file foobar.php does not exist.'
- );
-
+ );
+
$this->load->config('foobar', FALSE);
}
- // --------------------------------------------------------------------
-
-}
+} \ No newline at end of file
diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php
index 1796ba74d..3f6e3b07a 100644
--- a/tests/codeigniter/core/Security_test.php
+++ b/tests/codeigniter/core/Security_test.php
@@ -1,7 +1,7 @@
<?php
class Security_test extends CI_TestCase {
-
+
public function set_up()
{
// Set cookie for security test
@@ -14,9 +14,9 @@ class Security_test extends CI_TestCase {
$this->security = new Mock_Core_Security();
}
-
+
// --------------------------------------------------------------------
-
+
public function test_csrf_verify()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
@@ -25,7 +25,7 @@ class Security_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_csrf_verify_invalid()
{
// Without issuing $_POST[csrf_token_name], this request will triggering CSRF error
@@ -37,7 +37,7 @@ class Security_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_csrf_verify_valid()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
@@ -47,21 +47,21 @@ class Security_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_get_csrf_hash()
{
$this->assertEquals($this->security->csrf_hash, $this->security->get_csrf_hash());
}
// --------------------------------------------------------------------
-
+
public function test_get_csrf_token_name()
{
$this->assertEquals('ci_csrf_token', $this->security->get_csrf_token_name());
}
// --------------------------------------------------------------------
-
+
public function test_xss_clean()
{
$harm_string = "Hello, i try to <script>alert('Hack');</script> your site";
@@ -70,4 +70,37 @@ class Security_test extends CI_TestCase {
$this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", $harmless_string);
}
+
+ // --------------------------------------------------------------------
+
+ public function test_xss_hash()
+ {
+ $this->assertEmpty($this->security->xss_hash);
+
+ // Perform hash
+ $this->security->xss_hash();
+
+ $this->assertTrue(preg_match('#^[0-9a-f]{32}$#iS', $this->security->xss_hash) === 1);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_entity_decode()
+ {
+ $encoded = '&lt;div&gt;Hello &lt;b&gt;Booya&lt;/b&gt;&lt;/div&gt;';
+ $decoded = $this->security->entity_decode($encoded);
+
+ $this->assertEquals('<div>Hello <b>Booya</b></div>', $decoded);
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_sanitize_filename()
+ {
+ $filename = './<!--foo-->';
+ $safe_filename = $this->security->sanitize_filename($filename);
+
+ $this->assertEquals('foo', $safe_filename);
+ }
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php
index e340ddf73..60ed1a4e9 100644
--- a/tests/codeigniter/core/URI_test.php
+++ b/tests/codeigniter/core/URI_test.php
@@ -1,7 +1,7 @@
<?php
class URI_test extends CI_TestCase {
-
+
public function set_up()
{
$this->uri = new Mock_Core_URI();
@@ -9,23 +9,21 @@ class URI_test extends CI_TestCase {
// --------------------------------------------------------------------
+ /* As of the following commit, _set_uri_string() is a protected method:
+
+ https://github.com/EllisLab/CodeIgniter/commit/d461934184d95b0cfb2feec93f27b621ef72a5c2
+
public function test_set_uri_string()
{
// Slashes get killed
$this->uri->_set_uri_string('/');
-
- $a = '';
- $b =& $this->uri->uri_string;
-
- $this->assertEquals($a, $b);
-
+ $this->assertEquals('', $this->uri->uri_string);
+
$this->uri->_set_uri_string('nice/uri');
-
- $a = 'nice/uri';
-
- $this->assertEquals($a, $b);
+ $this->assertEquals('nice/uri', $this->uri->uri_string);
}
-
+ */
+
// --------------------------------------------------------------------
public function test_fetch_uri_string()
@@ -34,75 +32,61 @@ class URI_test extends CI_TestCase {
// uri_protocol: AUTO
$this->uri->config->set_item('uri_protocol', 'AUTO');
-
+
// Test a variety of request uris
$requests = array(
'/index.php/controller/method' => 'controller/method',
'/index.php?/controller/method' => 'controller/method',
'/index.php?/controller/method/?var=foo' => 'controller/method'
);
-
+
foreach($requests as $request => $expected)
{
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['REQUEST_URI'] = $request;
-
+
$this->uri->_fetch_uri_string();
$this->assertEquals($expected, $this->uri->uri_string );
}
-
+
// Test a subfolder
$_SERVER['SCRIPT_NAME'] = '/subfolder/index.php';
$_SERVER['REQUEST_URI'] = '/subfolder/index.php/controller/method';
-
+
$this->uri->_fetch_uri_string();
-
- $a = 'controller/method';
- $b = $this->uri->uri_string;
-
- $this->assertEquals($a, $b);
-
+ $this->assertEquals('controller/method', $this->uri->uri_string);
+
// death to request uri
unset($_SERVER['REQUEST_URI']);
-
+
// life to path info
- $_SERVER['PATH_INFO'] = '/controller/method/';
-
+ $_SERVER['PATH_INFO'] = $a = '/controller/method/';
+
$this->uri->_fetch_uri_string();
-
- $a = '/controller/method/';
- $b =& $this->uri->uri_string;
+ $this->assertEquals($a, $this->uri->uri_string);
- $this->assertEquals($a, $b);
-
// death to path info
// At this point your server must be seriously drunk
unset($_SERVER['PATH_INFO']);
-
+
$_SERVER['QUERY_STRING'] = '/controller/method/';
-
+
$this->uri->_fetch_uri_string();
+ $this->assertEquals($a, $this->uri->uri_string);
- $a = '/controller/method/';
- $b = $this->uri->uri_string;
-
- $this->assertEquals($a, $b);
-
// At this point your server is a labotomy victim
-
unset($_SERVER['QUERY_STRING']);
-
+
$_GET['/controller/method/'] = '';
-
+
$this->uri->_fetch_uri_string();
- $this->assertEquals($a, $b);
+ $this->assertEquals($a, $this->uri->uri_string);
// Test coverage implies that these will work
// uri_protocol: REQUEST_URI
// uri_protocol: CLI
-
}
-
+
// --------------------------------------------------------------------
public function test_explode_segments()
@@ -113,18 +97,15 @@ class URI_test extends CI_TestCase {
'/test2/uri2' => array('test2', 'uri2'),
'//test3/test3///' => array('test3', 'test3')
);
-
- foreach($uris as $uri => $a)
+
+ foreach ($uris as $uri => $a)
{
$this->uri->segments = array();
$this->uri->uri_string = $uri;
$this->uri->_explode_segments();
-
- $b = $this->uri->segments;
-
- $this->assertEquals($a, $b);
+
+ $this->assertEquals($a, $this->uri->segments);
}
-
}
// --------------------------------------------------------------------
@@ -133,7 +114,7 @@ class URI_test extends CI_TestCase {
{
$this->uri->config->set_item('enable_query_strings', FALSE);
$this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-');
-
+
$str_in = 'abc01239~%.:_-';
$str = $this->uri->_filter_uri($str_in);
@@ -145,52 +126,52 @@ class URI_test extends CI_TestCase {
public function test_filter_uri_escaping()
{
// ensure escaping even if dodgey characters are permitted
-
+
$this->uri->config->set_item('enable_query_strings', FALSE);
$this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-()$');
$str = $this->uri->_filter_uri('$destroy_app(foo)');
-
+
$this->assertEquals($str, '&#36;destroy_app&#40;foo&#41;');
}
// --------------------------------------------------------------------
- public function test_filter_uri_throws_error()
- {
+ public function test_filter_uri_throws_error()
+ {
$this->setExpectedException('RuntimeException');
-
+
$this->uri->config->set_item('enable_query_strings', FALSE);
$this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-');
$this->uri->_filter_uri('$this()');
- }
+ }
// --------------------------------------------------------------------
public function test_remove_url_suffix()
{
$this->uri->config->set_item('url_suffix', '.html');
-
+
$this->uri->uri_string = 'controller/method/index.html';
$this->uri->_remove_url_suffix();
-
+
$this->assertEquals($this->uri->uri_string, 'controller/method/index');
-
+
$this->uri->uri_string = 'controller/method/index.htmlify.html';
$this->uri->_remove_url_suffix();
-
+
$this->assertEquals($this->uri->uri_string, 'controller/method/index.htmlify');
}
// --------------------------------------------------------------------
-
+
public function test_segment()
{
$this->uri->segments = array(1 => 'controller');
$this->assertEquals($this->uri->segment(1), 'controller');
$this->assertEquals($this->uri->segment(2, 'default'), 'default');
}
-
+
// --------------------------------------------------------------------
public function test_rsegment()
@@ -205,32 +186,33 @@ class URI_test extends CI_TestCase {
public function test_uri_to_assoc()
{
$this->uri->segments = array('a', '1', 'b', '2', 'c', '3');
-
- $a = array('a' => '1', 'b' => '2', 'c' => '3');
- $b = $this->uri->uri_to_assoc(1);
- $this->assertEquals($a, $b);
-
- $a = array('b' => '2', 'c' => '3');
- $b = $this->uri->uri_to_assoc(3);
- $this->assertEquals($a, $b);
-
-
+
+ $this->assertEquals(
+ array('a' => '1', 'b' => '2', 'c' => '3'),
+ $this->uri->uri_to_assoc(1)
+ );
+
+ $this->assertEquals(
+ array('b' => '2', 'c' => '3'),
+ $this->uri->uri_to_assoc(3)
+ );
+
$this->uri->keyval = array(); // reset cache
-
$this->uri->segments = array('a', '1', 'b', '2', 'c');
-
- $a = array('a' => '1', 'b' => '2', 'c' => FALSE);
- $b = $this->uri->uri_to_assoc(1);
- $this->assertEquals($a, $b);
-
+
+ $this->assertEquals(
+ array('a' => '1', 'b' => '2', 'c' => FALSE),
+ $this->uri->uri_to_assoc(1)
+ );
+
$this->uri->keyval = array(); // reset cache
-
$this->uri->segments = array('a', '1');
-
+
// test default
- $a = array('a' => '1', 'b' => FALSE);
- $b = $this->uri->uri_to_assoc(1, array('a', 'b'));
- $this->assertEquals($a, $b);
+ $this->assertEquals(
+ array('a' => '1', 'b' => FALSE),
+ $this->uri->uri_to_assoc(1, array('a', 'b'))
+ );
}
// --------------------------------------------------------------------
@@ -238,33 +220,33 @@ class URI_test extends CI_TestCase {
public function test_ruri_to_assoc()
{
$this->uri->rsegments = array('x', '1', 'y', '2', 'z', '3');
-
- $a = array('x' => '1', 'y' => '2', 'z' => '3');
- $b = $this->uri->ruri_to_assoc(1);
- $this->assertEquals($a, $b);
-
- $a = array('y' => '2', 'z' => '3');
- $b = $this->uri->ruri_to_assoc(3);
- $this->assertEquals($a, $b);
-
-
+
+ $this->assertEquals(
+ array('x' => '1', 'y' => '2', 'z' => '3'),
+ $this->uri->ruri_to_assoc(1)
+ );
+
+ $this->assertEquals(
+ array('y' => '2', 'z' => '3'),
+ $this->uri->ruri_to_assoc(3)
+ );
+
$this->uri->keyval = array(); // reset cache
-
$this->uri->rsegments = array('x', '1', 'y', '2', 'z');
-
- $a = array('x' => '1', 'y' => '2', 'z' => FALSE);
- $b = $this->uri->ruri_to_assoc(1);
- $this->assertEquals($a, $b);
-
+
+ $this->assertEquals(
+ array('x' => '1', 'y' => '2', 'z' => FALSE),
+ $this->uri->ruri_to_assoc(1)
+ );
+
$this->uri->keyval = array(); // reset cache
-
$this->uri->rsegments = array('x', '1');
-
- // test default
- $a = array('x' => '1', 'y' => FALSE);
- $b = $this->uri->ruri_to_assoc(1, array('x', 'y'));
- $this->assertEquals($a, $b);
+ // test default
+ $this->assertEquals(
+ array('x' => '1', 'y' => FALSE),
+ $this->uri->ruri_to_assoc(1, array('x', 'y'))
+ );
}
// --------------------------------------------------------------------
@@ -272,11 +254,7 @@ class URI_test extends CI_TestCase {
public function test_assoc_to_uri()
{
$this->uri->config->set_item('uri_string_slashes', 'none');
-
- $arr = array('a' => 1, 'b' => 2);
- $a = 'a/1/b/2';
- $b = $this->uri->assoc_to_uri($arr);
- $this->assertEquals($a, $b);
+ $this->assertEquals('a/1/b/2', $this->uri->assoc_to_uri(array('a' => '1', 'b' => '2')));
}
// --------------------------------------------------------------------
@@ -286,28 +264,18 @@ class URI_test extends CI_TestCase {
$this->uri->segments[1] = 'segment';
$this->uri->rsegments[1] = 'segment';
- $a = '/segment/';
- $b = $this->uri->slash_segment(1, 'both');
- $this->assertEquals($a, $b);
- $b = $this->uri->slash_rsegment(1, 'both');
- $this->assertEquals($a, $b);
-
+ $this->assertEquals('/segment/', $this->uri->slash_segment(1, 'both'));
+ $this->assertEquals('/segment/', $this->uri->slash_rsegment(1, 'both'));
+
$a = '/segment';
- $b = $this->uri->slash_segment(1, 'leading');
- $this->assertEquals($a, $b);
- $b = $this->uri->slash_rsegment(1, 'leading');
- $this->assertEquals($a, $b);
-
- $a = 'segment/';
- $b = $this->uri->slash_segment(1, 'trailing');
- $this->assertEquals($a, $b);
- $b = $this->uri->slash_rsegment(1, 'trailing');
- $this->assertEquals($a, $b);
- }
+ $this->assertEquals('/segment', $this->uri->slash_segment(1, 'leading'));
+ $this->assertEquals('/segment', $this->uri->slash_rsegment(1, 'leading'));
+ $this->assertEquals('segment/', $this->uri->slash_segment(1, 'trailing'));
+ $this->assertEquals('segment/', $this->uri->slash_rsegment(1, 'trailing'));
+ }
}
-// END URI_test Class
/* End of file URI_test.php */
-/* Location: ./tests/core/URI_test.php */
+/* Location: ./tests/core/URI_test.php */ \ No newline at end of file
diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php
index fb40f0608..9e16e29b4 100644
--- a/tests/codeigniter/database/DB_driver_test.php
+++ b/tests/codeigniter/database/DB_driver_test.php
@@ -2,8 +2,6 @@
class DB_driver_test extends CI_TestCase {
- // ------------------------------------------------------------------------
-
public function test_initialize()
{
$config = Mock_Database_DB::config(DB_DRIVER);
@@ -32,5 +30,5 @@ class DB_driver_test extends CI_TestCase {
{
return new Mock_Database_Drivers_Postgre($config);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/DB_test.php b/tests/codeigniter/database/DB_test.php
index 9b93e223d..d5c0dea08 100644
--- a/tests/codeigniter/database/DB_test.php
+++ b/tests/codeigniter/database/DB_test.php
@@ -2,8 +2,6 @@
class DB_test extends CI_TestCase {
- // ------------------------------------------------------------------------
-
public function test_db_invalid()
{
$connection = new Mock_Database_DB(array(
@@ -45,5 +43,5 @@ class DB_test extends CI_TestCase {
$this->assertTrue($db instanceof CI_DB);
$this->assertTrue($db instanceof CI_DB_Driver);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/count_test.php b/tests/codeigniter/database/query_builder/count_test.php
index 5e691692d..90ac5283e 100644
--- a/tests/codeigniter/database/query_builder/count_test.php
+++ b/tests/codeigniter/database/query_builder/count_test.php
@@ -22,10 +22,7 @@ class Count_test extends CI_TestCase {
*/
public function test_count_all()
{
- $job_count = $this->db->count_all('job');
-
- // Check the result
- $this->assertEquals(4, $job_count);
+ $this->assertEquals(4, $this->db->count_all('job'));
}
// ------------------------------------------------------------------------
@@ -35,10 +32,7 @@ class Count_test extends CI_TestCase {
*/
public function test_count_all_results()
{
- $job_count = $this->db->like('name', 'ian')
- ->count_all_results('job');
-
- // Check the result
- $this->assertEquals(2, $job_count);
+ $this->assertEquals(2, $this->db->like('name', 'ian')->count_all_results('job'));
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/delete_test.php b/tests/codeigniter/database/query_builder/delete_test.php
index 84ea7616f..ab9d97f56 100644
--- a/tests/codeigniter/database/query_builder/delete_test.php
+++ b/tests/codeigniter/database/query_builder/delete_test.php
@@ -23,9 +23,7 @@ class Delete_test extends CI_TestCase {
public function test_delete()
{
// Check initial record
- $job1 = $this->db->where('id', 1)
- ->get('job')
- ->row();
+ $job1 = $this->db->where('id', 1)->get('job')->row();
$this->assertEquals('Developer', $job1->name);
@@ -33,8 +31,7 @@ class Delete_test extends CI_TestCase {
$this->db->delete('job', array('id' => 1));
// Check the record
- $job1 = $this->db->where('id', 1)
- ->get('job');
+ $job1 = $this->db->where('id', 1)->get('job');
$this->assertEmpty($job1->result_array());
}
@@ -47,13 +44,8 @@ class Delete_test extends CI_TestCase {
public function test_delete_several_tables()
{
// Check initial record
- $user4 = $this->db->where('id', 4)
- ->get('user')
- ->row();
-
- $job4 = $this->db->where('id', 4)
- ->get('job')
- ->row();
+ $user4 = $this->db->where('id', 4)->get('user')->row();
+ $job4 = $this->db->where('id', 4)->get('job')->row();
$this->assertEquals('Musician', $job4->name);
$this->assertEquals('Chris Martin', $user4->name);
diff --git a/tests/codeigniter/database/query_builder/distinct_test.php b/tests/codeigniter/database/query_builder/distinct_test.php
index 925eadb19..cc98009ce 100644
--- a/tests/codeigniter/database/query_builder/distinct_test.php
+++ b/tests/codeigniter/database/query_builder/distinct_test.php
@@ -23,11 +23,10 @@ class Distinct_test extends CI_TestCase {
public function test_distinct()
{
$users = $this->db->select('country')
- ->distinct()
- ->get('user')
- ->result_array();
-
- // Check the result
+ ->distinct()
+ ->get('user')
+ ->result_array();
+
$this->assertEquals(3, count($users));
}
diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php
new file mode 100644
index 000000000..27e678f22
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/escape_test.php
@@ -0,0 +1,68 @@
+<?php
+
+class Escape_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_escape_like_percent_sign()
+ {
+ // Escape the like string
+ $string = $this->db->escape_like_str('\%foo');
+
+ if (strpos(DB_DRIVER, 'mysql') !== FALSE)
+ {
+ $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '!';";
+ }
+ else
+ {
+ $sql = 'SELECT "value" FROM "misc" WHERE "key" LIKE \''.$string.'%\' ESCAPE \'!\';';
+ }
+
+ $res = $this->db->query($sql)->result_array();
+
+ // Check the result
+ $this->assertEquals(1, count($res));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_escape_like_backslash_sign()
+ {
+ // Escape the like string
+ $string = $this->db->escape_like_str('\\');
+
+ if (strpos(DB_DRIVER, 'mysql') !== FALSE)
+ {
+ $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '!';";
+ }
+ else
+ {
+ $sql = 'SELECT "value" FROM "misc" WHERE "key" LIKE \''.$string.'%\' ESCAPE \'!\';';
+ }
+
+ $res = $this->db->query($sql)->result_array();
+
+ // Check the result
+ $this->assertEquals(2, count($res));
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/from_test.php b/tests/codeigniter/database/query_builder/from_test.php
index 95ae4dfdb..7aaae348d 100644
--- a/tests/codeigniter/database/query_builder/from_test.php
+++ b/tests/codeigniter/database/query_builder/from_test.php
@@ -23,10 +23,9 @@ class From_test extends CI_TestCase {
public function test_from_simple()
{
$jobs = $this->db->from('job')
- ->get()
- ->result_array();
-
- // Check items
+ ->get()
+ ->result_array();
+
$this->assertEquals(4, count($jobs));
}
@@ -38,14 +37,13 @@ class From_test extends CI_TestCase {
public function test_from_with_where()
{
$job1 = $this->db->from('job')
- ->where('id', 1)
- ->get()
- ->row();
-
- // Check the result
+ ->where('id', 1)
+ ->get()
+ ->row();
+
$this->assertEquals('1', $job1->id);
$this->assertEquals('Developer', $job1->name);
$this->assertEquals('Awesome job, but sometimes makes you bored', $job1->description);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php
index 0751c9332..156027537 100644
--- a/tests/codeigniter/database/query_builder/get_test.php
+++ b/tests/codeigniter/database/query_builder/get_test.php
@@ -23,7 +23,7 @@ class Get_test extends CI_TestCase {
public function test_get_simple()
{
$jobs = $this->db->get('job')->result_array();
-
+
// Dummy jobs contain 4 rows
$this->assertCount(4, $jobs);
@@ -41,13 +41,13 @@ class Get_test extends CI_TestCase {
*/
public function test_get_where()
{
- $job1 = $this->db->get('job', array('id' => 1))->result_array();
-
+ $job1 = $this->db->get_where('job', array('id' => 1))->result_array();
+
// Dummy jobs contain 1 rows
$this->assertCount(1, $job1);
// Check rows item
$this->assertEquals('Developer', $job1[0]['name']);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php
index 7d8abc33f..5249f7c87 100644
--- a/tests/codeigniter/database/query_builder/group_test.php
+++ b/tests/codeigniter/database/query_builder/group_test.php
@@ -23,12 +23,11 @@ class Group_test extends CI_TestCase {
public function test_group_by()
{
$jobs = $this->db->select('name')
- ->from('job')
- ->group_by('name')
- ->get()
- ->result_array();
-
- // Check the result
+ ->from('job')
+ ->group_by('name')
+ ->get()
+ ->result_array();
+
$this->assertEquals(4, count($jobs));
}
@@ -40,14 +39,13 @@ class Group_test extends CI_TestCase {
public function test_having_by()
{
$jobs = $this->db->select('name')
- ->from('job')
- ->group_by('name')
- ->having('SUM(id) > 2')
- ->get()
- ->result_array();
-
- // Check the result
+ ->from('job')
+ ->group_by('name')
+ ->having('SUM(id) > 2')
+ ->get()
+ ->result_array();
+
$this->assertEquals(2, count($jobs));
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php
index 8ba60e242..a9aafb66e 100644
--- a/tests/codeigniter/database/query_builder/insert_test.php
+++ b/tests/codeigniter/database/query_builder/insert_test.php
@@ -26,7 +26,7 @@ class Insert_test extends CI_TestCase {
public function test_insert()
{
$job_data = array('id' => 1, 'name' => 'Grocery Sales', 'description' => 'Discount!');
-
+
// Do normal insert
$this->assertTrue($this->db->insert('job', $job_data));
@@ -45,10 +45,10 @@ class Insert_test extends CI_TestCase {
public function test_insert_batch()
{
$job_datas = array(
- array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'),
+ array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'),
array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'),
);
-
+
// Do insert batch except for sqlite driver
if (strpos(DB_DRIVER, 'sqlite') === FALSE)
{
@@ -62,5 +62,5 @@ class Insert_test extends CI_TestCase {
$this->assertEquals('Cab Driver', $job_3->name);
}
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php
index e05329d67..25bd4accb 100644
--- a/tests/codeigniter/database/query_builder/join_test.php
+++ b/tests/codeigniter/database/query_builder/join_test.php
@@ -34,5 +34,25 @@ class Join_test extends CI_TestCase {
$this->assertEquals('Derek Jones', $job_user[0]['user_name']);
$this->assertEquals('Developer', $job_user[0]['job_name']);
}
-
+
+ // ------------------------------------------------------------------------
+
+ public function test_join_escape_multiple_conditions()
+ {
+ // We just need a valid query produced, not one that makes sense
+ $fields = array($this->db->protect_identifiers('table1.field1'), $this->db->protect_identifiers('table2.field2'));
+
+ $expected = 'SELECT '.implode(', ', $fields)
+ ."\nFROM ".$this->db->escape_identifiers('table1')
+ ."\nLEFT JOIN ".$this->db->escape_identifiers('table2').' ON '.implode(' = ', $fields)
+ .' AND '.$fields[0]." = 'foo' AND ".$fields[1].' = 0';
+
+ $result = $this->db->select('table1.field1, table2.field2')
+ ->from('table1')
+ ->join('table2', "table1.field1 = table2.field2 AND table1.field1 = 'foo' AND table2.field2 = 0", 'LEFT')
+ ->get_compiled_select();
+
+ $this->assertEquals($expected, $result);
+ }
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/like_test.php b/tests/codeigniter/database/query_builder/like_test.php
index df98c713f..5f3e52228 100644
--- a/tests/codeigniter/database/query_builder/like_test.php
+++ b/tests/codeigniter/database/query_builder/like_test.php
@@ -86,5 +86,5 @@ class Like_test extends CI_TestCase {
$this->assertEquals('Accountant', $jobs[1]['name']);
$this->assertEquals('Musician', $jobs[2]['name']);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/limit_test.php b/tests/codeigniter/database/query_builder/limit_test.php
index 704f3b651..a0954c7ab 100644
--- a/tests/codeigniter/database/query_builder/limit_test.php
+++ b/tests/codeigniter/database/query_builder/limit_test.php
@@ -25,8 +25,7 @@ class Limit_test extends CI_TestCase {
$jobs = $this->db->limit(2)
->get('job')
->result_array();
-
- // Check the result
+
$this->assertEquals(2, count($jobs));
}
@@ -40,10 +39,10 @@ class Limit_test extends CI_TestCase {
$jobs = $this->db->limit(2, 2)
->get('job')
->result_array();
-
- // Check the result
+
$this->assertEquals(2, count($jobs));
$this->assertEquals('Accountant', $jobs[0]['name']);
$this->assertEquals('Musician', $jobs[1]['name']);
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/order_test.php b/tests/codeigniter/database/query_builder/order_test.php
index 01aa1c2b4..46f452bae 100644
--- a/tests/codeigniter/database/query_builder/order_test.php
+++ b/tests/codeigniter/database/query_builder/order_test.php
@@ -25,7 +25,7 @@ class Order_test extends CI_TestCase {
$jobs = $this->db->order_by('name', 'asc')
->get('job')
->result_array();
-
+
// Check the result
$this->assertEquals(4, count($jobs));
$this->assertEquals('Accountant', $jobs[0]['name']);
@@ -44,12 +44,12 @@ class Order_test extends CI_TestCase {
$jobs = $this->db->order_by('name', 'desc')
->get('job')
->result_array();
-
- // Check the result
+
$this->assertEquals(4, count($jobs));
$this->assertEquals('Politician', $jobs[0]['name']);
$this->assertEquals('Musician', $jobs[1]['name']);
$this->assertEquals('Developer', $jobs[2]['name']);
$this->assertEquals('Accountant', $jobs[3]['name']);
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php
index 0d299ed16..877b5d8c0 100644
--- a/tests/codeigniter/database/query_builder/select_test.php
+++ b/tests/codeigniter/database/query_builder/select_test.php
@@ -25,7 +25,7 @@ class Select_test extends CI_TestCase {
$jobs_name = $this->db->select('name')
->get('job')
->result_array();
-
+
// Check rows item
$this->assertArrayHasKey('name',$jobs_name[0]);
$this->assertFalse(array_key_exists('id', $jobs_name[0]));
@@ -42,7 +42,7 @@ class Select_test extends CI_TestCase {
$job_min = $this->db->select_min('id')
->get('job')
->row();
-
+
// Minimum id was 1
$this->assertEquals('1', $job_min->id);
}
@@ -57,7 +57,7 @@ class Select_test extends CI_TestCase {
$job_max = $this->db->select_max('id')
->get('job')
->row();
-
+
// Maximum id was 4
$this->assertEquals('4', $job_max->id);
}
@@ -72,7 +72,7 @@ class Select_test extends CI_TestCase {
$job_avg = $this->db->select_avg('id')
->get('job')
->row();
-
+
// Average should be 2.5
$this->assertEquals('2.5', $job_avg->id);
}
@@ -87,9 +87,9 @@ class Select_test extends CI_TestCase {
$job_sum = $this->db->select_sum('id')
->get('job')
->row();
-
+
// Sum of ids should be 10
$this->assertEquals('10', $job_sum->id);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/truncate_test.php b/tests/codeigniter/database/query_builder/truncate_test.php
index 2a9c8a91e..09923c7f1 100644
--- a/tests/codeigniter/database/query_builder/truncate_test.php
+++ b/tests/codeigniter/database/query_builder/truncate_test.php
@@ -24,7 +24,6 @@ class Truncate_test extends CI_TestCase {
{
// Check initial record
$jobs = $this->db->get('job')->result_array();
-
$this->assertEquals(4, count($jobs));
// Do the empty
@@ -32,7 +31,6 @@ class Truncate_test extends CI_TestCase {
// Check the record
$jobs = $this->db->get('job');
-
$this->assertEmpty($jobs->result_array());
}
@@ -45,16 +43,13 @@ class Truncate_test extends CI_TestCase {
{
// Check initial record
$users = $this->db->get('user')->result_array();
-
$this->assertEquals(4, count($users));
// Do the empty
- $this->db->from('user')
- ->truncate();
+ $this->db->from('user')->truncate();
// Check the record
$users = $this->db->get('user');
-
$this->assertEmpty($users->result_array());
}
diff --git a/tests/codeigniter/database/query_builder/update_test.php b/tests/codeigniter/database/query_builder/update_test.php
index f5bbffd4f..27a647c45 100644
--- a/tests/codeigniter/database/query_builder/update_test.php
+++ b/tests/codeigniter/database/query_builder/update_test.php
@@ -23,23 +23,14 @@ class Update_test extends CI_TestCase {
public function test_update()
{
// Check initial record
- $job1 = $this->db->where('id', 1)
- ->get('job')
- ->row();
-
+ $job1 = $this->db->where('id', 1)->get('job')->row();
$this->assertEquals('Developer', $job1->name);
// Do the update
- $job_data = array('name' => 'Programmer');
-
- $this->db->where('id', 1)
- ->update('job', $job_data);
+ $this->db->where('id', 1)->update('job', array('name' => 'Programmer'));
// Check updated record
- $job1 = $this->db->where('id', 1)
- ->get('job')
- ->row();
-
+ $job1 = $this->db->where('id', 1)->get('job')->row();
$this->assertEquals('Programmer', $job1->name);
}
@@ -51,10 +42,7 @@ class Update_test extends CI_TestCase {
public function test_update_with_set()
{
// Check initial record
- $job1 = $this->db->where('id', 4)
- ->get('job')
- ->row();
-
+ $job1 = $this->db->where('id', 4)->get('job')->row();
$this->assertEquals('Musician', $job1->name);
// Do the update
@@ -62,10 +50,8 @@ class Update_test extends CI_TestCase {
$this->db->update('job', NULL, 'id = 4');
// Check updated record
- $job1 = $this->db->where('id', 4)
- ->get('job')
- ->row();
-
+ $job1 = $this->db->where('id', 4)->get('job')->row();
$this->assertEquals('Vocalist', $job1->name);
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php
index 607eaa076..20b7a567c 100644
--- a/tests/codeigniter/database/query_builder/where_test.php
+++ b/tests/codeigniter/database/query_builder/where_test.php
@@ -22,11 +22,8 @@ class Where_test extends CI_TestCase {
*/
public function test_where_simple_key_value()
{
- $job1 = $this->db->where('id', 1)
- ->get('job')
- ->row();
+ $job1 = $this->db->where('id', 1)->get('job')->row();
- // Check the result
$this->assertEquals('1', $job1->id);
$this->assertEquals('Developer', $job1->name);
}
@@ -38,11 +35,7 @@ class Where_test extends CI_TestCase {
*/
public function test_where_custom_key_value()
{
- $jobs = $this->db->where('id !=', 1)
- ->get('job')
- ->result_array();
-
- // Check the result
+ $jobs = $this->db->where('id !=', 1)->get('job')->result_array();
$this->assertEquals(3, count($jobs));
}
@@ -54,16 +47,12 @@ class Where_test extends CI_TestCase {
public function test_where_associative_array()
{
$where = array('id >' => 2, 'name !=' => 'Accountant');
- $jobs = $this->db->where($where)
- ->get('job')
- ->result_array();
+ $jobs = $this->db->where($where)->get('job')->result_array();
- // Check the result
$this->assertEquals(1, count($jobs));
// Should be Musician
$job = current($jobs);
-
$this->assertEquals('Musician', $job['name']);
}
@@ -75,16 +64,12 @@ class Where_test extends CI_TestCase {
public function test_where_custom_string()
{
$where = "id > 2 AND name != 'Accountant'";
- $jobs = $this->db->where($where)
- ->get('job')
- ->result_array();
+ $jobs = $this->db->where($where)->get('job')->result_array();
- // Check the result
$this->assertEquals(1, count($jobs));
// Should be Musician
$job = current($jobs);
-
$this->assertEquals('Musician', $job['name']);
}
@@ -100,7 +85,6 @@ class Where_test extends CI_TestCase {
->get('job')
->result_array();
- // Check the result
$this->assertEquals(3, count($jobs));
$this->assertEquals('Developer', $jobs[0]['name']);
$this->assertEquals('Politician', $jobs[1]['name']);
@@ -118,7 +102,6 @@ class Where_test extends CI_TestCase {
->get('job')
->result_array();
- // Check the result
$this->assertEquals(2, count($jobs));
$this->assertEquals('Politician', $jobs[0]['name']);
$this->assertEquals('Accountant', $jobs[1]['name']);
@@ -135,10 +118,9 @@ class Where_test extends CI_TestCase {
->get('job')
->result_array();
- // Check the result
$this->assertEquals(2, count($jobs));
$this->assertEquals('Developer', $jobs[0]['name']);
$this->assertEquals('Musician', $jobs[1]['name']);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php
index 9cd15960f..ba46e86f9 100644
--- a/tests/codeigniter/helpers/array_helper_test.php
+++ b/tests/codeigniter/helpers/array_helper_test.php
@@ -1,7 +1,7 @@
<?php
class Array_helper_test extends CI_TestCase {
-
+
public function set_up()
{
$this->helper('array');
@@ -13,31 +13,31 @@ class Array_helper_test extends CI_TestCase {
'herb' => 'cook'
);
}
-
+
// ------------------------------------------------------------------------
-
+
public function test_element_with_existing_item()
- {
+ {
$this->assertEquals(FALSE, element('testing', $this->my_array));
-
+
$this->assertEquals('not set', element('testing', $this->my_array, 'not set'));
-
+
$this->assertEquals('bar', element('foo', $this->my_array));
}
-
- // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
public function test_random_element()
{
// Send a string, not an array to random_element
$this->assertEquals('my string', random_element('my string'));
-
+
// Test sending an array
$this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array));
}
- // ------------------------------------------------------------------------
-
+ // ------------------------------------------------------------------------
+
public function test_elements()
{
$this->assertEquals(TRUE, is_array(elements('test', $this->my_array)));
diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php
index 17d1ef21e..1b79b9480 100644
--- a/tests/codeigniter/helpers/date_helper_test.php
+++ b/tests/codeigniter/helpers/date_helper_test.php
@@ -5,153 +5,163 @@ class Date_helper_test extends CI_TestCase {
public function set_up()
{
$this->helper('date');
+
+ $this->time = time();
}
// ------------------------------------------------------------------------
public function test_now_local()
{
+ /*
+
// This stub job, is simply to cater $config['time_reference']
$config = $this->getMock('CI_Config');
$config->expects($this->any())
->method('item')
->will($this->returnValue('local'));
-
+
// Add the stub to our test instance
$this->ci_instance_var('config', $config);
- $expected = time();
- $test = now();
- $this->assertEquals($expected, $test);
+ */
+
+ $this->ci_set_config('time_reference', 'local');
+
+ $this->assertEquals(time(), now());
}
// ------------------------------------------------------------------------
- public function test_now_gmt()
+ public function test_now_utc()
{
+ /*
+
// This stub job, is simply to cater $config['time_reference']
$config = $this->getMock('CI_Config');
$config->expects($this->any())
->method('item')
- ->will($this->returnValue('gmt'));
-
+ ->will($this->returnValue('UTC'));
+
// 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);
+ */
+
+ $this->assertEquals(
+ mktime(gmdate('G'), gmdate('i'), gmdate('s'), gmdate('n'), gmdate('j'), gmdate('Y')),
+ now('UTC')
+ );
}
// ------------------------------------------------------------------------
public function test_mdate()
{
- $time = time();
- $expected = date("Y-m-d - h:i a", $time);
- $test = mdate("%Y-%m-%d - %h:%i %a", $time);
- $this->assertEquals($expected, $test);
+ $this->assertEquals(
+ date('Y-m-d - h:i a', $this->time),
+ mdate('%Y-%m-%d - %h:%i %a', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_rfc822()
{
- $time = time();
- $format = 'DATE_RFC822';
- $expected = date("D, d M y H:i:s O", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date(DATE_RFC822, $this->time),
+ standard_date('DATE_RFC822', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_atom()
{
- $time = time();
- $format = 'DATE_ATOM';
- $expected = date("Y-m-d\TH:i:sO", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date(DATE_ATOM, $this->time),
+ standard_date('DATE_ATOM', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_cookie()
{
- $time = time();
- $format = 'DATE_COOKIE';
- $expected = date("l, d-M-y H:i:s \U\T\C", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date(DATE_COOKIE, $this->time),
+ standard_date('DATE_COOKIE', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_iso8601()
{
- $time = time();
- $format = 'DATE_ISO8601';
- $expected = date("Y-m-d\TH:i:sO", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date(DATE_ISO8601, $this->time),
+ standard_date('DATE_ISO8601', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_rfc850()
{
- $time = time();
- $format = 'DATE_RFC850';
- $expected = date("l, d-M-y H:i:s \U\T\C", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date(DATE_RFC850, $this->time),
+ standard_date('DATE_RFC850', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_rfc1036()
{
- $time = time();
- $format = 'DATE_RFC1036';
- $expected = date("D, d M y H:i:s O", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date(DATE_RFC1036, $this->time),
+ standard_date('DATE_RFC1036', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_rfc1123()
{
- $time = time();
- $format = 'DATE_RFC1123';
- $expected = date("D, d M Y H:i:s O", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date(DATE_RFC1123, $this->time),
+ standard_date('DATE_RFC1123', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_rfc2822()
{
- $time = time();
- $format = 'DATE_RFC2822';
- $expected = date("D, d M Y H:i:s O", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date(DATE_RFC2822, $this->time),
+ standard_date('DATE_RFC2822', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_rss()
{
- $time = time();
- $format = 'DATE_RSS';
- $expected = date("D, d M Y H:i:s O", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date(DATE_RSS, $this->time),
+ standard_date('DATE_RSS', $this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_standard_date_w3c()
{
- $time = time();
- $format = 'DATE_W3C';
- $expected = date("Y-m-d\TH:i:sO", $time);
- $this->assertEquals($expected, standard_date($format, $time));
+ $this->assertEquals(
+ date(DATE_W3C, $this->time),
+ standard_date('DATE_W3C', $this->time)
+ );
}
// ------------------------------------------------------------------------
@@ -183,39 +193,36 @@ class Date_helper_test extends CI_TestCase {
public function test_local_to_gmt()
{
- $t = time();
- $expected = mktime(gmdate("H", $t), gmdate("i", $t), gmdate("s", $t), gmdate("m", $t), gmdate("d", $t), gmdate("Y", $t));
- $this->assertEquals($expected, local_to_gmt($t));
+ $this->assertEquals(
+ mktime(
+ gmdate('G', $this->time), gmdate('i', $this->time), gmdate('s', $this->time),
+ gmdate('n', $this->time), gmdate('j', $this->time), gmdate('Y', $this->time)
+ ),
+ local_to_gmt($this->time)
+ );
}
// ------------------------------------------------------------------------
public function test_gmt_to_local()
{
- $timestamp = '1140153693';
- $timezone = 'UM8';
- $daylight_saving = TRUE;
-
- $this->assertEquals(1140128493, gmt_to_local($timestamp, $timezone, $daylight_saving));
+ $this->assertEquals(1140128493, gmt_to_local('1140153693', 'UM8', TRUE));
}
// ------------------------------------------------------------------------
public function test_mysql_to_unix()
{
- $time = time();
- $this->assertEquals($time,
- mysql_to_unix(date("Y-m-d H:i:s", $time)));
+ $this->assertEquals($this->time, mysql_to_unix(date('Y-m-d H:i:s', $this->time)));
}
// ------------------------------------------------------------------------
public function test_unix_to_human()
{
- $time = time();
- $this->assertEquals(date("Y-m-d h:i A", $time), unix_to_human($time));
- $this->assertEquals(date("Y-m-d h:i:s A", $time), unix_to_human($time, TRUE, 'us'));
- $this->assertEquals(date("Y-m-d H:i:s", $time), unix_to_human($time, TRUE, 'eu'));
+ $this->assertEquals(date('Y-m-d h:i A', $this->time), unix_to_human($this->time));
+ $this->assertEquals(date('Y-m-d h:i:s A', $this->time), unix_to_human($this->time, TRUE, 'us'));
+ $this->assertEquals(date('Y-m-d H:i:s', $this->time), unix_to_human($this->time, TRUE, 'eu'));
}
// ------------------------------------------------------------------------
@@ -223,8 +230,7 @@ class Date_helper_test extends CI_TestCase {
public function test_human_to_unix()
{
$date = '2000-12-31 10:00:00 PM';
- $expected = strtotime($date);
- $this->assertEquals($expected, human_to_unix($date));
+ $this->assertEquals(strtotime($date), human_to_unix($date));
$this->assertFalse(human_to_unix());
}
@@ -283,6 +289,7 @@ class Date_helper_test extends CI_TestCase {
$this->assertArrayHasKey('UP3', timezones());
$this->assertEquals(0, timezones('non_existant'));
}
+
}
/* End of file date_helper_test.php */ \ No newline at end of file
diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php
index 3937d2913..c39ccd8d0 100644
--- a/tests/codeigniter/helpers/directory_helper_test.php
+++ b/tests/codeigniter/helpers/directory_helper_test.php
@@ -1,41 +1,52 @@
<?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' => ''));
-
+ $structure = array(
+ 'libraries' => array(
+ 'benchmark.html' => '',
+ 'database' => array('active_record.html' => '', 'binds.html' => ''),
+ 'email.html' => '',
+ '0' => '',
+ '.hiddenfile.txt' => ''
+ )
+ );
+
vfsStream::create($structure, $this->_test_dir);
// test default recursive behavior
- $expected = array('libraries' => array('benchmark.html', 'database' =>
- array('active_record.html', 'binds.html'), 'email.html'));
-
- $this->assertEquals($expected, directory_map(vfsStream::url('testDir')));
+ $expected = array(
+ 'libraries' => array(
+ 'benchmark.html',
+ 'database' => array('active_record.html', 'binds.html'),
+ 'email.html',
+ '0'
+ )
+ );
- // test recursion depth behavior
- $expected = array('libraries');
-
- $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), 1));
+ $this->assertEquals($expected, directory_map(vfsStream::url('testDir')));
// test detection of hidden files
- $expected = array('libraries' => array('benchmark.html', 'database' =>
- array('active_record.html', 'binds.html'), 'email.html', '.hiddenfile.txt'));
-
+ $expected['libraries'][] = '.hiddenfile.txt';
+
$this->assertEquals($expected, directory_map(vfsStream::url('testDir'), FALSE, TRUE));
- }
+
+ // test recursion depth behavior
+ $this->assertEquals(array('libraries'), directory_map(vfsStream::url('testDir'), 1));
+ }
+
}
/* End of file directory_helper_test.php */ \ No newline at end of file
diff --git a/tests/codeigniter/helpers/email_helper_test.php b/tests/codeigniter/helpers/email_helper_test.php
index a01f3d5af..fea452f5f 100644
--- a/tests/codeigniter/helpers/email_helper_test.php
+++ b/tests/codeigniter/helpers/email_helper_test.php
@@ -14,5 +14,5 @@ class Email_helper_test extends CI_TestCase {
$this->assertEquals(TRUE, valid_email('test@test.com'));
$this->assertEquals(TRUE, valid_email('my.test@test.com'));
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php
index 4b9c29485..9b03da9d7 100644
--- a/tests/codeigniter/helpers/file_helper_test.php
+++ b/tests/codeigniter/helpers/file_helper_test.php
@@ -5,24 +5,23 @@ class File_helper_Test extends CI_TestCase {
public function set_up()
{
$this->helper('file');
-
+
vfsStreamWrapper::register();
vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir'));
-
+
$this->_test_dir = vfsStreamWrapper::getRoot();
}
-
+
// --------------------------------------------------------------------
-
+
public function test_read_file()
{
$this->assertFalse(read_file('does_not_exist'));
-
+
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
-
- $file = vfsStream::newFile('my_file.txt')->withContent($content)
- ->at($this->_test_dir);
-
+
+ $file = vfsStream::newFile('my_file.txt')->withContent($content)->at($this->_test_dir);
+
$this->assertEquals($content, read_file(vfsStream::url('my_file.txt')));
}
@@ -31,126 +30,124 @@ class File_helper_Test extends CI_TestCase {
public function test_octal_permissions()
{
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
-
+
$file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
- ->lastModified(time() - 86400)
- ->at($this->_test_dir);
-
- $this->assertEquals('777', octal_permissions($file->getPermissions()));
+ ->lastModified(time() - 86400)
+ ->at($this->_test_dir);
+
+ $this->assertEquals('777', octal_permissions($file->getPermissions()));
}
- // --------------------------------------------------------------------
-
+ // --------------------------------------------------------------------
+
/**
* More tests should happen here, since I'm not hitting the whole function.
*/
public function test_symbolic_permissions()
{
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
-
+
$file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
- ->lastModified(time() - 86400)
- ->at($this->_test_dir);
-
- $this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions()));
+ ->lastModified(time() - 86400)
+ ->at($this->_test_dir);
+
+ $this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions()));
}
- // --------------------------------------------------------------------
-
+ // --------------------------------------------------------------------
+
public function test_get_mime_by_extension()
{
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
-
+
$file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
- ->lastModified(time() - 86400)
- ->at($this->_test_dir);
-
- $this->assertEquals('text/plain',
- get_mime_by_extension(vfsStream::url('my_file.txt')));
-
- // Test a mime with an array, such as png
+ ->lastModified(time() - 86400)
+ ->at($this->_test_dir);
+
+ $this->assertEquals('text/plain', get_mime_by_extension(vfsStream::url('my_file.txt')));
+
+ // Test a mime with an array, such as png
$file = vfsStream::newFile('foo.png')->at($this->_test_dir);
-
- $this->assertEquals('image/png', get_mime_by_extension(vfsStream::url('foo.png')));
-
+
+ $this->assertEquals('image/png', get_mime_by_extension(vfsStream::url('foo.png')));
+
// Test a file not in the mimes array
$file = vfsStream::newFile('foo.blarfengar')->at($this->_test_dir);
-
+
$this->assertFalse(get_mime_by_extension(vfsStream::url('foo.blarfengar')));
}
- // --------------------------------------------------------------------
+ // --------------------------------------------------------------------
public function test_get_file_info()
{
// Test Bad File
$this->assertFalse(get_file_info('i_am_bad_boo'));
-
+
// Test the rest
-
+
// First pass in an array
$vals = array(
'name', 'server_path', 'size', 'date',
- 'readable', 'writable', 'executable', 'fileperms'
+ 'readable', 'writable', 'executable', 'fileperms'
);
-
+
$this->_test_get_file_info($vals);
// Test passing in vals as a string.
- $vals = 'name, server_path, size, date, readable, writable, executable, fileperms';
- $this->_test_get_file_info($vals);
+ $this->_test_get_file_info(implode(', ', $vals));
}
-
+
private function _test_get_file_info($vals)
{
$content = 'Jack and Jill went up the mountain to fight a billy goat.';
$last_modified = time() - 86400;
-
+
$file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)
- ->lastModified($last_modified)
- ->at($this->_test_dir);
-
+ ->lastModified($last_modified)
+ ->at($this->_test_dir);
+
$ret_values = array(
- 'name' => 'my_file.txt',
- 'server_path' => 'vfs://my_file.txt',
- 'size' => 57,
- 'date' => $last_modified,
+ 'name' => 'my_file.txt',
+ 'server_path' => 'vfs://my_file.txt',
+ 'size' => 57,
+ 'date' => $last_modified,
'readable' => TRUE,
- 'writable' => TRUE,
- 'executable' => TRUE,
+ 'writable' => TRUE,
+ 'executable' => TRUE,
'fileperms' => 33279
);
-
+
$info = get_file_info(vfsStream::url('my_file.txt'), $vals);
-
+
foreach ($info as $k => $v)
{
$this->assertEquals($ret_values[$k], $v);
}
}
-
- // --------------------------------------------------------------------
+
+ // --------------------------------------------------------------------
// Skipping for now, as it's not implemented in vfsStreamWrapper
// flock(): vfsStreamWrapper::stream_lock is not implemented!
-
+
// public function test_write_file()
// {
- // if ( ! defined('FOPEN_WRITE_CREATE_DESTRUCTIVE'))
- // {
- // define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb');
- // }
- //
- // $content = 'Jack and Jill went up the mountain to fight a billy goat.';
- //
- // $file = vfsStream::newFile('write.txt', 0777)->withContent('')
- // ->lastModified(time() - 86400)
- // ->at($this->_test_dir);
- //
- // $this->assertTrue(write_file(vfsStream::url('write.txt'), $content));
- //
+ // if ( ! defined('FOPEN_WRITE_CREATE_DESTRUCTIVE'))
+ // {
+ // define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb');
+ // }
+ //
+ // $content = 'Jack and Jill went up the mountain to fight a billy goat.';
+ //
+ // $file = vfsStream::newFile('write.txt', 0777)->withContent('')
+ // ->lastModified(time() - 86400)
+ // ->at($this->_test_dir);
+ //
+ // $this->assertTrue(write_file(vfsStream::url('write.txt'), $content));
+ //
// }
- // --------------------------------------------------------------------
-
+ // --------------------------------------------------------------------
+
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php
index 80bace9d1..1a30ed993 100644
--- a/tests/codeigniter/helpers/form_helper_test.php
+++ b/tests/codeigniter/helpers/form_helper_test.php
@@ -3,26 +3,26 @@
require BASEPATH . 'core/Common.php';
require BASEPATH . 'helpers/form_helper.php';
-class Form_helper_test extends CI_TestCase
+class Form_helper_test extends CI_TestCase
{
public function test_form_hidden()
- {
+ {
$expected = <<<EOH
<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',
@@ -34,37 +34,37 @@ EOH;
$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
@@ -76,16 +76,16 @@ EOH;
</select>
EOH;
-
+
$options = array(
- 'small' => 'Small Shirt',
- 'med' => 'Medium Shirt',
- 'large' => 'Large Shirt',
- 'xlarge' => 'Extra Large Shirt',
+ 'small' => 'Small Shirt',
+ 'med' => 'Medium Shirt',
+ 'large' => 'Large Shirt',
+ 'xlarge' => 'Extra Large Shirt',
);
-
+
$this->assertEquals($expected, form_dropdown('shirts', $options, 'large'));
-
+
$expected = <<<EOH
<select name="shirts" multiple="multiple">
<option value="small" selected="selected">Small Shirt</option>
@@ -95,22 +95,22 @@ EOH;
</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'
+ 'volvo' => 'Volvo',
+ 'saab' => 'Saab'
),
'German Cars' => array(
- 'mercedes' => 'Mercedes',
- 'audi' => 'Audi'
+ 'mercedes' => 'Mercedes',
+ 'audi' => 'Audi'
)
);
-
+
$expected = <<<EOH
<select name="cars" multiple="multiple">
<optgroup label="Swedish Cars">
@@ -124,13 +124,10 @@ EOH;
</select>
EOH;
-
- $cars_on_sale = array('volvo', 'audi');
-
- $this->assertEquals($expected, form_dropdown('cars', $options, $cars_on_sale));
-
+
+ $this->assertEquals($expected, form_dropdown('cars', $options, array('volvo', 'audi')));
}
-
+
public function test_form_multiselect()
{
$expected = <<<EOH
@@ -142,17 +139,17 @@ EOH;
</select>
EOH;
-
+
$options = array(
- 'small' => 'Small Shirt',
- 'med' => 'Medium Shirt',
- 'large' => 'Large Shirt',
- 'xlarge' => 'Extra Large Shirt',
- );
-
+ 'small' => 'Small Shirt',
+ 'med' => 'Medium Shirt',
+ 'large' => 'Large Shirt',
+ 'xlarge' => 'Extra Large Shirt',
+ );
+
$this->assertEquals($expected, form_multiselect('shirts[]', $options, array('med', 'large')));
}
-
+
public function test_form_fieldset()
{
$expected = <<<EOH
@@ -160,7 +157,7 @@ EOH;
<legend>Address Information</legend>
EOH;
-
+
$this->assertEquals($expected, form_fieldset('Address Information'));
}
@@ -169,10 +166,10 @@ EOH;
$expected = <<<EOH
</fieldset></div></div>
EOH;
-
+
$this->assertEquals($expected, form_fieldset_close('</div></div>'));
}
-
+
public function test_form_checkbox()
{
$expected = <<<EOH
@@ -182,7 +179,7 @@ EOH;
$this->assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE));
}
-
+
public function test_form_radio()
{
$expected = <<<EOH
@@ -192,7 +189,7 @@ EOH;
$this->assertEquals($expected, form_radio('newsletter', 'accept', TRUE));
}
-
+
public function test_form_submit()
{
$expected = <<<EOH
@@ -202,7 +199,7 @@ EOH;
$this->assertEquals($expected, form_submit('mysubmit', 'Submit Post!'));
}
-
+
public function test_form_label()
{
$expected = <<<EOH
@@ -211,7 +208,7 @@ EOH;
$this->assertEquals($expected, form_label('What is your Name', 'username'));
}
-
+
public function test_form_reset()
{
$expected = <<<EOH
@@ -221,7 +218,7 @@ EOH;
$this->assertEquals($expected, form_reset('myreset', 'Reset'));
}
-
+
public function test_form_button()
{
$expected = <<<EOH
@@ -229,9 +226,9 @@ EOH;
EOH;
- $this->assertEquals($expected, form_button('name','content'));
+ $this->assertEquals($expected, form_button('name', 'content'));
}
-
+
public function test_form_close()
{
$expected = <<<EOH
@@ -240,13 +237,14 @@ EOH;
$this->assertEquals($expected, form_close('</div></div>'));
}
-
+
public function test_form_prep()
{
- $expected = "Here is a string containing &quot;quoted&quot; text.";
-
+ $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
index 28974b0f8..4dd717ff7 100644
--- a/tests/codeigniter/helpers/html_helper_test.php
+++ b/tests/codeigniter/helpers/html_helper_test.php
@@ -6,24 +6,40 @@ class Html_helper_test extends CI_TestCase {
{
$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_heading_array_attributes()
+ {
+ // Test array of attributes
+ $this->assertEquals('<h2 class="bar" id="foo">foobar</h2>', heading('foobar', 2, array('class' => 'bar', 'id' => 'foo')));
+ }
+
+ public function test_heading_object_attributes()
+ {
+ // Test array of attributes
+ $this->assertEquals('<h2 class="bar" id="foo">foobar</h2>', heading('foobar', 2, array('class' => 'bar', 'id' => 'foo')));
+ $test = new stdClass;
+ $test->class = "bar";
+ $test->id = "foo";
+ $this->assertEquals('<h2 class="bar" id="foo">foobar</h2>', heading('foobar', 2, $test));
+ }
+
// ------------------------------------------------------------------------
-
+
public function test_Ul()
{
$expect = <<<EOH
@@ -35,11 +51,9 @@ class Html_helper_test extends CI_TestCase {
EOH;
$expect = ltrim($expect);
-
$list = array('foo', 'bar');
-
- $this->assertEquals($expect, ul($list));
+ $this->assertEquals(ltrim($expect), ul($list));
$expect = <<<EOH
<ul class="test">
@@ -51,13 +65,11 @@ EOH;
$expect = ltrim($expect);
- $list = array('foo', 'bar');
-
$this->assertEquals($expect, ul($list, 'class="test"'));
$this->assertEquals($expect, ul($list, array('class' => 'test')));
}
-
+
// ------------------------------------------------------------------------
public function test_NBS()
@@ -66,15 +78,14 @@ EOH;
}
// ------------------------------------------------------------------------
-
+
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
index 9e9478711..f3b0ebbe8 100644
--- a/tests/codeigniter/helpers/inflector_helper_test.php
+++ b/tests/codeigniter/helpers/inflector_helper_test.php
@@ -1,12 +1,12 @@
<?php
class Inflector_helper_test extends CI_TestCase {
-
+
public function set_up()
{
$this->helper('inflector');
}
-
+
public function test_singular()
{
$strs = array(
@@ -16,15 +16,15 @@ class Inflector_helper_test extends CI_TestCase {
'smells' => 'smell',
'equipment' => 'equipment'
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, singular($str));
}
}
-
+
// --------------------------------------------------------------------
-
+
public function test_plural()
{
$strs = array(
@@ -35,15 +35,15 @@ class Inflector_helper_test extends CI_TestCase {
'witch' => 'witches',
'equipment' => 'equipment'
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, plural($str));
- }
- }
+ }
+ }
// --------------------------------------------------------------------
-
+
public function test_camelize()
{
$strs = array(
@@ -52,15 +52,15 @@ class Inflector_helper_test extends CI_TestCase {
'i-am-playing-a-trick' => 'i-am-playing-a-trick',
'what_do_you_think-yo?' => 'whatDoYouThink-yo?',
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, camelize($str));
}
- }
+ }
// --------------------------------------------------------------------
-
+
public function test_underscore()
{
$strs = array(
@@ -69,7 +69,7 @@ class Inflector_helper_test extends CI_TestCase {
'i-am-playing-a-trick' => 'i-am-playing-a-trick',
'what_do_you_think-yo?' => 'what_do_you_think-yo?',
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, underscore($str));
@@ -77,7 +77,7 @@ class Inflector_helper_test extends CI_TestCase {
}
// --------------------------------------------------------------------
-
+
public function test_humanize()
{
$strs = array(
@@ -86,10 +86,11 @@ class Inflector_helper_test extends CI_TestCase {
'i-am-playing-a-trick' => 'I-am-playing-a-trick',
'what_do_you_think-yo?' => 'What Do You Think-yo?',
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, humanize($str));
}
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php
index 4bb9a918a..ef6aae138 100644
--- a/tests/codeigniter/helpers/number_helper_test.php
+++ b/tests/codeigniter/helpers/number_helper_test.php
@@ -1,35 +1,35 @@
<?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 = new stdClass;
$obj->lang = $lang;
$this->ci_instance($obj);
}
-
+
// Quick helper to actually grab the language
// file. Consider moving this to ci_testcase?
public function _get_lang($name)
@@ -37,41 +37,40 @@ class Number_helper_test extends CI_TestCase {
require BASEPATH.'language/english/'.$name.'_lang.php';
return $lang;
}
-
+
public function test_byte_format()
{
$this->assertEquals('456 Bytes', byte_format(456));
}
-
+
public function test_kb_format()
{
$this->assertEquals('4.5 KB', byte_format(4567));
}
-
+
public function test_kb_format_medium()
{
$this->assertEquals('44.6 KB', byte_format(45678));
}
-
+
public function test_kb_format_large()
{
$this->assertEquals('446.1 KB', byte_format(456789));
}
-
+
public function test_mb_format()
{
$this->assertEquals('3.3 MB', byte_format(3456789));
}
-
+
public function test_gb_format()
{
$this->assertEquals('1.8 GB', byte_format(1932735283.2));
}
-
+
public function test_tb_format()
{
$this->assertEquals('112,283.3 TB', byte_format(123456789123456789));
}
-}
-// EOF \ No newline at end of file
+} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php
index 632f57501..0faf6f383 100644
--- a/tests/codeigniter/helpers/path_helper_test.php
+++ b/tests/codeigniter/helpers/path_helper_test.php
@@ -8,9 +8,8 @@ class Path_helper_test extends CI_TestCase {
}
public function test_set_realpath()
- {
- $expected = getcwd() . DIRECTORY_SEPARATOR;
- $this->assertEquals($expected, set_realpath(getcwd()));
+ {
+ $this->assertEquals(getcwd().DIRECTORY_SEPARATOR, set_realpath(getcwd()));
}
public function test_set_realpath_nonexistent_directory()
diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php
index 29c3d6594..75701ec13 100644
--- a/tests/codeigniter/helpers/string_helper_test.php
+++ b/tests/codeigniter/helpers/string_helper_test.php
@@ -10,18 +10,18 @@ class String_helper_test extends CI_TestCase {
public function test_strip_slashes()
{
$expected = array(
- "Is your name O'reilly?",
+ "Is your name O'reilly?",
"No, my name is O'connor."
);
-
+
$str = array(
"Is your name O\'reilly?",
"No, my name is O\'connor."
);
-
+
$this->assertEquals($expected, strip_slashes($str));
}
-
+
public function test_trim_slashes()
{
$strs = array(
@@ -144,4 +144,5 @@ class String_helper_test extends CI_TestCase {
$this->assertEquals('file-1', increment_string('file', '-', '1'));
$this->assertEquals(124, increment_string('123', ''));
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php
index 584066b0c..f131469cb 100644
--- a/tests/codeigniter/helpers/text_helper_test.php
+++ b/tests/codeigniter/helpers/text_helper_test.php
@@ -3,16 +3,16 @@
class Text_helper_test extends CI_TestCase {
private $_long_string;
-
+
public function set_up()
{
$this->helper('text');
-
+
$this->_long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.';
}
-
+
// ------------------------------------------------------------------------
-
+
public function test_word_limiter()
{
$this->assertEquals('Once upon a time,&#8230;', word_limiter($this->_long_string, 4));
@@ -20,8 +20,8 @@ class Text_helper_test extends CI_TestCase {
$this->assertEquals('', word_limiter('', 4));
}
- // ------------------------------------------------------------------------
-
+ // ------------------------------------------------------------------------
+
public function test_character_limiter()
{
$this->assertEquals('Once upon a time, a&#8230;', character_limiter($this->_long_string, 20));
@@ -30,22 +30,22 @@ class Text_helper_test extends CI_TestCase {
$this->assertEquals('Short', character_limiter('Short', 5));
}
- // ------------------------------------------------------------------------
-
+ // ------------------------------------------------------------------------
+
public function test_ascii_to_entities()
{
$strs = array(
'“‘ “test”' => '&#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()
{
@@ -53,27 +53,27 @@ class Text_helper_test extends CI_TestCase {
'&#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()
+
+ // ------------------------------------------------------------------------
+
+ public function test_convert_accented_characters()
{
$this->assertEquals('AAAeEEEIIOOEUUUeY', convert_accented_characters('ÀÂÄÈÊËÎÏÔŒÙÛÜŸ'));
$this->assertEquals('a e i o u n ue', convert_accented_characters('á é í ó ú ñ ü'));
}
- // ------------------------------------------------------------------------
-
+ // ------------------------------------------------------------------------
+
public function test_censored_words()
{
$censored = array('boob', 'nerd', 'ass', 'fart');
-
+
$strs = array(
'Ted bobbled the ball' => 'Ted bobbled the ball',
'Jake is a nerdo' => 'Jake is a nerdo',
@@ -81,28 +81,26 @@ class Text_helper_test extends CI_TestCase {
'Did Mary Fart?' => 'Did Mary $*#?',
'Jake is really a boob' => 'Jake is really a $*#'
);
-
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, word_censor($str, $censored, '$*#'));
}
-
+
// test censored words being sent as a string
$this->assertEquals('test', word_censor('test', 'test'));
}
- // ------------------------------------------------------------------------
+ // ------------------------------------------------------------------------
public function test_highlight_code()
{
- $code = '<?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));
+ $this->assertEquals($expect, highlight_code('<?php var_dump($this); ?>'));
}
- // ------------------------------------------------------------------------
+ // ------------------------------------------------------------------------
public function test_highlight_phrase()
{
@@ -113,16 +111,16 @@ class Text_helper_test extends CI_TestCase {
'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()
+ public function test_ellipsize()
{
$strs = array(
'0' => array(
@@ -144,16 +142,30 @@ class Text_helper_test extends CI_TestCase {
'short' => 'short'
),
);
-
+
foreach ($strs as $pos => $s)
{
foreach ($s as $str => $expect)
{
- $this->assertEquals($expect, ellipsize($str, 10, $pos));
+ $this->assertEquals($expect, ellipsize($str, 10, $pos));
}
}
}
- // ------------------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ public function test_word_wrap()
+ {
+ $string = 'Here is a simple string of text that will help us demonstrate this function.';
+ $this->assertEquals(substr_count(word_wrap($string, 25), "\n"), 4);
+ }
+
+ // ------------------------------------------------------------------------
+
+ public function test_default_word_wrap_charlim()
+ {
+ $string = "Here is a longer string of text that will help us demonstrate the default charlim of this function.";
+ $this->assertEquals(strpos(word_wrap($string), "\n"), 73);
+ }
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php
index c561809ce..c81c5f1b8 100644
--- a/tests/codeigniter/helpers/url_helper_test.php
+++ b/tests/codeigniter/helpers/url_helper_test.php
@@ -72,4 +72,5 @@ class Url_helper_test extends CI_TestCase {
$this->assertEquals($out, auto_link($in, 'url'));
}
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/helpers/xml_helper_test.php b/tests/codeigniter/helpers/xml_helper_test.php
index a83fef91e..e8cf411da 100644
--- a/tests/codeigniter/helpers/xml_helper_test.php
+++ b/tests/codeigniter/helpers/xml_helper_test.php
@@ -6,10 +6,10 @@ class Xml_helper_test extends CI_TestCase {
{
$this->helper('xml');
}
-
+
public function test_xml_convert()
{
$this->assertEquals('&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/Calendar_test.php b/tests/codeigniter/libraries/Calendar_test.php
new file mode 100644
index 000000000..95668d70d
--- /dev/null
+++ b/tests/codeigniter/libraries/Calendar_test.php
@@ -0,0 +1,204 @@
+<?php
+
+class Calendar_test extends CI_TestCase {
+
+ function __construct()
+ {
+ $obj = new stdClass;
+ $obj->calendar = new Mock_Libraries_Calendar();
+
+ $this->calendar = $obj->calendar;
+ }
+
+ function test_initialize()
+ {
+ $this->calendar->initialize(array(
+ 'month_type' => 'short',
+ 'start_day' => 'monday'
+ ));
+ $this->assertEquals('short', $this->calendar->month_type);
+ $this->assertEquals('monday', $this->calendar->start_day);
+ }
+
+ /**
+ * @covers Mock_Libraries_Calendar::parse_template
+ */
+ function test_generate()
+ {
+ $no_events = '<table border="0" cellpadding="4" cellspacing="0">
+
+<tr>
+<th colspan="7">September&nbsp;2011</th>
+
+</tr>
+
+<tr>
+<td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td>
+</tr>
+
+<tr>
+<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>1</td><td>2</td><td>3</td>
+</tr>
+
+<tr>
+<td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td>
+</tr>
+
+<tr>
+<td>11</td><td>12</td><td>13</td><td>14</td><td>15</td><td>16</td><td>17</td>
+</tr>
+
+<tr>
+<td>18</td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td>
+</tr>
+
+<tr>
+<td>25</td><td>26</td><td>27</td><td>28</td><td>29</td><td>30</td><td>&nbsp;</td>
+</tr>
+
+</table>';
+
+ $this->assertEquals($no_events, $this->calendar->generate(2011, 9));
+
+ $data = array(
+ 3 => 'http://example.com/news/article/2006/03/',
+ 7 => 'http://example.com/news/article/2006/07/',
+ 13 => 'http://example.com/news/article/2006/13/',
+ 26 => 'http://example.com/news/article/2006/26/'
+ );
+
+ $events = '<table border="0" cellpadding="4" cellspacing="0">
+
+<tr>
+<th colspan="7">September&nbsp;2011</th>
+
+</tr>
+
+<tr>
+<td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td>
+</tr>
+
+<tr>
+<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>1</td><td>2</td><td><a href="http://example.com/news/article/2006/03/">3</a></td>
+</tr>
+
+<tr>
+<td>4</td><td>5</td><td>6</td><td><a href="http://example.com/news/article/2006/07/">7</a></td><td>8</td><td>9</td><td>10</td>
+</tr>
+
+<tr>
+<td>11</td><td>12</td><td><a href="http://example.com/news/article/2006/13/">13</a></td><td>14</td><td>15</td><td>16</td><td>17</td>
+</tr>
+
+<tr>
+<td>18</td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td>
+</tr>
+
+<tr>
+<td>25</td><td><a href="http://example.com/news/article/2006/26/">26</a></td><td>27</td><td>28</td><td>29</td><td>30</td><td>&nbsp;</td>
+</tr>
+
+</table>';
+
+ $this->assertEquals($events, $this->calendar->generate(2011, 9, $data));
+ }
+
+ function test_get_month_name()
+ {
+ $this->calendar->month_type = NULL;
+ $this->assertEquals('January', $this->calendar->get_month_name('01'));
+
+ $this->calendar->month_type = 'short';
+ $this->assertEquals('Jan', $this->calendar->get_month_name('01'));
+ }
+
+ function test_get_day_names()
+ {
+ $this->assertEquals(array(
+ 'Sunday',
+ 'Monday',
+ 'Tuesday',
+ 'Wednesday',
+ 'Thursday',
+ 'Friday',
+ 'Saturday'
+ ), $this->calendar->get_day_names('long'));
+
+ $this->assertEquals(array(
+ 'Sun',
+ 'Mon',
+ 'Tue',
+ 'Wed',
+ 'Thu',
+ 'Fri',
+ 'Sat'
+ ), $this->calendar->get_day_names('short'));
+
+ $this->calendar->day_type = NULL;
+
+ $this->assertEquals(array(
+ 'Su',
+ 'Mo',
+ 'Tu',
+ 'We',
+ 'Th',
+ 'Fr',
+ 'Sa'
+ ), $this->calendar->get_day_names());
+ }
+
+ function test_adjust_date()
+ {
+ $this->assertEquals(array('month' => 8, 'year' => 2012), $this->calendar->adjust_date(8, 2012));
+ $this->assertEquals(array('month' => 1, 'year' => 2013), $this->calendar->adjust_date(13, 2012));
+ }
+
+ function test_get_total_days()
+ {
+ $this->assertEquals(0, $this->calendar->get_total_days(13, 2012));
+
+ $this->assertEquals(31, $this->calendar->get_total_days(1, 2012));
+ $this->assertEquals(28, $this->calendar->get_total_days(2, 2011));
+ $this->assertEquals(29, $this->calendar->get_total_days(2, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(3, 2012));
+ $this->assertEquals(30, $this->calendar->get_total_days(4, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(5, 2012));
+ $this->assertEquals(30, $this->calendar->get_total_days(6, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(7, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(8, 2012));
+ $this->assertEquals(30, $this->calendar->get_total_days(9, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(10, 2012));
+ $this->assertEquals(30, $this->calendar->get_total_days(11, 2012));
+ $this->assertEquals(31, $this->calendar->get_total_days(12, 2012));
+ }
+
+ function test_default_template()
+ {
+ $array = array(
+ 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',
+ 'heading_row_start' => '<tr>',
+ 'heading_previous_cell' => '<th><a href="{previous_url}">&lt;&lt;</a></th>',
+ 'heading_title_cell' => '<th colspan="{colspan}">{heading}</th>',
+ 'heading_next_cell' => '<th><a href="{next_url}">&gt;&gt;</a></th>',
+ 'heading_row_end' => '</tr>',
+ 'week_row_start' => '<tr>',
+ 'week_day_cell' => '<td>{week_day}</td>',
+ 'week_row_end' => '</tr>',
+ 'cal_row_start' => '<tr>',
+ 'cal_cell_start' => '<td>',
+ 'cal_cell_start_today' => '<td>',
+ 'cal_cell_content' => '<a href="{content}">{day}</a>',
+ 'cal_cell_content_today' => '<a href="{content}"><strong>{day}</strong></a>',
+ 'cal_cell_no_content' => '{day}',
+ 'cal_cell_no_content_today' => '<strong>{day}</strong>',
+ 'cal_cell_blank' => '&nbsp;',
+ 'cal_cell_end' => '</td>',
+ 'cal_cell_end_today' => '</td>',
+ 'cal_row_end' => '</tr>',
+ 'table_close' => '</table>'
+ );
+
+ $this->assertEquals($array, $this->calendar->default_template());
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php
new file mode 100644
index 000000000..153a25e1d
--- /dev/null
+++ b/tests/codeigniter/libraries/Encrypt_test.php
@@ -0,0 +1,72 @@
+<?php
+
+class Encrypt_test extends CI_TestCase {
+
+ public function set_up()
+ {
+ $obj = new stdClass;
+ $obj->encrypt = new Mock_Libraries_Encrypt();
+
+ $this->ci_instance($obj);
+ $this->encrypt = $obj->encrypt;
+
+ $this->ci_set_config('encryption_key', "Encryptin'glike@boss!");
+ $this->msg = 'My secret message';
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_encode()
+ {
+ $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_decode()
+ {
+ $encoded_msg = $this->encrypt->encode($this->msg);
+ $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_optional_key()
+ {
+ $key = 'Ohai!ù0129°03182%HD1892P0';
+ $encoded_msg = $this->encrypt->encode($this->msg, $key);
+ $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg, $key));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_default_cipher()
+ {
+ $this->assertEquals('rijndael-256', $this->encrypt->get_cipher());
+ }
+
+ // --------------------------------------------------------------------
+
+
+ public function test_set_cipher()
+ {
+ $this->encrypt->set_cipher(MCRYPT_BLOWFISH);
+ $this->assertEquals('blowfish', $this->encrypt->get_cipher());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_default_mode()
+ {
+ $this->assertEquals('cbc', $this->encrypt->get_mode());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_set_mode()
+ {
+ $this->encrypt->set_mode(MCRYPT_MODE_CFB);
+ $this->assertEquals('cfb', $this->encrypt->get_mode());
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php
index c3d88fa85..b68f44a33 100644
--- a/tests/codeigniter/libraries/Parser_test.php
+++ b/tests/codeigniter/libraries/Parser_test.php
@@ -1,73 +1,74 @@
<?php
class Parser_test extends CI_TestCase {
-
+
public function set_up()
{
- $obj = new StdClass;
+ $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(
@@ -78,16 +79,14 @@ class Parser_test extends CI_TestCase {
'flying' => 'no'),
)
);
-
+
$template = "{title}\n{powers}{invisibility}\n{flying}{/powers}";
-
- $result = "Super Heroes\nyes\nno";
-
- $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
+
+ $this->assertEquals("Super Heroes\nyes\nno", $this->parser->parse_string($template, $data, TRUE));
}
-
+
// --------------------------------------------------------------------
-
+
private function _mismatched_var_pair()
{
$data = array(
@@ -98,13 +97,11 @@ class Parser_test extends CI_TestCase {
'flying' => 'no'),
)
);
-
+
$template = "{title}\n{powers}{invisibility}\n{flying}";
-
$result = "Super Heroes\n{powers}{invisibility}\n{flying}";
-
- $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
+
+ $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
}
- // --------------------------------------------------------------------
} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php
new file mode 100644
index 000000000..135f71806
--- /dev/null
+++ b/tests/codeigniter/libraries/Session_test.php
@@ -0,0 +1,405 @@
+<?php
+
+/**
+ * Session driver library unit test
+ */
+class Session_test extends CI_TestCase {
+ protected $settings = array(
+ 'use_cookies' => 0,
+ 'use_only_cookies' => 0,
+ 'cache_limiter' => false
+ );
+ protected $setting_vals = array();
+ protected $cookie_vals;
+ protected $session;
+
+ /**
+ * Set up test framework
+ */
+ public function set_up()
+ {
+ // Override settings
+ foreach ($this->settings as $name => $value) {
+ $this->setting_vals[$name] = ini_get('session.'.$name);
+ ini_set('session.'.$name, $value);
+ }
+
+ // Start with clean environment
+ $this->cookie_vals = $_COOKIE;
+ $_COOKIE = array();
+
+ // Establish necessary support classes
+ $obj = new stdClass;
+ $classes = array(
+ 'config' => 'cfg',
+ 'load' => 'load',
+ 'input' => 'in'
+ );
+ foreach ($classes as $name => $abbr) {
+ $class = $this->ci_core_class($abbr);
+ $obj->$name = new $class;
+ }
+ $this->ci_instance($obj);
+
+ // Attach session instance locally
+ $config = array(
+ 'sess_encrypt_cookie' => FALSE,
+ 'sess_use_database' => FALSE,
+ 'sess_table_name' => '',
+ 'sess_expiration' => 7200,
+ 'sess_expire_on_close' => FALSE,
+ 'sess_match_ip' => FALSE,
+ 'sess_match_useragent' => TRUE,
+ 'sess_cookie_name' => 'ci_session',
+ 'cookie_path' => '',
+ 'cookie_domain' => '',
+ 'cookie_secure' => FALSE,
+ 'cookie_httponly' => FALSE,
+ 'sess_time_to_update' => 300,
+ 'time_reference' => 'local',
+ 'cookie_prefix' => '',
+ 'encryption_key' => 'foobar',
+ 'sess_valid_drivers' => array(
+ 'Mock_Libraries_Session_native',
+ 'Mock_Libraries_Session_cookie'
+ )
+ );
+ $this->session = new Mock_Libraries_Session($config);
+ }
+
+ /**
+ * Tear down test framework
+ */
+ public function tear_down()
+ {
+ // Restore environment
+ if (session_id()) session_destroy();
+ $_SESSION = array();
+ $_COOKIE = $this->cookie_vals;
+
+ // Restore settings
+ foreach ($this->settings as $name => $value) {
+ ini_set('session.'.$name, $this->setting_vals[$name]);
+ }
+ }
+
+ /**
+ * Test set_userdata() function
+ *
+ * @covers CI_Session::set_userdata
+ * @covers CI_Session::userdata
+ */
+ public function test_set_userdata()
+ {
+ // Set userdata values for each driver
+ $key1 = 'test1';
+ $ckey2 = 'test2';
+ $nkey2 = 'test3';
+ $cmsg1 = 'Some test data';
+ $cmsg2 = 42;
+ $nmsg1 = 'Other test data';
+ $nmsg2 = true;
+ $this->session->cookie->set_userdata($key1, $cmsg1);
+ $this->session->set_userdata($ckey2, $cmsg2);
+ $this->session->native->set_userdata($key1, $nmsg1);
+ $this->session->set_userdata($nkey2, $nmsg2);
+
+ // Verify independent messages
+ $this->assertEquals($cmsg1, $this->session->cookie->userdata($key1));
+ $this->assertEquals($nmsg1, $this->session->native->userdata($key1));
+
+ // Verify pre-selected driver sets
+ $this->assertEquals($cmsg2, $this->session->cookie->userdata($ckey2));
+ $this->assertEquals($nmsg2, $this->session->native->userdata($nkey2));
+
+ // Verify no crossover
+ $this->assertNull($this->session->cookie->userdata($nkey2));
+ $this->assertNull($this->session->native->userdata($ckey2));
+ }
+
+ /**
+ * Test the has_userdata() function
+ *
+ * @covers CI_Session::has_userdata
+ */
+ public function test_has_userdata()
+ {
+ // Set a userdata value for each driver
+ $key = 'hastest';
+ $cmsg = 'My test data';
+ $this->session->cookie->set_userdata($key, $cmsg);
+ $nmsg = 'Your test data';
+ $this->session->native->set_userdata($key, $nmsg);
+
+ // Verify values exist
+ $this->assertTrue($this->session->cookie->has_userdata($key));
+ $this->assertTrue($this->session->native->has_userdata($key));
+
+ // Verify non-existent values
+ $nokey = 'hasnot';
+ $this->assertFalse($this->session->cookie->has_userdata($nokey));
+ $this->assertFalse($this->session->native->has_userdata($nokey));
+ }
+
+ /**
+ * Test the all_userdata() function
+ *
+ * @covers CI_Session::all_userdata
+ */
+ public function test_all_userdata()
+ {
+ // Set a specific series of data for each driver
+ $cdata = array(
+ 'one' => 'first',
+ 'two' => 'second',
+ 'three' => 'third',
+ 'foo' => 'bar',
+ 'bar' => 'baz'
+ );
+ $ndata = array(
+ 'one' => 'gold',
+ 'two' => 'silver',
+ 'three' => 'bronze',
+ 'foo' => 'baz',
+ 'bar' => 'foo'
+ );
+ $this->session->cookie->set_userdata($cdata);
+ $this->session->native->set_userdata($ndata);
+
+ // Make sure all values are present
+ $call = $this->session->cookie->all_userdata();
+ foreach ($cdata as $key => $value) {
+ $this->assertEquals($value, $call[$key]);
+ }
+ $nall = $this->session->native->all_userdata();
+ foreach ($ndata as $key => $value) {
+ $this->assertEquals($value, $nall[$key]);
+ }
+ }
+
+ /**
+ * Test the unset_userdata() function
+ *
+ * @covers CI_Session::unset_userdata
+ */
+ public function test_unset_userdata()
+ {
+ // Set a userdata message for each driver
+ $key = 'untest';
+ $cmsg = 'Other test data';
+ $this->session->cookie->set_userdata($key, $cmsg);
+ $nmsg = 'Sundry test data';
+ $this->session->native->set_userdata($key, $nmsg);
+
+ // Verify independent messages
+ $this->assertEquals($this->session->cookie->userdata($key), $cmsg);
+ $this->assertEquals($this->session->native->userdata($key), $nmsg);
+
+ // Unset them and verify absence
+ $this->session->cookie->unset_userdata($key);
+ $this->session->native->unset_userdata($key);
+ $this->assertNull($this->session->cookie->userdata($key));
+ $this->assertNull($this->session->native->userdata($key));
+ }
+
+ /**
+ * Test the flashdata() functions
+ *
+ * @covers CI_Session::set_flashdata
+ * @covers CI_Session::flashdata
+ */
+ public function test_flashdata()
+ {
+ // Set flashdata message for each driver
+ $key = 'fltest';
+ $cmsg = 'Some flash data';
+ $this->session->cookie->set_flashdata($key, $cmsg);
+ $nmsg = 'Other flash data';
+ $this->session->native->set_flashdata($key, $nmsg);
+
+ // Simulate page reload
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+
+ // Verify independent messages
+ $this->assertEquals($cmsg, $this->session->cookie->flashdata($key));
+ $this->assertEquals($nmsg, $this->session->native->flashdata($key));
+
+ // Simulate next page reload
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+
+ // Verify absence of messages
+ $this->assertNull($this->session->cookie->flashdata($key));
+ $this->assertNull($this->session->native->flashdata($key));
+ }
+
+ /**
+ * Test the keep_flashdata() function
+ *
+ * @covers CI_Session::keep_flashdata
+ */
+ public function test_keep_flashdata()
+ {
+ // Set flashdata message for each driver
+ $key = 'kfltest';
+ $cmsg = 'My flash data';
+ $this->session->cookie->set_flashdata($key, $cmsg);
+ $nmsg = 'Your flash data';
+ $this->session->native->set_flashdata($key, $nmsg);
+
+ // Simulate page reload and verify independent messages
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+ $this->assertEquals($cmsg, $this->session->cookie->flashdata($key));
+ $this->assertEquals($nmsg, $this->session->native->flashdata($key));
+
+ // Keep messages
+ $this->session->cookie->keep_flashdata($key);
+ $this->session->native->keep_flashdata($key);
+
+ // Simulate next page reload and verify message persistence
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+ $this->assertEquals($cmsg, $this->session->cookie->flashdata($key));
+ $this->assertEquals($nmsg, $this->session->native->flashdata($key));
+
+ // Simulate next page reload and verify absence of messages
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+ $this->assertNull($this->session->cookie->flashdata($key));
+ $this->assertNull($this->session->native->flashdata($key));
+ }
+
+ /**
+ * Test the all_flashdata() function
+ *
+ * @covers CI_Session::all_flashdata
+ */
+ public function test_all_flashdata()
+ {
+ // Set a specific series of data for each driver
+ $cdata = array(
+ 'one' => 'first',
+ 'two' => 'second',
+ 'three' => 'third',
+ 'foo' => 'bar',
+ 'bar' => 'baz'
+ );
+ $ndata = array(
+ 'one' => 'gold',
+ 'two' => 'silver',
+ 'three' => 'bronze',
+ 'foo' => 'baz',
+ 'bar' => 'foo'
+ );
+ $this->session->cookie->set_flashdata($cdata);
+ $this->session->native->set_flashdata($ndata);
+
+ // Simulate page reload and make sure all values are present
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+ $this->assertEquals($cdata, $this->session->cookie->all_flashdata());
+ $this->assertEquals($ndata, $this->session->native->all_flashdata());
+ }
+
+ /**
+ * Test the tempdata() functions
+ *
+ * @covers CI_Session::set_tempdata
+ * @covers CI_Session::tempdata
+ */
+ public function test_set_tempdata()
+ {
+ // Set tempdata message for each driver - 1 second timeout
+ $key = 'tmptest';
+ $cmsg = 'Some temp data';
+ $this->session->cookie->set_tempdata($key, $cmsg, 1);
+ $nmsg = 'Other temp data';
+ $this->session->native->set_tempdata($key, $nmsg, 1);
+
+ // Simulate page reload and verify independent messages
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+ $this->assertEquals($cmsg, $this->session->cookie->tempdata($key));
+ $this->assertEquals($nmsg, $this->session->native->tempdata($key));
+
+ // Wait 2 seconds, simulate page reload and verify message absence
+ sleep(2);
+ $this->session->cookie->reload();
+ $this->session->native->reload();
+ $this->assertNull($this->session->cookie->tempdata($key));
+ $this->assertNull($this->session->native->tempdata($key));
+ }
+
+ /**
+ * Test the unset_tempdata() function
+ *
+ * @covers CI_Session::unset_tempdata
+ */
+ public function test_unset_tempdata()
+ {
+ // Set tempdata message for each driver - 1 second timeout
+ $key = 'utmptest';
+ $cmsg = 'My temp data';
+ $this->session->cookie->set_tempdata($key, $cmsg, 1);
+ $nmsg = 'Your temp data';
+ $this->session->native->set_tempdata($key, $nmsg, 1);
+
+ // Verify independent messages
+ $this->assertEquals($cmsg, $this->session->cookie->tempdata($key));
+ $this->assertEquals($nmsg, $this->session->native->tempdata($key));
+
+ // Unset data and verify message absence
+ $this->session->cookie->unset_tempdata($key);
+ $this->session->native->unset_tempdata($key);
+ $this->assertNull($this->session->cookie->tempdata($key));
+ $this->assertNull($this->session->native->tempdata($key));
+ }
+
+ /**
+ * Test the sess_regenerate() function
+ *
+ * @covers CI_Session::sess_regenerate
+ */
+ public function test_sess_regenerate()
+ {
+ // Get current session id, regenerate, and compare
+ // Cookie driver
+ $oldid = $this->session->cookie->userdata('session_id');
+ $this->session->cookie->sess_regenerate();
+ $newid = $this->session->cookie->userdata('session_id');
+ $this->assertNotEquals($oldid, $newid);
+
+ // Native driver - bug #55267 (https://bugs.php.net/bug.php?id=55267) prevents testing this
+ // $oldid = session_id();
+ // $this->session->native->sess_regenerate();
+ // $oldid = session_id();
+ // $this->assertNotEquals($oldid, $newid);
+ }
+
+ /**
+ * Test the sess_destroy() function
+ *
+ * @covers CI_Session::sess_destroy
+ */
+ public function test_sess_destroy()
+ {
+ // Set a userdata message, destroy session, and verify absence
+ $key = 'dsttest';
+ $msg = 'More test data';
+
+ // Cookie driver
+ $this->session->cookie->set_userdata($key, $msg);
+ $this->assertEquals($msg, $this->session->cookie->userdata($key));
+ $this->session->cookie->sess_destroy();
+ $this->assertNull($this->session->cookie->userdata($key));
+
+ // Native driver
+ $this->session->native->set_userdata($key, $msg);
+ $this->assertEquals($msg, $this->session->native->userdata($key));
+ $this->session->native->sess_destroy();
+ $this->assertNull($this->session->native->userdata($key));
+ }
+}
+
diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php
index 13f338c6b..edfc83dd0 100644
--- a/tests/codeigniter/libraries/Table_test.php
+++ b/tests/codeigniter/libraries/Table_test.php
@@ -4,43 +4,39 @@ class Table_test extends CI_TestCase {
public function set_up()
{
- $obj = new StdClass;
+ $obj = new stdClass;
$obj->table = new Mock_Libraries_Table();
-
+
$this->ci_instance($obj);
-
+
$this->table = $obj->table;
}
-
// Setter Methods
// --------------------------------------------------------------------
-
+
public function test_set_template()
{
$this->assertFalse($this->table->set_template('not an array'));
-
- $template = array(
- 'a' => 'b'
- );
-
+
+ $template = array('a' => 'b');
+
$this->table->set_template($template);
$this->assertEquals($template, $this->table->template);
}
-
+
public function test_set_empty()
{
$this->table->set_empty('nada');
$this->assertEquals('nada', $this->table->empty_cells);
}
-
+
public function test_set_caption()
{
$this->table->set_caption('awesome cap');
$this->assertEquals('awesome cap', $this->table->caption);
}
-
-
+
/*
* @depends testPrepArgs
*/
@@ -49,9 +45,9 @@ class Table_test extends CI_TestCase {
// uses _prep_args internally, so we'll just do a quick
// check to verify that func_get_args and prep_args are
// being called.
-
+
$this->table->set_heading('name', 'color', 'size');
-
+
$this->assertEquals(
array(
array('data' => 'name'),
@@ -61,8 +57,7 @@ class Table_test extends CI_TestCase {
$this->table->heading
);
}
-
-
+
/*
* @depends testPrepArgs
*/
@@ -71,13 +66,13 @@ class Table_test extends CI_TestCase {
// uses _prep_args internally, so we'll just do a quick
// check to verify that func_get_args and prep_args are
// being called.
-
+
$this->table->add_row('my', 'pony', 'sings');
$this->table->add_row('your', 'pony', 'stinks');
$this->table->add_row('my pony', '>', 'your pony');
-
+
$this->assertEquals(count($this->table->rows), 3);
-
+
$this->assertEquals(
array(
array('data' => 'your'),
@@ -87,11 +82,10 @@ class Table_test extends CI_TestCase {
$this->table->rows[1]
);
}
-
-
+
// Uility Methods
// --------------------------------------------------------------------
-
+
public function test_prep_args()
{
$expected = array(
@@ -99,7 +93,7 @@ class Table_test extends CI_TestCase {
array('data' => 'color'),
array('data' => 'size')
);
-
+
$this->assertEquals(
$expected,
$this->table->prep_args(array('name', 'color', 'size'))
@@ -114,7 +108,7 @@ class Table_test extends CI_TestCase {
$this->table->prep_args(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome')))
);
}
-
+
public function test_default_template_keys()
{
$keys = array(
@@ -126,132 +120,124 @@ class Table_test extends CI_TestCase {
'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end',
'table_close'
);
-
+
foreach ($keys as $key)
{
$this->assertArrayHasKey($key, $this->table->default_template());
}
}
-
+
public function test_compile_template()
{
$this->assertFalse($this->table->set_template('invalid_junk'));
-
+
// non default key
$this->table->set_template(array('nonsense' => 'foo'));
$this->table->compile_template();
-
+
$this->assertArrayHasKey('nonsense', $this->table->template);
$this->assertEquals('foo', $this->table->template['nonsense']);
-
+
// override default
$this->table->set_template(array('table_close' => '</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;')
+ 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')
+ array('Katie', 'Blue')
);
-
+
$this->table->set_from_array($data, FALSE);
$this->assertEmpty($this->table->heading);
-
+
$this->table->clear();
-
- $expected_heading = array(
+
+ $this->table->set_from_array($data);
+ $this->assertEquals(count($this->table->rows), 2);
+
+ $expected = array(
array('data' => 'name'),
array('data' => 'color'),
array('data' => 'number')
);
-
- $expected_second = array(
+
+ $this->assertEquals($expected, $this->table->heading);
+
+ $expected = array(
array('data' => 'Katie'),
array('data' => 'Blue'),
);
-
- $this->table->set_from_array($data);
- $this->assertEquals(count($this->table->rows), 2);
-
- $this->assertEquals(
- $expected_heading,
- $this->table->heading
- );
-
- $this->assertEquals(
- $expected_second,
- $this->table->rows[1]
- );
+
+ $this->assertEquals($expected, $this->table->rows[1]);
}
-
- function test_set_from_object()
+
+ public function test_set_from_object()
{
// Make a stub of query instance
$query = new CI_TestCase();
@@ -268,29 +254,44 @@ class Table_test extends CI_TestCase {
return 2;
};
- $expected_heading = array(
+ $this->table->set_from_object($query);
+
+ $expected = array(
array('data' => 'name'),
array('data' => 'email')
);
- $expected_second = array(
+ $this->assertEquals($expected, $this->table->heading);
+
+ $expected = array(
'name' => array('data' => 'Foo Bar'),
'email' => array('data' => 'foo@bar.com'),
);
- $this->table->set_from_object($query);
+ $this->assertEquals($expected, $this->table->rows[1]);
+ }
- $this->assertEquals(
- $expected_heading,
- $this->table->heading
- );
-
- $this->assertEquals(
- $expected_second,
- $this->table->rows[1]
+ public function test_generate()
+ {
+ // Prepare the data
+ $data = array(
+ array('Name', 'Color', 'Size'),
+ array('Fred', 'Blue', 'Small'),
+ array('Mary', 'Red', 'Large'),
+ array('John', 'Green', 'Medium')
);
+
+ $table = $this->table->generate($data);
+
+ // Test the table header
+ $this->assertTrue(strpos($table, '<th>Name</th>') !== FALSE);
+ $this->assertTrue(strpos($table, '<th>Color</th>') !== FALSE);
+ $this->assertTrue(strpos($table, '<th>Size</th>') !== FALSE);
+
+ // Test the first entry
+ $this->assertTrue(strpos($table, '<td>Fred</td>') !== FALSE);
+ $this->assertTrue(strpos($table, '<td>Blue</td>') !== FALSE);
+ $this->assertTrue(strpos($table, '<td>Small</td>') !== FALSE);
}
-
- // 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
index 250aefb24..eb6dacb73 100644
--- a/tests/codeigniter/libraries/Typography_test.php
+++ b/tests/codeigniter/libraries/Typography_test.php
@@ -4,11 +4,11 @@ class Typography_test extends CI_TestCase {
public function set_up()
{
- $obj = new StdClass;
+ $obj = new stdClass;
$obj->type = new Mock_Libraries_Typography();
-
+
$this->ci_instance($obj);
-
+
$this->type = $obj->type;
}
@@ -33,18 +33,18 @@ class Typography_test extends CI_TestCase {
'foo..' => 'foo..',
'foo...bar.' => 'foo&#8230;bar.',
'test. new' => 'test.&nbsp; new',
- );
-
+ );
+
foreach ($strs as $str => $expected)
{
- $this->assertEquals($expected, $this->type->format_characters($str));
+ $this->assertEquals($expected, $this->type->format_characters($str));
}
}
// --------------------------------------------------------------------
public function test_nl2br_except_pre()
- {
+ {
$str = <<<EOH
Hello, I'm a happy string with some new lines.
@@ -85,12 +85,11 @@ That's my story and I'm sticking to it.<br />
The End.
EOH;
- $this->assertEquals($expected,
- $this->type->nl2br_except_pre($str));
+ $this->assertEquals($expected, $this->type->nl2br_except_pre($str));
}
// --------------------------------------------------------------------
-
+
public function test_auto_typography()
{
$this->_blank_string();
@@ -103,7 +102,7 @@ EOH;
}
// --------------------------------------------------------------------
-
+
private function _blank_string()
{
// Test blank string
@@ -131,7 +130,7 @@ EOH;
{
$str = "This has way too many linebreaks.\n\n\n\nSee?";
$expect = "<p>This has way too many linebreaks.</p>\n\n<p>See?</p>";
-
+
$this->assertEquals($expect, $this->type->auto_typography($str, TRUE));
}
@@ -141,7 +140,7 @@ EOH;
{
$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));
}
@@ -151,7 +150,7 @@ EOH;
{
$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));
}
@@ -161,7 +160,7 @@ EOH;
{
$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));
}
@@ -170,19 +169,18 @@ EOH;
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));
-
+ $this->assertEquals($expect, $this->type->auto_typography($str));
}
+
} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php
new file mode 100644
index 000000000..d79a3ffc9
--- /dev/null
+++ b/tests/codeigniter/libraries/Upload_test.php
@@ -0,0 +1,270 @@
+<?php
+
+class Upload_test extends CI_TestCase {
+
+ function set_up()
+ {
+ $obj = new stdClass;
+ $obj->upload = new Mock_Libraries_Upload();
+ $obj->security = new Mock_Core_Security();
+ $obj->lang = new Mock_Core_Lang();
+
+ $this->ci_instance($obj);
+ $this->upload = $obj->upload;
+
+ vfsStreamWrapper::register();
+ vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir'));
+
+ $this->_test_dir = vfsStreamWrapper::getRoot();
+ }
+
+ function test_do_upload()
+ {
+ $this->markTestIncomplete('We can\'t really test this at the moment because of the call to `is_uploaded_file` in do_upload which isn\'t supported by vfsStream');
+ }
+
+ function test_data()
+ {
+ $data = array(
+ 'file_name' => 'hello.txt',
+ 'file_type' => 'text/plain',
+ 'file_path' => '/tmp/',
+ 'full_path' => '/tmp/hello.txt',
+ 'raw_name' => 'hello',
+ 'orig_name' => 'hello.txt',
+ 'client_name' => '',
+ 'file_ext' => '.txt',
+ 'file_size' => 100,
+ 'is_image' => FALSE,
+ 'image_width' => '',
+ 'image_height' => '',
+ 'image_type' => '',
+ 'image_size_str' => ''
+ );
+
+ $this->upload->set_upload_path('/tmp/');
+
+ foreach ($data as $k => $v)
+ {
+ $this->upload->{$k} = $v;
+ }
+
+ $this->assertEquals('hello.txt', $this->upload->data('file_name'));
+ $this->assertEquals($data, $this->upload->data());
+ }
+
+ function test_set_upload_path()
+ {
+ $this->upload->set_upload_path('/tmp/');
+ $this->assertEquals('/tmp/', $this->upload->upload_path);
+
+ $this->upload->set_upload_path('/tmp');
+ $this->assertEquals('/tmp/', $this->upload->upload_path);
+ }
+
+ function test_set_filename()
+ {
+ $file1 = vfsStream::newFile('hello-world.txt')->withContent('Hello world.')->at($this->_test_dir);
+ $this->upload->file_ext = '.txt';
+
+ $this->assertEquals('helloworld.txt', $this->upload->set_filename(vfsStream::url('testDir').'/', 'helloworld.txt'));
+ $this->assertEquals('hello-world1.txt', $this->upload->set_filename(vfsStream::url('testDir').'/', 'hello-world.txt'));
+ }
+
+ function test_set_max_filesize()
+ {
+ $this->upload->set_max_filesize(100);
+ $this->assertEquals(100, $this->upload->max_size);
+ }
+
+ function test_set_max_filename()
+ {
+ $this->upload->set_max_filename(100);
+ $this->assertEquals(100, $this->upload->max_filename);
+ }
+
+ function test_set_max_width()
+ {
+ $this->upload->set_max_width(100);
+ $this->assertEquals(100, $this->upload->max_width);
+ }
+
+ function test_set_max_height()
+ {
+ $this->upload->set_max_height(100);
+ $this->assertEquals(100, $this->upload->max_height);
+ }
+
+ function test_set_allowed_types()
+ {
+ $this->upload->set_allowed_types('*');
+ $this->assertEquals('*', $this->upload->allowed_types);
+
+ $this->upload->set_allowed_types('foo|bar');
+ $this->assertEquals(array('foo', 'bar'), $this->upload->allowed_types);
+ }
+
+ function test_set_image_properties()
+ {
+ $this->upload->file_type = 'image/gif';
+ $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif';
+
+ $props = array(
+ 'image_width' => 170,
+ 'image_height' => 73,
+ 'image_type' => 'gif',
+ 'image_size_str' => 'width="170" height="73"'
+ );
+
+ $this->upload->set_image_properties($this->upload->file_temp);
+
+ $this->assertEquals($props['image_width'], $this->upload->image_width);
+ $this->assertEquals($props['image_height'], $this->upload->image_height);
+ $this->assertEquals($props['image_type'], $this->upload->image_type);
+ $this->assertEquals($props['image_size_str'], $this->upload->image_size_str);
+ }
+
+ function test_set_xss_clean()
+ {
+ $this->upload->set_xss_clean(TRUE);
+ $this->assertTrue($this->upload->xss_clean);
+
+ $this->upload->set_xss_clean(FALSE);
+ $this->assertFalse($this->upload->xss_clean);
+ }
+
+ function test_is_image()
+ {
+ $this->upload->file_type = 'image/x-png';
+ $this->assertTrue($this->upload->is_image());
+
+ $this->upload->file_type = 'text/plain';
+ $this->assertFalse($this->upload->is_image());
+ }
+
+ function test_is_allowed_filetype()
+ {
+ $this->upload->allowed_types = array('html', 'gif');
+
+ $this->upload->file_ext = '.txt';
+ $this->upload->file_type = 'text/plain';
+ $this->assertFalse($this->upload->is_allowed_filetype(FALSE));
+ $this->assertFalse($this->upload->is_allowed_filetype(TRUE));
+
+ $this->upload->file_ext = '.html';
+ $this->upload->file_type = 'text/html';
+ $this->assertTrue($this->upload->is_allowed_filetype(FALSE));
+ $this->assertTrue($this->upload->is_allowed_filetype(TRUE));
+
+ $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif';
+ $this->upload->file_ext = '.gif';
+ $this->upload->file_type = 'image/gif';
+ $this->assertTrue($this->upload->is_allowed_filetype());
+ }
+
+ function test_is_allowed_filesize()
+ {
+ $this->upload->max_size = 100;
+ $this->upload->file_size = 99;
+
+ $this->assertTrue($this->upload->is_allowed_filesize());
+
+ $this->upload->file_size = 101;
+ $this->assertFalse($this->upload->is_allowed_filesize());
+ }
+
+ function test_is_allowed_dimensions()
+ {
+ $this->upload->file_type = 'text/plain';
+ $this->assertTrue($this->upload->is_allowed_dimensions());
+
+ $this->upload->file_type = 'image/gif';
+ $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif';
+
+ $this->upload->max_width = 10;
+ $this->assertFalse($this->upload->is_allowed_dimensions());
+
+ $this->upload->max_width = 170;
+ $this->upload->max_height = 10;
+ $this->assertFalse($this->upload->is_allowed_dimensions());
+
+ $this->upload->max_height = 73;
+ $this->assertTrue($this->upload->is_allowed_dimensions());
+ }
+
+ function test_validate_upload_path()
+ {
+ $this->upload->upload_path = '';
+ $this->assertFalse($this->upload->validate_upload_path());
+
+ $this->upload->upload_path = vfsStream::url('testDir');
+ $this->assertTrue($this->upload->validate_upload_path());
+ }
+
+ function test_get_extension()
+ {
+ $this->assertEquals('.txt', $this->upload->get_extension('hello.txt'));
+ $this->assertEquals('.htaccess', $this->upload->get_extension('.htaccess'));
+ $this->assertEquals('', $this->upload->get_extension('hello'));
+ }
+
+ function test_clean_file_name()
+ {
+ $this->assertEquals('hello.txt', $this->upload->clean_file_name('hello.txt'));
+ $this->assertEquals('hello.txt', $this->upload->clean_file_name('%253chell>o.txt'));
+ }
+
+ function test_limit_filename_length()
+ {
+ $this->assertEquals('hello.txt', $this->upload->limit_filename_length('hello.txt', 10));
+ $this->assertEquals('hello.txt', $this->upload->limit_filename_length('hello-world.txt', 9));
+ }
+
+ function test_do_xss_clean()
+ {
+ $file1 = vfsStream::newFile('file1.txt')->withContent('The billy goat was waiting for them.')->at($this->_test_dir);
+ $file2 = vfsStream::newFile('file2.txt')->at($this->_test_dir);
+ $file3 = vfsStream::newFile('file3.txt')->withContent('<script type="text/javascript">alert("Boo! said the billy goat")</script>')->at($this->_test_dir);
+
+ $this->upload->file_temp = vfsStream::url('file1.txt');
+ $this->assertTrue($this->upload->do_xss_clean());
+
+ $this->upload->file_temp = vfsStream::url('file2.txt');
+ $this->assertFalse($this->upload->do_xss_clean());
+
+ $this->upload->file_temp = vfsStream::url('file3.txt');
+ $this->assertFalse($this->upload->do_xss_clean());
+
+ $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif';
+ $this->assertTrue($this->upload->do_xss_clean());
+ }
+
+ function test_set_error()
+ {
+ $errors = array(
+ 'An error!'
+ );
+
+ $another = 'Another error!';
+
+ $this->upload->set_error($errors);
+ $this->assertEquals($errors, $this->upload->error_msg);
+
+ $errors[] = $another;
+ $this->upload->set_error($another);
+ $this->assertEquals($errors, $this->upload->error_msg);
+ }
+
+ function test_display_errors()
+ {
+ $this->upload->error_msg[] = 'Error test';
+ $this->assertEquals('<p>Error test</p>', $this->upload->display_errors());
+ }
+
+ function test_mimes_types()
+ {
+ $this->assertEquals('text/plain', $this->upload->mimes_types('txt'));
+ $this->assertFalse($this->upload->mimes_types('foobar'));
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Useragent_test.php b/tests/codeigniter/libraries/Useragent_test.php
index 7dad7ac54..89383f807 100644
--- a/tests/codeigniter/libraries/Useragent_test.php
+++ b/tests/codeigniter/libraries/Useragent_test.php
@@ -1,7 +1,7 @@
<?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';
@@ -10,7 +10,7 @@ class UserAgent_test extends CI_TestCase {
// set a baseline user agent
$_SERVER['HTTP_USER_AGENT'] = $this->_user_agent;
- $obj = new StdClass;
+ $obj = new stdClass;
$obj->agent = new Mock_Libraries_UserAgent();
$this->ci_instance($obj);
@@ -82,6 +82,4 @@ class UserAgent_test extends CI_TestCase {
$this->assertFalse($this->agent->accept_charset());
}
- // --------------------------------------------------------------------
-
} \ No newline at end of file