summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2014-01-20 14:03:43 +0100
committerAndrey Andreev <narf@devilix.net>2014-01-20 14:03:43 +0100
commitea801ab4ab80042638ffddc6056483a1ec43fa80 (patch)
treef75f30c0df6a8f861ca7df22af09fa3240b0bbd6 /tests/codeigniter
parent1c08d557a21ecb0f79cd1a1de4e06817a26e0537 (diff)
parent4d0571666d03511ac5b4a1f2a6882ccb1509a209 (diff)
Merge branch 'develop' into feature/user-guide-cleanup
Diffstat (limited to 'tests/codeigniter')
-rw-r--r--tests/codeigniter/core/Benchmark_test.php26
-rw-r--r--tests/codeigniter/core/Config_test.php10
-rw-r--r--tests/codeigniter/core/Input_test.php59
-rw-r--r--tests/codeigniter/core/Loader_test.php94
-rw-r--r--tests/codeigniter/core/Model_test.php37
-rw-r--r--tests/codeigniter/core/Security_test.php2
-rw-r--r--tests/codeigniter/core/URI_test.php43
-rw-r--r--tests/codeigniter/core/Utf8_test.php13
-rw-r--r--tests/codeigniter/helpers/text_helper_test.php12
-rw-r--r--tests/codeigniter/libraries/Calendar_test.php33
-rw-r--r--tests/codeigniter/libraries/Parser_test.php18
-rw-r--r--tests/codeigniter/libraries/Useragent_test.php57
12 files changed, 270 insertions, 134 deletions
diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php
index a239ba51d..7fd0727e2 100644
--- a/tests/codeigniter/core/Benchmark_test.php
+++ b/tests/codeigniter/core/Benchmark_test.php
@@ -27,10 +27,34 @@ class Benchmark_test extends CI_TestCase {
$this->assertEmpty($this->benchmark->elapsed_time('undefined_point'));
$this->benchmark->mark('code_start');
- sleep(1);
$this->benchmark->mark('code_end');
+ // Override values, because time isn't testable, but make sure the markers were set
+ if (isset($this->benchmark->marker['code_start']) && is_float($this->benchmark->marker['code_start']))
+ {
+ $this->benchmark->marker['code_start'] = 1389956144.1944;
+ }
+
+ if (isset($this->benchmark->marker['code_end']) && is_float($this->benchmark->marker['code_end']))
+ {
+ $this->benchmark->marker['code_end'] = 1389956145.1946;
+ }
+
+ $this->assertEquals('1', $this->benchmark->elapsed_time('code_start', 'code_end', 0));
$this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1));
+ $this->assertEquals('1.00', $this->benchmark->elapsed_time('code_start', 'code_end', 2));
+ $this->assertEquals('1.000', $this->benchmark->elapsed_time('code_start', 'code_end', 3));
+ $this->assertEquals('1.0002', $this->benchmark->elapsed_time('code_start', 'code_end', 4));
+ $this->assertEquals('1.0002', $this->benchmark->elapsed_time('code_start', 'code_end'));
+
+ // Test with non-existing 2nd marker, but again - we need to override the value
+ $this->benchmark->elapsed_time('code_start', 'code_end2');
+ if (isset($this->benchmark->marker['code_end2']) && is_float($this->benchmark->marker['code_end2']))
+ {
+ $this->benchmark->marker['code_end2'] = 1389956146.2046;
+ }
+
+ $this->assertEquals('2.0102', $this->benchmark->elapsed_time('code_start', 'code_end2'));
}
// --------------------------------------------------------------------
diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php
index e3be8a3fc..ba9a2c070 100644
--- a/tests/codeigniter/core/Config_test.php
+++ b/tests/codeigniter/core/Config_test.php
@@ -24,18 +24,18 @@ class Config_test extends CI_TestCase {
$this->assertEquals($this->cfg['base_url'], $this->config->item('base_url'));
// Bad Config value
- $this->assertFalse($this->config->item('no_good_item'));
+ $this->assertNull($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'));
+ $this->assertNull($this->config->item('no_good_item', 'bad_index'));
+ $this->assertNull($this->config->item('no_good_item', 'default'));
}
// --------------------------------------------------------------------
public function test_set_item()
{
- $this->assertFalse($this->config->item('not_yet_set'));
+ $this->assertNull($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'));
@@ -46,7 +46,7 @@ class Config_test extends CI_TestCase {
public function test_slash_item()
{
// Bad Config value
- $this->assertFalse($this->config->slash_item('no_good_item'));
+ $this->assertNull($this->config->slash_item('no_good_item'));
$this->assertEquals($this->cfg['base_url'], $this->config->slash_item('base_url'));
$this->assertEquals($this->cfg['subclass_prefix'].'/', $this->config->slash_item('subclass_prefix'));
diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php
index 5cf25fefa..95833fc91 100644
--- a/tests/codeigniter/core/Input_test.php
+++ b/tests/codeigniter/core/Input_test.php
@@ -82,11 +82,21 @@ class Input_test extends CI_TestCase {
// --------------------------------------------------------------------
- public function test_get_post()
+ public function test_post_get()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['foo'] = 'bar';
+ $this->assertEquals('bar', $this->input->post_get('foo'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_get_post()
+ {
+ $_SERVER['REQUEST_METHOD'] = 'GET';
+ $_GET['foo'] = 'bar';
+
$this->assertEquals('bar', $this->input->get_post('foo'));
}
@@ -128,13 +138,24 @@ class Input_test extends CI_TestCase {
public function test_valid_ip()
{
- $ip_v4 = '192.18.0.1';
- $this->assertTrue($this->input->valid_ip($ip_v4));
+ $this->assertTrue($this->input->valid_ip('192.18.0.1'));
+ $this->assertTrue($this->input->valid_ip('192.18.0.1', 'ipv4'));
+ $this->assertFalse($this->input->valid_ip('555.0.0.0'));
+ $this->assertFalse($this->input->valid_ip('2001:db8:0:85a3::ac1f:8001', 'ipv4'));
+
+ // v6 tests
+ $this->assertFalse($this->input->valid_ip('192.18.0.1', 'ipv6'));
+
+ $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'
+ );
- $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));
+ $this->assertTrue($this->input->valid_ip($ip, 'ipv6'));
}
}
@@ -161,4 +182,34 @@ class Input_test extends CI_TestCase {
$this->assertTrue($this->input->is_ajax_request());
}
+ // --------------------------------------------------------------------
+
+ public function test_input_stream()
+ {
+ $this->markTestSkipped('TODO: Find a way to test input://');
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_set_cookie()
+ {
+ $this->markTestSkipped('TODO: Find a way to test HTTP headers');
+ }
+
+ public function test_ip_address()
+ {
+ // 127.0.0.1 is set in our Bootstrap file
+ $this->assertEquals('127.0.0.1', $this->input->ip_address());
+
+ // Invalid
+ $_SERVER['REMOTE_ADDR'] = 'invalid_ip_address';
+ $this->input->ip_address = FALSE; // reset cached value
+ $this->assertEquals('0.0.0.0', $this->input->ip_address());
+
+ // TODO: Add proxy_ips tests
+
+ // Back to reality
+ $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // back to reality
+ }
+
} \ No newline at end of file
diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php
index ac2656e75..799bcd967 100644
--- a/tests/codeigniter/core/Loader_test.php
+++ b/tests/codeigniter/core/Loader_test.php
@@ -28,18 +28,15 @@ class Loader_test extends CI_TestCase {
$this->ci_vfs_create(ucfirst($lib), '<?php class '.$class.' { }', $this->ci_base_root, 'libraries');
// Test is_loaded fail
- $this->assertFalse($this->load->is_loaded($lib));
+ $this->assertFalse($this->load->is_loaded(ucfirst($lib)));
// Test loading as an array.
- $this->assertNull($this->load->library(array($lib)));
+ $this->assertInstanceOf('CI_Loader', $this->load->library(array($lib)));
$this->assertTrue(class_exists($class), $class.' does not exist');
$this->assertAttributeInstanceOf($class, $lib, $this->ci_obj);
- // Test no lib given
- $this->assertNull($this->load->library());
-
// Test a string given to params
- $this->assertNull($this->load->library($lib, ' '));
+ $this->assertInstanceOf('CI_Loader', $this->load->library($lib, ' '));
// Create library w/o class
$lib = 'bad_test_lib';
@@ -50,7 +47,7 @@ class Loader_test extends CI_TestCase {
'RuntimeException',
'CI Error: Unable to load the requested class: '.ucfirst($lib)
);
- $this->assertNull($this->load->library($lib));
+ $this->assertInstanceOf('CI_Loader', $this->load->library($lib));
}
// --------------------------------------------------------------------
@@ -66,7 +63,7 @@ class Loader_test extends CI_TestCase {
$this->ci_vfs_create($ext, '<?php class '.$ext.' extends '.$class.' { }', $this->ci_app_root, 'libraries');
// Test loading with extension
- $this->assertNull($this->load->library($lib));
+ $this->assertInstanceOf('CI_Loader', $this->load->library($lib));
$this->assertTrue(class_exists($class), $class.' does not exist');
$this->assertTrue(class_exists($ext), $ext.' does not exist');
$this->assertAttributeInstanceOf($class, $name, $this->ci_obj);
@@ -74,13 +71,13 @@ class Loader_test extends CI_TestCase {
// Test reloading with object name
$obj = 'exttest';
- $this->assertNull($this->load->library($lib, NULL, $obj));
+ $this->assertInstanceOf('CI_Loader', $this->load->library($lib, NULL, $obj));
$this->assertAttributeInstanceOf($class, $obj, $this->ci_obj);
$this->assertAttributeInstanceOf($ext, $obj, $this->ci_obj);
// Test reloading
unset($this->ci_obj->$name);
- $this->assertNull($this->load->library($lib));
+ $this->assertInstanceOf('CI_Loader', $this->load->library($lib));
$this->assertObjectNotHasAttribute($name, $this->ci_obj);
// Create baseless library
@@ -94,7 +91,7 @@ class Loader_test extends CI_TestCase {
'RuntimeException',
'CI Error: Unable to load the requested class: '.$lib
);
- $this->assertNull($this->load->library($lib));
+ $this->assertInstanceOf('CI_Loader', $this->load->library($lib));
}
// --------------------------------------------------------------------
@@ -117,13 +114,13 @@ class Loader_test extends CI_TestCase {
// Test object name and config
$obj = 'testy';
- $this->assertNull($this->load->library($lib, NULL, $obj));
+ $this->assertInstanceOf('CI_Loader', $this->load->library($lib, NULL, $obj));
$this->assertTrue(class_exists($class), $class.' does not exist');
$this->assertAttributeInstanceOf($class, $obj, $this->ci_obj);
$this->assertEquals($cfg, $this->ci_obj->$obj->config);
// Test is_loaded
- $this->assertEquals($obj, $this->load->is_loaded($lib));
+ $this->assertEquals($obj, $this->load->is_loaded(ucfirst($lib)));
}
// --------------------------------------------------------------------
@@ -136,7 +133,7 @@ class Loader_test extends CI_TestCase {
$this->ci_vfs_create(ucfirst($lib), '<?php class '.$class.' { }', $this->ci_app_root, 'libraries');
// Load library
- $this->assertNull($this->load->library($lib));
+ $this->assertInstanceOf('CI_Loader', $this->load->library($lib));
// Was the model class instantiated.
$this->assertTrue(class_exists($class), $class.' does not exist');
@@ -158,20 +155,17 @@ class Loader_test extends CI_TestCase {
$this->ci_vfs_create(ucfirst($driver), $content, $this->ci_base_root, 'libraries/'.$dir);
// Test loading as an array.
- $this->assertNull($this->load->driver(array($driver)));
+ $this->assertInstanceOf('CI_Loader', $this->load->driver(array($driver)));
$this->assertTrue(class_exists($class), $class.' does not exist');
$this->assertAttributeInstanceOf($class, $driver, $this->ci_obj);
// Test loading as a library with a name
$obj = 'testdrive';
- $this->assertNull($this->load->library($driver, NULL, $obj));
+ $this->assertInstanceOf('CI_Loader', $this->load->library($driver, NULL, $obj));
$this->assertAttributeInstanceOf($class, $obj, $this->ci_obj);
- // Test no driver given
- $this->assertFalse($this->load->driver());
-
// Test a string given to params
- $this->assertNull($this->load->driver($driver, ' '));
+ $this->assertInstanceOf('CI_Loader', $this->load->driver($driver, ' '));
}
// --------------------------------------------------------------------
@@ -181,19 +175,19 @@ class Loader_test extends CI_TestCase {
$this->ci_set_core_class('model', 'CI_Model');
// Create model in VFS
- $model = 'unit_test_model';
- $class = ucfirst($model);
- $content = '<?php class '.$class.' extends CI_Model {} ';
+ $model = 'Unit_test_model';
+ $content = '<?php class '.$model.' extends CI_Model {} ';
$this->ci_vfs_create($model, $content, $this->ci_app_root, 'models');
// Load model
- $this->assertNull($this->load->model($model));
+ $this->assertInstanceOf('CI_Loader', $this->load->model($model));
// Was the model class instantiated.
- $this->assertTrue(class_exists($class));
+ $this->assertTrue(class_exists($model));
+ $this->assertObjectHasAttribute($model, $this->ci_obj);
// Test no model given
- $this->assertNull($this->load->model(''));
+ $this->assertInstanceOf('CI_Loader', $this->load->model(''));
}
// --------------------------------------------------------------------
@@ -204,22 +198,21 @@ class Loader_test extends CI_TestCase {
$this->ci_core_class('model');
// Create modelin VFS
- $model = 'test_sub_model';
+ $model = 'Test_sub_model';
$base = 'CI_Model';
- $class = ucfirst($model);
$subdir = 'cars';
- $this->ci_vfs_create($model, '<?php class '.$class.' extends '.$base.' { }', $this->ci_app_root,
+ $this->ci_vfs_create($model, '<?php class '.$model.' extends '.$base.' { }', $this->ci_app_root,
array('models', $subdir));
// Load model
$name = 'testors';
- $this->assertNull($this->load->model($subdir.'/'.$model, $name));
+ $this->assertInstanceOf('CI_Loader', $this->load->model($subdir.'/'.$model, $name));
// Was the model class instantiated?
- $this->assertTrue(class_exists($class));
+ $this->assertTrue(class_exists($model));
$this->assertObjectHasAttribute($name, $this->ci_obj);
$this->assertAttributeInstanceOf($base, $name, $this->ci_obj);
- $this->assertAttributeInstanceOf($class, $name, $this->ci_obj);
+ $this->assertAttributeInstanceOf($model, $name, $this->ci_obj);
// Test name conflict
$obj = 'conflict';
@@ -237,7 +230,7 @@ class Loader_test extends CI_TestCase {
{
$this->setExpectedException(
'RuntimeException',
- 'CI Error: Unable to locate the model you have specified: ci_test_nonexistent_model.php'
+ 'CI Error: Unable to locate the model you have specified: Ci_test_nonexistent_model.php'
);
$this->load->model('ci_test_nonexistent_model.php');
@@ -247,8 +240,8 @@ class Loader_test extends CI_TestCase {
// public function testDatabase()
// {
- // $this->assertNull($this->load->database());
- // $this->assertNull($this->load->dbutil());
+ // $this->assertInstanceOf('CI_Loader', $this->load->database());
+ // $this->assertInstanceOf('CI_Loader', $this->load->dbutil());
// }
// --------------------------------------------------------------------
@@ -272,7 +265,7 @@ class Loader_test extends CI_TestCase {
$this->ci_instance_var('output', $output);
// Test view output
- $this->assertNull($this->load->view($view, array($var => $value)));
+ $this->assertInstanceOf('CI_Loader', $this->load->view($view, array($var => $value)));
}
// --------------------------------------------------------------------
@@ -318,8 +311,8 @@ class Loader_test extends CI_TestCase {
$val1 = 'bar';
$key2 = 'boo';
$val2 = 'hoo';
- $this->assertNull($this->load->vars(array($key1 => $val1)));
- $this->assertNull($this->load->vars($key2, $val2));
+ $this->assertInstanceOf('CI_Loader', $this->load->vars(array($key1 => $val1)));
+ $this->assertInstanceOf('CI_Loader', $this->load->vars($key2, $val2));
$this->assertEquals($val1, $this->load->get_var($key1));
$this->assertEquals(array($key1 => $val1, $key2 => $val2), $this->load->get_vars());
}
@@ -340,7 +333,7 @@ class Loader_test extends CI_TestCase {
$this->ci_vfs_create($this->prefix.$helper.'_helper', $content, $this->ci_app_root, 'helpers');
// Load helper
- $this->assertNull($this->load->helper($helper));
+ $this->assertInstanceOf('CI_Loader', $this->load->helper($helper));
$this->assertTrue(function_exists($func), $func.' does not exist');
$this->assertTrue(function_exists($exfunc), $exfunc.' does not exist');
@@ -385,7 +378,7 @@ class Loader_test extends CI_TestCase {
$this->ci_vfs_create($files, NULL, $this->ci_base_root, 'helpers');
// Load helpers
- $this->assertNull($this->load->helpers($helpers));
+ $this->assertInstanceOf('CI_Loader', $this->load->helpers($helpers));
// Verify helper existence
foreach ($funcs as $func) {
@@ -402,7 +395,7 @@ class Loader_test extends CI_TestCase {
$lang = $this->getMock('CI_Lang', array('load'));
$lang->expects($this->once())->method('load')->with($file);
$this->ci_instance_var('lang', $lang);
- $this->assertNull($this->load->language($file));
+ $this->assertInstanceOf('CI_Loader', $this->load->language($file));
}
// --------------------------------------------------------------------
@@ -420,24 +413,24 @@ class Loader_test extends CI_TestCase {
// Add path and verify
$path = APPPATH.$dir.'/';
- $this->assertNull($this->load->add_package_path($path));
+ $this->assertInstanceOf('CI_Loader', $this->load->add_package_path($path));
$this->assertContains($path, $this->load->get_package_paths(TRUE));
// Test successful load
- $this->assertNull($this->load->library($lib));
+ $this->assertInstanceOf('CI_Loader', $this->load->library($lib));
$this->assertTrue(class_exists($class), $class.' does not exist');
// Add another path
$path2 = APPPATH.'another/';
- $this->assertNull($this->load->add_package_path($path2));
+ $this->assertInstanceOf('CI_Loader', $this->load->add_package_path($path2));
$this->assertContains($path2, $this->load->get_package_paths(TRUE));
// Remove last path
- $this->assertNull($this->load->remove_package_path());
+ $this->assertInstanceOf('CI_Loader', $this->load->remove_package_path());
$this->assertNotContains($path2, $this->load->get_package_paths(TRUE));
// Remove path and verify restored paths
- $this->assertNull($this->load->remove_package_path($path));
+ $this->assertInstanceOf('CI_Loader', $this->load->remove_package_path($path));
$this->assertEquals($paths, $this->load->get_package_paths(TRUE));
// Test failed load without path
@@ -481,9 +474,8 @@ class Loader_test extends CI_TestCase {
// Create model in VFS package path
$dir = 'testdir';
$path = APPPATH.$dir.'/';
- $model = 'automod';
- $mod_class = ucfirst($model);
- $this->ci_vfs_create($model, '<?php class '.$mod_class.' { }', $this->ci_app_root, array($dir, 'models'));
+ $model = 'Automod';
+ $this->ci_vfs_create($model, '<?php class '.$model.' { }', $this->ci_app_root, array($dir, 'models'));
// Create autoloader config
$cfg = array(
@@ -513,8 +505,8 @@ class Loader_test extends CI_TestCase {
$this->assertAttributeInstanceOf($drv_class, $drv, $this->ci_obj);
// Verify model
- $this->assertTrue(class_exists($mod_class), $mod_class.' does not exist');
- $this->assertAttributeInstanceOf($mod_class, $model, $this->ci_obj);
+ $this->assertTrue(class_exists($model), $model.' does not exist');
+ $this->assertAttributeInstanceOf($model, $model, $this->ci_obj);
// Verify config calls
$this->assertEquals($cfg['config'], $this->ci_obj->config->loaded);
diff --git a/tests/codeigniter/core/Model_test.php b/tests/codeigniter/core/Model_test.php
new file mode 100644
index 000000000..80dc97b3b
--- /dev/null
+++ b/tests/codeigniter/core/Model_test.php
@@ -0,0 +1,37 @@
+<?php
+
+class Model_test extends CI_TestCase {
+
+ private $ci_obj;
+
+ public function set_up()
+ {
+ $loader = $this->ci_core_class('loader');
+ $this->load = new $loader();
+ $this->ci_obj = $this->ci_instance();
+ $this->ci_set_core_class('model', 'CI_Model');
+
+ $model_code =<<<MODEL
+<?php
+class Test_model extends CI_Model {
+
+ public \$property = 'foo';
+
+}
+MODEL;
+
+ $this->ci_vfs_create('Test_model', $model_code, $this->ci_app_root, 'models');
+ $this->load->model('test_model');
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test__get()
+ {
+ $this->assertEquals('foo', $this->ci_obj->test_model->property);
+
+ $this->ci_obj->controller_property = 'bar';
+ $this->assertEquals('bar', $this->ci_obj->test_model->controller_property);
+ }
+
+} \ No newline at end of file
diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php
index 3f6e3b07a..433ad313f 100644
--- a/tests/codeigniter/core/Security_test.php
+++ b/tests/codeigniter/core/Security_test.php
@@ -5,7 +5,7 @@ class Security_test extends CI_TestCase {
public function set_up()
{
// Set cookie for security test
- $_COOKIE['ci_csrf_cookie'] = md5(uniqid(rand(), TRUE));
+ $_COOKIE['ci_csrf_cookie'] = md5(uniqid(mt_rand(), TRUE));
// Set config for Security class
$this->ci_set_config('csrf_protection', TRUE);
diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php
index 7fa0e6265..6589c1f5a 100644
--- a/tests/codeigniter/core/URI_test.php
+++ b/tests/codeigniter/core/URI_test.php
@@ -26,6 +26,10 @@ class URI_test extends CI_TestCase {
// --------------------------------------------------------------------
+ /*
+
+ This has been moved to the constructor
+
public function test_fetch_uri_string()
{
define('SELF', 'index.php');
@@ -86,9 +90,14 @@ class URI_test extends CI_TestCase {
// uri_protocol: REQUEST_URI
// uri_protocol: CLI
}
+ */
// --------------------------------------------------------------------
+ /*
+
+ This has been moved into _set_uri_string()
+
public function test_explode_segments()
{
// Let's test the function's ability to clean up this mess
@@ -107,16 +116,15 @@ class URI_test extends CI_TestCase {
$this->assertEquals($a, $this->uri->segments);
}
}
-
+ */
// --------------------------------------------------------------------
public function test_filter_uri()
{
- $this->uri->config->set_item('enable_query_strings', FALSE);
- $this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-');
+ $this->uri->_set_permitted_uri_chars('a-z 0-9~%.:_\-');
$str_in = 'abc01239~%.:_-';
- $str = $this->uri->_filter_uri($str_in);
+ $str = $this->uri->filter_uri($str_in);
$this->assertEquals($str, $str_in);
}
@@ -126,11 +134,9 @@ class URI_test extends CI_TestCase {
public function test_filter_uri_escaping()
{
// ensure escaping even if dodgey characters are permitted
+ $this->uri->_set_permitted_uri_chars('a-z 0-9~%.:_\-()$');
- $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)');
+ $str = $this->uri->filter_uri('$destroy_app(foo)');
$this->assertEquals($str, '&#36;destroy_app&#40;foo&#41;');
}
@@ -142,25 +148,8 @@ class URI_test extends CI_TestCase {
$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');
+ $this->uri->_set_permitted_uri_chars('a-z 0-9~%.:_\-');
+ $this->uri->filter_uri('$this()');
}
// --------------------------------------------------------------------
diff --git a/tests/codeigniter/core/Utf8_test.php b/tests/codeigniter/core/Utf8_test.php
index caa7b6986..71299134e 100644
--- a/tests/codeigniter/core/Utf8_test.php
+++ b/tests/codeigniter/core/Utf8_test.php
@@ -11,10 +11,15 @@ class Utf8_test extends CI_TestCase {
public function test_convert_to_utf8()
{
- $this->assertEquals(
- $this->utf8->convert_to_utf8('๒ๅ๑๒', 'WINDOWS-1251'),
- 'ั‚ะตัั‚'
- );
+ $this->assertEquals('ั‚ะตัั‚', $this->utf8->convert_to_utf8('๒ๅ๑๒', 'WINDOWS-1251'));
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_is_ascii()
+ {
+ $this->assertTrue($this->utf8->is_ascii_test('foo bar'));
+ $this->assertFalse($this->utf8->is_ascii_test('ั‚ะตัั‚'));
}
} \ 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 d75d26208..7a7dc0a12 100644
--- a/tests/codeigniter/helpers/text_helper_test.php
+++ b/tests/codeigniter/helpers/text_helper_test.php
@@ -106,17 +106,19 @@ class Text_helper_test extends CI_TestCase {
public function test_highlight_phrase()
{
$strs = array(
- 'this is a phrase' => '<strong>this is</strong> a phrase',
- 'this is another' => '<strong>this is</strong> another',
- 'Gimme a test, Sally' => 'Gimme a test, Sally',
- 'Or tell me what this is' => 'Or tell me what <strong>this is</strong>',
- '' => ''
+ 'this is a phrase' => '<mark>this is</mark> a phrase',
+ 'this is another' => '<mark>this is</mark> another',
+ 'Gimme a test, Sally' => 'Gimme a test, Sally',
+ 'Or tell me what this is' => 'Or tell me what <mark>this is</mark>',
+ '' => ''
);
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, highlight_phrase($str, 'this is'));
}
+
+ $this->assertEquals('<strong>this is</strong> a strong test', highlight_phrase('this is a strong test', 'this is', '<strong>', '</strong>'));
}
// ------------------------------------------------------------------------
diff --git a/tests/codeigniter/libraries/Calendar_test.php b/tests/codeigniter/libraries/Calendar_test.php
index 952e8a8d2..768bc8573 100644
--- a/tests/codeigniter/libraries/Calendar_test.php
+++ b/tests/codeigniter/libraries/Calendar_test.php
@@ -169,30 +169,33 @@ class Calendar_test extends CI_TestCase {
$this->assertEquals(31, $this->calendar->get_total_days(12, 2012));
}
- function test_default_template()
+ public function test_default_template()
{
$array = array(
- 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',
- 'heading_row_start' => '<tr>',
+ '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>',
+ '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' => '<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_blank' => '&nbsp;',
+ 'cal_cell_end' => '</td>',
'cal_cell_end_today' => '</td>',
- 'cal_row_end' => '</tr>',
- 'table_close' => '</table>'
+ 'cal_row_end' => '</tr>',
+ 'table_close' => '</table>',
+ 'cal_cell_start_other' => '<td style="color: #666;">',
+ 'cal_cell_other' => '{day}',
+ 'cal_cell_end_other' => '</td>'
);
$this->assertEquals($array, $this->calendar->default_template());
diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php
index 394c22692..3755cf1a0 100644
--- a/tests/codeigniter/libraries/Parser_test.php
+++ b/tests/codeigniter/libraries/Parser_test.php
@@ -33,7 +33,7 @@ class Parser_test extends CI_TestCase {
// --------------------------------------------------------------------
- public function test_parse_simple_string()
+ public function test_parse_string()
{
$data = array(
'title' => 'Page Title',
@@ -69,16 +69,12 @@ class Parser_test extends CI_TestCase {
{
$data = array(
'title' => 'Super Heroes',
- 'powers' => array(
- array(
- 'invisibility' => 'yes',
- 'flying' => 'no'),
- )
+ 'powers' => array(array('invisibility' => 'yes', 'flying' => 'no'))
);
- $template = "{title}\n{powers}{invisibility}\n{flying}{/powers}";
+ $template = "{title}\n{powers}{invisibility}\n{flying}{/powers}\nsecond:{powers} {invisibility} {flying}{/powers}";
- $this->assertEquals("Super Heroes\nyes\nno", $this->parser->parse_string($template, $data, TRUE));
+ $this->assertEquals("Super Heroes\nyes\nno\nsecond: yes no", $this->parser->parse_string($template, $data, TRUE));
}
// --------------------------------------------------------------------
@@ -87,11 +83,7 @@ class Parser_test extends CI_TestCase {
{
$data = array(
'title' => 'Super Heroes',
- 'powers' => array(
- array(
- 'invisibility' => 'yes',
- 'flying' => 'no'),
- )
+ 'powers' => array(array('invisibility' => 'yes', 'flying' => 'no'))
);
$template = "{title}\n{powers}{invisibility}\n{flying}";
diff --git a/tests/codeigniter/libraries/Useragent_test.php b/tests/codeigniter/libraries/Useragent_test.php
index e3726554e..aed38b8c2 100644
--- a/tests/codeigniter/libraries/Useragent_test.php
+++ b/tests/codeigniter/libraries/Useragent_test.php
@@ -11,9 +11,7 @@ class UserAgent_test extends CI_TestCase {
$_SERVER['HTTP_USER_AGENT'] = $this->_user_agent;
$this->ci_vfs_clone('application/config/user_agents.php');
-
$this->agent = new Mock_Libraries_UserAgent();
-
$this->ci_instance_var('agent', $this->agent);
}
@@ -40,12 +38,27 @@ class UserAgent_test extends CI_TestCase {
// --------------------------------------------------------------------
- public function test_util_is_functions()
+ public function test_is_functions()
{
$this->assertTrue($this->agent->is_browser());
+ $this->assertTrue($this->agent->is_browser('Safari'));
+ $this->assertFalse($this->agent->is_browser('Firefox'));
$this->assertFalse($this->agent->is_robot());
$this->assertFalse($this->agent->is_mobile());
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_referrer()
+ {
+ $_SERVER['HTTP_REFERER'] = 'http://codeigniter.com/user_guide/';
+ $this->assertTrue($this->agent->is_referral());
+ $this->assertEquals('http://codeigniter.com/user_guide/', $this->agent->referrer());
+
+ $this->agent->referer = NULL;
+ unset($_SERVER['HTTP_REFERER']);
$this->assertFalse($this->agent->is_referral());
+ $this->assertEquals('', $this->agent->referrer());
}
// --------------------------------------------------------------------
@@ -63,7 +76,6 @@ class UserAgent_test extends CI_TestCase {
$this->assertEquals('Safari', $this->agent->browser());
$this->assertEquals('533.20.27', $this->agent->version());
$this->assertEquals('', $this->agent->robot());
- $this->assertEquals('', $this->agent->referrer());
}
// --------------------------------------------------------------------
@@ -71,14 +83,43 @@ class UserAgent_test extends CI_TestCase {
public function test_charsets()
{
$_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8';
+ $this->agent->charsets = array();
+ $this->agent->charsets();
+ $this->assertTrue($this->agent->accept_charset('utf8'));
+ $this->assertFalse($this->agent->accept_charset('foo'));
+ $this->assertEquals('utf8', $this->agent->charsets[0]);
+
+ $_SERVER['HTTP_ACCEPT_CHARSET'] = '';
+ $this->agent->charsets = array();
+ $this->assertFalse($this->agent->accept_charset());
+ $this->assertEquals('Undefined', $this->agent->charsets[0]);
- $charsets = $this->agent->charsets();
-
- $this->assertEquals('utf8', $charsets[0]);
+ $_SERVER['HTTP_ACCEPT_CHARSET'] = 'iso-8859-5, unicode-1-1; q=0.8';
+ $this->agent->charsets = array();
+ $this->assertTrue($this->agent->accept_charset('iso-8859-5'));
+ $this->assertTrue($this->agent->accept_charset('unicode-1-1'));
+ $this->assertFalse($this->agent->accept_charset('foo'));
+ $this->assertEquals('iso-8859-5', $this->agent->charsets[0]);
+ $this->assertEquals('unicode-1-1', $this->agent->charsets[1]);
unset($_SERVER['HTTP_ACCEPT_CHARSET']);
+ }
- $this->assertFalse($this->agent->accept_charset());
+ public function test_parse()
+ {
+ $new_agent = 'Mozilla/5.0 (Android; Mobile; rv:13.0) Gecko/13.0 Firefox/13.0';
+ $this->agent->parse($new_agent);
+
+ $this->assertEquals('Android', $this->agent->platform());
+ $this->assertEquals('Firefox', $this->agent->browser());
+ $this->assertEquals('13.0', $this->agent->version());
+ $this->assertEquals('', $this->agent->robot());
+ $this->assertEquals('Android', $this->agent->mobile());
+ $this->assertEquals($new_agent, $this->agent->agent_string());
+ $this->assertTrue($this->agent->is_browser());
+ $this->assertFalse($this->agent->is_robot());
+ $this->assertTrue($this->agent->is_mobile());
+ $this->assertTrue($this->agent->is_mobile('android'));
}
} \ No newline at end of file