summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/core
diff options
context:
space:
mode:
Diffstat (limited to 'tests/codeigniter/core')
-rw-r--r--tests/codeigniter/core/Benchmark_test.php67
-rw-r--r--tests/codeigniter/core/Common_test.php69
-rw-r--r--tests/codeigniter/core/Config_test.php240
-rw-r--r--tests/codeigniter/core/Input_test.php289
-rw-r--r--tests/codeigniter/core/Lang_test.php101
-rw-r--r--tests/codeigniter/core/Loader_test.php594
-rw-r--r--tests/codeigniter/core/Log_test.php63
-rw-r--r--tests/codeigniter/core/Model_test.php37
-rw-r--r--tests/codeigniter/core/Output_test.php63
-rw-r--r--tests/codeigniter/core/Security_test.php356
-rw-r--r--tests/codeigniter/core/URI_test.php254
-rw-r--r--tests/codeigniter/core/Utf8_test.php91
-rw-r--r--tests/codeigniter/core/compat/hash_test.php77
-rw-r--r--tests/codeigniter/core/compat/mbstring_test.php54
-rw-r--r--tests/codeigniter/core/compat/password_test.php159
-rw-r--r--tests/codeigniter/core/compat/standard_test.php378
16 files changed, 0 insertions, 2892 deletions
diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php
deleted file mode 100644
index 33bd742b2..000000000
--- a/tests/codeigniter/core/Benchmark_test.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-
-class Benchmark_test extends CI_TestCase {
-
- public function set_up()
- {
- $this->benchmark = new CI_Benchmark();
- }
-
- // --------------------------------------------------------------------
-
- public function test_mark()
- {
- $this->assertEmpty($this->benchmark->marker);
-
- $this->benchmark->mark('code_start');
-
- $this->assertCount(1, $this->benchmark->marker);
- $this->assertArrayHasKey('code_start', $this->benchmark->marker);
- }
-
- // --------------------------------------------------------------------
-
- public function test_elapsed_time()
- {
- $this->assertEquals('{elapsed_time}', $this->benchmark->elapsed_time());
- $this->assertEmpty($this->benchmark->elapsed_time('undefined_point'));
-
- $this->benchmark->mark('code_start');
- $this->benchmark->mark('code_end');
-
- // Override values, because time isn't testable, but make sure the markers were set
- if (isset($this->benchmark->marker['code_start']) && is_float($this->benchmark->marker['code_start']))
- {
- $this->benchmark->marker['code_start'] = 1389956144.1944;
- }
-
- if (isset($this->benchmark->marker['code_end']) && is_float($this->benchmark->marker['code_end']))
- {
- $this->benchmark->marker['code_end'] = 1389956145.1946;
- }
-
- $this->assertEquals('1', $this->benchmark->elapsed_time('code_start', 'code_end', 0));
- $this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1));
- $this->assertEquals('1.00', $this->benchmark->elapsed_time('code_start', 'code_end', 2));
- $this->assertEquals('1.000', $this->benchmark->elapsed_time('code_start', 'code_end', 3));
- $this->assertEquals('1.0002', $this->benchmark->elapsed_time('code_start', 'code_end', 4));
- $this->assertEquals('1.0002', $this->benchmark->elapsed_time('code_start', 'code_end'));
-
- // Test with non-existing 2nd marker, but again - we need to override the value
- $this->benchmark->elapsed_time('code_start', 'code_end2');
- if (isset($this->benchmark->marker['code_end2']) && is_float($this->benchmark->marker['code_end2']))
- {
- $this->benchmark->marker['code_end2'] = 1389956146.2046;
- }
-
- $this->assertEquals('2.0102', $this->benchmark->elapsed_time('code_start', 'code_end2'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_memory_usage()
- {
- $this->assertEquals('{memory_usage}', $this->benchmark->memory_usage());
- }
-
-}
diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php
deleted file mode 100644
index effae50c5..000000000
--- a/tests/codeigniter/core/Common_test.php
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-
-class Common_test extends CI_TestCase {
-
- public function test_is_php()
- {
- $this->assertTrue(is_php('1.2.0'));
- $this->assertFalse(is_php('9999.9.9'));
- }
-
- // ------------------------------------------------------------------------
-
- public function test_stringify_attributes()
- {
- $this->assertEquals(' class="foo" id="bar"', _stringify_attributes(array('class' => 'foo', 'id' => 'bar')));
-
- $atts = new stdClass;
- $atts->class = 'foo';
- $atts->id = 'bar';
- $this->assertEquals(' class="foo" id="bar"', _stringify_attributes($atts));
-
- $atts = new stdClass;
- $this->assertEquals('', _stringify_attributes($atts));
-
- $this->assertEquals(' class="foo" id="bar"', _stringify_attributes('class="foo" id="bar"'));
-
- $this->assertEquals('', _stringify_attributes(array()));
- }
-
- // ------------------------------------------------------------------------
-
- public function test_stringify_js_attributes()
- {
- $this->assertEquals('width=800,height=600', _stringify_attributes(array('width' => '800', 'height' => '600'), TRUE));
-
- $atts = new stdClass;
- $atts->width = 800;
- $atts->height = 600;
- $this->assertEquals('width=800,height=600', _stringify_attributes($atts, TRUE));
- }
-
- // ------------------------------------------------------------------------
-
- public function test_html_escape()
- {
- $this->assertEquals(
- html_escape('Here is a string containing "quoted" text.'),
- 'Here is a string containing &quot;quoted&quot; text.'
- );
-
- $this->assertEquals(
- html_escape(array('associative' => 'and', array('multi' => 'dimentional'))),
- array('associative' => 'and', array('multi' => 'dimentional'))
- );
- }
-
- // ------------------------------------------------------------------------
-
- public function test_remove_invisible_characters()
- {
- $raw_string = 'Here is a string containing invisible'.chr(0x08).' text %0e.';
- $removed_string = 'Here is a string containing invisible text %0e.';
- $this->assertEquals($removed_string, remove_invisible_characters($raw_string, FALSE));
-
- $raw_string = 'Here is a string %0econtaining url_encoded invisible%1F text.';
- $removed_string = 'Here is a string containing url_encoded invisible text.';
- $this->assertEquals($removed_string, remove_invisible_characters($raw_string));
- }
-}
diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php
deleted file mode 100644
index b5c9e849d..000000000
--- a/tests/codeigniter/core/Config_test.php
+++ /dev/null
@@ -1,240 +0,0 @@
-<?php
-
-class Config_test extends CI_TestCase {
-
- public function set_up()
- {
- $cls =& $this->ci_core_class('cfg');
-
- // set predictable config values
- $this->cfg = array(
- 'index_page' => 'index.php',
- 'base_url' => 'http://example.com/',
- 'subclass_prefix' => 'MY_'
- );
- $this->ci_set_config($this->cfg);
-
- $this->config = new $cls;
- }
-
- // --------------------------------------------------------------------
-
- public function test_item()
- {
- $this->assertEquals($this->cfg['base_url'], $this->config->item('base_url'));
-
- // Bad Config value
- $this->assertNull($this->config->item('no_good_item'));
-
- // Index
- $this->assertNull($this->config->item('no_good_item', 'bad_index'));
- $this->assertNull($this->config->item('no_good_item', 'default'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_set_item()
- {
- $this->assertNull($this->config->item('not_yet_set'));
-
- $this->config->set_item('not_yet_set', 'is set');
- $this->assertEquals('is set', $this->config->item('not_yet_set'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_slash_item()
- {
- // Bad Config value
- $this->assertNull($this->config->slash_item('no_good_item'));
-
- $this->assertEquals($this->cfg['base_url'], $this->config->slash_item('base_url'));
- $this->assertEquals($this->cfg['subclass_prefix'].'/', $this->config->slash_item('subclass_prefix'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_base_url()
- {
- // Test regular base URL
- $base_url = $this->cfg['base_url'];
- $this->assertEquals($base_url, $this->config->base_url());
-
- // Test with URI
- $uri = 'test';
- $this->assertEquals($base_url.$uri, $this->config->base_url($uri));
-
- // Clear base_url
- $this->ci_set_config('base_url', '');
-
- // Rerun constructor
- $cls =& $this->ci_core_class('cfg');
- $this->config = new $cls;
-
- // Test default base
- $this->assertEquals('http://localhost/', $this->config->base_url());
-
- // Capture server vars
- $old_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : NULL;
- $old_script_name = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : NULL;
- $old_script_filename = $_SERVER['SCRIPT_FILENAME'];
- $old_https = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : NULL;
- $old_server_addr = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : NULL;
-
- // The 'Host' header is user input and must not be trusted
- $_SERVER['HTTP_HOST'] = 'test.com';
- $this->config = new $cls;
- $this->assertEquals('http://localhost/', $this->config->base_url());
-
- // However, we may fallback to the server's IP address
- $_SERVER['SERVER_ADDR'] = '127.0.0.1';
- $_SERVER['SCRIPT_NAME'] = '/base_test.php';
- $_SERVER['SCRIPT_FILENAME'] = '/foo/bar/base_test.php';
- $this->config = new $cls;
- $this->assertEquals('http://127.0.0.1/', $this->config->base_url());
-
- // Making sure that HTTPS and URI path are also detected
- $_SERVER['HTTPS'] = 'on';
- $_SERVER['SCRIPT_NAME'] = '/path/base_test.php';
- $_SERVER['SCRIPT_FILENAME'] = '/foo/bar/path/base_test.php';
- $this->config = new $cls;
- $this->assertEquals('https://127.0.0.1/path/', $this->config->base_url());
-
- // Restore server vars
- $_SERVER['HTTP_HOST'] = $old_host;
- $_SERVER['SCRIPT_NAME'] = $old_script_name;
- $_SERVER['SCRIPT_FILENAME'] = $old_script_filename;
- $_SERVER['HTTPS'] = $old_https;
- $_SERVER['SERVER_ADDR'] = $old_server_addr;
- }
-
- // --------------------------------------------------------------------
-
- public function test_site_url()
- {
- $base_url = $this->cfg['base_url'];
- $index_page = $this->cfg['index_page'];
- $this->assertEquals($base_url.$index_page, $this->config->site_url());
-
- $old_base = $this->config->item('base_url');
- $this->config->set_item('base_url', '');
-
- $q_string = $this->config->item('enable_query_strings');
- $this->config->set_item('enable_query_strings', FALSE);
-
- $uri = 'test';
- $uri2 = '1';
- $this->assertEquals($index_page.'/'.$uri, $this->config->site_url($uri));
- $this->assertEquals($index_page.'/'.$uri.'/'.$uri2, $this->config->site_url(array($uri, $uri2)));
-
- $this->assertEquals($index_page.'/test/', $this->config->site_url('test/'));
-
- $suffix = 'ing';
- $this->config->set_item('url_suffix', $suffix);
-
- $arg = 'pass';
- $this->assertEquals($index_page.'/'.$uri.$suffix, $this->config->site_url($uri));
- $this->assertEquals($index_page.'/'.$uri.$suffix.'?'.$arg, $this->config->site_url($uri.'?'.$arg));
-
- $this->config->set_item('url_suffix', FALSE);
- $this->config->set_item('enable_query_strings', TRUE);
-
- $this->assertEquals($index_page.'?'.$uri, $this->config->site_url($uri));
- $this->assertEquals($index_page.'?0='.$uri.'&1='.$uri2, $this->config->site_url(array($uri, $uri2)));
-
- $this->config->set_item('base_url', $old_base);
-
- $this->assertEquals($base_url.$index_page.'?'.$uri, $this->config->site_url($uri));
-
- // back to home base
- $this->config->set_item('enable_query_strings', $q_string);
- }
-
- // --------------------------------------------------------------------
-
- public function test_system_url()
- {
- $this->assertEquals($this->cfg['base_url'].'system/', $this->config->system_url());
- }
-
- // --------------------------------------------------------------------
-
- public function test_load()
- {
- // Test regular load
- $file = 'test.php';
- $key = 'testconfig';
- $val = 'my_value';
- $cfg = array($key => $val);
- $this->ci_vfs_create($file, '<?php $config = '.var_export($cfg, TRUE).';', $this->ci_app_root, 'config');
- $this->assertTrue($this->config->load($file));
- $this->assertEquals($val, $this->config->item($key));
-
- // Test reload - value should not change
- $val2 = 'new_value';
- $cfg = array($key => $val2);
- $this->ci_vfs_create($file, '<?php $config = '.var_export($cfg, TRUE).';', $this->ci_app_root, 'config');
- $this->assertTrue($this->config->load($file));
- $this->assertEquals($val, $this->config->item($key));
-
- // Test section load
- $file = 'secttest';
- $cfg = array(
- 'one' => 'prime',
- 'two' => 2,
- 'three' => TRUE
- );
- $this->ci_vfs_create($file.'.php', '<?php $config = '.var_export($cfg, TRUE).';', $this->ci_app_root, 'config');
- $this->assertTrue($this->config->load($file, TRUE));
- $this->assertEquals($cfg, $this->config->item($file));
-
- // Test section merge
- $cfg2 = array(
- 'three' => 'tres',
- 'number' => 42,
- 'letter' => 'Z'
- );
-
- $pkg_dir = 'package';
- $this->ci_vfs_create(
- $file.'.php',
- '<?php $config = '.var_export($cfg2, TRUE).';',
- $this->ci_app_root,
- array($pkg_dir, 'config')
- );
- array_unshift($this->config->_config_paths, $this->ci_vfs_path($pkg_dir.'/', APPPATH));
- $this->assertTrue($this->config->load($file, TRUE));
- $this->assertEquals(array_merge($cfg, $cfg2), $this->config->item($file));
- array_shift($this->config->_config_paths);
-
- // Test graceful fail of invalid file
- $file = 'badfile';
- $this->ci_vfs_create($file, '', $this->ci_app_root, 'config');
- $this->assertFalse($this->config->load($file, FALSE, TRUE));
-
- // Test regular fail of invalid file
- $this->setExpectedException(
- 'RuntimeException',
- 'CI Error: Your '.$this->ci_vfs_path('config/'.$file.'.php', APPPATH).
- ' file does not appear to contain a valid configuration array.'
- );
- $this->assertNull($this->config->load($file));
- }
-
- // --------------------------------------------------------------------
-
- public function test_load_nonexistent()
- {
- // Test graceful fail of nonexistent file
- $this->assertFalse($this->config->load('not_config_file', FALSE, TRUE));
-
- // Test regular fail
- $file = 'absentia';
- $this->setExpectedException(
- 'RuntimeException',
- 'CI Error: The configuration file '.$file.'.php does not exist.'
- );
- $this->assertNull($this->config->load($file));
- }
-
-} \ No newline at end of file
diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php
deleted file mode 100644
index 3cce00414..000000000
--- a/tests/codeigniter/core/Input_test.php
+++ /dev/null
@@ -1,289 +0,0 @@
-<?php
-
-class Input_test extends CI_TestCase {
-
- public function set_up()
- {
- // Set server variable to GET as default, since this will leave unset in STDIN env
- $_SERVER['REQUEST_METHOD'] = 'GET';
-
- // Set config for Input class
- $this->ci_set_config('allow_get_array', TRUE);
- $this->ci_set_config('global_xss_filtering', FALSE);
- $this->ci_set_config('csrf_protection', FALSE);
-
- $security = new Mock_Core_Security();
-
- $this->ci_set_config('charset', 'UTF-8');
- $utf8 = new Mock_Core_Utf8();
-
- $this->input = new Mock_Core_Input($security, $utf8);
- }
-
- // --------------------------------------------------------------------
-
- public function tear_down()
- {
- $_POST = [];
- $_GET = [];
- }
-
- // --------------------------------------------------------------------
-
- public function test_get_not_exists()
- {
- $this->assertSame(array(), $this->input->get());
- $this->assertNull($this->input->get('foo'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_get_exist()
- {
- $_SERVER['REQUEST_METHOD'] = 'GET';
- $_GET['foo'] = 'bar';
-
- $this->assertArrayHasKey('foo', $this->input->get());
- $this->assertEquals('bar', $this->input->get('foo'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_get_exist_with_xss_clean()
- {
- $_SERVER['REQUEST_METHOD'] = 'GET';
- $_GET['harm'] = "Hello, i try to <script>alert('Hack');</script> your site";
-
- $this->assertArrayHasKey('harm', $this->input->get());
- $this->assertEquals("Hello, i try to <script>alert('Hack');</script> your site", $this->input->get('harm'));
- $this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", $this->input->get('harm', TRUE));
- }
-
- // --------------------------------------------------------------------
-
- public function test_post_not_exists()
- {
- $this->assertSame(array(), $this->input->post());
- $this->assertNull($this->input->post('foo'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_post_exist()
- {
- $_SERVER['REQUEST_METHOD'] = 'POST';
- $_POST['foo'] = 'bar';
-
- $this->assertArrayHasKey('foo', $this->input->post());
- $this->assertEquals('bar', $this->input->post('foo'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_post_exist_with_xss_clean()
- {
- $_SERVER['REQUEST_METHOD'] = 'POST';
- $_POST['harm'] = "Hello, i try to <script>alert('Hack');</script> your site";
-
- $this->assertArrayHasKey('harm', $this->input->post());
- $this->assertEquals("Hello, i try to <script>alert('Hack');</script> your site", $this->input->post('harm'));
- $this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", $this->input->post('harm', TRUE));
- }
-
- // --------------------------------------------------------------------
-
- public function test_post_get()
- {
- $_SERVER['REQUEST_METHOD'] = 'POST';
- $_POST['foo'] = 'bar';
-
- $this->assertEquals('bar', $this->input->post_get('foo'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_get_post()
- {
- $_SERVER['REQUEST_METHOD'] = 'GET';
- $_GET['foo'] = 'bar';
-
- $this->assertEquals('bar', $this->input->get_post('foo'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_cookie()
- {
- $_COOKIE['foo'] = 'bar';
- $this->assertEquals('bar', $this->input->cookie('foo'));
- $this->assertNull($this->input->cookie('bar'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_server()
- {
- $this->assertEquals('GET', $this->input->server('REQUEST_METHOD'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_fetch_from_array()
- {
- $data = array(
- 'foo' => 'bar',
- 'harm' => 'Hello, i try to <script>alert(\'Hack\');</script> your site',
- );
-
- $foo = $this->input->fetch_from_array($data, 'foo');
- $harm = $this->input->fetch_from_array($data, 'harm');
- $harmless = $this->input->fetch_from_array($data, 'harm', TRUE);
-
- $this->assertEquals('bar', $foo);
- $this->assertEquals("Hello, i try to <script>alert('Hack');</script> your site", $harm);
- $this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", $harmless);
-
- $_SERVER['REQUEST_METHOD'] = 'POST';
- $_POST['foo'] = array('bar' => 'baz');
- $barArray = array('bar' => 'baz');
-
- $this->assertEquals('baz', $this->input->post('foo[bar]'));
- $this->assertEquals($barArray, $this->input->post('foo[]'));
- $this->assertNull($this->input->post('foo[baz]'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_valid_ip()
- {
- $this->assertTrue($this->input->valid_ip('192.18.0.1'));
- $this->assertTrue($this->input->valid_ip('192.18.0.1', 'ipv4'));
- $this->assertFalse($this->input->valid_ip('555.0.0.0'));
- $this->assertFalse($this->input->valid_ip('2001:db8:0:85a3::ac1f:8001', 'ipv4'));
-
- // v6 tests
- $this->assertFalse($this->input->valid_ip('192.18.0.1', 'ipv6'));
-
- $ip_v6 = array(
- '2001:0db8:0000:85a3:0000:0000:ac1f:8001',
- '2001:db8:0:85a3:0:0:ac1f:8001',
- '2001:db8:0:85a3::ac1f:8001'
- );
-
- foreach ($ip_v6 as $ip)
- {
- $this->assertTrue($this->input->valid_ip($ip));
- $this->assertTrue($this->input->valid_ip($ip, 'ipv6'));
- }
- }
-
- // --------------------------------------------------------------------
-
- public function test_method()
- {
- $_SERVER['REQUEST_METHOD'] = 'GET';
- $this->assertEquals('get', $this->input->method());
- $this->assertEquals('GET', $this->input->method(TRUE));
- $_SERVER['REQUEST_METHOD'] = 'POST';
- $this->assertEquals('post', $this->input->method());
- $this->assertEquals('POST', $this->input->method(TRUE));
- }
-
- // --------------------------------------------------------------------
-
- public function test_is_ajax_request()
- {
- $this->assertFalse($this->input->is_ajax_request());
- $_SERVER['HTTP_X_REQUESTED_WITH'] = 'test';
- $this->assertFalse($this->input->is_ajax_request());
- $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
- $this->assertTrue($this->input->is_ajax_request());
- }
-
- // --------------------------------------------------------------------
-
- public function test_input_stream()
- {
- $this->markTestSkipped('TODO: Find a way to test input://');
- }
-
- // --------------------------------------------------------------------
-
- public function test_set_cookie()
- {
- $this->markTestSkipped('TODO: Find a way to test HTTP headers');
- }
-
- // --------------------------------------------------------------------
-
- public function test_get_request_header()
- {
- $this->markTestSkipped('TODO: Find a way to test HTTP headers');
- }
-
- // --------------------------------------------------------------------
-
- public function test_ip_address()
- {
- $this->input->ip_address = '127.0.0.1';
- $this->assertEquals('127.0.0.1', $this->input->ip_address());
-
- // 127.0.0.1 is set in our Bootstrap file
- $this->input->ip_address = FALSE;
- $this->assertEquals('127.0.0.1', $this->input->ip_address());
-
- // Invalid
- $_SERVER['REMOTE_ADDR'] = 'invalid_ip_address';
- $this->input->ip_address = FALSE; // reset cached value
- $this->assertEquals('0.0.0.0', $this->input->ip_address());
-
- $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
-
- // Proxy_ips tests
- $this->input->ip_address = FALSE;
- $this->ci_set_config('proxy_ips', '127.0.0.3, 127.0.0.4, 127.0.0.2');
- $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.2';
- $this->assertEquals('127.0.0.1', $this->input->ip_address());
-
- // Invalid spoof
- $this->input->ip_address = FALSE;
- $this->ci_set_config('proxy_ips', 'invalid_ip_address');
- $_SERVER['HTTP_CLIENT_IP'] = 'invalid_ip_address';
- $this->assertEquals('127.0.0.1', $this->input->ip_address());
-
- $this->input->ip_address = FALSE;
- $this->ci_set_config('proxy_ips', 'http://foo/bar/baz, 127.0.0.1/1');
- $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.1';
- $this->assertEquals('127.0.0.1', $this->input->ip_address());
-
- $this->input->ip_address = FALSE;
- $this->ci_set_config('proxy_ips', 'http://foo/bar/baz, 127.0.0.2');
- $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.2';
- $_SERVER['REMOTE_ADDR'] = '127.0.0.2';
- $this->assertEquals('127.0.0.2', $this->input->ip_address());
-
- //IPv6
- $this->input->ip_address = FALSE;
- $this->ci_set_config('proxy_ips', 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329/1, FE80:0000:0000:0000:0202:B3FF:FE1E:8300/2');
- $_SERVER['HTTP_CLIENT_IP'] = 'FE80:0000:0000:0000:0202:B3FF:FE1E:8300';
- $_SERVER['REMOTE_ADDR'] = 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329';
- $this->assertEquals('FE80:0000:0000:0000:0202:B3FF:FE1E:8300', $this->input->ip_address());
-
- $this->input->ip_address = FALSE;
- $this->ci_set_config('proxy_ips', '0::/32');
- $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.7';
- $_SERVER['REMOTE_ADDR'] = '0000:0000:0000:0000:0000:0000:0000:0001';
- $this->assertEquals('127.0.0.7', $this->input->ip_address());
-
- $this->input->ip_address = FALSE;
- $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // back to reality
- }
-
- // --------------------------------------------------------------------
-
- public function test_user_agent()
- {
- $_SERVER['HTTP_USER_AGENT'] = 'test';
- $this->assertEquals('test', $this->input->user_agent());
- }
-}
diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php
deleted file mode 100644
index 4958f42e1..000000000
--- a/tests/codeigniter/core/Lang_test.php
+++ /dev/null
@@ -1,101 +0,0 @@
-<?php
-
-class Lang_test extends CI_TestCase {
-
- protected $lang;
-
- public function set_up()
- {
- $loader_cls = $this->ci_core_class('load');
- $this->ci_instance_var('load', new $loader_cls);
- $cls = $this->ci_core_class('lang');
- $this->lang = new $cls;
- }
-
- // --------------------------------------------------------------------
-
- public function test_load()
- {
- // Regular usage
- $this->ci_vfs_clone('system/language/english/profiler_lang.php');
- $this->assertTrue($this->lang->load('profiler', 'english'));
- $this->assertEquals('URI STRING', $this->lang->language['profiler_uri_string']);
-
- // Already loaded file
- $this->assertNull($this->lang->load('profiler', 'english'));
-
- // Unspecified language (defaults to english)
- $this->ci_vfs_clone('system/language/english/date_lang.php');
- $this->assertTrue($this->lang->load('date'));
- $this->assertEquals('Year', $this->lang->language['date_year']);
-
- // A language other than english
- $this->ci_vfs_clone('system/language/english/email_lang.php', 'system/language/german/');
- $this->assertTrue($this->lang->load('email', 'german'));
- $this->assertEquals('german', $this->lang->is_loaded['email_lang.php']);
-
- // Non-existent file
- $this->setExpectedException(
- 'RuntimeException',
- 'CI Error: Unable to load the requested language file: language/english/nonexistent_lang.php'
- );
- $this->lang->load('nonexistent');
- }
-
- // --------------------------------------------------------------------
-
- public function test_non_alpha_idiom()
- {
- // Non-alpha idiom (should act the same as unspecified language)
- // test with existing file
- $this->ci_vfs_clone('system/language/english/number_lang.php');
- $this->ci_vfs_clone('system/language/english/number_lang.php', 'system/language/123funny/');
- $this->assertTrue($this->lang->load('number', '123funny'));
- $this->assertEquals('Bytes', $this->lang->language['bytes']);
-
- // test without existing file
- $this->ci_vfs_clone('system/language/english/email_lang.php');
- $this->assertTrue($this->lang->load('email', '456funny'));
- $this->assertEquals('You did not specify a SMTP hostname.', $this->lang->language['email_no_hostname']);
- }
-
- // --------------------------------------------------------------------
-
- public function test_multiple_file_load()
- {
- // Multiple files
- $this->ci_vfs_clone('system/language/english/profiler_lang.php');
- $files = array(
- 0 => 'profiler',
- 1 => 'nonexistent'
- );
- $this->setExpectedException(
- 'RuntimeException',
- 'CI Error: Unable to load the requested language file: language/english/nonexistent_lang.php'
- );
- $this->lang->load($files, 'english');
- }
-
- // --------------------------------------------------------------------
-
- public function test_alternative_path_load()
- {
- // Alternative Path
- $this->ci_vfs_clone('system/language/english/profiler_lang.php');
- $this->assertTrue($this->lang->load('profiler', 'english', FALSE, TRUE, 'vfs://system/'));
- }
-
- // --------------------------------------------------------------------
-
- /**
- * @depends test_load
- */
- public function test_line()
- {
- $this->ci_vfs_clone('system/language/english/profiler_lang.php');
- $this->lang->load('profiler', 'english');
- $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string'));
- $this->assertFalse($this->lang->line('nonexistent_string'));
- $this->assertFalse($this->lang->line(NULL));
- }
-}
diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php
deleted file mode 100644
index 6a7aa916a..000000000
--- a/tests/codeigniter/core/Loader_test.php
+++ /dev/null
@@ -1,594 +0,0 @@
-<?php
-
-class Loader_test extends CI_TestCase {
-
- private $ci_obj;
-
- public function set_up()
- {
- // Instantiate a new loader
- $loader = $this->ci_core_class('loader');
- $this->load = new $loader();
-
- // Get CI instance
- $this->ci_obj = $this->ci_instance();
-
- // Set subclass prefix
- $this->prefix = 'MY_';
- $this->ci_set_config('subclass_prefix', $this->prefix);
- }
-
- // --------------------------------------------------------------------
-
- public function test_library()
- {
- // Test getting CI_Loader object
- $this->assertInstanceOf('CI_Loader', $this->load->library(NULL));
-
- // Create library in VFS
- $lib = 'unit_test_lib';
- $class = 'CI_'.ucfirst($lib);
- $this->ci_vfs_create(ucfirst($lib), '<?php class '.$class.' { }', $this->ci_base_root, 'libraries');
-
- // Test is_loaded fail
- $this->assertFalse($this->load->is_loaded(ucfirst($lib)));
-
- // Test loading as an array.
- $this->assertInstanceOf('CI_Loader', $this->load->library(array($lib)));
- $this->assertTrue(class_exists($class), $class.' does not exist');
- $this->assertObjectHasAttribute($lib, $this->ci_obj);
- $this->assertInstanceOf($class, $this->ci_obj->$lib);
-
- // Create library in VFS
- $lib = array('unit_test_lib' => 'unit_test_lib');
-
- // Test loading as an array (int).
- $this->assertInstanceOf('CI_Loader', $this->load->library($lib));
- $this->assertTrue(class_exists($class), $class.' does not exist');
-
- // Test a string given to params
- $this->assertInstanceOf('CI_Loader', $this->load->library($lib, ' '));
-
- // test non existent lib
- $lib = 'non_existent_test_lib';
-
- $this->setExpectedException(
- 'RuntimeException',
- 'CI Error: Unable to load the requested class: '.ucfirst($lib)
- );
- $this->assertInstanceOf('CI_Loader', $this->load->library($lib));
- }
-
- // --------------------------------------------------------------------
-
- public function test_bad_library()
- {
- $lib = 'bad_test_lib';
- $this->ci_vfs_create(ucfirst($lib), '', $this->ci_app_root, 'libraries');
- $this->setExpectedException(
- 'RuntimeException',
- 'CI Error: Non-existent class: '.ucfirst($lib)
- );
- $this->assertInstanceOf('CI_Loader', $this->load->library($lib));
- }
-
- // --------------------------------------------------------------------
-
- public function test_library_extension()
- {
- // Create library and extension in VFS
- $name = 'ext_test_lib';
- $lib = ucfirst($name);
- $class = 'CI_'.$lib;
- $ext = $this->prefix.$lib;
- $this->ci_vfs_create($lib, '<?php class '.$class.' { }', $this->ci_base_root, 'libraries');
- $this->ci_vfs_create($ext, '<?php class '.$ext.' extends '.$class.' { }', $this->ci_app_root, 'libraries');
-
- // Test loading with extension
- $this->assertInstanceOf('CI_Loader', $this->load->library($lib));
- $this->assertTrue(class_exists($class), $class.' does not exist');
- $this->assertTrue(class_exists($ext), $ext.' does not exist');
- $this->assertObjectHasAttribute($name, $this->ci_obj);
- $this->assertInstanceOf($class, $this->ci_obj->$name);
- $this->assertInstanceOf($ext, $this->ci_obj->$name);
-
- // Test reloading with object name
- $obj = 'exttest';
- $this->assertInstanceOf('CI_Loader', $this->load->library($lib, NULL, $obj));
- $this->assertObjectHasAttribute($obj, $this->ci_obj);
- $this->assertInstanceOf($class, $this->ci_obj->$obj);
- $this->assertInstanceOf($ext, $this->ci_obj->$obj);
-
- // Test reloading
- unset($this->ci_obj->$name);
- $this->assertInstanceOf('CI_Loader', $this->load->library($lib));
- $this->assertObjectHasAttribute($name, $this->ci_obj);
-
- // Create baseless library
- $name = 'ext_baseless_lib';
- $lib = ucfirst($name);
- $class = $this->prefix.$lib;
- $this->ci_vfs_create($class, '<?php class '.$class.' { }', $this->ci_app_root, 'libraries');
-
- // Test missing base class
- $this->setExpectedException(
- 'RuntimeException',
- 'CI Error: Unable to load the requested class: '.$lib
- );
- $this->assertInstanceOf('CI_Loader', $this->load->library($lib));
- }
-
- // --------------------------------------------------------------------
-
- public function test_library_config()
- {
- // Create library in VFS
- $lib = 'unit_test_config_lib';
- $class = 'CI_'.ucfirst($lib);
- $content = '<?php class '.$class.' { public function __construct($params) { $this->config = $params; } }';
- $this->ci_vfs_create(ucfirst($lib), $content, $this->ci_base_root, 'libraries');
-
- // Create config file
- $cfg = array(
- 'foo' => 'bar',
- 'bar' => 'baz',
- 'baz' => false
- );
- $this->ci_vfs_create($lib, '<?php $config = '.var_export($cfg, TRUE).';', $this->ci_app_root, 'config');
-
- // Test object name and config
- $obj = 'testy';
- $this->assertInstanceOf('CI_Loader', $this->load->library($lib, NULL, $obj));
- $this->assertTrue(class_exists($class), $class.' does not exist');
- $this->assertObjectHasAttribute($obj, $this->ci_obj);
- $this->assertInstanceOf($class, $this->ci_obj->$obj);
- $this->assertEquals($cfg, $this->ci_obj->$obj->config);
-
- // Test is_loaded
- $this->assertEquals($obj, $this->load->is_loaded(ucfirst($lib)));
-
- // Test to load another class with the same object name
- $lib = 'another_test_lib';
- $class = ucfirst($lib);
- $this->ci_vfs_create(ucfirst($lib), '<?php class '.$class.' { }', $this->ci_app_root, 'libraries');
- $this->setExpectedException(
- 'RuntimeException',
- "CI Error: Resource '".$obj."' already exists and is not a ".$class." instance."
- );
- $this->load->library($lib, NULL, $obj);
- }
-
- // --------------------------------------------------------------------
-
- public function test_load_library_in_application_dir()
- {
- // Create library in VFS
- $lib = 'super_test_library';
- $class = ucfirst($lib);
- $this->ci_vfs_create(ucfirst($lib), '<?php class '.$class.' { }', $this->ci_app_root, 'libraries');
-
- // Load library
- $this->assertInstanceOf('CI_Loader', $this->load->library($lib));
-
- // Was the model class instantiated.
- $this->assertTrue(class_exists($class), $class.' does not exist');
- $this->assertObjectHasAttribute($lib, $this->ci_obj);
- $this->assertInstanceOf($class, $this->ci_obj->$lib);
- }
-
- // --------------------------------------------------------------------
-
- public function test_driver()
- {
- // Call the autoloader, to include system/libraries/Driver.php
- class_exists('CI_Driver_Library', TRUE);
-
- // Create driver in VFS
- $driver = 'unit_test_driver';
- $dir = ucfirst($driver);
- $class = 'CI_'.$dir;
- $content = '<?php class '.$class.' { } ';
- $this->ci_vfs_create(ucfirst($driver), $content, $this->ci_base_root, 'libraries/'.$dir);
-
- // Test loading as an array.
- $this->assertInstanceOf('CI_Loader', $this->load->driver(array($driver)));
- $this->assertTrue(class_exists($class), $class.' does not exist');
- $this->assertObjectHasAttribute($driver, $this->ci_obj);
- $this->assertInstanceOf($class, $this->ci_obj->$driver);
-
- // Test loading as a library with a name
- $obj = 'testdrive';
- $this->assertInstanceOf('CI_Loader', $this->load->library($driver, NULL, $obj));
- $this->assertObjectHasAttribute($obj, $this->ci_obj);
- $this->assertInstanceOf($class, $this->ci_obj->$obj);
-
- // Test a string given to params
- $this->assertInstanceOf('CI_Loader', $this->load->driver($driver, ' '));
- }
-
- // --------------------------------------------------------------------
-
- public function test_models()
- {
- $this->ci_set_core_class('model', 'CI_Model');
-
- // Create model in VFS
- $model = 'Unit_test_model';
- $content = '<?php class '.$model.' extends CI_Model {} ';
- $this->ci_vfs_create($model, $content, $this->ci_app_root, 'models');
-
- // Load model
- $this->assertInstanceOf('CI_Loader', $this->load->model($model));
-
- // Was the model class instantiated.
- $this->assertTrue(class_exists($model));
- $this->assertObjectHasAttribute($model, $this->ci_obj);
-
- // Test no model given
- $this->assertInstanceOf('CI_Loader', $this->load->model(''));
- }
-
- // --------------------------------------------------------------------
-
- public function test_model_subdir()
- {
- // Make sure base class is loaded - we'll test _ci_include later
- $this->ci_core_class('model');
-
- // Create modelin VFS
- $model = 'Test_sub_model';
- $base = 'CI_Model';
- $subdir = 'cars';
- $this->ci_vfs_create($model, '<?php class '.$model.' extends '.$base.' { }', $this->ci_app_root,
- array('models', $subdir));
-
- // Load model
- $name = 'testors';
- $this->assertInstanceOf('CI_Loader', $this->load->model($subdir.'/'.$model, $name));
-
- // Was the model class instantiated?
- $this->assertTrue(class_exists($model));
- $this->assertObjectHasAttribute($name, $this->ci_obj);
- $this->assertObjectHasAttribute($name, $this->ci_obj);
- $this->assertInstanceOf($base, $this->ci_obj->$name);
- $this->assertInstanceOf($model, $this->ci_obj->$name);
-
- // Test name conflict
- $obj = 'conflict';
- $this->ci_obj->$obj = new stdClass();
- $this->setExpectedException(
- 'RuntimeException',
- 'The model name you are loading is the name of a resource that is already being used: '.$obj
- );
- $this->load->model('not_real', $obj);
- }
-
- // --------------------------------------------------------------------
-
- public function test_non_existent_model()
- {
- $this->setExpectedException(
- 'RuntimeException',
- 'Unable to locate the model you have specified: Ci_test_nonexistent_model.php'
- );
-
- $this->load->model('ci_test_nonexistent_model.php');
- }
-
- // --------------------------------------------------------------------
-
- // public function testDatabase()
- // {
- // $this->assertInstanceOf('CI_Loader', $this->load->database());
- // $this->assertInstanceOf('CI_Loader', $this->load->dbutil());
- // }
-
- // --------------------------------------------------------------------
-
- public function test_load_view()
- {
- // Create view in VFS
- $view = 'unit_test_view';
- $var = 'hello';
- $value = 'World!';
- $content = 'This is my test page. ';
- $this->ci_vfs_create($view, $content.'<?php echo $'.$var.';', $this->ci_app_root, 'views');
-
- // Test returning view
- $out = $this->load->view($view, array($var => $value), TRUE);
- $this->assertEquals($content.$value, $out);
-
- // Mock output class
- $output = $this->getMockBuilder('CI_Output')->setMethods(array('append_output'))->getMock();
- $output->expects($this->once())->method('append_output')->with($content.$value);
- $this->ci_instance_var('output', $output);
-
- // Test view output and $vars as an object
- $vars = new stdClass();
- $vars->$var = $value;
- $this->assertInstanceOf('CI_Loader', $this->load->view($view, $vars));
- }
-
- // --------------------------------------------------------------------
-
- public function test_non_existent_view()
- {
- $this->setExpectedException(
- 'RuntimeException',
- 'CI Error: Unable to load the requested file: ci_test_nonexistent_view.php'
- );
-
- $this->load->view('ci_test_nonexistent_view', array('foo' => 'bar'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_file()
- {
- // Create view in VFS
- $dir = 'views';
- $file = 'ci_test_mock_file';
- $content = 'Here is a test file, which we will load now.';
- $this->ci_vfs_create($file, $content, $this->ci_app_root, $dir);
-
- // Just like load->view(), take the output class out of the mix here.
- $out = $this->load->file(APPPATH.$dir.'/'.$file.'.php', TRUE);
- $this->assertEquals($content, $out);
-
- // Test non-existent file
- $this->setExpectedException(
- 'RuntimeException',
- 'CI Error: Unable to load the requested file: ci_test_file_not_exists'
- );
-
- $this->load->file('ci_test_file_not_exists', TRUE);
- }
-
- // --------------------------------------------------------------------
-
- public function test_vars()
- {
- $key1 = 'foo';
- $val1 = 'bar';
- $key2 = 'boo';
- $val2 = 'hoo';
- $this->assertInstanceOf('CI_Loader', $this->load->vars(array($key1 => $val1)));
- $this->assertInstanceOf('CI_Loader', $this->load->vars($key2, $val2));
- $this->assertEquals($val1, $this->load->get_var($key1));
- $this->assertEquals(array($key1 => $val1, $key2 => $val2), $this->load->get_vars());
- }
-
- // --------------------------------------------------------------------
-
- public function test_clear_vars()
- {
- $key1 = 'foo';
- $val1 = 'bar';
- $key2 = 'boo';
- $val2 = 'hoo';
- $this->assertInstanceOf('CI_Loader', $this->load->vars(array($key1 => $val1)));
- $this->assertInstanceOf('CI_Loader', $this->load->vars($key2, $val2));
- $this->assertEquals($val1, $this->load->get_var($key1));
- $this->assertEquals(array($key1 => $val1, $key2 => $val2), $this->load->get_vars());
-
- $this->assertInstanceOf('CI_Loader', $this->load->clear_vars());
- $this->assertEquals('', $this->load->get_var($key1));
- $this->assertEquals('', $this->load->get_var($key2));
- }
-
- // --------------------------------------------------------------------
-
- public function test_helper()
- {
- // Create helper in VFS
- $helper = 'test';
- $func = '_my_helper_test_func';
- $content = '<?php function '.$func.'() { return TRUE; } ';
- $this->ci_vfs_create($helper.'_helper', $content, $this->ci_base_root, 'helpers');
-
- // Create helper extension
- $exfunc = '_my_extension_func';
- $content = '<?php function '.$exfunc.'() { return TRUE; } ';
- $this->ci_vfs_create($this->prefix.$helper.'_helper', $content, $this->ci_app_root, 'helpers');
-
- // Load helper
- $this->assertInstanceOf('CI_Loader', $this->load->helper($helper));
- $this->assertTrue(function_exists($func), $func.' does not exist');
- $this->assertTrue(function_exists($exfunc), $exfunc.' does not exist');
-
- // Create baseless extension
- $ext = 'bad_ext';
- $this->ci_vfs_create($this->prefix.$ext.'_helper', '', $this->ci_app_root, 'helpers');
-
- // Test bad extension
- $this->setExpectedException(
- 'RuntimeException',
- 'CI Error: Unable to load the requested file: helpers/'.$ext.'_helper.php'
- );
- $this->load->helper($ext);
- }
-
- // --------------------------------------------------------------------
-
- public function test_non_existent_helper()
- {
- $this->setExpectedException(
- 'RuntimeException',
- 'CI Error: Unable to load the requested file: helpers/bad_helper.php'
- );
- $this->load->helper('bad');
- }
-
- // --------------------------------------------------------------------
-
- public function test_loading_multiple_helpers()
- {
- // Create helpers in VFS
- $helpers = array();
- $funcs = array();
- $files = array();
- for ($i = 1; $i <= 3; ++$i) {
- $helper = 'test'.$i;
- $helpers[] = $helper;
- $func = '_my_helper_test_func'.$i;
- $funcs[] = $func;
- $files[$helper.'_helper'] = '<?php function '.$func.'() { return TRUE; } ';
- }
- $this->ci_vfs_create($files, NULL, $this->ci_base_root, 'helpers');
-
- // Load helpers
- $this->assertInstanceOf('CI_Loader', $this->load->helpers($helpers));
-
- // Verify helper existence
- foreach ($funcs as $func) {
- $this->assertTrue(function_exists($func), $func.' does not exist');
- }
- }
-
- // --------------------------------------------------------------------
-
- public function test_language()
- {
- // Mock lang class and test load call
- $file = 'test';
- $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock();
- $lang->expects($this->once())->method('load')->with($file);
- $this->ci_instance_var('lang', $lang);
- $this->assertInstanceOf('CI_Loader', $this->load->language($file));
- }
-
- // --------------------------------------------------------------------
-
- public function test_packages()
- {
- // Create model in VFS package path
- $dir = 'third-party';
- $lib = 'unit_test_package';
- $class = ucfirst($lib);
- $this->ci_vfs_create(ucfirst($lib), '<?php class '.$class.' { }', $this->ci_app_root, array($dir, 'libraries'));
-
- // Get paths
- $paths = $this->load->get_package_paths(TRUE);
-
- // Test failed load without path
- $this->setExpectedException(
- 'RuntimeException',
- 'CI Error: Unable to load the requested class: '.ucfirst($lib)
- );
- $this->load->library($lib);
-
- // Add path and verify
- $path = APPPATH.$dir.'/';
- $this->assertInstanceOf('CI_Loader', $this->load->add_package_path($path));
- $this->assertContains($path, $this->load->get_package_paths(TRUE));
-
- // Test successful load
- $this->assertInstanceOf('CI_Loader', $this->load->library($lib));
- $this->assertTrue(class_exists($class), $class.' does not exist');
-
- // Add another path
- $path2 = APPPATH.'another/';
- $this->assertInstanceOf('CI_Loader', $this->load->add_package_path($path2));
- $this->assertContains($path2, $this->load->get_package_paths(TRUE));
-
- // Remove last path
- $this->assertInstanceOf('CI_Loader', $this->load->remove_package_path());
- $this->assertNotContains($path2, $this->load->get_package_paths(TRUE));
-
- // Remove path and verify restored paths
- $this->assertInstanceOf('CI_Loader', $this->load->remove_package_path($path));
- $this->assertEquals($paths, $this->load->get_package_paths(TRUE));
- }
-
- // --------------------------------------------------------------------
-
- public function test_remove_package_path()
- {
- $dir = 'third-party';
- $path = APPPATH.$dir.'/';
- $path2 = APPPATH.'another/';
- $paths = $this->load->get_package_paths(TRUE);
-
- $this->assertInstanceOf('CI_Loader', $this->load->add_package_path($path));
- $this->assertInstanceOf('CI_Loader', $this->load->remove_package_path($path));
- $this->assertEquals($paths, $this->load->get_package_paths(TRUE));
-
- $this->assertInstanceOf('CI_Loader', $this->load->add_package_path($path2));
- $this->assertInstanceOf('CI_Loader', $this->load->remove_package_path());
- $this->assertNotContains($path2, $this->load->get_package_paths(TRUE));
- }
-
- // --------------------------------------------------------------------
-
- public function test_load_config()
- {
- $cfg = 'someconfig';
- $this->assertTrue($this->load->config($cfg, FALSE));
- $this->assertContains($cfg, $this->ci_obj->config->loaded);
- }
-
- // --------------------------------------------------------------------
-
- public function test_initialize()
- {
- // Create helper in VFS
- $helper = 'autohelp';
- $hlp_func = '_autohelp_test_func';
- $content = '<?php function '.$hlp_func.'() { return TRUE; }';
- $this->ci_vfs_create($helper.'_helper', $content, $this->ci_app_root, 'helpers');
-
- // Create library in VFS
- $lib = 'autolib';
- $lib_class = 'CI_'.ucfirst($lib);
- $this->ci_vfs_create(ucfirst($lib), '<?php class '.$lib_class.' { }', $this->ci_base_root, 'libraries');
-
- // Create driver in VFS
- $drv = 'autodrv';
- $subdir = ucfirst($drv);
- $drv_class = 'CI_'.$subdir;
- $this->ci_vfs_create(ucfirst($drv), '<?php class '.$drv_class.' { }', $this->ci_base_root, array('libraries', $subdir));
-
- // Create model in VFS package path
- $dir = 'testdir';
- $path = APPPATH.$dir.'/';
- $model = 'Automod';
- $this->ci_vfs_create($model, '<?php class '.$model.' { }', $this->ci_app_root, array($dir, 'models'));
-
- // Create autoloader config
- $cfg = array(
- 'packages' => array($path),
- 'helper' => array($helper),
- 'libraries' => array($lib),
- 'drivers' => array($drv),
- 'model' => array($model),
- 'config' => array('config1', 'config2')
- );
- $this->ci_vfs_create('autoload', '<?php $autoload = '.var_export($cfg, TRUE).';', $this->ci_app_root, 'config');
-
- $this->load->initialize();
-
- // Verify path
- $this->assertContains($path, $this->load->get_package_paths());
-
- // Verify helper
- $this->assertTrue(function_exists($hlp_func), $hlp_func.' does not exist');
-
- // Verify library
- $this->assertTrue(class_exists($lib_class), $lib_class.' does not exist');
- $this->assertObjectHasAttribute($lib, $this->ci_obj);
- $this->assertInstanceOf($lib_class, $this->ci_obj->$lib);
-
- // Verify driver
- $this->assertTrue(class_exists($drv_class), $drv_class.' does not exist');
- $this->assertObjectHasAttribute($drv, $this->ci_obj);
- $this->assertInstanceOf($drv_class, $this->ci_obj->$drv);
-
- // Verify model
- $this->assertTrue(class_exists($model), $model.' does not exist');
- $this->assertObjectHasAttribute($model, $this->ci_obj);
- $this->assertInstanceOf($model, $this->ci_obj->$model);
-
- // Verify config calls
- $this->assertEquals($cfg['config'], $this->ci_obj->config->loaded);
- }
-}
diff --git a/tests/codeigniter/core/Log_test.php b/tests/codeigniter/core/Log_test.php
deleted file mode 100644
index 927984385..000000000
--- a/tests/codeigniter/core/Log_test.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-class Log_test extends CI_TestCase {
-
- public function test_configuration()
- {
- $path = new ReflectionProperty('CI_Log', '_log_path');
- $path->setAccessible(TRUE);
- $threshold = new ReflectionProperty('CI_Log', '_threshold');
- $threshold->setAccessible(TRUE);
- $date_fmt = new ReflectionProperty('CI_Log', '_date_fmt');
- $date_fmt->setAccessible(TRUE);
- $file_ext = new ReflectionProperty('CI_Log', '_file_ext');
- $file_ext->setAccessible(TRUE);
- $file_perms = new ReflectionProperty('CI_Log', '_file_permissions');
- $file_perms->setAccessible(TRUE);
- $enabled = new ReflectionProperty('CI_Log', '_enabled');
- $enabled->setAccessible(TRUE);
-
- $this->ci_set_config('log_path', '/root/');
- $this->ci_set_config('log_threshold', 'z');
- $this->ci_set_config('log_date_format', 'd.m.Y');
- $this->ci_set_config('log_file_extension', '');
- $this->ci_set_config('log_file_permissions', '');
- $instance = new CI_Log();
-
- $this->assertEquals($path->getValue($instance), '/root/');
- $this->assertEquals($threshold->getValue($instance), 1);
- $this->assertEquals($date_fmt->getValue($instance), 'd.m.Y');
- $this->assertEquals($file_ext->getValue($instance), 'php');
- $this->assertEquals($file_perms->getValue($instance), 0644);
- $this->assertFalse($enabled->getValue($instance));
-
- $this->ci_set_config('log_path', '');
- $this->ci_set_config('log_threshold', '0');
- $this->ci_set_config('log_date_format', '');
- $this->ci_set_config('log_file_extension', '.log');
- $this->ci_set_config('log_file_permissions', 0600);
- $instance = new CI_Log();
-
- $this->assertEquals($path->getValue($instance), APPPATH.'logs/');
- $this->assertEquals($threshold->getValue($instance), 0);
- $this->assertEquals($date_fmt->getValue($instance), 'Y-m-d H:i:s');
- $this->assertEquals($file_ext->getValue($instance), 'log');
- $this->assertEquals($file_perms->getValue($instance), 0600);
- $this->assertEquals($enabled->getValue($instance), TRUE);
- }
-
- // --------------------------------------------------------------------
-
- public function test_format_line()
- {
- $this->ci_set_config('log_path', '');
- $this->ci_set_config('log_threshold', 0);
- $instance = new CI_Log();
-
- $format_line = new ReflectionMethod($instance, '_format_line');
- $format_line->setAccessible(TRUE);
- $this->assertEquals(
- $format_line->invoke($instance, 'LEVEL', 'Timestamp', 'Message'),
- "LEVEL - Timestamp --> Message".PHP_EOL
- );
- }
-}
diff --git a/tests/codeigniter/core/Model_test.php b/tests/codeigniter/core/Model_test.php
deleted file mode 100644
index 80dc97b3b..000000000
--- a/tests/codeigniter/core/Model_test.php
+++ /dev/null
@@ -1,37 +0,0 @@
-<?php
-
-class Model_test extends CI_TestCase {
-
- private $ci_obj;
-
- public function set_up()
- {
- $loader = $this->ci_core_class('loader');
- $this->load = new $loader();
- $this->ci_obj = $this->ci_instance();
- $this->ci_set_core_class('model', 'CI_Model');
-
- $model_code =<<<MODEL
-<?php
-class Test_model extends CI_Model {
-
- public \$property = 'foo';
-
-}
-MODEL;
-
- $this->ci_vfs_create('Test_model', $model_code, $this->ci_app_root, 'models');
- $this->load->model('test_model');
- }
-
- // --------------------------------------------------------------------
-
- public function test__get()
- {
- $this->assertEquals('foo', $this->ci_obj->test_model->property);
-
- $this->ci_obj->controller_property = 'bar';
- $this->assertEquals('bar', $this->ci_obj->test_model->controller_property);
- }
-
-} \ No newline at end of file
diff --git a/tests/codeigniter/core/Output_test.php b/tests/codeigniter/core/Output_test.php
deleted file mode 100644
index 887c077d7..000000000
--- a/tests/codeigniter/core/Output_test.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-
-class Output_test extends CI_TestCase {
-
- public $output;
- protected $_output_data = '';
-
- public function set_up()
- {
- $this->_output_data =<<<HTML
- <html>
- <head>
- <title>Basic HTML</title>
- </head>
- <body>
- Test
- </body>
- </html>
-HTML;
- $this->ci_set_config('charset', 'UTF-8');
- $output = $this->ci_core_class('output');
- $this->output = new $output();
- }
-
- // --------------------------------------------------------------------
-
- public function test_set_get_append_output()
- {
- $append = "<!-- comment /-->\n";
-
- $this->assertEquals(
- $this->_output_data.$append,
- $this->output
- ->set_output($this->_output_data)
- ->append_output("<!-- comment /-->\n")
- ->get_output()
- );
- }
-
- // --------------------------------------------------------------------
-
- public function test_get_content_type()
- {
- $this->assertEquals('text/html', $this->output->get_content_type());
- }
-
- // --------------------------------------------------------------------
-
- public function test_get_header()
- {
- $this->assertNull($this->output->get_header('Non-Existent-Header'));
-
- // TODO: Find a way to test header() values as well. Currently,
- // PHPUnit prevents this by not using output buffering.
-
- $this->output->set_content_type('text/plain', 'WINDOWS-1251');
- $this->assertEquals(
- 'text/plain; charset=WINDOWS-1251',
- $this->output->get_header('content-type')
- );
- }
-
-}
diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php
deleted file mode 100644
index c650315ce..000000000
--- a/tests/codeigniter/core/Security_test.php
+++ /dev/null
@@ -1,356 +0,0 @@
-<?php
-
-class Security_test extends CI_TestCase {
-
- public function set_up()
- {
- // Set cookie for security test
- $_COOKIE['ci_csrf_cookie'] = md5(uniqid(mt_rand(), TRUE));
-
- // Set config for Security class
- $this->ci_set_config('csrf_protection', TRUE);
- $this->ci_set_config('csrf_token_name', 'ci_csrf_token');
- $this->ci_set_config('csrf_cookie_name', 'ci_csrf_cookie');
-
- $this->security = new Mock_Core_Security();
- }
-
- // --------------------------------------------------------------------
-
- public function test_csrf_verify()
- {
- $_SERVER['REQUEST_METHOD'] = 'GET';
-
- $this->assertInstanceOf('CI_Security', $this->security->csrf_verify());
- }
-
- // --------------------------------------------------------------------
-
- public function test_csrf_verify_invalid()
- {
- // Without issuing $_POST[csrf_token_name], this request will triggering CSRF error
- $_SERVER['REQUEST_METHOD'] = 'POST';
-
- $this->setExpectedException('RuntimeException', 'CI Error: The action you have requested is not allowed');
-
- $this->security->csrf_verify();
- }
-
- // --------------------------------------------------------------------
-
- public function test_csrf_verify_valid()
- {
- $_SERVER['REQUEST_METHOD'] = 'POST';
- $_POST[$this->security->csrf_token_name] = $this->security->csrf_hash;
-
- $this->assertInstanceOf('CI_Security', $this->security->csrf_verify());
- }
-
- // --------------------------------------------------------------------
-
- public function test_get_csrf_hash()
- {
- $this->assertEquals($this->security->csrf_hash, $this->security->get_csrf_hash());
- }
-
- // --------------------------------------------------------------------
-
- public function test_get_csrf_token_name()
- {
- $this->assertEquals('ci_csrf_token', $this->security->get_csrf_token_name());
- }
-
- // --------------------------------------------------------------------
-
- public function test_xss_clean()
- {
- $harm_string = "Hello, i try to <script>alert('Hack');</script> your site";
-
- $harmless_string = $this->security->xss_clean($harm_string);
-
- $this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", $harmless_string);
- }
-
- // --------------------------------------------------------------------
-
- public function test_xss_clean_string_array()
- {
- $harm_strings = array(
- "Hello, i try to <script>alert('Hack');</script> your site",
- "Simple clean string",
- "Hello, i try to <script>alert('Hack');</script> your site"
- );
-
- $harmless_strings = $this->security->xss_clean($harm_strings);
-
- $this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", $harmless_strings[0]);
- $this->assertEquals("Simple clean string", $harmless_strings[1]);
- $this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", $harmless_strings[2]);
- }
-
- // --------------------------------------------------------------------
-
- public function test_xss_clean_image_valid()
- {
- $harm_string = '<img src="test.png">';
-
- $xss_clean_return = $this->security->xss_clean($harm_string, TRUE);
-
-// $this->assertTrue($xss_clean_return);
- }
-
- // --------------------------------------------------------------------
-
- public function test_xss_clean_image_invalid()
- {
- $harm_string = '<img src=javascript:alert(String.fromCharCode(88,83,83))>';
-
- $xss_clean_return = $this->security->xss_clean($harm_string, TRUE);
-
- $this->assertFalse($xss_clean_return);
- }
-
- // --------------------------------------------------------------------
-
- public function test_xss_clean_entity_double_encoded()
- {
- $input = '<a href="&#38&#35&#49&#48&#54&#38&#35&#57&#55&#38&#35&#49&#49&#56&#38&#35&#57&#55&#38&#35&#49&#49&#53&#38&#35&#57&#57&#38&#35&#49&#49&#52&#38&#35&#49&#48&#53&#38&#35&#49&#49&#50&#38&#35&#49&#49&#54&#38&#35&#53&#56&#38&#35&#57&#57&#38&#35&#49&#49&#49&#38&#35&#49&#49&#48&#38&#35&#49&#48&#50&#38&#35&#49&#48&#53&#38&#35&#49&#49&#52&#38&#35&#49&#48&#57&#38&#35&#52&#48&#38&#35&#52&#57&#38&#35&#52&#49">Clickhere</a>';
- $this->assertEquals('<a>Clickhere</a>', $this->security->xss_clean($input));
- }
-
- // --------------------------------------------------------------------
-
- public function text_xss_clean_js_link_removal()
- {
- // This one is to prevent a false positive
- $this->assertEquals(
- "<a href=\"javascrip\n<t\n:alert\n&#40;1&#41;\"\n>",
- $this->security->xss_clean("<a href=\"javascrip\n<t\n:alert\n(1)\"\n>")
- );
- }
-
- // --------------------------------------------------------------------
-
- public function test_xss_clean_js_img_removal()
- {
- $input = '<img src="&#38&#35&#49&#48&#54&#38&#35&#57&#55&#38&#35&#49&#49&#56&#38&#35&#57&#55&#38&#35&#49&#49&#53&#38&#35&#57&#57&#38&#35&#49&#49&#52&#38&#35&#49&#48&#53&#38&#35&#49&#49&#50&#38&#35&#49&#49&#54&#38&#35&#53&#56&#38&#35&#57&#57&#38&#35&#49&#49&#49&#38&#35&#49&#49&#48&#38&#35&#49&#48&#50&#38&#35&#49&#48&#53&#38&#35&#49&#49&#52&#38&#35&#49&#48&#57&#38&#35&#52&#48&#38&#35&#52&#57&#38&#35&#52&#49">Clickhere';
- $this->assertEquals('<img>', $this->security->xss_clean($input));
- }
-
- // --------------------------------------------------------------------
-
- public function test_xss_clean_sanitize_naughty_html_tags()
- {
- $this->assertEquals('&lt;unclosedTag', $this->security->xss_clean('<unclosedTag'));
- $this->assertEquals('&lt;blink&gt;', $this->security->xss_clean('<blink>'));
- $this->assertEquals('<fubar>', $this->security->xss_clean('<fubar>'));
-
- $this->assertEquals(
- '<img svg=""> src="x">',
- $this->security->xss_clean('<img <svg=""> src="x">')
- );
-
- $this->assertEquals(
- '<img src="b on=">on=">"x onerror="alert&#40;1&#41;">',
- $this->security->xss_clean('<img src="b on="<x">on=">"x onerror="alert(1)">')
- );
-
- $this->assertEquals(
- "\n>&lt;!-\n<b d=\"'e><iframe onload=alert&#40;1&#41; src=x>\n<a HREF=\">\n",
- $this->security->xss_clean("\n><!-\n<b\n<c d=\"'e><iframe onload=alert(1) src=x>\n<a HREF=\"\">\n")
- );
- }
-
- // --------------------------------------------------------------------
-
- public function test_xss_clean_sanitize_naughty_html_attributes()
- {
- $this->assertEquals('<foo xss=removed>', $this->security->xss_clean('<foo onAttribute="bar">'));
- $this->assertEquals('<foo xss=removed>', $this->security->xss_clean('<foo onAttributeNoQuotes=bar>'));
- $this->assertEquals('<foo xss=removed>', $this->security->xss_clean('<foo onAttributeWithSpaces = bar>'));
- $this->assertEquals('<foo prefixOnAttribute="bar">', $this->security->xss_clean('<foo prefixOnAttribute="bar">'));
- $this->assertEquals('<foo>onOutsideOfTag=test</foo>', $this->security->xss_clean('<foo>onOutsideOfTag=test</foo>'));
- $this->assertEquals('onNoTagAtAll = true', $this->security->xss_clean('onNoTagAtAll = true'));
- $this->assertEquals('<foo xss=removed>', $this->security->xss_clean('<foo fscommand=case-insensitive>'));
- $this->assertEquals('<foo xss=removed>', $this->security->xss_clean('<foo seekSegmentTime=whatever>'));
-
- $this->assertEquals(
- '<foo bar=">" baz=\'>\' xss=removed>',
- $this->security->xss_clean('<foo bar=">" baz=\'>\' onAfterGreaterThan="quotes">')
- );
- $this->assertEquals(
- '<foo bar=">" baz=\'>\' xss=removed>',
- $this->security->xss_clean('<foo bar=">" baz=\'>\' onAfterGreaterThan=noQuotes>')
- );
-
- $this->assertEquals(
- '<img src="x" on=""> on=&lt;svg&gt; onerror=alert&#40;1&#41;>',
- $this->security->xss_clean('<img src="x" on=""> on=<svg> onerror=alert(1)>')
- );
-
- $this->assertEquals(
- '<img src="on=\'">"&lt;svg&gt; onerror=alert&#40;1&#41; onmouseover=alert&#40;1&#41;>',
- $this->security->xss_clean('<img src="on=\'">"<svg> onerror=alert(1) onmouseover=alert(1)>')
- );
-
- $this->assertEquals(
- '<img src="x"> on=\'x\' onerror=``,alert&#40;1&#41;>',
- $this->security->xss_clean('<img src="x"> on=\'x\' onerror=``,alert(1)>')
- );
-
- $this->assertEquals(
- '<a xss=removed>',
- $this->security->xss_clean('<a< onmouseover="alert(1)">')
- );
-
- $this->assertEquals(
- '<img src="x"> on=\'x\' onerror=,xssm()>',
- $this->security->xss_clean('<img src="x"> on=\'x\' onerror=,xssm()>')
- );
-
- $this->assertEquals(
- '<image src="<>" xss=removed>',
- $this->security->xss_clean('<image src="<>" onerror=\'alert(1)\'>')
- );
-
- $this->assertEquals(
- '<b xss=removed>',
- $this->security->xss_clean('<b "=<= onmouseover=alert(1)>')
- );
-
- $this->assertEquals(
- '<b xss=removed xss=removed>1">',
- $this->security->xss_clean('<b a=<=" onmouseover="alert(1),1>1">')
- );
-
- $this->assertEquals(
- '<b x=" onmouseover=alert&#40;1&#41;//">',
- $this->security->xss_clean('<b "="< x=" onmouseover=alert(1)//">')
- );
- }
-
- // --------------------------------------------------------------------
-
- /**
- * @depends test_xss_clean_sanitize_naughty_html_tags
- * @depends test_xss_clean_sanitize_naughty_html_attributes
- */
- public function test_naughty_html_plus_evil_attributes()
- {
- $this->assertEquals(
- '&lt;svg<img src="x" xss=removed>',
- $this->security->xss_clean('<svg<img > src="x" onerror="location=/javascript/.source+/:alert/.source+/(1)/.source">')
- );
- }
-
- // --------------------------------------------------------------------
-
- public function test_xss_hash()
- {
- $this->assertEmpty($this->security->xss_hash);
-
- // Perform hash
- $this->security->xss_hash();
-
- $assertRegExp = class_exists('PHPUnit_Runner_Version')
- ? 'assertRegExp'
- : 'assertMatchesRegularExpression';
- $this->$assertRegExp('#^[0-9a-f]{32}$#iS', $this->security->xss_hash);
- }
-
- // --------------------------------------------------------------------
-
- public function test_get_random_bytes()
- {
- $length = "invalid";
- $this->assertFalse($this->security->get_random_bytes($length));
-
- $length = 10;
- $this->assertNotEmpty($this->security->get_random_bytes($length));
- }
-
- // --------------------------------------------------------------------
-
- public function test_entity_decode()
- {
- $encoded = '&lt;div&gt;Hello &lt;b&gt;Booya&lt;/b&gt;&lt;/div&gt;';
- $decoded = $this->security->entity_decode($encoded);
-
- $this->assertEquals('<div>Hello <b>Booya</b></div>', $decoded);
-
- $this->assertEquals('colon:', $this->security->entity_decode('colon&colon;'));
- $this->assertEquals("NewLine\n", $this->security->entity_decode('NewLine&NewLine;'));
- $this->assertEquals("Tab\t", $this->security->entity_decode('Tab&Tab;'));
- $this->assertEquals("lpar(", $this->security->entity_decode('lpar&lpar;'));
- $this->assertEquals("rpar)", $this->security->entity_decode('rpar&rpar;'));
-
- // Issue #3057 (https://github.com/bcit-ci/CodeIgniter/issues/3057)
- $this->assertEquals(
- '&foo should not include a semicolon',
- $this->security->entity_decode('&foo should not include a semicolon')
- );
- }
-
- // --------------------------------------------------------------------
-
- public function test_sanitize_filename()
- {
- $filename = './<!--foo-->';
- $safe_filename = $this->security->sanitize_filename($filename);
-
- $this->assertEquals('foo', $safe_filename);
- }
-
- // --------------------------------------------------------------------
-
- public function test_strip_image_tags()
- {
- $imgtags = array(
- '<img src="smiley.gif" alt="Smiley face" height="42" width="42">',
- '<img alt="Smiley face" height="42" width="42" src="smiley.gif">',
- '<img src="http://www.w3schools.com/images/w3schools_green.jpg">',
- '<img src="/img/sunset.gif" height="100%" width="100%">',
- '<img src="mdn-logo-sm.png" alt="MD Logo" srcset="mdn-logo-HD.png 2x, mdn-logo-small.png 15w, mdn-banner-HD.png 100w 2x" />',
- '<img sqrc="/img/sunset.gif" height="100%" width="100%">',
- '<img srqc="/img/sunset.gif" height="100%" width="100%">',
- '<img srcq="/img/sunset.gif" height="100%" width="100%">',
- '<img src=non-quoted.attribute foo="bar">'
- );
-
- $urls = array(
- 'smiley.gif',
- 'smiley.gif',
- 'http://www.w3schools.com/images/w3schools_green.jpg',
- '/img/sunset.gif',
- 'mdn-logo-sm.png',
- '<img sqrc="/img/sunset.gif" height="100%" width="100%">',
- '<img srqc="/img/sunset.gif" height="100%" width="100%">',
- '<img srcq="/img/sunset.gif" height="100%" width="100%">',
- 'non-quoted.attribute'
- );
-
- for ($i = 0; $i < count($imgtags); $i++)
- {
- $this->assertEquals($urls[$i], $this->security->strip_image_tags($imgtags[$i]));
- }
- }
-
- // --------------------------------------------------------------------
-
- public function test_csrf_set_hash()
- {
- // Set cookie for security test
- $_COOKIE['ci_csrf_cookie'] = md5(uniqid(mt_rand(), TRUE));
-
- // Set config for Security class
- $this->ci_set_config('csrf_protection', TRUE);
- $this->ci_set_config('csrf_token_name', 'ci_csrf_token');
-
- // leave csrf_cookie_name as blank to test _csrf_set_hash function
- $this->ci_set_config('csrf_cookie_name', '');
-
- $this->security = new Mock_Core_Security();
-
- $this->assertNotEmpty($this->security->get_csrf_hash());
- }
-}
diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php
deleted file mode 100644
index 42dff3639..000000000
--- a/tests/codeigniter/core/URI_test.php
+++ /dev/null
@@ -1,254 +0,0 @@
-<?php
-
-class URI_test extends CI_TestCase {
-
- public function set_up()
- {
- $this->uri = new Mock_Core_URI();
- }
-
- // --------------------------------------------------------------------
-
- /* As of the following commit, _set_uri_string() is a protected method:
-
- https://github.com/bcit-ci/CodeIgniter/commit/d461934184d95b0cfb2feec93f27b621ef72a5c2
-
- public function test_set_uri_string()
- {
- // Slashes get killed
- $this->uri->_set_uri_string('/');
- $this->assertEquals('', $this->uri->uri_string);
-
- $this->uri->_set_uri_string('nice/uri');
- $this->assertEquals('nice/uri', $this->uri->uri_string);
- }
- */
-
- // --------------------------------------------------------------------
-
- /*
-
- This has been moved to the constructor
-
- public function test_fetch_uri_string()
- {
- define('SELF', 'index.php');
-
- // uri_protocol: AUTO
- $this->uri->config->set_item('uri_protocol', 'AUTO');
-
- // Test a variety of request uris
- $requests = array(
- '/index.php/controller/method' => 'controller/method',
- '/index.php?/controller/method' => 'controller/method',
- '/index.php?/controller/method/?var=foo' => 'controller/method'
- );
-
- foreach ($requests as $request => $expected)
- {
- $_SERVER['SCRIPT_NAME'] = '/index.php';
- $_SERVER['REQUEST_URI'] = $request;
-
- $this->uri->_fetch_uri_string();
- $this->assertEquals($expected, $this->uri->uri_string);
- }
-
- // Test a subfolder
- $_SERVER['SCRIPT_NAME'] = '/subfolder/index.php';
- $_SERVER['REQUEST_URI'] = '/subfolder/index.php/controller/method';
-
- $this->uri->_fetch_uri_string();
- $this->assertEquals('controller/method', $this->uri->uri_string);
-
- // death to request uri
- unset($_SERVER['REQUEST_URI']);
-
- // life to path info
- $_SERVER['PATH_INFO'] = '/controller/method/';
-
- $this->uri->_fetch_uri_string();
- $this->assertEquals('controller/method', $this->uri->uri_string);
-
- // death to path info
- // At this point your server must be seriously drunk
- unset($_SERVER['PATH_INFO']);
-
- $_SERVER['QUERY_STRING'] = '/controller/method/';
-
- $this->uri->_fetch_uri_string();
- $this->assertEquals('controller/method', $this->uri->uri_string);
-
- // At this point your server is a labotomy victim
- unset($_SERVER['QUERY_STRING']);
-
- $_GET['/controller/method/'] = '';
-
- $this->uri->_fetch_uri_string();
- $this->assertEquals('controller/method', $this->uri->uri_string);
-
- // Test coverage implies that these will work
- // uri_protocol: REQUEST_URI
- // uri_protocol: CLI
- }
- */
-
- // --------------------------------------------------------------------
-
- /*
-
- This has been moved into _set_uri_string()
-
- public function test_explode_segments()
- {
- // Let's test the function's ability to clean up this mess
- $uris = array(
- 'test/uri' => array('test', 'uri'),
- '/test2/uri2' => array('test2', 'uri2'),
- '//test3/test3///' => array('test3', 'test3')
- );
-
- foreach ($uris as $uri => $a)
- {
- $this->uri->segments = array();
- $this->uri->uri_string = $uri;
- $this->uri->_explode_segments();
-
- $this->assertEquals($a, $this->uri->segments);
- }
- }
- */
- // --------------------------------------------------------------------
-
- public function test_filter_uri_passing()
- {
- $this->uri->_set_permitted_uri_chars('a-z 0-9~%.:_\-');
-
- $str = 'abc01239~%.:_-';
- $this->uri->filter_uri($str);
- }
-
- // --------------------------------------------------------------------
-
- public function test_filter_uri_throws_error()
- {
- $this->setExpectedException('RuntimeException');
-
- $this->uri->config->set_item('enable_query_strings', FALSE);
- $this->uri->_set_permitted_uri_chars('a-z 0-9~%.:_\-');
- $segment = '$this()'; // filter_uri() accepts by reference
- $this->uri->filter_uri($segment);
- }
-
- // --------------------------------------------------------------------
-
- public function test_segment()
- {
- $this->uri->segments = array(1 => 'controller');
- $this->assertEquals($this->uri->segment(1), 'controller');
- $this->assertEquals($this->uri->segment(2, 'default'), 'default');
- }
-
- // --------------------------------------------------------------------
-
- public function test_rsegment()
- {
- $this->uri->rsegments = array(1 => 'method');
- $this->assertEquals($this->uri->rsegment(1), 'method');
- $this->assertEquals($this->uri->rsegment(2, 'default'), 'default');
- }
-
- // --------------------------------------------------------------------
-
- public function test_uri_to_assoc()
- {
- $this->uri->segments = array('a', '1', 'b', '2', 'c', '3');
-
- $this->assertEquals(
- array('a' => '1', 'b' => '2', 'c' => '3'),
- $this->uri->uri_to_assoc(1)
- );
-
- $this->assertEquals(
- array('b' => '2', 'c' => '3'),
- $this->uri->uri_to_assoc(3)
- );
-
- $this->uri->keyval = array(); // reset cache
- $this->uri->segments = array('a', '1', 'b', '2', 'c');
-
- $this->assertEquals(
- array('a' => '1', 'b' => '2', 'c' => FALSE),
- $this->uri->uri_to_assoc(1)
- );
-
- $this->uri->keyval = array(); // reset cache
- $this->uri->segments = array('a', '1');
-
- // test default
- $this->assertEquals(
- array('a' => '1', 'b' => FALSE),
- $this->uri->uri_to_assoc(1, array('a', 'b'))
- );
- }
-
- // --------------------------------------------------------------------
-
- public function test_ruri_to_assoc()
- {
- $this->uri->rsegments = array('x', '1', 'y', '2', 'z', '3');
-
- $this->assertEquals(
- array('x' => '1', 'y' => '2', 'z' => '3'),
- $this->uri->ruri_to_assoc(1)
- );
-
- $this->assertEquals(
- array('y' => '2', 'z' => '3'),
- $this->uri->ruri_to_assoc(3)
- );
-
- $this->uri->keyval = array(); // reset cache
- $this->uri->rsegments = array('x', '1', 'y', '2', 'z');
-
- $this->assertEquals(
- array('x' => '1', 'y' => '2', 'z' => FALSE),
- $this->uri->ruri_to_assoc(1)
- );
-
- $this->uri->keyval = array(); // reset cache
- $this->uri->rsegments = array('x', '1');
-
- // test default
- $this->assertEquals(
- array('x' => '1', 'y' => FALSE),
- $this->uri->ruri_to_assoc(1, array('x', 'y'))
- );
- }
-
- // --------------------------------------------------------------------
-
- public function test_assoc_to_uri()
- {
- $this->uri->config->set_item('uri_string_slashes', 'none');
- $this->assertEquals('a/1/b/2', $this->uri->assoc_to_uri(array('a' => '1', 'b' => '2')));
- }
-
- // --------------------------------------------------------------------
-
- public function test_slash_segment()
- {
- $this->uri->segments[1] = 'segment';
- $this->uri->rsegments[1] = 'segment';
-
- $this->assertEquals('/segment/', $this->uri->slash_segment(1, 'both'));
- $this->assertEquals('/segment/', $this->uri->slash_rsegment(1, 'both'));
-
- $a = '/segment';
- $this->assertEquals('/segment', $this->uri->slash_segment(1, 'leading'));
- $this->assertEquals('/segment', $this->uri->slash_rsegment(1, 'leading'));
-
- $this->assertEquals('segment/', $this->uri->slash_segment(1, 'trailing'));
- $this->assertEquals('segment/', $this->uri->slash_rsegment(1, 'trailing'));
- }
-
-}
diff --git a/tests/codeigniter/core/Utf8_test.php b/tests/codeigniter/core/Utf8_test.php
deleted file mode 100644
index c02c1dd87..000000000
--- a/tests/codeigniter/core/Utf8_test.php
+++ /dev/null
@@ -1,91 +0,0 @@
-<?php
-
-class Utf8_test extends CI_TestCase {
-
- public function set_up()
- {
- $this->ci_set_config('charset', 'UTF-8');
- $this->utf8 = new Mock_Core_Utf8();
- $this->ci_instance_var('utf8', $this->utf8);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * __construct() test
- *
- * @covers CI_Utf8::__construct
- */
- public function test___construct()
- {
- if (defined('PREG_BAD_UTF8_ERROR') && (ICONV_ENABLED === TRUE OR MB_ENABLED === TRUE) && strtoupper(config_item('charset')) === 'UTF-8')
- {
- $this->assertTrue(UTF8_ENABLED);
- }
- else
- {
- $this->assertFalse(UTF8_ENABLED);
- }
- }
-
- // --------------------------------------------------------------------
-
- /**
- * is_ascii() test
- *
- * Note: DO NOT move this below test_clean_string()
- */
- public function test_is_ascii()
- {
- $this->assertTrue($this->utf8->is_ascii('foo bar'));
- $this->assertFalse($this->utf8->is_ascii('тест'));
- }
-
- // --------------------------------------------------------------------
-
- /**
- * clean_string() test
- *
- * @depends test_is_ascii
- * @covers CI_Utf8::clean_string
- */
- public function test_clean_string()
- {
- $this->assertEquals('foo bar', $this->utf8->clean_string('foo bar'));
-
- $illegal_utf8 = "\xc0тест";
- if (MB_ENABLED)
- {
- $this->assertEquals('тест', $this->utf8->clean_string($illegal_utf8));
- }
- elseif (ICONV_ENABLED)
- {
- // This is a known issue, iconv doesn't always work with //IGNORE
- $this->assertContains($this->utf8->clean_string($illegal_utf8), array('тест', ''));
- }
- else
- {
- $this->assertEquals($illegal_utf8, $this->utf8->clean_string($illegal_utf8));
- }
- }
-
- // --------------------------------------------------------------------
-
- /**
- * convert_to_utf8() test
- *
- * @covers CI_Utf8::convert_to_utf8
- */
- public function test_convert_to_utf8()
- {
- if (MB_ENABLED OR ICONV_ENABLED)
- {
- $this->assertEquals('тест', $this->utf8->convert_to_utf8('', 'WINDOWS-1251'));
- }
- else
- {
- $this->assertFalse($this->utf8->convert_to_utf8('', 'WINDOWS-1251'));
- }
- }
-
-}
diff --git a/tests/codeigniter/core/compat/hash_test.php b/tests/codeigniter/core/compat/hash_test.php
deleted file mode 100644
index d8cd0bb16..000000000
--- a/tests/codeigniter/core/compat/hash_test.php
+++ /dev/null
@@ -1,77 +0,0 @@
-<?php
-
-class hash_test extends CI_TestCase {
-
- public function test_bootstrap()
- {
- if (is_php('5.6'))
- {
- return $this->markTestSkipped('ext/hash is available on PHP 5.6');
- }
-
- $this->assertTrue(function_exists('hash_equals'));
- is_php('5.5') OR $this->assertTrue(function_exists('hash_pbkdf2'));
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * hash_equals() test
- *
- * Borrowed from PHP's own tests
- *
- * @depends test_bootstrap
- */
- public function test_hash_equals()
- {
- $this->assertTrue(hash_equals('same', 'same'));
- $this->assertFalse(hash_equals('not1same', 'not2same'));
- $this->assertFalse(hash_equals('short', 'longer'));
- $this->assertFalse(hash_equals('longer', 'short'));
- $this->assertFalse(hash_equals('', 'notempty'));
- $this->assertFalse(hash_equals('notempty', ''));
- $this->assertTrue(hash_equals('', ''));
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * hash_pbkdf2() test
- *
- * Borrowed from PHP's own tests
- *
- * @depends test_bootstrap
- */
- public function test_hash_pbkdf2()
- {
- if (is_php('5.5'))
- {
- return $this->markTestSkipped('hash_pbkdf2() is available on PHP 5.5');
- }
-
- $this->assertEquals('0c60c80f961f0e71f3a9', hash_pbkdf2('sha1', 'password', 'salt', 1, 20));
- $this->assertEquals(
- "\x0c\x60\xc8\x0f\x96\x1f\x0e\x71\xf3\xa9\xb5\x24\xaf\x60\x12\x06\x2f\xe0\x37\xa6",
- hash_pbkdf2('sha1', 'password', 'salt', 1, 20, TRUE)
- );
- $this->assertEquals('3d2eec4fe41c849b80c8d8366', hash_pbkdf2('sha1', 'passwordPASSWORDpassword', 'saltSALTsaltSALTsaltSALTsaltSALTsalt', 4096, 25));
- $this->assertEquals(
- "\x3d\x2e\xec\x4f\xe4\x1c\x84\x9b\x80\xc8\xd8\x36\x62\xc0\xe4\x4a\x8b\x29\x1a\x96\x4c\xf2\xf0\x70\x38",
- hash_pbkdf2('sha1', 'passwordPASSWORDpassword', 'saltSALTsaltSALTsaltSALTsaltSALTsalt', 4096, 25, TRUE)
- );
- $this->assertEquals('120fb6cffcf8b32c43e7', hash_pbkdf2('sha256', 'password', 'salt', 1, 20));
- $this->assertEquals(
- "\x12\x0f\xb6\xcf\xfc\xf8\xb3\x2c\x43\xe7\x22\x52\x56\xc4\xf8\x37\xa8\x65\x48\xc9",
- hash_pbkdf2('sha256', 'password', 'salt', 1, 20, TRUE)
- );
- $this->assertEquals(
- '348c89dbcbd32b2f32d814b8116e84cf2b17347e',
- hash_pbkdf2('sha256', 'passwordPASSWORDpassword', 'saltSALTsaltSALTsaltSALTsaltSALTsalt', 4096, 40)
- );
- $this->assertEquals(
- "\x34\x8c\x89\xdb\xcb\xd3\x2b\x2f\x32\xd8\x14\xb8\x11\x6e\x84\xcf\x2b\x17\x34\x7e\xbc\x18\x00\x18\x1c\x4e\x2a\x1f\xb8\xdd\x53\xe1\xc6\x35\x51\x8c\x7d\xac\x47\xe9",
- hash_pbkdf2('sha256', 'passwordPASSWORDpassword', 'saltSALTsaltSALTsaltSALTsaltSALTsalt', 4096, 40, TRUE)
- );
- }
-
-} \ No newline at end of file
diff --git a/tests/codeigniter/core/compat/mbstring_test.php b/tests/codeigniter/core/compat/mbstring_test.php
deleted file mode 100644
index 39f48ac10..000000000
--- a/tests/codeigniter/core/compat/mbstring_test.php
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-
-class mbstring_test extends CI_TestCase {
-
- public function test_bootstrap()
- {
- if (MB_ENABLED)
- {
- return $this->markTestSkipped('ext/mbstring is loaded');
- }
-
- $this->assertTrue(function_exists('mb_strlen'));
- $this->assertTrue(function_exists('mb_substr'));
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * @depends test_bootstrap
- */
- public function test_mb_strlen()
- {
- $this->assertEquals(ICONV_ENABLED ? 4 : 8, mb_strlen('тест'));
- $this->assertEquals(ICONV_ENABLED ? 4 : 8, mb_strlen('тест', 'UTF-8'));
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * @depends test_bootstrap
- */
- public function test_mb_strpos()
- {
- $this->assertEquals(ICONV_ENABLED ? 2 : 4, mb_strpos('тест', 'с'));
- $this->assertFalse(mb_strpos('тест', 'с', 3));
- $this->assertEquals(ICONV_ENABLED ? 2 : 4, mb_strpos('тест', 'с', 1, 'UTF-8'));
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * @depends test_bootstrap
- */
- public function test_mb_substr()
- {
- $this->assertEquals(ICONV_ENABLED ? 'стинг' : 'естинг', mb_substr('тестинг', 2));
- $this->assertEquals(ICONV_ENABLED ? 'нг' : 'г', mb_substr('тестинг', -2));
- $this->assertEquals(ICONV_ENABLED ? 'ст' : 'е', mb_substr('тестинг', 2, 2));
- $this->assertEquals(ICONV_ENABLED ? 'стинг' : 'естинг', mb_substr('тестинг', 2, NULL, 'UTF-8'));
- $this->assertEquals(ICONV_ENABLED ? 'нг' : 'г', mb_substr('тестинг', -2, NULL, 'UTF-8'));
- $this->assertEquals(ICONV_ENABLED ? 'ст' : 'е', mb_substr('тестинг', 2, 2, 'UTF-8'));
- }
-
-}
diff --git a/tests/codeigniter/core/compat/password_test.php b/tests/codeigniter/core/compat/password_test.php
deleted file mode 100644
index b6dbcfab1..000000000
--- a/tests/codeigniter/core/compat/password_test.php
+++ /dev/null
@@ -1,159 +0,0 @@
-<?php
-
-class password_test extends CI_TestCase {
-
- public function test_bootstrap()
- {
- if (is_php('5.5'))
- {
- return $this->markTestSkipped('ext/standard/password is available on PHP 5.5');
- }
- // defined as of HHVM 2.3.0, which is also when they introduce password_*() as well
- // Note: Do NOT move this after the CRYPT_BLOWFISH check
- elseif (defined('HHVM_VERSION'))
- {
- $this->markTestSkipped('HHVM 2.3.0+ already has it');
- }
- elseif ( ! defined('CRYPT_BLOWFISH') OR CRYPT_BLOWFISH !== 1)
- {
- $this->assertFalse(defined('PASSWORD_BCRYPT'));
- return $this->markTestSkipped('CRYPT_BLOWFISH is not available');
- }
-
- $this->assertTrue(defined('PASSWORD_BCRYPT'));
- $this->assertTrue(defined('PASSWORD_DEFAULT'));
- $this->assertEquals(1, PASSWORD_BCRYPT);
- $this->assertEquals(PASSWORD_BCRYPT, PASSWORD_DEFAULT);
- $this->assertTrue(function_exists('password_get_info'));
- $this->assertTrue(function_exists('password_hash'));
- $this->assertTrue(function_exists('password_needs_rehash'));
- $this->assertTrue(function_exists('password_verify'));
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * password_get_info() test
- *
- * Borrowed from PHP's own tests
- *
- * @depends test_bootstrap
- */
- public function test_password_get_info()
- {
- $expected = array(
- 'algo' => 1,
- 'algoName' => 'bcrypt',
- 'options' => array('cost' => 10)
- );
-
- // default
- $this->assertEquals($expected, password_get_info('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y'));
-
- $expected['options']['cost'] = 11;
-
- // cost
- $this->assertEquals($expected, password_get_info('$2y$11$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y'));
-
- $expected = array(
- 'algo' => 0,
- 'algoName' => 'unknown',
- 'options' => array()
- );
-
- // invalid length
- $this->assertEquals($expected, password_get_info('$2y$11$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100'));
-
- // non-bcrypt
- $this->assertEquals($expected, password_get_info('$1$rasmusle$rISCgZzpwk3UhDidwXvin0'));
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * password_hash() test
- *
- * Borrowed from PHP's own tests
- *
- * @depends test_bootstrap
- */
- public function test_password_hash()
- {
- // FALSE is returned if no CSPRNG source is available
- if ( ! defined('MCRYPT_DEV_URANDOM') && ! function_exists('openssl_random_pseudo_bytes')
- && (DIRECTORY_SEPARATOR !== '/' OR ! is_readable('/dev/arandom') OR ! is_readable('/dev/urandom'))
- )
- {
- $this->assertFalse(password_hash('foo', PASSWORD_BCRYPT));
- }
- else
- {
- $this->assertEquals(60, strlen(password_hash('foo', PASSWORD_BCRYPT)));
- $this->assertTrue(($hash = password_hash('foo', PASSWORD_BCRYPT)) === crypt('foo', $hash));
- }
-
- $this->assertEquals(
- '$2y$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi',
- password_hash('rasmuslerdorf', PASSWORD_BCRYPT, array('cost' => 7, 'salt' => 'usesomesillystringforsalt'))
- );
-
- $this->assertEquals(
- '$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y',
- password_hash('test', PASSWORD_BCRYPT, array('salt' => '123456789012345678901'.chr(0)))
- );
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * password_needs_rehash() test
- *
- * Borrowed from PHP's own tests
- *
- * @depends test_password_get_info
- */
- public function test_password_needs_rehash()
- {
- // invalid hash: always rehash
- $this->assertTrue(password_needs_rehash('', PASSWORD_BCRYPT));
-
- // valid, because it's an unknown algorithm
- $this->assertFalse(password_needs_rehash('', 0));
-
- // valid with same cost
- $this->assertFalse(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 10)));
-
- // valid with same cost and additional parameters
- $this->assertFalse(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 10, 'foo' => 3)));
-
- // invalid: different (lower) cost
- $this->assertTrue(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 9)));
-
- // invalid: different (higher) cost
- $this->assertTrue(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 11)));
-
- // valid with default cost
- $this->assertFalse(password_needs_rehash('$2y$'.str_pad(10, 2, '0', STR_PAD_LEFT).'$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT));
-
- // invalid: 'foo' is cast to 0
- $this->assertTrue(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 'foo')));
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * password_verify() test
- *
- * Borrowed from PHP's own tests
- *
- * @depends test_bootstrap
- */
- public function test_password_verify()
- {
- $this->assertFalse(password_verify(123, 123));
- $this->assertFalse(password_verify('foo', '$2a$07$usesomesillystringforsalt$'));
- $this->assertFalse(password_verify('rasmusler', '$2a$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi'));
- $this->assertTrue(password_verify('rasmuslerdorf', '$2a$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi'));
- }
-
-}
diff --git a/tests/codeigniter/core/compat/standard_test.php b/tests/codeigniter/core/compat/standard_test.php
deleted file mode 100644
index a98460129..000000000
--- a/tests/codeigniter/core/compat/standard_test.php
+++ /dev/null
@@ -1,378 +0,0 @@
-<?php
-
-class standard_test extends CI_TestCase {
-
- public function test_bootstrap()
- {
- if (is_php('5.5'))
- {
- return $this->markTestSkipped('All array functions are already available on PHP 5.5');
- }
-
- $this->assertTrue(function_exists('array_column'));
-
- if ( ! is_php('5.4'))
- {
- $this->assertTrue(function_exists('hex2bin'));
- }
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * array_column() test
- *
- * Borrowed from PHP's own tests
- *
- * @depends test_bootstrap
- */
- public function test_array_column()
- {
- // Basic tests
-
- $input = array(
- array(
- 'id' => 1,
- 'first_name' => 'John',
- 'last_name' => 'Doe'
- ),
- array(
- 'id' => 2,
- 'first_name' => 'Sally',
- 'last_name' => 'Smith'
- ),
- array(
- 'id' => 3,
- 'first_name' => 'Jane',
- 'last_name' => 'Jones'
- )
- );
-
- // Ensure internal array position doesn't break it
- next($input);
-
- $this->assertEquals(
- array('John', 'Sally', 'Jane'),
- array_column($input, 'first_name')
- );
-
- $this->assertEquals(
- array(1, 2, 3),
- array_column($input, 'id')
- );
-
- $this->assertEquals(
- array(
- 1 => 'Doe',
- 2 => 'Smith',
- 3 => 'Jones'
- ),
- array_column($input, 'last_name', 'id')
- );
-
- $this->assertEquals(
- array(
- 'John' => 'Doe',
- 'Sally' => 'Smith',
- 'Jane' => 'Jones'
- ),
- array_column($input, 'last_name', 'first_name')
- );
-
- // Object key search
-
- $f = new Foo();
- $b = new Bar();
-
- $this->assertEquals(
- array('Doe', 'Smith', 'Jones'),
- array_column($input, $f)
- );
-
- $this->assertEquals(
- array(
- 'John' => 'Doe',
- 'Sally' => 'Smith',
- 'Jane' => 'Jones'
- ),
- array_column($input, $f, $b)
- );
-
- // NULL parameters
-
- $input = array(
- 456 => array(
- 'id' => '3',
- 'title' => 'Foo',
- 'date' => '2013-03-25'
- ),
- 457 => array(
- 'id' => '5',
- 'title' => 'Bar',
- 'date' => '2012-05-20'
- )
- );
-
- $this->assertEquals(
- array(
- 3 => array(
- 'id' => '3',
- 'title' => 'Foo',
- 'date' => '2013-03-25'
- ),
- 5 => array(
- 'id' => '5',
- 'title' => 'Bar',
- 'date' => '2012-05-20'
- )
- ),
- array_column($input, NULL, 'id')
- );
-
- $this->assertEquals(
- array(
- array(
- 'id' => '3',
- 'title' => 'Foo',
- 'date' => '2013-03-25'
- ),
- array(
- 'id' => '5',
- 'title' => 'Bar',
- 'date' => '2012-05-20'
- )
- ),
- array_column($input, NULL, 'foo')
- );
-
- $this->assertEquals(
- array(
- array(
- 'id' => '3',
- 'title' => 'Foo',
- 'date' => '2013-03-25'
- ),
- array(
- 'id' => '5',
- 'title' => 'Bar',
- 'date' => '2012-05-20'
- )
- ),
- array_column($input, NULL)
- );
-
- // Data types
-
- $fh = fopen(__FILE__, 'r', TRUE);
- $stdClass = new stdClass();
- $input = array(
- array(
- 'id' => 1,
- 'value' => $stdClass
- ),
- array(
- 'id' => 2,
- 'value' => 34.2345
- ),
- array(
- 'id' => 3,
- 'value' => TRUE
- ),
- array(
- 'id' => 4,
- 'value' => FALSE
- ),
- array(
- 'id' => 5,
- 'value' => NULL
- ),
- array(
- 'id' => 6,
- 'value' => 1234
- ),
- array(
- 'id' => 7,
- 'value' => 'Foo'
- ),
- array(
- 'id' => 8,
- 'value' => $fh
- )
- );
-
- $this->assertEquals(
- array(
- $stdClass,
- 34.2345,
- TRUE,
- FALSE,
- NULL,
- 1234,
- 'Foo',
- $fh
- ),
- array_column($input, 'value')
- );
-
- $this->assertEquals(
- array(
- 1 => $stdClass,
- 2 => 34.2345,
- 3 => TRUE,
- 4 => FALSE,
- 5 => NULL,
- 6 => 1234,
- 7 => 'Foo',
- 8 => $fh
- ),
- array_column($input, 'value', 'id')
- );
-
- // Numeric column keys
-
- $input = array(
- array('aaa', '111'),
- array('bbb', '222'),
- array('ccc', '333', -1 => 'ddd')
- );
-
- $this->assertEquals(
- array('111', '222', '333'),
- array_column($input, 1)
- );
-
- $this->assertEquals(
- array(
- 'aaa' => '111',
- 'bbb' => '222',
- 'ccc' => '333'
- ),
- array_column($input, 1, 0)
- );
-
- $this->assertEquals(
- array(
- 'aaa' => '111',
- 'bbb' => '222',
- 'ccc' => '333'
- ),
- array_column($input, 1, 0.123)
- );
-
- $this->assertEquals(
- array(
- 0 => '111',
- 1 => '222',
- 'ddd' => '333'
- ),
- array_column($input, 1, -1)
- );
-
- // Non-existing columns
-
- $this->assertEquals(array(), array_column($input, 2));
- $this->assertEquals(array(), array_column($input, 'foo'));
- $this->assertEquals(
- array('aaa', 'bbb', 'ccc'),
- array_column($input, 0, 'foo')
- );
- $this->assertEquals(array(), array_column($input, 3.14));
-
- // One-dimensional array
- $this->assertEquals(array(), array_column(array('foo', 'bar', 'baz'), 1));
-
- // Columns not present in all rows
-
- $input = array(
- array('a' => 'foo', 'b' => 'bar', 'e' => 'bbb'),
- array('a' => 'baz', 'c' => 'qux', 'd' => 'aaa'),
- array('a' => 'eee', 'b' => 'fff', 'e' => 'ggg')
- );
-
- $this->assertEquals(
- array('qux'),
- array_column($input, 'c')
- );
-
- $this->assertEquals(
- array('baz' => 'qux'),
- array_column($input, 'c', 'a')
- );
-
- $this->assertEquals(
- array(
- 0 => 'foo',
- 'aaa' => 'baz',
- 1 => 'eee'
- ),
- array_column($input, 'a', 'd')
- );
-
- $this->assertEquals(
- array(
- 'bbb' => 'foo',
- 0 => 'baz',
- 'ggg' => 'eee'
- ),
- array_column($input, 'a', 'e')
- );
-
- $this->assertEquals(
- array('bar', 'fff'),
- array_column($input, 'b')
- );
-
- $this->assertEquals(
- array(
- 'foo' => 'bar',
- 'eee' => 'fff'
- ),
- array_column($input, 'b', 'a')
- );
- }
-
- // ------------------------------------------------------------------------
-
- /**
- * hex2bin() tests
- *
- * @depends test_bootstrap
- */
- public function test_hex2bin()
- {
- if (is_php('5.4'))
- {
- return $this->markTestSkipped('hex2bin() is already available on PHP 5.4');
- }
-
- $this->assertEquals("\x03\x04", hex2bin("0304"));
- $this->assertEquals('', hex2bin(''));
- $this->assertEquals("\x01\x02\x03", hex2bin(new FooHex()));
- }
-}
-
-// ------------------------------------------------------------------------
-
-class Foo {
-
- public function __toString()
- {
- return 'last_name';
- }
-}
-
-class Bar {
-
- public function __toString()
- {
- return 'first_name';
- }
-}
-
-class FooHex {
-
- public function __toString()
- {
- return '010203';
- }
-}