summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/libraries
diff options
context:
space:
mode:
Diffstat (limited to 'tests/codeigniter/libraries')
-rw-r--r--tests/codeigniter/libraries/Calendar_test.php6
-rw-r--r--tests/codeigniter/libraries/Driver_test.php4
-rw-r--r--tests/codeigniter/libraries/Encrypt_test.php6
-rw-r--r--tests/codeigniter/libraries/Encryption_test.php10
-rw-r--r--tests/codeigniter/libraries/Form_validation_test.php84
-rw-r--r--tests/codeigniter/libraries/Session_test.php5
-rw-r--r--tests/codeigniter/libraries/Upload_test.php18
7 files changed, 87 insertions, 46 deletions
diff --git a/tests/codeigniter/libraries/Calendar_test.php b/tests/codeigniter/libraries/Calendar_test.php
index 54879fec9..ad1f45e8c 100644
--- a/tests/codeigniter/libraries/Calendar_test.php
+++ b/tests/codeigniter/libraries/Calendar_test.php
@@ -5,9 +5,9 @@ class Calendar_test extends CI_TestCase {
public function set_up()
{
// Required for get_total_days()
- $this->ci_instance_var('load', $this->getMock('CI_Loader', array('helper')));
+ $this->ci_instance_var('load', $this->getMockBuilder('CI_Loader')->setMethods(array('helper'))->getMock());
- $lang = $this->getMock('CI_Lang', array('load', 'line'));
+ $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load', 'line'))->getMock();
$lang->expects($this->any())->method('line')->will($this->returnValue(FALSE));
$this->ci_instance_var('lang', $lang);
@@ -219,4 +219,4 @@ class Calendar_test extends CI_TestCase {
$this->assertEquals($array, $this->calendar->default_template());
}
-} \ No newline at end of file
+}
diff --git a/tests/codeigniter/libraries/Driver_test.php b/tests/codeigniter/libraries/Driver_test.php
index c62cbee45..e4401e688 100644
--- a/tests/codeigniter/libraries/Driver_test.php
+++ b/tests/codeigniter/libraries/Driver_test.php
@@ -16,7 +16,7 @@ class Driver_test extends CI_TestCase {
// Mock Loader->get_package_paths
$paths = 'get_package_paths';
- $ldr = $this->getMock('CI_Loader', array($paths));
+ $ldr = $this->getMockBuilder('CI_Loader')->setMethods(array($paths))->getMock();
$ldr->expects($this->any())->method($paths)->will($this->returnValue(array(APPPATH, BASEPATH)));
$this->ci_instance_var('load', $ldr);
@@ -175,4 +175,4 @@ class Driver_test extends CI_TestCase {
$this->assertEquals($return, $child->$method());
}
-} \ No newline at end of file
+}
diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php
index ced763301..adbca31b2 100644
--- a/tests/codeigniter/libraries/Encrypt_test.php
+++ b/tests/codeigniter/libraries/Encrypt_test.php
@@ -10,6 +10,10 @@ class Encrypt_test extends CI_TestCase {
{
return;
}
+ elseif (version_compare(PHP_VERSION, '7.1.0-alpha', '>='))
+ {
+ return $this->markTestSkipped('ext/mcrypt is deprecated since PHP 7.1 and will generate notices here.');
+ }
$this->encrypt = new Mock_Libraries_Encrypt();
$this->ci_instance_var('encrypt', $this->encrypt);
@@ -72,4 +76,4 @@ class Encrypt_test extends CI_TestCase {
$this->assertEquals('cfb', $this->encrypt->get_mode());
}
-} \ No newline at end of file
+}
diff --git a/tests/codeigniter/libraries/Encryption_test.php b/tests/codeigniter/libraries/Encryption_test.php
index cbcae3133..96e52ada8 100644
--- a/tests/codeigniter/libraries/Encryption_test.php
+++ b/tests/codeigniter/libraries/Encryption_test.php
@@ -240,6 +240,10 @@ class Encryption_test extends CI_TestCase {
{
return $this->markTestSkipped('Cannot test MCrypt because it is not available.');
}
+ elseif (version_compare(PHP_VERSION, '7.1.0-alpha', '>='))
+ {
+ return $this->markTestSkipped('ext/mcrypt is deprecated since PHP 7.1 and will generate notices here.');
+ }
$this->assertTrue(is_resource($this->encryption->__driver_get_handle('mcrypt', 'rijndael-128', 'cbc')));
}
@@ -274,6 +278,10 @@ class Encryption_test extends CI_TestCase {
$this->markTestSkipped('Both MCrypt and OpenSSL support are required for portability tests.');
return;
}
+ elseif (version_compare(PHP_VERSION, '7.1.0-alpha', '>='))
+ {
+ return $this->markTestSkipped('ext/mcrypt is deprecated since PHP 7.1 and will generate notices here.');
+ }
$message = 'This is a message encrypted via MCrypt and decrypted via OpenSSL, or vice-versa.';
@@ -377,4 +385,4 @@ class Encryption_test extends CI_TestCase {
$this->assertEquals('stream', $this->encryption->mode);
}
-} \ No newline at end of file
+}
diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php
index 26d82ec93..035410724 100644
--- a/tests/codeigniter/libraries/Form_validation_test.php
+++ b/tests/codeigniter/libraries/Form_validation_test.php
@@ -8,15 +8,13 @@ class Form_validation_test extends CI_TestCase {
// Create a mock loader since load->helper() looks in the wrong directories for unit tests,
// We'll use CI_TestCase->helper() instead
- $loader = $this->getMock('CI_Loader', array('helper'));
+ $loader = $this->getMockBuilder('CI_Loader')->setMethods(array('helper'))->getMock();
// Same applies for lang
- $lang = $this->getMock('CI_Lang', array('load'));
+ $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock();
- $this->ci_set_config('charset', 'UTF-8');
- $utf8 = new Mock_Core_Utf8();
- $security = new Mock_Core_Security();
- $input = new Mock_Core_Input($security, $utf8);
+ $security = new Mock_Core_Security('UTF-8');
+ $input = new CI_Input($security);
$this->ci_instance_var('lang', $lang);
$this->ci_instance_var('load', $loader);
@@ -28,13 +26,34 @@ class Form_validation_test extends CI_TestCase {
$this->form_validation = new CI_Form_validation();
}
+ public function test_empty_array_input()
+ {
+ $this->assertFalse(
+ $this->run_rules(
+ array(array('field' => 'foo', 'label' => 'Foo Label', 'rules' => 'required')),
+ array('foo' => array())
+ )
+ );
+ }
+
public function test_rule_required()
{
- $rules = array(array('field' => 'foo', 'label' => 'foo_label', 'rules' => 'required'));
- $this->assertTrue($this->run_rules($rules, array('foo' => 'bar')));
+ $rules = array(array('field' => 'foo', 'label' => 'Foo', 'rules' => 'is_numeric'));
+
+ // Empty, not required
+ $this->assertTrue($this->run_rules($rules, array('foo' => '')));
+
+ // Not required, but also not empty
+ $this->assertTrue($this->run_rules($rules, array('foo' => '123')));
+ $this->assertFalse($this->run_rules($rules, array('foo' => 'bar')));
+
+ // Required variations
+ $rules[0]['rules'] .= '|required';
+ $this->assertTrue($this->run_rules($rules, array('foo' => '123')));
$this->assertFalse($this->run_rules($rules, array('foo' => '')));
$this->assertFalse($this->run_rules($rules, array('foo' => ' ')));
+ $this->assertFalse($this->run_rules($rules, array('foo' => 'bar')));
}
public function test_rule_matches()
@@ -45,9 +64,9 @@ class Form_validation_test extends CI_TestCase {
);
$values_base = array('foo' => 'sample');
- $this->assertTrue($this->run_rules($rules, array_merge($values_base, array('bar' => ''))));
$this->assertTrue($this->run_rules($rules, array_merge($values_base, array('bar' => 'sample'))));
+ $this->assertFalse($this->run_rules($rules, array_merge($values_base, array('bar' => ''))));
$this->assertFalse($this->run_rules($rules, array_merge($values_base, array('bar' => 'Sample'))));
$this->assertFalse($this->run_rules($rules, array_merge($values_base, array('bar' => ' sample'))));
}
@@ -229,7 +248,17 @@ class Form_validation_test extends CI_TestCase {
public function test_rule_valid_url()
{
$this->assertTrue($this->form_validation->valid_url('www.codeigniter.com'));
- $this->assertTrue($this->form_validation->valid_url('http://codeigniter.eu'));
+ $this->assertTrue($this->form_validation->valid_url('http://codeigniter.com'));
+
+ // https://bugs.php.net/bug.php?id=51192
+ $this->assertTrue($this->form_validation->valid_url('http://accept-dashes.tld'));
+ $this->assertFalse($this->form_validation->valid_url('http://reject_underscores.tld'));
+
+ // https://github.com/bcit-ci/CodeIgniter/issues/4415
+ $this->assertTrue($this->form_validation->valid_url('http://[::1]/ipv6'));
+
+ // URI scheme case-sensitivity: https://github.com/bcit-ci/CodeIgniter/pull/4758
+ $this->assertTrue($this->form_validation->valid_url('HtTp://127.0.0.1/'));
$this->assertFalse($this->form_validation->valid_url('htt://www.codeIgniter.com'));
$this->assertFalse($this->form_validation->valid_url(''));
@@ -239,7 +268,6 @@ class Form_validation_test extends CI_TestCase {
public function test_rule_valid_email()
{
$this->assertTrue($this->form_validation->valid_email('email@sample.com'));
-
$this->assertFalse($this->form_validation->valid_email('valid_email', '@sample.com'));
}
@@ -265,10 +293,22 @@ class Form_validation_test extends CI_TestCase {
$this->assertFalse($this->form_validation->valid_ip('127.0.0.259'));
}
+ public function test_rule_valid_mac()
+ {
+ $this->assertTrue($this->form_validation->valid_mac("01-23-45-67-89-aB"));
+ $this->assertTrue($this->form_validation->valid_mac("01:23:45:67:89:aB"));
+ $this->assertTrue($this->form_validation->valid_mac("0123.4567.89aB"));
+
+ $this->assertFalse($this->form_validation->valid_mac("-01-23-45-67-89-ab"));
+ $this->assertFalse($this->form_validation->valid_mac("01:23:45:67:89:ab:"));
+ $this->assertFalse($this->form_validation->valid_mac("01:23:45:67:89:ab\n"));
+ $this->assertFalse($this->form_validation->valid_mac("01:23:45:67:89:ag:"));
+ $this->assertFalse($this->form_validation->valid_mac('0123456789ab'));
+ }
+
public function test_rule_valid_base64()
{
$this->assertTrue($this->form_validation->valid_base64(base64_encode('string')));
-
$this->assertFalse($this->form_validation->valid_base64('FA08GG'));
}
@@ -404,6 +444,12 @@ class Form_validation_test extends CI_TestCase {
$this->assertFalse($form_validation->run('fail'));
}
+ public function test_set_rules_exception()
+ {
+ $this->setExpectedException('BadMethodCallException');
+ $this->form_validation->set_rules('foo', 'bar');
+ }
+
public function test_has_rule()
{
$this->form_validation->reset_validation();
@@ -542,20 +588,6 @@ class Form_validation_test extends CI_TestCase {
$this->assertFalse($this->form_validation->regex_match('bar', $regex));
}
- public function test_prep_for_form()
- {
- $this->form_validation->reset_validation();
- $error_msg_unprepped = '<error =\'foobar\'">';
- $error_msg_prepped = '&lt;error =&#39;foobar&#39;&quot;&gt;';
- $this->form_validation->set_rules('foo', 'label', 'required', array('required' => $error_msg_unprepped));
- $_POST = array('foo' => '');
- $this->form_validation->run();
- $error_arr = $this->form_validation->error_array();
-
- $this->assertEquals('', $this->form_validation->prep_for_form(''));
- $this->assertEquals(array('foo' => $error_msg_prepped), $this->form_validation->prep_for_form($error_arr));
- }
-
public function test_prep_url()
{
$this->assertEquals('', $this->form_validation->prep_url(''));
diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php
index 76a4fcc98..840df076a 100644
--- a/tests/codeigniter/libraries/Session_test.php
+++ b/tests/codeigniter/libraries/Session_test.php
@@ -37,7 +37,8 @@ return;
$ci = $this->ci_instance();
$ldr = $this->ci_core_class('load');
$ci->load = new $ldr();
- $ci->input = new Mock_Core_Input(NULL, NULL);
+ $security = new Mock_Core_Security('UTF-8');
+ $ci->input = new CI_Input($security);
// Make sure string helper is available
$this->ci_vfs_clone('system/helpers/string_helper.php');
@@ -437,4 +438,4 @@ return;
$this->assertNull($this->session->native->userdata($key));
}
-} \ No newline at end of file
+}
diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php
index 4fbc11ef0..74a7d2c22 100644
--- a/tests/codeigniter/libraries/Upload_test.php
+++ b/tests/codeigniter/libraries/Upload_test.php
@@ -6,8 +6,8 @@ class Upload_test extends CI_TestCase {
{
$ci = $this->ci_instance();
$ci->upload = new CI_Upload();
- $ci->security = new Mock_Core_Security();
- $ci->lang = $this->getMock('CI_Lang', array('load', 'line'));
+ $ci->security = new Mock_Core_Security('UTF-8');
+ $ci->lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load', 'line'))->getMock();
$ci->lang->expects($this->any())->method('line')->will($this->returnValue(FALSE));
$this->upload = $ci->upload;
}
@@ -25,14 +25,10 @@ class Upload_test extends CI_TestCase {
)
);
- // ReflectionProperty::setAccessible() is not available in PHP 5.2.x
- if (is_php('5.3'))
- {
- $reflection = new ReflectionClass($upload);
- $reflection = $reflection->getProperty('_file_name_override');
- $reflection->setAccessible(TRUE);
- $this->assertEquals('foo', $reflection->getValue($upload));
- }
+ $reflection = new ReflectionClass($upload);
+ $reflection = $reflection->getProperty('_file_name_override');
+ $reflection->setAccessible(TRUE);
+ $this->assertEquals('foo', $reflection->getValue($upload));
$this->assertTrue($upload->file_ext_tolower);
@@ -300,4 +296,4 @@ class Upload_test extends CI_TestCase {
$this->assertEquals('<p>Error test</p>', $this->upload->display_errors());
}
-} \ No newline at end of file
+}