summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/libraries
diff options
context:
space:
mode:
Diffstat (limited to 'tests/codeigniter/libraries')
-rw-r--r--tests/codeigniter/libraries/Encrypt_test.php79
-rw-r--r--tests/codeigniter/libraries/Form_validation_test.php78
-rw-r--r--tests/codeigniter/libraries/Session_test.php5
-rw-r--r--tests/codeigniter/libraries/Upload_test.php2
4 files changed, 62 insertions, 102 deletions
diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php
deleted file mode 100644
index adbca31b2..000000000
--- a/tests/codeigniter/libraries/Encrypt_test.php
+++ /dev/null
@@ -1,79 +0,0 @@
-<?php
-/**
- * @requires extension mcrypt
- */
-class Encrypt_test extends CI_TestCase {
-
- public function set_up()
- {
- if ( ! extension_loaded('mcrypt'))
- {
- 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);
-
- $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());
- }
-
-}
diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php
index 6872b3abd..1bafd50c3 100644
--- a/tests/codeigniter/libraries/Form_validation_test.php
+++ b/tests/codeigniter/libraries/Form_validation_test.php
@@ -13,10 +13,8 @@ class Form_validation_test extends CI_TestCase {
// Same applies for lang
$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);
@@ -45,7 +43,6 @@ class Form_validation_test extends CI_TestCase {
// 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')));
@@ -58,6 +55,13 @@ class Form_validation_test extends CI_TestCase {
$this->assertFalse($this->run_rules($rules, array('foo' => 'bar')));
}
+ public function test_rule_is_array()
+ {
+ $rules = array(array('field' => 'foo', 'label' => 'Foo', 'rules' => 'is_array'));
+ $this->assertTrue($this->run_rules($rules, array('foo' => array('1', '2'))));
+ $this->assertFalse($this->run_rules($rules, array('foo' => '')));
+ }
+
public function test_rule_matches()
{
$rules = array(
@@ -299,10 +303,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'));
}
@@ -437,6 +453,12 @@ class Form_validation_test extends CI_TestCase {
$_POST = array();
}
+ public function test_set_rules_exception()
+ {
+ $this->setExpectedException('BadMethodCallException');
+ $this->form_validation->set_rules('foo', 'bar');
+ }
+
public function test_has_rule()
{
$this->form_validation->set_rules('foo', 'label', 'required');
@@ -462,6 +484,19 @@ class Form_validation_test extends CI_TestCase {
$_POST = array();
}
+ public function test_issue_5202()
+ {
+ $data = array('person' => array('firstname' => 'Dick', 'lastname' => 'Tracy '));
+ $this->form_validation->set_rules('person[firstname]', 'First Name', 'required|trim');
+ $this->form_validation->set_rules('person[lastname]', 'Last Name', 'required|trim');
+ $this->form_validation->set_data($data);
+ $valid = $this->form_validation->run('', $data);
+
+ $this->assertTrue($valid);
+ $this->assertEquals('Dick', $data['person']['firstname']);
+ $this->assertEquals('Tracy', $data['person']['lastname']);
+ }
+
public function test_set_select()
{
// Test 1: No options selected
@@ -575,20 +610,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(''));
@@ -604,6 +625,23 @@ class Form_validation_test extends CI_TestCase {
$this->assertEquals('?&gt;', $this->form_validation->encode_php_tags('?>'));
}
+ public function test_validated_data_assignment()
+ {
+ $_POST = $post_original = array('foo' => ' bar ', 'bar' => 'baz');
+
+ $this->form_validation->set_data($_POST);
+ $this->form_validation->set_rules('foo', 'Foo', 'required|trim');
+
+ $data_processed = NULL;
+ $validation_result = $this->form_validation->run('', $data_processed);
+
+ $this->assertTrue($validation_result);
+ $this->assertEquals($post_original, $_POST);
+ $this->assertEquals(array('foo' => 'bar', 'bar' => 'baz'), $data_processed);
+
+ $_POST = array();
+ }
+
/**
* Run rules
*
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 8bac597b3..74a7d2c22 100644
--- a/tests/codeigniter/libraries/Upload_test.php
+++ b/tests/codeigniter/libraries/Upload_test.php
@@ -6,7 +6,7 @@ class Upload_test extends CI_TestCase {
{
$ci = $this->ci_instance();
$ci->upload = new CI_Upload();
- $ci->security = new Mock_Core_Security();
+ $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;