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.php222
-rw-r--r--tests/codeigniter/libraries/Driver_test.php178
-rw-r--r--tests/codeigniter/libraries/Encrypt_test.php79
-rw-r--r--tests/codeigniter/libraries/Encryption_test.php400
-rw-r--r--tests/codeigniter/libraries/Form_validation_test.php626
-rw-r--r--tests/codeigniter/libraries/Parser_test.php95
-rw-r--r--tests/codeigniter/libraries/Session_test.php440
-rw-r--r--tests/codeigniter/libraries/Table_test.php300
-rw-r--r--tests/codeigniter/libraries/Typography_test.php182
-rw-r--r--tests/codeigniter/libraries/Upload_test.php299
-rw-r--r--tests/codeigniter/libraries/Useragent_test.php125
11 files changed, 0 insertions, 2946 deletions
diff --git a/tests/codeigniter/libraries/Calendar_test.php b/tests/codeigniter/libraries/Calendar_test.php
deleted file mode 100644
index ad1f45e8c..000000000
--- a/tests/codeigniter/libraries/Calendar_test.php
+++ /dev/null
@@ -1,222 +0,0 @@
-<?php
-
-class Calendar_test extends CI_TestCase {
-
- public function set_up()
- {
- // Required for get_total_days()
- $this->ci_instance_var('load', $this->getMockBuilder('CI_Loader')->setMethods(array('helper'))->getMock());
-
- $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);
-
- $this->calendar = new CI_Calendar();
- }
-
- // --------------------------------------------------------------------
-
- public 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);
- }
-
- // --------------------------------------------------------------------
-
- public 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));
- }
-
- // --------------------------------------------------------------------
-
- public 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'));
- }
-
- // --------------------------------------------------------------------
-
- public 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());
- }
-
- // --------------------------------------------------------------------
-
- public 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));
- }
-
- // --------------------------------------------------------------------
-
- public 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));
- }
-
- // --------------------------------------------------------------------
-
- public 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>',
- '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/Driver_test.php b/tests/codeigniter/libraries/Driver_test.php
deleted file mode 100644
index e4401e688..000000000
--- a/tests/codeigniter/libraries/Driver_test.php
+++ /dev/null
@@ -1,178 +0,0 @@
-<?php
-
-/**
- * Driver library base class unit test
- */
-class Driver_test extends CI_TestCase {
-
- /**
- * Set up test framework
- */
- public function set_up()
- {
- // Set our subclass prefix
- $this->subclass = 'Mock_Libraries_';
- $this->ci_set_config('subclass_prefix', $this->subclass);
-
- // Mock Loader->get_package_paths
- $paths = 'get_package_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);
-
- // Create mock driver library
- $this->name = 'Driver';
- $this->lib = new Mock_Libraries_Driver();
- }
-
- /**
- * Test driver child loading
- */
- public function test_load_driver()
- {
- // Create driver file
- $driver = 'basic';
- $file = $this->name.'_'.$driver;
- $class = 'CI_'.$file;
- $prop = 'called';
- $content = '<?php class '.$class.' extends CI_Driver { public $'.$prop.' = FALSE; '.
- 'public function decorate($parent) { $this->'.$prop.' = TRUE; } }';
- $this->ci_vfs_create($file, $content, $this->ci_base_root, array('libraries', $this->name, 'drivers'));
-
- // Make driver valid
- $this->lib->driver_list($driver);
-
- // Load driver
- $this->assertNotNull($this->lib->load_driver($driver));
-
- // Did lib name get set?
- $this->assertEquals($this->name, $this->lib->get_name());
-
- // Was driver loaded?
- $this->assertObjectHasAttribute($driver, $this->lib);
- $this->assertAttributeInstanceOf($class, $driver, $this->lib);
- $this->assertAttributeInstanceOf('CI_Driver', $driver, $this->lib);
-
- // Was decorate called?
- $this->assertObjectHasAttribute($prop, $this->lib->$driver);
- $this->assertTrue($this->lib->$driver->$prop);
-
- // Do we get an error for an invalid driver?
- $driver = 'unlisted';
- $this->setExpectedException('RuntimeException', 'CI Error: Invalid driver requested: '.$this->name.'_'.$driver);
- $this->lib->load_driver($driver);
- }
-
- /**
- * Test loading lowercase from app path
- */
- public function test_load_app_driver()
- {
- // Create driver file
- $driver = 'lowpack';
- $file = $this->name.'_'.$driver;
- $class = 'CI_'.$file;
- $content = '<?php class '.$class.' extends CI_Driver { }';
- $this->ci_vfs_create($file, $content, $this->ci_app_root,
- array('libraries', $this->name, 'drivers'));
-
- // Make valid list
- $nodriver = 'absent';
- $this->lib->driver_list(array($driver, $nodriver));
-
- // Load driver
- $this->assertNotNull($this->lib->load_driver($driver));
-
- // Was driver loaded?
- $this->assertObjectHasAttribute($driver, $this->lib);
- $this->assertAttributeInstanceOf($class, $driver, $this->lib);
- $this->assertAttributeInstanceOf('CI_Driver', $driver, $this->lib);
-
- // Do we get an error for a non-existent driver?
- $this->setExpectedException('RuntimeException', 'CI Error: Unable to load the requested driver: CI_'.
- $this->name.'_'.$nodriver);
- $this->lib->load_driver($nodriver);
- }
-
- /**
- * Test loading driver extension
- */
- public function test_load_driver_ext()
- {
- // Create base file
- $driver = 'extend';
- $base = $this->name.'_'.$driver;
- $baseclass = 'CI_'.$base;
- $content = '<?php class '.$baseclass.' extends CI_Driver { }';
- $this->ci_vfs_create($base, $content, $this->ci_base_root, array('libraries', $this->name, 'drivers'));
-
- // Create driver file
- $class = $this->subclass.$base;
- $content = '<?php class '.$class.' extends '.$baseclass.' { }';
- $this->ci_vfs_create($class, $content, $this->ci_app_root, array('libraries', $this->name, 'drivers'));
-
- // Make valid list
- $this->lib->driver_list($driver);
-
- // Load driver
- $this->assertNotNull($this->lib->load_driver($driver));
-
- // Was driver loaded?
- $this->assertObjectHasAttribute($driver, $this->lib);
- $this->assertAttributeInstanceOf($class, $driver, $this->lib);
- $this->assertAttributeInstanceOf($baseclass, $driver, $this->lib);
- $this->assertAttributeInstanceOf('CI_Driver', $driver, $this->lib);
-
- // Create driver extension without base
- $driver = 'baseless';
- $base = $this->name.'_'.$driver;
- $class = $this->subclass.$base;
- $content = '<?php class '.$class.' extends CI_Driver { }';
- $this->ci_vfs_create($class, $content, $this->ci_app_root, array('libraries', $this->name, 'drivers'));
- $this->lib->driver_list($driver);
-
- // Do we get an error when base class isn't found?
- $this->setExpectedException('RuntimeException', 'CI Error: Unable to load the requested class: CI_'.$base);
- $this->lib->load_driver($driver);
- }
-
- /**
- * Test decorating driver with parent attributes
- */
- public function test_decorate()
- {
- // Create parent with a method and property to access
- $pclass = 'Test_Parent';
- $prop = 'parent_prop';
- $value = 'initial';
- $method = 'parent_func';
- $return = 'func return';
- $code = 'class '.$pclass.' { public $'.$prop.' = \''.$value.'\'; '.
- 'public function '.$method.'() { return \''.$return.'\'; } }';
- eval($code);
- $parent = new $pclass();
-
- // Create child driver to decorate
- $class = 'Test_Driver';
- eval('class '.$class.' extends CI_Driver { }');
- $child = new $class();
-
- // Decorate child
- $child->decorate($parent);
-
- // Do we get the initial parent property value?
- $this->assertEquals($value, $child->$prop);
-
- // Can we change the parent property?
- $newval = 'changed';
- $child->$prop = $newval;
- $this->assertEquals($newval, $parent->$prop);
-
- // Do we get back the updated value?
- $this->assertEquals($newval, $child->$prop);
-
- // Can we call the parent method?
- $this->assertEquals($return, $child->$method());
- }
-
-}
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/Encryption_test.php b/tests/codeigniter/libraries/Encryption_test.php
deleted file mode 100644
index 8e411d9fa..000000000
--- a/tests/codeigniter/libraries/Encryption_test.php
+++ /dev/null
@@ -1,400 +0,0 @@
-<?php
-
-class Encryption_test extends CI_TestCase {
-
- public function set_up()
- {
- $this->encryption = new Mock_Libraries_Encryption();
- }
-
- // --------------------------------------------------------------------
-
- /**
- * __construct test
- *
- * Covers behavior with $config['encryption_key'] set or not
- */
- public function test___construct()
- {
- // Assume no configuration from set_up()
- $this->assertNull($this->encryption->get_key());
-
- // Try with an empty value
- $this->ci_set_config('encryption_key');
- $this->encrypt = new Mock_Libraries_Encryption();
- $this->assertNull($this->encrypt->get_key());
-
- $this->ci_set_config('encryption_key', str_repeat("\x0", 16));
- $this->encrypt = new Mock_Libraries_Encryption();
- $this->assertEquals(str_repeat("\x0", 16), $this->encrypt->get_key());
- }
-
- // --------------------------------------------------------------------
-
- /**
- * hkdf() test
- *
- * Applies test vectors described in Appendix A(1-3) RFC5869.
- * Described vectors 4-7 SHA-1, which we don't support and are
- * therefore excluded.
- *
- * Because our implementation is a single method instead of being
- * split into hkdf_extract() and hkdf_expand(), we cannot test for
- * the PRK value. As long as the OKM is correct though, it's fine.
- *
- * @link https://tools.ietf.org/rfc/rfc5869.txt
- */
- public function test_hkdf()
- {
- $vectors = array(
- // A.1: Basic test case with SHA-256
- array(
- 'digest' => 'sha256',
- 'ikm' => "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
- 'salt' => "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c",
- 'length' => 42,
- 'info' => "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9",
- // 'prk' => "\x07\x77\x09\x36\x2c\x2e\x32\xdf\x0d\xdc\x3f\x0d\xc4\x7b\xba\x63\x90\xb6\xc7\x3b\xb5\x0f\x9c\x31\x22\xec\x84\x4a\xd7\xc2\xb3\xe5",
- 'okm' => "\x3c\xb2\x5f\x25\xfa\xac\xd5\x7a\x90\x43\x4f\x64\xd0\x36\x2f\x2a\x2d\x2d\x0a\x90\xcf\x1a\x5a\x4c\x5d\xb0\x2d\x56\xec\xc4\xc5\xbf\x34\x00\x72\x08\xd5\xb8\x87\x18\x58\x65"
- ),
- // A.2: Test with SHA-256 and longer inputs/outputs
- array(
- 'digest' => 'sha256',
- 'ikm' => "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
- 'salt' => "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf",
- 'length' => 82,
- 'info' => "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
- // 'prk' => "\x06\xa6\xb8\x8c\x58\x53\x36\x1a\x06\x10\x4c\x9c\xeb\x35\xb4\x5c\xef\x76\x00\x14\x90\x46\x71\x01\x4a\x19\x3f\x40\xc1\x5f\xc2\x44",
- 'okm' => "\xb1\x1e\x39\x8d\xc8\x03\x27\xa1\xc8\xe7\xf7\x8c\x59\x6a\x49\x34\x4f\x01\x2e\xda\x2d\x4e\xfa\xd8\xa0\x50\xcc\x4c\x19\xaf\xa9\x7c\x59\x04\x5a\x99\xca\xc7\x82\x72\x71\xcb\x41\xc6\x5e\x59\x0e\x09\xda\x32\x75\x60\x0c\x2f\x09\xb8\x36\x77\x93\xa9\xac\xa3\xdb\x71\xcc\x30\xc5\x81\x79\xec\x3e\x87\xc1\x4c\x01\xd5\xc1\xf3\x43\x4f\x1d\x87",
- ),
- // A.3: Test with SHA-256 and zero-length salt/info
- array(
- 'digest' => 'sha256',
- 'ikm' => "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
- 'salt' => '',
- 'length' => 42,
- 'info' => '',
- // 'prk' => "\x19\xef\x24\xa3\x2c\x71\x7b\x16\x7f\x33\xa9\x1d\x6f\x64\x8b\xdf\x96\x59\x67\x76\xaf\xdb\x63\x77\xac\x43\x4c\x1c\x29\x3c\xcb\x04",
- 'okm' => "\x8d\xa4\xe7\x75\xa5\x63\xc1\x8f\x71\x5f\x80\x2a\x06\x3c\x5a\x31\xb8\xa1\x1f\x5c\x5e\xe1\x87\x9e\xc3\x45\x4e\x5f\x3c\x73\x8d\x2d\x9d\x20\x13\x95\xfa\xa4\xb6\x1a\x96\xc8",
- )
- );
-
- foreach ($vectors as $test)
- {
- $this->assertEquals(
- $test['okm'],
- $this->encryption->hkdf(
- $test['ikm'],
- $test['digest'],
- $test['salt'],
- $test['length'],
- $test['info']
- )
- );
- }
-
- // Test default length, it must match the digest size
- $hkdf_result = $this->encryption->hkdf('foobar', 'sha512');
- $this->assertEquals(
- 64,
- defined('MB_OVERLOAD_STRING')
- ? mb_strlen($hkdf_result, '8bit')
- : strlen($hkdf_result)
- );
-
- // Test maximum length (RFC5869 says that it must be up to 255 times the digest size)
- $hkdf_result = $this->encryption->hkdf('foobar', 'sha384', NULL, 48 * 255);
- $this->assertEquals(
- 12240,
- defined('MB_OVERLOAD_STRING')
- ? mb_strlen($hkdf_result, '8bit')
- : strlen($hkdf_result)
- );
- $this->assertFalse($this->encryption->hkdf('foobar', 'sha224', NULL, 28 * 255 + 1));
-
- // CI-specific test for an invalid digest
- $this->assertFalse($this->encryption->hkdf('fobar', 'sha1'));
- }
-
- // --------------------------------------------------------------------
-
- /**
- * _get_params() test
- */
- public function test__get_params()
- {
- $key = str_repeat("\x0", 16);
-
- // Invalid custom parameters
- $params = array(
- // No cipher, mode or key
- array('cipher' => 'aes-128', 'mode' => 'cbc'),
- array('cipher' => 'aes-128', 'key' => $key),
- array('mode' => 'cbc', 'key' => $key),
- // No HMAC key or not a valid digest
- array('cipher' => 'aes-128', 'mode' => 'cbc', 'key' => $key),
- array('cipher' => 'aes-128', 'mode' => 'cbc', 'key' => $key, 'hmac_digest' => 'sha1', 'hmac_key' => $key),
- // Invalid mode
- array('cipher' => 'aes-128', 'mode' => 'foo', 'key' => $key, 'hmac_digest' => 'sha256', 'hmac_key' => $key)
- );
-
- for ($i = 0, $c = count($params); $i < $c; $i++)
- {
- $this->assertFalse($this->encryption->__get_params($params[$i]));
- }
-
- // Valid parameters
- $params = array(
- 'cipher' => 'aes-128',
- 'mode' => 'cbc',
- 'key' => str_repeat("\x0", 16),
- 'hmac_key' => str_repeat("\x0", 16)
- );
-
- $this->assertInternalType('array', $this->encryption->__get_params($params));
-
- $params['base64'] = TRUE;
- $params['hmac_digest'] = 'sha512';
-
- // Including all parameters
- $params = array(
- 'cipher' => 'aes-128',
- 'mode' => 'cbc',
- 'key' => str_repeat("\x0", 16),
- 'raw_data' => TRUE,
- 'hmac_key' => str_repeat("\x0", 16),
- 'hmac_digest' => 'sha256'
- );
-
- $output = $this->encryption->__get_params($params);
- unset($output['handle'], $output['cipher'], $params['raw_data'], $params['cipher']);
- $params['base64'] = FALSE;
- $this->assertEquals($params, $output);
-
- // HMAC disabled
- unset($params['hmac_key'], $params['hmac_digest']);
- $params['hmac'] = $params['raw_data'] = FALSE;
- $params['cipher'] = 'aes-128';
- $output = $this->encryption->__get_params($params);
- unset($output['handle'], $output['cipher'], $params['hmac'], $params['raw_data'], $params['cipher']);
- $params['base64'] = TRUE;
- $params['hmac_digest'] = $params['hmac_key'] = NULL;
- $this->assertEquals($params, $output);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * initialize(), encrypt(), decrypt() test
- *
- * Testing the three methods separately is not realistic as they are
- * designed to work together. A more thorough test for initialize()
- * though is the OpenSSL/MCrypt compatibility test.
- *
- * @depends test_hkdf
- * @depends test__get_params
- */
- public function test_initialize_encrypt_decrypt()
- {
- $message = 'This is a plain-text message.';
- $key = "\xd0\xc9\x08\xc4\xde\x52\x12\x6e\xf8\xcc\xdb\x03\xea\xa0\x3a\x5c";
-
- // Default state (AES-128/Rijndael-128 in CBC mode)
- $this->encryption->initialize(array('key' => $key));
-
- // Was the key properly set?
- $this->assertEquals($key, $this->encryption->get_key());
-
- $this->assertEquals($message, $this->encryption->decrypt($this->encryption->encrypt($message)));
-
- // Try DES in ECB mode, just for the sake of changing stuff
- $this->encryption->initialize(array('cipher' => 'des', 'mode' => 'ecb', 'key' => substr($key, 0, 8)));
- $this->assertEquals($message, $this->encryption->decrypt($this->encryption->encrypt($message)));
- }
-
- // --------------------------------------------------------------------
-
- /**
- * encrypt(), decrypt test with custom parameters
- *
- * @depends test___get_params
- */
- public function test_encrypt_decrypt_custom()
- {
- $message = 'Another plain-text message.';
-
- // A random invalid parameter
- $this->assertFalse($this->encryption->encrypt($message, array('foo')));
- $this->assertFalse($this->encryption->decrypt($message, array('foo')));
-
- // No HMAC, binary output
- $params = array(
- 'cipher' => 'tripledes',
- 'mode' => 'cfb',
- 'key' => str_repeat("\x1", 16),
- 'base64' => FALSE,
- 'hmac' => FALSE
- );
-
- $ciphertext = $this->encryption->encrypt($message, $params);
-
- $this->assertEquals($message, $this->encryption->decrypt($ciphertext, $params));
- }
-
- // --------------------------------------------------------------------
-
- /**
- * _mcrypt_get_handle() test
- */
- public function test__mcrypt_get_handle()
- {
- if ($this->encryption->drivers['mcrypt'] === FALSE)
- {
- 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->assertInternalType('resource', $this->encryption->__driver_get_handle('mcrypt', 'rijndael-128', 'cbc'));
- }
-
- // --------------------------------------------------------------------
-
- /**
- * _openssl_get_handle() test
- */
- public function test__openssl_mcrypt_get_handle()
- {
- if ($this->encryption->drivers['openssl'] === FALSE)
- {
- return $this->markTestSkipped('Cannot test OpenSSL because it is not available.');
- }
-
- $this->assertEquals('aes-128-cbc', $this->encryption->__driver_get_handle('openssl', 'aes-128', 'cbc'));
- $this->assertEquals('rc4-40', $this->encryption->__driver_get_handle('openssl', 'rc4-40', 'stream'));
- }
-
- // --------------------------------------------------------------------
-
- /**
- * OpenSSL/MCrypt portability test
- *
- * Amongst the obvious stuff, _cipher_alias() is also tested here.
- */
- public function test_portability()
- {
- if ( ! $this->encryption->drivers['mcrypt'] OR ! $this->encryption->drivers['openssl'])
- {
- $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.';
-
- // Format is: <Cipher name>, <Cipher mode>, <Key size>
- $portable = array(
- array('aes-128', 'cbc', 16),
- array('aes-128', 'cfb', 16),
- array('aes-128', 'cfb8', 16),
- array('aes-128', 'ofb', 16),
- array('aes-128', 'ecb', 16),
- array('aes-128', 'ctr', 16),
- array('aes-192', 'cbc', 24),
- array('aes-192', 'cfb', 24),
- array('aes-192', 'cfb8', 24),
- array('aes-192', 'ofb', 24),
- array('aes-192', 'ecb', 24),
- array('aes-192', 'ctr', 24),
- array('aes-256', 'cbc', 32),
- array('aes-256', 'cfb', 32),
- array('aes-256', 'cfb8', 32),
- array('aes-256', 'ofb', 32),
- array('aes-256', 'ecb', 32),
- array('aes-256', 'ctr', 32),
- array('des', 'cbc', 7),
- array('des', 'cfb', 7),
- array('des', 'cfb8', 7),
- array('des', 'ofb', 7),
- array('des', 'ecb', 7),
- array('tripledes', 'cbc', 7),
- array('tripledes', 'cfb', 7),
- array('tripledes', 'cfb8', 7),
- array('tripledes', 'ofb', 7),
- array('tripledes', 'cbc', 14),
- array('tripledes', 'cfb', 14),
- array('tripledes', 'cfb8', 14),
- array('tripledes', 'ofb', 14),
- array('tripledes', 'cbc', 21),
- array('tripledes', 'cfb', 21),
- array('tripledes', 'cfb8', 21),
- array('tripledes', 'ofb', 21),
- array('blowfish', 'cbc', 16),
- array('blowfish', 'cfb', 16),
- array('blowfish', 'ofb', 16),
- array('blowfish', 'ecb', 16),
- array('blowfish', 'cbc', 56),
- array('blowfish', 'cfb', 56),
- array('blowfish', 'ofb', 56),
- array('blowfish', 'ecb', 56),
- array('cast5', 'cbc', 11),
- array('cast5', 'cfb', 11),
- array('cast5', 'ofb', 11),
- array('cast5', 'ecb', 11),
- array('cast5', 'cbc', 16),
- array('cast5', 'cfb', 16),
- array('cast5', 'ofb', 16),
- array('cast5', 'ecb', 16),
- array('rc4', 'stream', 5),
- array('rc4', 'stream', 8),
- array('rc4', 'stream', 16),
- array('rc4', 'stream', 32),
- array('rc4', 'stream', 64),
- array('rc4', 'stream', 128),
- array('rc4', 'stream', 256)
- );
- $driver_index = array('mcrypt', 'openssl');
-
- foreach ($portable as &$test)
- {
- // Add some randomness to the selected driver
- $driver = mt_rand(0,1);
- $params = array(
- 'driver' => $driver_index[$driver],
- 'cipher' => $test[0],
- 'mode' => $test[1],
- 'key' => openssl_random_pseudo_bytes($test[2])
- );
-
- $this->encryption->initialize($params);
- $ciphertext = $this->encryption->encrypt($message);
-
- $driver = (int) ! $driver;
- $params['driver'] = $driver_index[$driver];
-
- $this->encryption->initialize($params);
- $this->assertEquals($message, $this->encryption->decrypt($ciphertext));
- }
- }
-
- // --------------------------------------------------------------------
-
- /**
- * __get() test
- */
- public function test_magic_get()
- {
- $this->assertNull($this->encryption->foo);
- $this->assertEquals(array('mcrypt', 'openssl'), array_keys($this->encryption->drivers));
-
- // 'stream' mode is translated into an empty string for OpenSSL
- $this->encryption->initialize(array('cipher' => 'rc4', 'mode' => 'stream'));
- $this->assertEquals('stream', $this->encryption->mode);
- }
-
-}
diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php
deleted file mode 100644
index 3280f5bd8..000000000
--- a/tests/codeigniter/libraries/Form_validation_test.php
+++ /dev/null
@@ -1,626 +0,0 @@
-<?php
-
-class Form_validation_test extends CI_TestCase {
-
- public function set_up()
- {
- $_SERVER['REQUEST_METHOD'] = 'POST';
-
- // Create a mock loader since load->helper() looks in the wrong directories for unit tests,
- // We'll use CI_TestCase->helper() instead
- $loader = $this->getMockBuilder('CI_Loader')->setMethods(array('helper'))->getMock();
-
- // 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);
-
- $this->ci_instance_var('lang', $lang);
- $this->ci_instance_var('load', $loader);
- $this->ci_instance_var('input', $input);
-
- $this->lang('form_validation');
- $this->helper('form');
-
- $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', '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()
- {
- $rules = array(
- array('field' => 'foo', 'label' => 'label', 'rules' => 'required'),
- array('field' => 'bar', 'label' => 'label2', 'rules' => 'matches[foo]')
- );
- $values_base = array('foo' => 'sample');
-
- $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'))));
- }
-
- public function test_rule_differs()
- {
- $rules = array(
- array('field' => 'foo', 'label' => 'label', 'rules' => 'required'),
- array('field' => 'bar', 'label' => 'label2', 'rules' => 'differs[foo]')
- );
- $values_base = array('foo' => 'sample');
-
- $this->assertTrue($this->run_rules($rules, array_merge($values_base, array('bar' => 'does_not_match'))));
- $this->assertTrue($this->run_rules($rules, array_merge($values_base, array('bar' => 'Sample'))));
- $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' => 'sample'))));
- }
-
- public function test_rule_min_length()
- {
- $this->assertTrue($this->form_validation->min_length('12345', '5'));
- $this->assertTrue($this->form_validation->min_length('test', '0'));
-
- $this->assertFalse($this->form_validation->min_length('123', '4'));
- $this->assertFalse($this->form_validation->min_length('should_fail', 'A'));
- $this->assertFalse($this->form_validation->min_length('', '4'));
- }
-
- public function test_rule_max_length()
- {
- $this->assertTrue($this->form_validation->max_length('', '4'));
- $this->assertTrue($this->form_validation->max_length('1234', '4'));
-
- $this->assertFalse($this->form_validation->max_length('12345', '4'));
- $this->assertFalse($this->form_validation->max_length('should_fail', 'A'));
- }
-
- public function test_rule_exact_length()
- {
- $this->assertTrue($this->form_validation->exact_length('1234', '4'));
-
- $this->assertFalse($this->form_validation->exact_length('', '3'));
- $this->assertFalse($this->form_validation->exact_length('12345', '4'));
- $this->assertFalse($this->form_validation->exact_length('123', '4'));
- $this->assertFalse($this->form_validation->exact_length('should_fail', 'A'));
- }
-
- public function test_rule_greater_than()
- {
- $this->assertTrue($this->form_validation->greater_than('-10', '-11'));
- $this->assertTrue($this->form_validation->greater_than('10', '9'));
-
- $this->assertFalse($this->form_validation->greater_than('10', '10'));
- $this->assertFalse($this->form_validation->greater_than('10', 'a'));
- $this->assertFalse($this->form_validation->greater_than('10a', '10'));
- }
-
- public function test_rule_greater_than_equal_to()
- {
- $this->assertTrue($this->form_validation->greater_than_equal_to('0', '0'));
- $this->assertTrue($this->form_validation->greater_than_equal_to('1', '0'));
-
- $this->assertFalse($this->form_validation->greater_than_equal_to('-1', '0'));
- $this->assertFalse($this->form_validation->greater_than_equal_to('10a', '0'));
- }
-
- public function test_rule_less_than()
- {
- $this->assertTrue($this->form_validation->less_than('4', '5'));
- $this->assertTrue($this->form_validation->less_than('-1', '0'));
-
- $this->assertFalse($this->form_validation->less_than('4', '4'));
- $this->assertFalse($this->form_validation->less_than('10a', '5'));
- }
-
- public function test_rule_less_than_equal_to()
- {
- $this->assertTrue($this->form_validation->less_than_equal_to('-1', '0'));
- $this->assertTrue($this->form_validation->less_than_equal_to('-1', '-1'));
- $this->assertTrue($this->form_validation->less_than_equal_to('4', '4'));
-
- $this->assertFalse($this->form_validation->less_than_equal_to('0', '-1'));
- $this->assertFalse($this->form_validation->less_than_equal_to('10a', '0'));
- }
-
- public function test_rule_in_list()
- {
- $this->assertTrue($this->form_validation->in_list('red', 'red,Blue,123'));
- $this->assertTrue($this->form_validation->in_list('Blue', 'red,Blue,123'));
- $this->assertTrue($this->form_validation->in_list('123', 'red,Blue,123'));
-
- $this->assertFalse($this->form_validation->in_list('Red', 'red,Blue,123'));
- $this->assertFalse($this->form_validation->in_list(' red', 'red,Blue,123'));
- $this->assertFalse($this->form_validation->in_list('1234', 'red,Blue,123'));
- }
-
- public function test_rule_alpha()
- {
- $this->assertTrue($this->form_validation->alpha('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ'));
-
- $this->assertFalse($this->form_validation->alpha('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ '));
- $this->assertFalse($this->form_validation->alpha('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ1'));
- $this->assertFalse($this->form_validation->alpha('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ*'));
- }
-
- public function test_rule_alpha_numeric()
- {
- $this->assertTrue($this->form_validation->alpha_numeric('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ0123456789'));
-
- $this->assertFalse($this->form_validation->alpha_numeric('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ0123456789\ '));
- $this->assertFalse($this->form_validation->alpha_numeric('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ0123456789_'));
- }
-
- public function test_rule_alpha_numeric_spaces()
- {
- $this->assertTrue($this->form_validation->alpha_numeric_spaces(' abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ0123456789'));
-
- $this->assertFalse($this->form_validation->alpha_numeric_spaces(' abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ0123456789_'));
- }
-
- public function test_rule_alpha_dash()
- {
- $this->assertTrue($this->form_validation->alpha_dash('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ0123456789-_'));
-
- $this->assertFalse($this->form_validation->alpha_dash('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ0123456789-_\ '));
- }
-
- public function test_rule_numeric()
- {
- $this->assertTrue($this->form_validation->numeric('0'));
- $this->assertTrue($this->form_validation->numeric('12314'));
- $this->assertTrue($this->form_validation->numeric('-42'));
-
- $this->assertFalse($this->form_validation->numeric('123a'));
- $this->assertFalse($this->form_validation->numeric('--1'));
- }
-
- public function test_rule_integer()
- {
- $this->assertTrue($this->form_validation->integer('0'));
- $this->assertTrue($this->form_validation->integer('42'));
- $this->assertTrue($this->form_validation->integer('-1'));
-
- $this->assertFalse($this->form_validation->integer('124a'));
- $this->assertFalse($this->form_validation->integer('1.9'));
- $this->assertFalse($this->form_validation->integer('--1'));
- }
-
- public function test_rule_decimal()
- {
- $this->assertTrue($this->form_validation->decimal('1.0'));
- $this->assertTrue($this->form_validation->decimal('-0.98'));
-
- $this->assertFalse($this->form_validation->decimal('0'));
- $this->assertFalse($this->form_validation->decimal('1.0a'));
- $this->assertFalse($this->form_validation->decimal('-i'));
- $this->assertFalse($this->form_validation->decimal('--1'));
- }
-
- public function test_rule_is_natural()
- {
- $this->assertTrue($this->form_validation->is_natural('0'));
- $this->assertTrue($this->form_validation->is_natural('12'));
-
- $this->assertFalse($this->form_validation->is_natural('42a'));
- $this->assertFalse($this->form_validation->is_natural('-1'));
- }
-
- public function test_rule_is_natural_no_zero()
- {
- $this->assertTrue($this->form_validation->is_natural_no_zero('42'));
-
- $this->assertFalse($this->form_validation->is_natural_no_zero('0'));
- $this->assertFalse($this->form_validation->is_natural_no_zero('42a'));
- $this->assertFalse($this->form_validation->is_natural_no_zero('-1'));
- }
-
- 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.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(''));
- $this->assertFalse($this->form_validation->valid_url('code igniter'));
- }
-
- public function test_rule_valid_email()
- {
- $this->assertTrue($this->form_validation->valid_email('email@sample.com'));
- $this->assertFalse($this->form_validation->valid_email('email@sample.com foo bar'));
- $this->assertFalse($this->form_validation->valid_email('valid_email', '@sample.com'));
- }
-
- public function test_rule_valid_emails()
- {
- $this->assertTrue($this->form_validation->valid_emails('1@sample.com,2@sample.com'));
- $this->assertTrue($this->form_validation->valid_emails('email@sample.com'));
-
- $this->assertFalse($this->form_validation->valid_emails('valid_email', '@sample.com'));
- $this->assertFalse($this->form_validation->valid_emails('@sample.com,2@sample.com,validemail@email.ca'));
- }
-
- public function test_rule_valid_ip()
- {
- $this->assertTrue($this->form_validation->valid_ip('127.0.0.1'));
- $this->assertTrue($this->form_validation->valid_ip('127.0.0.1', 'ipv4'));
- $this->assertTrue($this->form_validation->valid_ip('2001:0db8:85a3:0000:0000:8a2e:0370:7334'));
- $this->assertTrue($this->form_validation->valid_ip('2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'ipv6'));
-
- $this->assertFalse($this->form_validation->valid_ip('2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'ipv4'));
- $this->assertFalse($this->form_validation->valid_ip('127.0.0.1', 'ipv6'));
- $this->assertFalse($this->form_validation->valid_ip('H001:0db8:85a3:0000:0000:8a2e:0370:7334'));
- $this->assertFalse($this->form_validation->valid_ip('127.0.0.259'));
- }
-
- public function test_rule_valid_base64()
- {
- $this->assertTrue($this->form_validation->valid_base64(base64_encode('string')));
-
- $this->assertFalse($this->form_validation->valid_base64('FA08GG'));
- }
-
- public function test_set_data()
- {
- $data = array('field' => 'some_data');
- $this->form_validation->set_data($data);
- $this->form_validation->set_rules('field', 'label', 'required');
- $this->assertTrue($this->form_validation->run());
-
- // Test with empty array
- $_POST = array();
- $this->form_validation->reset_validation();
- $data = array('field' => 'some_data');
- $this->form_validation->set_data($data);
- // This should do nothing. Old data will still be used
- $this->form_validation->set_data(array());
- $this->form_validation->set_rules('field', 'label', 'required');
- $this->assertTrue($this->form_validation->run());
- }
-
- public function test_set_message()
- {
- $err_message = 'What a terrible error!';
- $rules = array(
- array(
- 'field' => 'req_field',
- 'label' => 'label',
- 'rules' => 'required'
- )
- );
- $errorless_data = array('req_field' => 'some text');
- $erroneous_data = array('req_field' => '');
-
- $this->form_validation->set_message('required', $err_message);
- $this->form_validation->set_data($erroneous_data);
- $this->form_validation->set_rules($rules);
- $this->form_validation->run();
- $this->assertEquals('<p>'.$err_message.'</p>', $this->form_validation->error('req_field'));
-
- $this->form_validation->reset_validation();
- $this->form_validation->set_message('required', $err_message);
- $this->form_validation->set_data($errorless_data);
- $this->form_validation->set_rules($rules);
- $this->form_validation->run();
- $this->assertEquals('', $this->form_validation->error('req_field'));
- }
-
- public function test_set_error_delimiters()
- {
- $prefix = '<div class="error">';
- $suffix = '</div>';
- $this->form_validation->set_error_delimiters($prefix, $suffix);
- $this->form_validation->set_rules('foo', 'label', 'required');
- $_POST = array('foo' => '');
- $this->form_validation->run();
- $error_msg = $this->form_validation->error('foo');
-
- $this->assertStringStartsWith($prefix, $error_msg);
- $this->assertTrue(strrpos($error_msg, $suffix, -strlen($suffix)) === (strlen($error_msg) - strlen($suffix)));
-
- $_POST = array();
- }
-
- public function test_error_array()
- {
- $error_message = 'What a terrible error!';
- $this->form_validation->set_message('required', $error_message);
- $this->form_validation->set_rules('foo', 'label', 'required');
- $_POST = array('foo' => '');
- $this->form_validation->run();
- $error_array = $this->form_validation->error_array();
- $this->assertEquals($error_message, $error_array['foo']);
-
- $_POST = array();
- }
-
- public function test_error_string()
- {
- $error_message = 'What a terrible error!';
- $prefix_default = '<foo>';
- $suffix_default = '</foo>';
- $prefix_test = '<bar>';
- $suffix_test = '</bar>';
- $this->form_validation->set_error_delimiters($prefix_default, $suffix_default);
- $this->form_validation->set_message('required', $error_message);
- $this->form_validation->set_rules('foo', 'label', 'required');
- $_POST = array('foo' => '');
- $this->form_validation->run();
-
- $this->assertEquals($prefix_default.$error_message.$suffix_default."\n", $this->form_validation->error_string());
- $this->assertEquals($prefix_test.$error_message.$suffix_default."\n", $this->form_validation->error_string($prefix_test, ''));
- $this->assertEquals($prefix_default.$error_message.$suffix_test."\n", $this->form_validation->error_string('', $suffix_test));
- $this->assertEquals($prefix_test.$error_message.$suffix_test."\n", $this->form_validation->error_string($prefix_test, $suffix_test));
-
- $this->form_validation->reset_validation();
- $this->form_validation->set_rules('foo', 'label', 'required');
- $_POST = array('foo' => 'bar');
- $this->form_validation->run();
- $this->assertEquals('', $this->form_validation->error_string());
-
- $_POST = array();
- }
-
- public function test_run()
- {
- // form_validation->run() is tested in many of the other unit tests
- // This test will only test run(group='') when group is not empty
- $config = array(
- 'pass' => array(
- array(
- 'field' => 'username',
- 'label' => 'user',
- 'rules' => 'alpha_numeric'
- )
- ),
- 'fail' => array(
- array(
- 'field' => 'username',
- 'label' => 'user',
- 'rules' => 'alpha'
- )
- )
- );
- $_POST = array('username' => 'foo42');
- $form_validation = new CI_Form_validation($config);
- $this->assertTrue($form_validation->run('pass'));
-
- $form_validation = new CI_Form_validation($config);
- $this->assertFalse($form_validation->run('fail'));
-
- $_POST = array();
- }
-
- public function test_has_rule()
- {
- $this->form_validation->set_rules('foo', 'label', 'required');
-
- $this->assertTrue($this->form_validation->has_rule('foo'));
- $this->assertFalse($this->form_validation->has_rule('bar'));
- }
-
- public function test_set_value()
- {
- $default = 'default';
- $this->form_validation->set_rules('foo', 'label', 'required');
- $this->form_validation->set_rules('bar[]', 'label', 'required');
-
- // No post data yet: should return the default value provided
- $this->assertEquals($default, $this->form_validation->set_value('foo', $default));
- $_POST = array('foo' => 'foo', 'bar' => array('bar1', 'bar2'));
- $this->form_validation->run();
- $this->assertEquals('foo', $this->form_validation->set_value('foo', $default));
- $this->assertEquals('bar1', $this->form_validation->set_value('bar[]', $default));
- $this->assertEquals('bar2', $this->form_validation->set_value('bar[]', $default));
-
- $_POST = array();
- }
-
- public function test_set_select()
- {
- // Test 1: No options selected
- $this->form_validation->run();
-
- $this->assertEquals('', $this->form_validation->set_select('select', 'foo'));
- $this->assertEquals(' selected="selected"', $this->form_validation->set_select('select', 'bar', TRUE));
-
- // Test 2: 1 option selected
- $this->form_validation->reset_validation();
- $this->form_validation->set_rules('select', 'label', 'alpha_numeric');
- $_POST = array('select' => 'foo');
- $this->form_validation->run();
-
- $this->assertEquals(' selected="selected"', $this->form_validation->set_select('select', 'foo'));
- $this->assertEquals(' selected="selected"', $this->form_validation->set_select('select', 'foo', TRUE));
- $this->assertEquals('', $this->form_validation->set_select('select', 'bar'));
- $this->assertEquals('', $this->form_validation->set_select('select', 'bar', TRUE));
-
- // Test 3: Multiple options selected
- $this->form_validation->reset_validation();
- $this->form_validation->set_rules('select[]', 'label', 'alpha_numeric');
- $_POST = array('select' => array('foo', 'bar'));
- $this->form_validation->run();
-
- $this->assertEquals(' selected="selected"', $this->form_validation->set_select('select[]', 'foo'));
- $this->assertEquals(' selected="selected"', $this->form_validation->set_select('select[]', 'foo', TRUE));
- $this->assertEquals(' selected="selected"', $this->form_validation->set_select('select[]', 'bar'));
- $this->assertEquals(' selected="selected"', $this->form_validation->set_select('select[]', 'bar', TRUE));
- $this->assertEquals('', $this->form_validation->set_select('select[]', 'foobar'));
- $this->assertEquals('', $this->form_validation->set_select('select[]', 'foobar', TRUE));
-
- $_POST = array();
- }
-
- public function test_set_radio()
- {
- // Test 1: No options selected
- $this->form_validation->run();
-
- $this->assertEquals('', $this->form_validation->set_radio('select', 'foo'));
- // Default should only work when no rules are set
- $this->assertEquals(' checked="checked"', $this->form_validation->set_radio('select', 'bar', TRUE));
-
- // Test 2: 1 option selected
- $this->form_validation->reset_validation();
- $this->form_validation->set_rules('select', 'label', 'alpha_numeric');
- $_POST = array('select' => 'foo');
- $this->form_validation->run();
-
- $this->assertEquals(' checked="checked"', $this->form_validation->set_radio('select', 'foo'));
- $this->assertEquals(' checked="checked"', $this->form_validation->set_radio('select', 'foo', TRUE));
- $this->assertEquals('', $this->form_validation->set_radio('select', 'bar'));
- $this->assertEquals('', $this->form_validation->set_radio('select', 'bar', TRUE));
-
- // Test 3: Multiple options checked
- $this->form_validation->reset_validation();
- $this->form_validation->set_rules('select[]', 'label', 'alpha_numeric');
- $_POST = array('select' => array('foo', 'bar'));
- $this->form_validation->run();
-
- $this->assertEquals(' checked="checked"', $this->form_validation->set_radio('select[]', 'foo'));
- $this->assertEquals(' checked="checked"', $this->form_validation->set_radio('select[]', 'foo', TRUE));
- $this->assertEquals(' checked="checked"', $this->form_validation->set_radio('select[]', 'bar'));
- $this->assertEquals(' checked="checked"', $this->form_validation->set_radio('select[]', 'bar', TRUE));
- $this->assertEquals('', $this->form_validation->set_radio('select[]', 'foobar'));
- $this->assertEquals('', $this->form_validation->set_radio('select[]', 'foobar', TRUE));
-
- $_POST = array();
- }
-
- public function test_set_checkbox()
- {
- // Test 1: No options selected
- $this->form_validation->run();
-
- $this->assertEquals('', $this->form_validation->set_checkbox('select', 'foo'));
- $this->assertEquals(' checked="checked"', $this->form_validation->set_checkbox('select', 'bar', TRUE));
-
- // Test 2: 1 option selected
- $this->form_validation->reset_validation();
- $this->form_validation->set_rules('select', 'label', 'alpha_numeric');
- $_POST = array('select' => 'foo');
- $this->form_validation->run();
-
- $this->assertEquals(' checked="checked"', $this->form_validation->set_checkbox('select', 'foo'));
- $this->assertEquals(' checked="checked"', $this->form_validation->set_checkbox('select', 'foo', TRUE));
- $this->assertEquals('', $this->form_validation->set_checkbox('select', 'bar'));
- $this->assertEquals('', $this->form_validation->set_checkbox('select', 'bar', TRUE));
-
- // Test 3: Multiple options selected
- $this->form_validation->reset_validation();
- $this->form_validation->set_rules('select[]', 'label', 'alpha_numeric');
- $_POST = array('select' => array('foo', 'bar'));
- $this->form_validation->run();
-
- $this->assertEquals(' checked="checked"', $this->form_validation->set_checkbox('select[]', 'foo'));
- $this->assertEquals(' checked="checked"', $this->form_validation->set_checkbox('select[]', 'foo', TRUE));
- $this->assertEquals(' checked="checked"', $this->form_validation->set_checkbox('select[]', 'bar'));
- $this->assertEquals(' checked="checked"', $this->form_validation->set_checkbox('select[]', 'bar', TRUE));
- $this->assertEquals('', $this->form_validation->set_checkbox('select[]', 'foobar'));
- $this->assertEquals('', $this->form_validation->set_checkbox('select[]', 'foobar', TRUE));
-
- $_POST = array();
- }
-
- public function test_regex_match()
- {
- $regex = '/f[a-zA-Z]+/';
- $this->assertTrue($this->form_validation->regex_match('foo', $regex));
- $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(''));
- $this->assertEquals('http://codeigniter.com', $this->form_validation->prep_url('codeigniter.com'));
- $this->assertEquals('https://codeigniter.com', $this->form_validation->prep_url('https://codeigniter.com'));
- $this->assertEquals('http://codeigniter.com', $this->form_validation->prep_url('http://codeigniter.com'));
- $this->assertEquals('http://www.codeigniter.com', $this->form_validation->prep_url('www.codeigniter.com'));
- }
-
- public function test_encode_php_tags()
- {
- $this->assertEquals("&lt;?php", $this->form_validation->encode_php_tags('<?php'));
- $this->assertEquals('?&gt;', $this->form_validation->encode_php_tags('?>'));
- }
-
- /**
- * Run rules
- *
- * Helper method to set rules and run them at once, not
- * an actual test case.
- */
- public function run_rules($rules, $values)
- {
- $this->form_validation->reset_validation();
- $_POST = array();
- $this->form_validation->set_rules($rules);
-
- foreach ($values as $field => $value)
- {
- $_POST[$field] = $value;
- }
-
- $valid = $this->form_validation->run();
- $_POST = array();
-
- return $valid;
- }
-}
diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php
deleted file mode 100644
index 2a2348793..000000000
--- a/tests/codeigniter/libraries/Parser_test.php
+++ /dev/null
@@ -1,95 +0,0 @@
-<?php
-
-class Parser_test extends CI_TestCase {
-
- public function set_up()
- {
- $this->parser = new CI_Parser();
- $this->ci_instance_var('parser', $this->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_string()
- {
- $data = array(
- 'title' => 'Page Title',
- 'body' => 'Lorem ipsum dolor sit amet.'
- );
-
- $template = "{title}\n{body}";
-
- $result = implode("\n", $data);
-
- $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
- }
-
- // --------------------------------------------------------------------
-
- public function test_parse()
- {
- $this->_parse_no_template();
- $this->_parse_var_pair();
- $this->_mismatched_var_pair();
- }
-
- // --------------------------------------------------------------------
-
- private function _parse_no_template()
- {
- $this->assertFalse($this->parser->parse_string('', '', TRUE));
- }
-
- // --------------------------------------------------------------------
-
- private function _parse_var_pair()
- {
- $data = array(
- 'title' => 'Super Heroes',
- 'powers' => array(array('invisibility' => 'yes', 'flying' => 'no'))
- );
-
- $template = "{title}\n{powers}{invisibility}\n{flying}{/powers}\nsecond:{powers} {invisibility} {flying}{/powers}";
-
- $this->assertEquals("Super Heroes\nyes\nno\nsecond: yes no", $this->parser->parse_string($template, $data, TRUE));
- }
-
- // --------------------------------------------------------------------
-
- private function _mismatched_var_pair()
- {
- $data = array(
- 'title' => 'Super Heroes',
- 'powers' => array(array('invisibility' => 'yes', 'flying' => 'no'))
- );
-
- $template = "{title}\n{powers}{invisibility}\n{flying}";
- $result = "Super Heroes\n{powers}{invisibility}\n{flying}";
-
- $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
- }
-
-} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php
deleted file mode 100644
index 76a4fcc98..000000000
--- a/tests/codeigniter/libraries/Session_test.php
+++ /dev/null
@@ -1,440 +0,0 @@
-<?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()
- {
-return;
- // 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();
-
- // Set subclass prefix to match our mock
- $this->ci_set_config('subclass_prefix', 'Mock_Libraries_');
-
- // Establish necessary support classes
- $ci = $this->ci_instance();
- $ldr = $this->ci_core_class('load');
- $ci->load = new $ldr();
- $ci->input = new Mock_Core_Input(NULL, NULL);
-
- // Make sure string helper is available
- $this->ci_vfs_clone('system/helpers/string_helper.php');
-
- // 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'
- );
- $this->session = new Mock_Libraries_Session($config);
- }
-
- /**
- * Tear down test framework
- */
- public function tear_down()
- {
-return;
- // 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
- */
- public function test_set_userdata()
- {
-return;
- // 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
- */
- public function test_has_userdata()
- {
-return;
- // 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
- */
- public function test_all_userdata()
- {
-return;
- // 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->userdata();
- foreach ($cdata as $key => $value) {
- $this->assertEquals($value, $call[$key]);
- }
- $nall = $this->session->native->userdata();
- foreach ($ndata as $key => $value) {
- $this->assertEquals($value, $nall[$key]);
- }
- }
-
- /**
- * Test the unset_userdata() function
- */
- public function test_unset_userdata()
- {
-return;
- // 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
- */
- public function test_flashdata()
- {
-return;
- // 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
- */
- public function test_keep_flashdata()
- {
-return;
- // 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));
- }
-
- public function test_keep_flashdata_with_array()
- {
-return;
- // Set flashdata array 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'
- );
- $kdata = array(
- 'one',
- 'two',
- 'three',
- 'foo',
- 'bar'
- );
- $this->session->cookie->set_flashdata($cdata);
- $this->session->native->set_flashdata($ndata);
-
- // Simulate page reload and verify independent messages
- $this->session->cookie->reload();
- $this->session->native->reload();
- $this->assertEquals($cdata, $this->session->cookie->flashdata());
- $this->assertEquals($ndata, $this->session->native->flashdata());
-
- // Keep messages
- $this->session->cookie->keep_flashdata($kdata);
- $this->session->native->keep_flashdata($kdata);
-
- // Simulate next page reload and verify message persistence
- $this->session->cookie->reload();
- $this->session->native->reload();
- $this->assertEquals($cdata, $this->session->cookie->flashdata());
- $this->assertEquals($ndata, $this->session->native->flashdata());
-
- // Simulate next page reload and verify absence of messages
- $this->session->cookie->reload();
- $this->session->native->reload();
- $this->assertEmpty($this->session->cookie->flashdata());
- $this->assertEmpty($this->session->native->flashdata());
- }
-
- /**
- * Test the all_flashdata() function
- */
- public function test_all_flashdata()
- {
-return;
- // 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->flashdata());
- $this->assertEquals($ndata, $this->session->native->flashdata());
- }
-
- /**
- * Test the tempdata() functions
- */
- public function test_set_tempdata()
- {
-return;
- // 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
- */
- public function test_unset_tempdata()
- {
-return;
- // 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
- */
- public function test_sess_regenerate()
- {
-return;
- // 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
- */
- public function test_sess_destroy()
- {
-return;
- // 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));
- }
-
-} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php
deleted file mode 100644
index f505a43fc..000000000
--- a/tests/codeigniter/libraries/Table_test.php
+++ /dev/null
@@ -1,300 +0,0 @@
-<?php
-
-class Table_test extends CI_TestCase {
-
- public function set_up()
- {
- $this->table = new Mock_Libraries_Table();
- $this->ci_instance_var('table', $this->table);
- }
-
- // Setter Methods
- // --------------------------------------------------------------------
-
- public function test_set_template()
- {
- $this->assertFalse($this->table->set_template('not an array'));
-
- $template = array('a' => 'b');
-
- $this->table->set_template($template);
- $this->assertEquals($template, $this->table->template);
- }
-
- public function test_set_empty()
- {
- $this->table->set_empty('nada');
- $this->assertEquals('nada', $this->table->empty_cells);
- }
-
- public function test_set_caption()
- {
- $this->table->set_caption('awesome cap');
- $this->assertEquals('awesome cap', $this->table->caption);
- }
-
- /*
- * @depends test_prep_args
- */
- public function test_set_heading()
- {
- // uses _prep_args internally, so we'll just do a quick
- // check to verify that func_get_args and prep_args are
- // being called.
-
- $this->table->set_heading('name', 'color', 'size');
-
- $this->assertEquals(
- array(
- array('data' => 'name'),
- array('data' => 'color'),
- array('data' => 'size')
- ),
- $this->table->heading
- );
- }
-
- /*
- * @depends test_prep_args
- */
- public function test_add_row()
- {
- // uses _prep_args internally, so we'll just do a quick
- // check to verify that func_get_args and prep_args are
- // being called.
-
- $this->table->add_row('my', 'pony', 'sings');
- $this->table->add_row('your', 'pony', 'stinks');
- $this->table->add_row('my pony', '>', 'your pony');
-
- $this->assertCount(3, $this->table->rows);
-
- $this->assertEquals(
- array(
- array('data' => 'your'),
- array('data' => 'pony'),
- array('data' => 'stinks')
- ),
- $this->table->rows[1]
- );
- }
-
- // Uility Methods
- // --------------------------------------------------------------------
-
- public function test_prep_args()
- {
- $expected = array(
- array('data' => 'name'),
- array('data' => 'color'),
- array('data' => 'size')
- );
-
- $this->assertEquals(
- $expected,
- $this->table->prep_args(array('name', 'color', 'size'))
- );
-
- // with cell attributes
- // need to add that new argument row to our expected outcome
- $expected[] = array('data' => 'weight', 'class' => 'awesome');
-
- $this->assertEquals(
- $expected,
- $this->table->prep_args(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome')))
- );
- }
-
- public function test_default_template_keys()
- {
- $keys = array(
- 'table_open',
- 'thead_open', 'thead_close',
- 'heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end',
- 'tbody_open', 'tbody_close',
- 'row_start', 'row_end', 'cell_start', 'cell_end',
- 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end',
- 'table_close'
- );
-
- foreach ($keys as $key)
- {
- $this->assertArrayHasKey($key, $this->table->default_template());
- }
- }
-
- public function test_compile_template()
- {
- $this->assertFalse($this->table->set_template('invalid_junk'));
-
- // non default key
- $this->table->set_template(array('nonsense' => 'foo'));
- $this->table->compile_template();
-
- $this->assertArrayHasKey('nonsense', $this->table->template);
- $this->assertEquals('foo', $this->table->template['nonsense']);
-
- // override default
- $this->table->set_template(array('table_close' => '</table junk>'));
- $this->table->compile_template();
-
- $this->assertArrayHasKey('table_close', $this->table->template);
- $this->assertEquals('</table junk>', $this->table->template['table_close']);
- }
-
- public function test_make_columns()
- {
- // Test bogus parameters
- $this->assertFalse($this->table->make_columns('invalid_junk'));
- $this->assertFalse($this->table->make_columns(array()));
- $this->assertFalse($this->table->make_columns(array('one', 'two'), '2.5'));
-
- // Now on to the actual column creation
-
- $five_values = array(
- 'Laura', 'Red', '15',
- 'Katie', 'Blue'
- );
-
- // No column count - no changes to the array
- $this->assertEquals(
- $five_values,
- $this->table->make_columns($five_values)
- );
-
- // Column count of 3 leaves us with one &nbsp;
- $this->assertEquals(
- array(
- array('Laura', 'Red', '15'),
- array('Katie', 'Blue', '&nbsp;')
- ),
- $this->table->make_columns($five_values, 3)
- );
- }
-
- public function test_clear()
- {
- $this->table->set_heading('Name', 'Color', 'Size');
-
- // Make columns changes auto_heading
- $rows = $this->table->make_columns(array(
- 'Laura', 'Red', '15',
- 'Katie', 'Blue'
- ), 3);
-
- foreach ($rows as $row)
- {
- $this->table->add_row($row);
- }
-
- $this->assertFalse($this->table->auto_heading);
- $this->assertCount(3, $this->table->heading);
- $this->assertCount(2, $this->table->rows);
-
- $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()
- {
- $data = array(
- array('name', 'color', 'number'),
- array('Laura', 'Red', '22'),
- array('Katie', 'Blue')
- );
-
- $this->table->auto_heading = FALSE;
- $this->table->set_from_array($data);
- $this->assertEmpty($this->table->heading);
-
- $this->table->clear();
-
- $this->table->set_from_array($data);
- $this->assertCount(2, $this->table->rows);
-
- $expected = array(
- array('data' => 'name'),
- array('data' => 'color'),
- array('data' => 'number')
- );
-
- $this->assertEquals($expected, $this->table->heading);
-
- $expected = array(
- array('data' => 'Katie'),
- array('data' => 'Blue'),
- );
-
- $this->assertEquals($expected, $this->table->rows[1]);
- }
-
- public function test_set_from_object()
- {
- // This needs to be passed by reference to CI_DB_result::__construct()
- $dummy = new stdClass();
- $dummy->conn_id = NULL;
- $dummy->result_id = NULL;
-
- $db_result = new DB_result_dummy($dummy);
-
- $this->table->set_from_db_result($db_result);
-
- $expected = array(
- array('data' => 'name'),
- array('data' => 'email')
- );
-
- $this->assertEquals($expected, $this->table->heading);
-
- $expected = array(
- 'name' => array('data' => 'Foo Bar'),
- 'email' => array('data' => 'foo@bar.com'),
- );
-
- $this->assertEquals($expected, $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->assertContains('<th>Name</th>', $table);
- $this->assertContains('<th>Color</th>', $table);
- $this->assertContains('<th>Size</th>', $table);
-
- // Test the first entry
- $this->assertContains('<td>Fred</td>', $table);
- $this->assertContains('<td>Blue</td>', $table);
- $this->assertContains('<td>Small</td>', $table);
- }
-
-}
-
-// We need this for the _set_from_db_result() test
-class DB_result_dummy extends CI_DB_result
-{
- public function list_fields()
- {
- return array('name', 'email');
- }
-
- public function result_array()
- {
- return array(
- array('name' => 'John Doe', 'email' => 'john@doe.com'),
- array('name' => 'Foo Bar', 'email' => 'foo@bar.com')
- );
- }
-}
diff --git a/tests/codeigniter/libraries/Typography_test.php b/tests/codeigniter/libraries/Typography_test.php
deleted file mode 100644
index e6ee7b05c..000000000
--- a/tests/codeigniter/libraries/Typography_test.php
+++ /dev/null
@@ -1,182 +0,0 @@
-<?php
-
-class Typography_test extends CI_TestCase {
-
- public function set_up()
- {
- $this->type = new CI_Typography();
- $this->ci_instance('type', $this->type);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Tests the format_characters() function.
- *
- * this can and should grow.
- */
- public function test_format_characters()
- {
- $strs = array(
- '"double quotes"' => '&#8220;double quotes&#8221;',
- '"testing" in "theory" that is' => '&#8220;testing&#8221; in &#8220;theory&#8221; that is',
- "Here's what I'm" => 'Here&#8217;s what I&#8217;m',
- '&' => '&amp;',
- '&amp;' => '&amp;',
- '&nbsp;' => '&nbsp;',
- '--' => '&#8212;',
- 'foo...' => 'foo&#8230;',
- 'foo..' => 'foo..',
- 'foo...bar.' => 'foo&#8230;bar.',
- 'test. new' => 'test.&nbsp; new',
- );
-
- foreach ($strs as $str => $expected)
- {
- $this->assertEquals($expected, $this->type->format_characters($str));
- }
- }
-
- // --------------------------------------------------------------------
-
- public function test_nl2br_except_pre()
- {
- $str = <<<EOH
-Hello, I'm a happy string with some new lines.
-
-I like to skip.
-
-Jump
-
-and sing.
-
-<pre>
-I am inside a pre tag. Please don't mess with me.
-
-k?
-</pre>
-
-That's my story and I'm sticking to it.
-
-The End.
-EOH;
-
- $expected = <<<EOH
-Hello, I'm a happy string with some new lines. <br />
-<br />
-I like to skip.<br />
-<br />
-Jump<br />
-<br />
-and sing.<br />
-<br />
-<pre>
-I am inside a pre tag. Please don't mess with me.
-
-k?
-</pre><br />
-<br />
-That's my story and I'm sticking to it.<br />
-<br />
-The End.
-EOH;
-
- $this->assertEquals($expected, $this->type->nl2br_except_pre($str));
- }
-
- // --------------------------------------------------------------------
-
- public function test_auto_typography()
- {
- $this->_blank_string();
- $this->_standardize_new_lines();
- $this->_reduce_linebreaks();
- $this->_remove_comments();
- $this->_protect_pre();
- $this->_no_opening_block();
- $this->_protect_braced_quotes();
- }
-
- // --------------------------------------------------------------------
-
- private function _blank_string()
- {
- // Test blank string
- $this->assertEquals('', $this->type->auto_typography(''));
- }
-
- // --------------------------------------------------------------------
-
- private function _standardize_new_lines()
- {
- $strs = array(
- "My string\rhas return characters" => "<p>My string<br />\nhas return characters</p>",
- 'This one does not!' => '<p>This one does not!</p>'
- );
-
- foreach ($strs as $str => $expect)
- {
- $this->assertEquals($expect, $this->type->auto_typography($str));
- }
- }
-
- // --------------------------------------------------------------------
-
- private function _reduce_linebreaks()
- {
- $str = "This has way too many linebreaks.\n\n\n\nSee?";
- $expect = "<p>This has way too many linebreaks.</p>\n\n<p>See?</p>";
-
- $this->assertEquals($expect, $this->type->auto_typography($str, TRUE));
- }
-
- // --------------------------------------------------------------------
-
- private function _remove_comments()
- {
- $str = '<!-- I can haz comments? --> But no!';
- $expect = '<p><!-- I can haz comments? -->&nbsp; But no!</p>';
-
- $this->assertEquals($expect, $this->type->auto_typography($str));
- }
-
- // --------------------------------------------------------------------
-
- private function _protect_pre()
- {
- $str = '<p>My Sentence</p><pre>var_dump($this);</pre>';
- $expect = '<p>My Sentence</p><pre>var_dump($this);</pre>';
-
- $this->assertEquals($expect, $this->type->auto_typography($str));
- }
-
- // --------------------------------------------------------------------
-
- private function _no_opening_block()
- {
- $str = 'My Sentence<pre>var_dump($this);</pre>';
- $expect = '<p>My Sentence</p><pre>var_dump($this);</pre>';
-
- $this->assertEquals($expect, $this->type->auto_typography($str));
- }
-
- // --------------------------------------------------------------------
-
- public function _protect_braced_quotes()
- {
- $this->type->protect_braced_quotes = TRUE;
-
- $str = 'Test {parse="foobar"}';
- $expect = '<p>Test {parse="foobar"}</p>';
-
- $this->assertEquals($expect, $this->type->auto_typography($str));
-
- $this->type->protect_braced_quotes = FALSE;
-
- $str = 'Test {parse="foobar"}';
- $expect = '<p>Test {parse=&#8220;foobar&#8221;}</p>';
-
- $this->assertEquals($expect, $this->type->auto_typography($str));
- }
-
-} \ No newline at end of file
diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php
deleted file mode 100644
index 8bac597b3..000000000
--- a/tests/codeigniter/libraries/Upload_test.php
+++ /dev/null
@@ -1,299 +0,0 @@
-<?php
-
-class Upload_test extends CI_TestCase {
-
- public function set_up()
- {
- $ci = $this->ci_instance();
- $ci->upload = new CI_Upload();
- $ci->security = new Mock_Core_Security();
- $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;
- }
-
- // --------------------------------------------------------------------
-
- public function test___construct_initialize()
- {
- // via __construct
-
- $upload = new CI_Upload(
- array(
- 'file_name' => 'foo',
- 'file_ext_tolower' => TRUE
- )
- );
-
- $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);
-
- // reset (defaults to true)
-
- $upload->initialize(array('file_name' => 'bar'));
- $this->assertEquals('bar', $upload->file_name);
- $this->assertFalse($upload->file_ext_tolower);
-
- // no reset
-
- $upload->initialize(array('file_ext_tolower' => TRUE), FALSE);
- $this->assertTrue($upload->file_ext_tolower);
- $this->assertEquals('bar', $upload->file_name);
- }
-
- // --------------------------------------------------------------------
-
- public function test_do_upload()
- {
- $this->markTestSkipped("We can't 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()
- {
- $dir = 'uploads';
- $isnew = 'helloworld.txt';
- $exists = 'hello-world.txt';
- $this->ci_vfs_create($exists, 'Hello world.', $this->ci_app_root, $dir);
- $path = $this->ci_vfs_path($dir.'/', APPPATH);
- $this->upload->file_ext = '.txt';
-
- $this->assertEquals($isnew, $this->upload->set_filename($path, $isnew));
- $this->assertEquals('hello-world1.txt', $this->upload->set_filename($path, $exists));
- }
-
- 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 = realpath(PROJECT_BASE.'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 = realpath(PROJECT_BASE.'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 = realpath(PROJECT_BASE.'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());
-
- $dir = 'uploads';
- $this->ci_vfs_mkdir($dir);
- $this->upload->upload_path = $this->ci_vfs_path($dir);
- $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_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()
- {
- $dir = 'uploads';
- $file1 = 'file1.txt';
- $file2 = 'file2.txt';
- $file3 = 'file3.txt';
- $this->ci_vfs_create($file1, 'The billy goat was waiting for them.', $this->ci_vfs_root, $dir);
- $this->ci_vfs_create($file2, '', $this->ci_vfs_root, $dir);
- $this->ci_vfs_create($file3, '<script type="text/javascript">alert("Boo! said the billy goat")</script>', $this->ci_vfs_root, $dir);
-
- $this->upload->file_temp = $this->ci_vfs_path($file1, $dir);
- $this->assertTrue($this->upload->do_xss_clean());
-
- $this->upload->file_temp = $this->ci_vfs_path($file2, $dir);
- $this->assertFalse($this->upload->do_xss_clean());
-
- $this->upload->file_temp = $this->ci_vfs_path($file3, $dir);
- $this->assertFalse($this->upload->do_xss_clean());
-
- $this->upload->file_temp = realpath(PROJECT_BASE.'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());
- }
-
-}
diff --git a/tests/codeigniter/libraries/Useragent_test.php b/tests/codeigniter/libraries/Useragent_test.php
deleted file mode 100644
index c02f2bd9d..000000000
--- a/tests/codeigniter/libraries/Useragent_test.php
+++ /dev/null
@@ -1,125 +0,0 @@
-<?php
-
-class UserAgent_test extends CI_TestCase {
-
- protected $_user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27';
- protected $_mobile_ua = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7';
-
- public function set_up()
- {
- // set a baseline user agent
- $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent;
-
- $this->ci_vfs_clone('application/config/user_agents.php');
- $this->agent = new CI_User_agent();
- $this->ci_instance_var('agent', $this->agent);
- }
-
- // --------------------------------------------------------------------
-
- public function test_accept_lang()
- {
- $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en';
- $this->assertTrue($this->agent->accept_lang());
- unset($_SERVER['HTTP_ACCEPT_LANGUAGE']);
- $this->assertTrue($this->agent->accept_lang('en'));
- $this->assertFalse($this->agent->accept_lang('fr'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_mobile()
- {
- // Mobile Not Set
- $_SERVER['HTTP_USER_AGENT'] = $this->_mobile_ua;
- $this->assertEquals('', $this->agent->mobile());
- unset($_SERVER['HTTP_USER_AGENT']);
- }
-
- // --------------------------------------------------------------------
-
- public function test_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());
- }
-
- // --------------------------------------------------------------------
-
- public function test_agent_string()
- {
- $this->assertEquals($this->_user_agent, $this->agent->agent_string());
- }
-
- // --------------------------------------------------------------------
-
- public function test_browser_info()
- {
- $this->assertEquals('Mac OS X', $this->agent->platform());
- $this->assertEquals('Safari', $this->agent->browser());
- $this->assertEquals('533.20.27', $this->agent->version());
- $this->assertEquals('', $this->agent->robot());
- }
-
- // --------------------------------------------------------------------
-
- 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]);
-
- $_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']);
- }
-
- 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