diff options
Diffstat (limited to 'tests/codeigniter')
66 files changed, 0 insertions, 8873 deletions
diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php deleted file mode 100644 index 43545822a..000000000 --- a/tests/codeigniter/Setup_test.php +++ /dev/null @@ -1,13 +0,0 @@ -<?php - -class Setup_test extends \PHPUnit\Framework\TestCase { - - public function test_bootstrap_constants() - { - $this->assertTrue(defined('PROJECT_BASE')); - $this->assertTrue(defined('BASEPATH')); - $this->assertTrue(defined('APPPATH')); - $this->assertTrue(defined('VIEWPATH')); - } - -}
\ No newline at end of file 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 "quoted" 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('Hack');[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('Hack');[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('Hack');[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('Hack');[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('Hack');[removed] your site", $harmless_strings[0]); - $this->assertEquals("Simple clean string", $harmless_strings[1]); - $this->assertEquals("Hello, i try to [removed]alert('Hack');[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="&#106&#97&#118&#97&#115&#99&#114&#105&#112&#116&#58&#99&#111&#110&#102&#105&#114&#109&#40&#49&#41">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(1)\"\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="&#106&#97&#118&#97&#115&#99&#114&#105&#112&#116&#58&#99&#111&#110&#102&#105&#114&#109&#40&#49&#41">Clickhere'; - $this->assertEquals('<img>', $this->security->xss_clean($input)); - } - - // -------------------------------------------------------------------- - - public function test_xss_clean_sanitize_naughty_html_tags() - { - $this->assertEquals('<unclosedTag', $this->security->xss_clean('<unclosedTag')); - $this->assertEquals('<blink>', $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(1)">', - $this->security->xss_clean('<img src="b on="<x">on=">"x onerror="alert(1)">') - ); - - $this->assertEquals( - "\n><!-\n<b d=\"'e><iframe onload=alert(1) 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=<svg> onerror=alert(1)>', - $this->security->xss_clean('<img src="x" on=""> on=<svg> onerror=alert(1)>') - ); - - $this->assertEquals( - '<img src="on=\'">"<svg> onerror=alert(1) onmouseover=alert(1)>', - $this->security->xss_clean('<img src="on=\'">"<svg> onerror=alert(1) onmouseover=alert(1)>') - ); - - $this->assertEquals( - '<img src="x"> on=\'x\' onerror=``,alert(1)>', - $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(1)//">', - $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( - '<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 = '<div>Hello <b>Booya</b></div>'; - $decoded = $this->security->entity_decode($encoded); - - $this->assertEquals('<div>Hello <b>Booya</b></div>', $decoded); - - $this->assertEquals('colon:', $this->security->entity_decode('colon:')); - $this->assertEquals("NewLine\n", $this->security->entity_decode('NewLine
')); - $this->assertEquals("Tab\t", $this->security->entity_decode('Tab	')); - $this->assertEquals("lpar(", $this->security->entity_decode('lpar(')); - $this->assertEquals("rpar)", $this->security->entity_decode('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'; - } -} diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php deleted file mode 100644 index 26416d3fc..000000000 --- a/tests/codeigniter/database/DB_driver_test.php +++ /dev/null @@ -1,39 +0,0 @@ -<?php - -class DB_driver_test extends CI_TestCase { - - public function test_initialize() - { - $config = Mock_Database_DB::config(DB_DRIVER); - sscanf(DB_DRIVER, '%[^/]/', $driver_name); - $driver = $this->{$driver_name}($config[DB_DRIVER]); - - $this->assertTrue($driver->initialize()); - } - - protected function pdo($config) - { - return new Mock_Database_Drivers_PDO($config); - } - - protected function mysql($config) - { - return new Mock_Database_Drivers_Mysql($config); - } - - protected function mysqli($config) - { - return new Mock_Database_Drivers_Mysqli($config); - } - - protected function sqlite($config) - { - return new Mock_Database_Drivers_Sqlite($config); - } - - protected function pgsql($config) - { - return new Mock_Database_Drivers_Postgre($config); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/database/DB_test.php b/tests/codeigniter/database/DB_test.php deleted file mode 100644 index 9d53fd6f2..000000000 --- a/tests/codeigniter/database/DB_test.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php - -class DB_test extends CI_TestCase { - - public function test_db_invalid() - { - $connection = new Mock_Database_DB(array( - 'undefined' => array( - 'dsn' => '', - 'hostname' => 'undefined', - 'username' => 'undefined', - 'password' => 'undefined', - 'database' => 'undefined', - 'dbdriver' => 'undefined', - ), - )); - - $this->setExpectedException('RuntimeException', 'CI Error: Invalid DB driver'); - - Mock_Database_DB::DB($connection->set_dsn('undefined'), TRUE); - } - - // ------------------------------------------------------------------------ - - public function test_db_valid() - { - $config = Mock_Database_DB::config(DB_DRIVER); - $connection = new Mock_Database_DB($config); - - // E_DEPRECATED notices thrown by mysql_connect(), mysql_pconnect() - // on PHP 5.5+ cause the tests to fail - if (DB_DRIVER === 'mysql' && version_compare(PHP_VERSION, '5.5', '>=')) - { - error_reporting(E_ALL & ~E_DEPRECATED); - } - - $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER), TRUE); - - $this->assertInstanceOf('CI_DB', $db); - $this->assertInstanceOf('CI_DB_Driver', $db); - } - - // ------------------------------------------------------------------------ - -/* - This test is unusable, because whoever wrote it apparently thought that - an E_WARNING should equal an Exception and based the whole test suite - around that bogus assumption. - - public function test_db_failover() - { - $config = Mock_Database_DB::config(DB_DRIVER); - $connection = new Mock_Database_DB($config); - $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER.'_failover'), TRUE); - - $this->assertInstanceOf('CI_DB', $db); - $this->assertInstanceOf('CI_DB_Driver', $db); - } -*/ - -} diff --git a/tests/codeigniter/database/query_builder/count_test.php b/tests/codeigniter/database/query_builder/count_test.php deleted file mode 100644 index da312d866..000000000 --- a/tests/codeigniter/database/query_builder/count_test.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php - -class Count_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_count_all() - { - $this->assertEquals(4, $this->db->count_all('job')); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_count_all_results() - { - $this->assertEquals(2, $this->db->like('name', 'ian')->count_all_results('job')); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_count_all_results_limit() - { - $this->assertEquals(1, $this->db->like('name', 'ian')->limit(1)->count_all_results('job')); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/delete_test.php b/tests/codeigniter/database/query_builder/delete_test.php deleted file mode 100644 index ab9d97f56..000000000 --- a/tests/codeigniter/database/query_builder/delete_test.php +++ /dev/null @@ -1,64 +0,0 @@ -<?php - -class Delete_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_delete() - { - // Check initial record - $job1 = $this->db->where('id', 1)->get('job')->row(); - - $this->assertEquals('Developer', $job1->name); - - // Do the delete - $this->db->delete('job', array('id' => 1)); - - // Check the record - $job1 = $this->db->where('id', 1)->get('job'); - - $this->assertEmpty($job1->result_array()); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_delete_several_tables() - { - // Check initial record - $user4 = $this->db->where('id', 4)->get('user')->row(); - $job4 = $this->db->where('id', 4)->get('job')->row(); - - $this->assertEquals('Musician', $job4->name); - $this->assertEquals('Chris Martin', $user4->name); - - // Do the delete - $this->db->delete(array('job', 'user'), array('id' => 4)); - - // Check the record - $job4 = $this->db->where('id', 4)->get('job'); - $user4 = $this->db->where('id', 4)->get('user'); - - $this->assertEmpty($job4->result_array()); - $this->assertEmpty($user4->result_array()); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/distinct_test.php b/tests/codeigniter/database/query_builder/distinct_test.php deleted file mode 100644 index 81fabe448..000000000 --- a/tests/codeigniter/database/query_builder/distinct_test.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -class Distinct_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_distinct() - { - $users = $this->db->select('country') - ->distinct() - ->get('user') - ->result_array(); - - $this->assertCount(3, $users); - } - -} diff --git a/tests/codeigniter/database/query_builder/empty_test.php b/tests/codeigniter/database/query_builder/empty_test.php deleted file mode 100644 index 3f63a60f5..000000000 --- a/tests/codeigniter/database/query_builder/empty_test.php +++ /dev/null @@ -1,39 +0,0 @@ -<?php - -class Empty_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_empty_table() - { - // Check initial record - $jobs = $this->db->get('job')->result_array(); - - $this->assertCount(4, $jobs); - - // Do the empty - $this->db->empty_table('job'); - - // Check the record - $jobs = $this->db->get('job'); - - $this->assertEmpty($jobs->result_array()); - } - -} diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php deleted file mode 100644 index de6cd0a9d..000000000 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php - -class Escape_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_escape_like_percent_sign() - { - // Escape the like string - $string = $this->db->escape_like_str('\%foo'); - - if (strpos(DB_DRIVER, 'mysql') !== FALSE) - { - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '!';"; - } - else - { - $sql = 'SELECT "value" FROM "misc" WHERE "key" LIKE \''.$string.'%\' ESCAPE \'!\';'; - } - - $res = $this->db->query($sql)->result_array(); - - // Check the result - $this->assertCount(1, $res); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_escape_like_backslash_sign() - { - // Escape the like string - $string = $this->db->escape_like_str('\\'); - - if (strpos(DB_DRIVER, 'mysql') !== FALSE) - { - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '!';"; - } - else - { - $sql = 'SELECT "value" FROM "misc" WHERE "key" LIKE \''.$string.'%\' ESCAPE \'!\';'; - } - - $res = $this->db->query($sql)->result_array(); - - // Check the result - $this->assertCount(2, $res); - } - -} diff --git a/tests/codeigniter/database/query_builder/from_test.php b/tests/codeigniter/database/query_builder/from_test.php deleted file mode 100644 index 5a4ac690d..000000000 --- a/tests/codeigniter/database/query_builder/from_test.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php - -class From_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_from_simple() - { - $jobs = $this->db->from('job') - ->get() - ->result_array(); - - $this->assertCount(4, $jobs); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_from_with_where() - { - $job1 = $this->db->from('job') - ->where('id', 1) - ->get() - ->row(); - - $this->assertEquals('1', $job1->id); - $this->assertEquals('Developer', $job1->name); - $this->assertEquals('Awesome job, but sometimes makes you bored', $job1->description); - } - -} diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php deleted file mode 100644 index 156027537..000000000 --- a/tests/codeigniter/database/query_builder/get_test.php +++ /dev/null @@ -1,53 +0,0 @@ -<?php - -class Get_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_get_simple() - { - $jobs = $this->db->get('job')->result_array(); - - // Dummy jobs contain 4 rows - $this->assertCount(4, $jobs); - - // Check rows item - $this->assertEquals('Developer', $jobs[0]['name']); - $this->assertEquals('Politician', $jobs[1]['name']); - $this->assertEquals('Accountant', $jobs[2]['name']); - $this->assertEquals('Musician', $jobs[3]['name']); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_get_where() - { - $job1 = $this->db->get_where('job', array('id' => 1))->result_array(); - - // Dummy jobs contain 1 rows - $this->assertCount(1, $job1); - - // Check rows item - $this->assertEquals('Developer', $job1[0]['name']); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php deleted file mode 100644 index b40e5e507..000000000 --- a/tests/codeigniter/database/query_builder/group_test.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php - -class Group_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_group_by() - { - $jobs = $this->db->select('name') - ->from('job') - ->group_by('name') - ->get() - ->result_array(); - - $this->assertCount(4, $jobs); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_having_by() - { - $jobs = $this->db->select('name') - ->from('job') - ->group_by('name') - ->having('SUM(id) > 2') - ->get() - ->result_array(); - - $this->assertCount(2, $jobs); - } -} diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php deleted file mode 100644 index 30c055680..000000000 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ /dev/null @@ -1,66 +0,0 @@ -<?php - -class Insert_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - * @see ./mocks/schema/skeleton.php - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - - // Truncate the current datas - $this->db->truncate('job'); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_insert() - { - $job_data = array('id' => 1, 'name' => 'Grocery Sales', 'description' => 'Discount!'); - - // Do normal insert - $this->assertTrue($this->db->insert('job', $job_data)); - - $job1 = $this->db->get('job')->row(); - - // Check the result - $this->assertEquals('Grocery Sales', $job1->name); - - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_insert_batch() - { - $job_datas = array( - array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'), - array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'), - ); - - // Do insert batch except for sqlite driver - if (strpos(DB_DRIVER, 'sqlite') === FALSE) - { - $this->assertEquals(2, $this->db->insert_batch('job', $job_datas)); - - $job_2 = $this->db->where('id', 2)->get('job')->row(); - $job_3 = $this->db->where('id', 3)->get('job')->row(); - - // Check the result - $this->assertEquals('Commedian', $job_2->name); - $this->assertEquals('Cab Driver', $job_3->name); - } - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php deleted file mode 100644 index 54b2a4e18..000000000 --- a/tests/codeigniter/database/query_builder/join_test.php +++ /dev/null @@ -1,101 +0,0 @@ -<?php - -class Join_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_join_simple() - { - $job_user = $this->db->select('job.id as job_id, job.name as job_name, user.id as user_id, user.name as user_name') - ->from('job') - ->join('user', 'user.id = job.id') - ->get() - ->result_array(); - - // Check the result - $this->assertEquals('1', $job_user[0]['job_id']); - $this->assertEquals('1', $job_user[0]['user_id']); - $this->assertEquals('Derek Jones', $job_user[0]['user_name']); - $this->assertEquals('Developer', $job_user[0]['job_name']); - } - - // ------------------------------------------------------------------------ - - public function test_join_escape_is_null() - { - $expected = 'SELECT '.$this->db->escape_identifiers('field') - ."\nFROM ".$this->db->escape_identifiers('table1') - ."\nJOIN ".$this->db->escape_identifiers('table2').' ON '.$this->db->escape_identifiers('field').' IS NULL'; - - $this->assertEquals( - $expected, - $this->db->select('field')->from('table1')->join('table2', 'field IS NULL')->get_compiled_select() - ); - - $expected = 'SELECT '.$this->db->escape_identifiers('field') - ."\nFROM ".$this->db->escape_identifiers('table1') - ."\nJOIN ".$this->db->escape_identifiers('table2').' ON '.$this->db->escape_identifiers('field').' IS NOT NULL'; - - $this->assertEquals( - $expected, - $this->db->select('field')->from('table1')->join('table2', 'field IS NOT NULL')->get_compiled_select() - ); - } - - // ------------------------------------------------------------------------ - - public function test_join_escape_multiple_conditions() - { - // We just need a valid query produced, not one that makes sense - $fields = array($this->db->protect_identifiers('table1.field1'), $this->db->protect_identifiers('table2.field2')); - - $expected = 'SELECT '.implode(', ', $fields) - ."\nFROM ".$this->db->escape_identifiers('table1') - ."\nLEFT JOIN ".$this->db->escape_identifiers('table2').' ON '.implode(' = ', $fields) - .' AND '.$fields[0]." = 'foo' AND ".$fields[1].' = 0'; - - $result = $this->db->select('table1.field1, table2.field2') - ->from('table1') - ->join('table2', "table1.field1 = table2.field2 AND table1.field1 = 'foo' AND table2.field2 = 0", 'LEFT') - ->get_compiled_select(); - - $this->assertEquals($expected, $result); - } - - // ------------------------------------------------------------------------ - - public function test_join_escape_multiple_conditions_with_parentheses() - { - // We just need a valid query produced, not one that makes sense - $fields = array($this->db->protect_identifiers('table1.field1'), $this->db->protect_identifiers('table2.field2')); - - $expected = 'SELECT '.implode(', ', $fields) - ."\nFROM ".$this->db->escape_identifiers('table1') - ."\nRIGHT JOIN ".$this->db->escape_identifiers('table2').' ON '.implode(' = ', $fields) - .' AND ('.$fields[0]." = 'foo' OR ".$fields[1].' IS NULL)'; - - $result = $this->db->select('table1.field1, table2.field2') - ->from('table1') - ->join('table2', "table1.field1 = table2.field2 AND (table1.field1 = 'foo' OR table2.field2 IS NULL)", 'RIGHT') - ->get_compiled_select(); - - $this->assertEquals($expected, $result); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/like_test.php b/tests/codeigniter/database/query_builder/like_test.php deleted file mode 100644 index 4d8673d99..000000000 --- a/tests/codeigniter/database/query_builder/like_test.php +++ /dev/null @@ -1,129 +0,0 @@ -<?php - -class Like_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_like() - { - $job1 = $this->db->like('name', 'veloper') - ->get('job') - ->row(); - - // Check the result - $this->assertEquals('1', $job1->id); - $this->assertEquals('Developer', $job1->name); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_or_like() - { - $jobs = $this->db->like('name', 'ian') - ->or_like('name', 'veloper') - ->get('job') - ->result_array(); - - // Check the result - $this->assertCount(3, $jobs); - $this->assertEquals('Developer', $jobs[0]['name']); - $this->assertEquals('Politician', $jobs[1]['name']); - $this->assertEquals('Musician', $jobs[2]['name']); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_not_like() - { - $jobs = $this->db->not_like('name', 'veloper') - ->get('job') - ->result_array(); - - // Check the result - $this->assertCount(3, $jobs); - $this->assertEquals('Politician', $jobs[0]['name']); - $this->assertEquals('Accountant', $jobs[1]['name']); - $this->assertEquals('Musician', $jobs[2]['name']); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_or_not_like() - { - $jobs = $this->db->like('name', 'an') - ->or_not_like('name', 'veloper') - ->get('job') - ->result_array(); - - // Check the result - $this->assertCount(3, $jobs); - $this->assertEquals('Politician', $jobs[0]['name']); - $this->assertEquals('Accountant', $jobs[1]['name']); - $this->assertEquals('Musician', $jobs[2]['name']); - } - - // ------------------------------------------------------------------------ - - /** - * GitHub issue #273 - * - * @see ./mocks/schema/skeleton.php - */ - public function test_like_spaces_and_tabs() - { - $spaces = $this->db->like('value', ' ')->get('misc')->result_array(); - $tabs = $this->db->like('value', "\t")->get('misc')->result_array(); - - $this->assertCount(1, $spaces); - $this->assertCount(1, $tabs); - } - - /** - * GitHub issue #5462 - * - * @see ./mocks/schema/skeleton.php - * - * @dataProvider like_set_side_provider - */ - public function test_like_set_side($str, $side, $expected_name) - { - $actual = $this->db->like('name', $str, $side)->get('job')->result_array(); - $this->assertCount(1, $actual); - $this->assertEquals($expected_name, $actual[0]['name']); - } - - public function like_set_side_provider() - { - return array( - array('Developer', 'none', 'Developer'), - array('tician', 'before', 'Politician'), - array('Accou', 'after', 'Accountant'), - array('usicia', 'both', 'Musician'), - ); - } -} diff --git a/tests/codeigniter/database/query_builder/limit_test.php b/tests/codeigniter/database/query_builder/limit_test.php deleted file mode 100644 index a1976d457..000000000 --- a/tests/codeigniter/database/query_builder/limit_test.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php - -class Limit_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_limit() - { - $jobs = $this->db->limit(2) - ->get('job') - ->result_array(); - - $this->assertCount(2, $jobs); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_limit_and_offset() - { - $jobs = $this->db->limit(2, 2) - ->get('job') - ->result_array(); - - $this->assertCount(2, $jobs); - $this->assertEquals('Accountant', $jobs[0]['name']); - $this->assertEquals('Musician', $jobs[1]['name']); - } - -} diff --git a/tests/codeigniter/database/query_builder/order_test.php b/tests/codeigniter/database/query_builder/order_test.php deleted file mode 100644 index ff5bc543d..000000000 --- a/tests/codeigniter/database/query_builder/order_test.php +++ /dev/null @@ -1,55 +0,0 @@ -<?php - -class Order_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_order_ascending() - { - $jobs = $this->db->order_by('name', 'asc') - ->get('job') - ->result_array(); - - // Check the result - $this->assertCount(4, $jobs); - $this->assertEquals('Accountant', $jobs[0]['name']); - $this->assertEquals('Developer', $jobs[1]['name']); - $this->assertEquals('Musician', $jobs[2]['name']); - $this->assertEquals('Politician', $jobs[3]['name']); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_order_descending() - { - $jobs = $this->db->order_by('name', 'desc') - ->get('job') - ->result_array(); - - $this->assertCount(4, $jobs); - $this->assertEquals('Politician', $jobs[0]['name']); - $this->assertEquals('Musician', $jobs[1]['name']); - $this->assertEquals('Developer', $jobs[2]['name']); - $this->assertEquals('Accountant', $jobs[3]['name']); - } - -} diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php deleted file mode 100644 index facda791f..000000000 --- a/tests/codeigniter/database/query_builder/select_test.php +++ /dev/null @@ -1,95 +0,0 @@ -<?php - -class Select_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_select_only_one_collumn() - { - $jobs_name = $this->db->select('name') - ->get('job') - ->result_array(); - - // Check rows item - $this->assertArrayHasKey('name',$jobs_name[0]); - $this->assertArrayNotHasKey('id', $jobs_name[0]); - $this->assertArrayNotHasKey('description', $jobs_name[0]); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_select_min() - { - $job_min = $this->db->select_min('id') - ->get('job') - ->row(); - - // Minimum id was 1 - $this->assertEquals('1', $job_min->id); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_select_max() - { - $job_max = $this->db->select_max('id') - ->get('job') - ->row(); - - // Maximum id was 4 - $this->assertEquals('4', $job_max->id); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_select_avg() - { - $job_avg = $this->db->select_avg('id') - ->get('job') - ->row(); - - // Average should be 2.5 - $this->assertEquals(2.5, (float) $job_avg->id); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_select_sum() - { - $job_sum = $this->db->select_sum('id') - ->get('job') - ->row(); - - // Sum of ids should be 10 - $this->assertEquals('10', $job_sum->id); - } - -} diff --git a/tests/codeigniter/database/query_builder/truncate_test.php b/tests/codeigniter/database/query_builder/truncate_test.php deleted file mode 100644 index 64abe2872..000000000 --- a/tests/codeigniter/database/query_builder/truncate_test.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php - -class Truncate_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_truncate() - { - // Check initial record - $jobs = $this->db->get('job')->result_array(); - $this->assertCount(4, $jobs); - - // Do the empty - $this->db->truncate('job'); - - // Check the record - $jobs = $this->db->get('job'); - $this->assertEmpty($jobs->result_array()); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_truncate_with_from() - { - // Check initial record - $users = $this->db->get('user')->result_array(); - $this->assertCount(4, $users); - - // Do the empty - $this->db->from('user')->truncate(); - - // Check the record - $users = $this->db->get('user'); - $this->assertEmpty($users->result_array()); - } - -} diff --git a/tests/codeigniter/database/query_builder/update_test.php b/tests/codeigniter/database/query_builder/update_test.php deleted file mode 100644 index 27a647c45..000000000 --- a/tests/codeigniter/database/query_builder/update_test.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php - -class Update_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_update() - { - // Check initial record - $job1 = $this->db->where('id', 1)->get('job')->row(); - $this->assertEquals('Developer', $job1->name); - - // Do the update - $this->db->where('id', 1)->update('job', array('name' => 'Programmer')); - - // Check updated record - $job1 = $this->db->where('id', 1)->get('job')->row(); - $this->assertEquals('Programmer', $job1->name); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_update_with_set() - { - // Check initial record - $job1 = $this->db->where('id', 4)->get('job')->row(); - $this->assertEquals('Musician', $job1->name); - - // Do the update - $this->db->set('name', 'Vocalist'); - $this->db->update('job', NULL, 'id = 4'); - - // Check updated record - $job1 = $this->db->where('id', 4)->get('job')->row(); - $this->assertEquals('Vocalist', $job1->name); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php deleted file mode 100644 index 8a7a09ddb..000000000 --- a/tests/codeigniter/database/query_builder/where_test.php +++ /dev/null @@ -1,134 +0,0 @@ -<?php - -class Where_test extends CI_TestCase { - - /** - * @var object Database/Query Builder holder - */ - protected $db; - - public function set_up() - { - $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - - Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_where_simple_key_value() - { - $job1 = $this->db->where('id', 1)->get('job')->row(); - - $this->assertEquals('1', $job1->id); - $this->assertEquals('Developer', $job1->name); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_where_custom_key_value() - { - $jobs = $this->db->where('id !=', 1)->get('job')->result_array(); - $this->assertCount(3, $jobs); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_where_associative_array() - { - $where = array('id >' => 2, 'name !=' => 'Accountant'); - $jobs = $this->db->where($where)->get('job')->result_array(); - - $this->assertCount(1, $jobs); - - // Should be Musician - $job = current($jobs); - $this->assertEquals('Musician', $job['name']); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_where_custom_string() - { - $where = "id > 2 AND name != 'Accountant'"; - $jobs = $this->db->where($where)->get('job')->result_array(); - - $this->assertCount(1, $jobs); - - // Should be Musician - $job = current($jobs); - $this->assertEquals('Musician', $job['name']); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_where_or() - { - $jobs = $this->db->where('name !=', 'Accountant') - ->or_where('id >', 3) - ->get('job') - ->result_array(); - - $this->assertCount(3, $jobs); - $this->assertEquals('Developer', $jobs[0]['name']); - $this->assertEquals('Politician', $jobs[1]['name']); - $this->assertEquals('Musician', $jobs[2]['name']); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_where_in() - { - $jobs = $this->db->where_in('name', array('Politician', 'Accountant')) - ->get('job') - ->result_array(); - - $this->assertCount(2, $jobs); - $this->assertEquals('Politician', $jobs[0]['name']); - $this->assertEquals('Accountant', $jobs[1]['name']); - } - - // ------------------------------------------------------------------------ - - /** - * @see ./mocks/schema/skeleton.php - */ - public function test_where_not_in() - { - $jobs = $this->db->where_not_in('name', array('Politician', 'Accountant')) - ->get('job') - ->result_array(); - - $this->assertCount(2, $jobs); - $this->assertEquals('Developer', $jobs[0]['name']); - $this->assertEquals('Musician', $jobs[1]['name']); - } - - // ------------------------------------------------------------------------ - - public function test_issue4093() - { - $input = 'bar and baz or qux'; - $sql = $this->db->where('foo', $input)->get_compiled_select('dummy'); - $this->assertEquals("'".$input."'", substr($sql, -20)); - } -} diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php deleted file mode 100644 index f4e344673..000000000 --- a/tests/codeigniter/helpers/array_helper_test.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php - -class Array_helper_test extends CI_TestCase { - - public $my_array = array( - 'foo' => 'bar', - 'sally' => 'jim', - 'maggie' => 'bessie', - 'herb' => 'cook' - ); - - public function set_up() - { - $this->helper('array'); - } - - // ------------------------------------------------------------------------ - - public function test_element_with_existing_item() - { - $this->assertEquals(FALSE, element('testing', $this->my_array)); - $this->assertEquals('not set', element('testing', $this->my_array, 'not set')); - $this->assertEquals('bar', element('foo', $this->my_array)); - } - - // ------------------------------------------------------------------------ - - public function test_random_element() - { - // Send a string, not an array to random_element - $this->assertEquals('my string', random_element('my string')); - - // Test sending an array - $this->assertContains(random_element($this->my_array), $this->my_array); - } - - // ------------------------------------------------------------------------ - - public function test_elements() - { - $this->assertEquals('array', gettype(elements('test', $this->my_array))); - $this->assertEquals('array', gettype(elements('foo', $this->my_array))); - } - -} diff --git a/tests/codeigniter/helpers/captcha_helper_test.php b/tests/codeigniter/helpers/captcha_helper_test.php deleted file mode 100644 index bb8760a15..000000000 --- a/tests/codeigniter/helpers/captcha_helper_test.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -class Captcha_helper_test extends CI_TestCase { - - public function test_create_captcha() - { - $this->markTestSkipped("Can't test"); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/helpers/cookie_helper_test.php b/tests/codeigniter/helpers/cookie_helper_test.php deleted file mode 100644 index fba68f20f..000000000 --- a/tests/codeigniter/helpers/cookie_helper_test.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php - -class Cookie_helper_test extends CI_TestCase { - - public function set_up() - { - $this->helper('cookie'); - } - - // ------------------------------------------------------------------------ - - function test_set_cookie() - { - /*$input_cls = $this->ci_core_class('input'); - $this->ci_instance_var('input', new $input_cls); - - $this->assertTrue(set_cookie( - 'my_cookie', - 'foobar' - ));*/ - - $this->markTestSkipped('Need to find a way to overcome a headers already set exception'); - } - - // ------------------------------------------------------------------------ - - function test_get_cookie() - { - $_COOKIE['foo'] = 'bar'; - - $security = new Mock_Core_Security(); - $utf8 = new Mock_Core_Utf8(); - $input_cls = $this->ci_core_class('input'); - $this->ci_instance_var('input', new Mock_Core_Input($security, $utf8)); - - $this->assertEquals('bar', get_cookie('foo', FALSE)); - $this->assertEquals('bar', get_cookie('foo', TRUE)); - - $_COOKIE['bar'] = "Hello, i try to <script>alert('Hack');</script> your site"; - - $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", get_cookie('bar', TRUE)); - $this->assertEquals("Hello, i try to <script>alert('Hack');</script> your site", get_cookie('bar', FALSE)); - } - - // ------------------------------------------------------------------------ - - function test_delete_cookie() - { - /*$input_cls = $this->ci_core_class('input'); - $this->ci_instance_var('input', new $input_cls); - - $this->assertTrue(delete_cookie( - 'my_cookie' - ));*/ - - $this->markTestSkipped('Need to find a way to overcome a headers already set exception'); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php deleted file mode 100644 index b419418bf..000000000 --- a/tests/codeigniter/helpers/date_helper_test.php +++ /dev/null @@ -1,325 +0,0 @@ -<?php - -class Date_helper_test extends CI_TestCase { - - public function set_up() - { - $this->helper('date'); - $this->time = time(); - } - - // ------------------------------------------------------------------------ - - public function test_nice_date() - { - $this->assertEquals('2016-11-01', nice_date('201611', 'Y-m-d')); - $this->assertEquals('2016-11-23', nice_date('20161123', 'Y-m-d')); - } - - // ------------------------------------------------------------------------ - - public function test_now_local() - { - /* - - // This stub job, is simply to cater $config['time_reference'] - $config = $this->getMockBuilder('CI_Config')->getMock(); - $config->expects($this->any()) - ->method('item') - ->will($this->returnValue('local')); - - // Add the stub to our test instance - $this->ci_instance_var('config', $config); - - */ - - $this->ci_set_config('time_reference', 'local'); - - $this->assertEquals(time(), now()); - } - - // ------------------------------------------------------------------------ - - public function test_now_utc() - { - /* - - // This stub job, is simply to cater $config['time_reference'] - $config = $this->getMockBuilder('CI_Config')->getMock(); - $config->expects($this->any()) - ->method('item') - ->will($this->returnValue('UTC')); - - // Add the stub to our stdClass - $this->ci_instance_var('config', $config); - - */ - - $this->assertEquals( - mktime(gmdate('G'), gmdate('i'), gmdate('s'), gmdate('n'), gmdate('j'), gmdate('Y')), - now('UTC') - ); - } - - // ------------------------------------------------------------------------ - - public function test_mdate() - { - $this->assertEquals( - date('Y-m-d - h:i a', $this->time), - mdate('%Y-%m-%d - %h:%i %a', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_rfc822() - { - $this->assertEquals( - date(DATE_RFC822, $this->time), - standard_date('DATE_RFC822', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_atom() - { - $this->assertEquals( - date(DATE_ATOM, $this->time), - standard_date('DATE_ATOM', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_cookie() - { - $this->assertEquals( - date(DATE_COOKIE, $this->time), - standard_date('DATE_COOKIE', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_iso8601() - { - $this->assertEquals( - date(DATE_ISO8601, $this->time), - standard_date('DATE_ISO8601', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_rfc850() - { - $this->assertEquals( - date(DATE_RFC850, $this->time), - standard_date('DATE_RFC850', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_rfc1036() - { - $this->assertEquals( - date(DATE_RFC1036, $this->time), - standard_date('DATE_RFC1036', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_rfc1123() - { - $this->assertEquals( - date(DATE_RFC1123, $this->time), - standard_date('DATE_RFC1123', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_rfc2822() - { - $this->assertEquals( - date(DATE_RFC2822, $this->time), - standard_date('DATE_RFC2822', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_rss() - { - $this->assertEquals( - date(DATE_RSS, $this->time), - standard_date('DATE_RSS', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_w3c() - { - $this->assertEquals( - date(DATE_W3C, $this->time), - standard_date('DATE_W3C', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_timespan() - { - $this->ci_vfs_clone('system/language/english/date_lang.php'); - - $loader_cls = $this->ci_core_class('load'); - $this->ci_instance_var('load', new $loader_cls); - - $lang_cls = $this->ci_core_class('lang'); - $this->ci_instance_var('lang', new $lang_cls); - - $this->assertEquals('1 Second', timespan(time(), time()+1)); - $this->assertEquals('1 Minute', timespan(time(), time()+60)); - $this->assertEquals('1 Hour', timespan(time(), time()+3600)); - $this->assertEquals('2 Hours', timespan(time(), time()+7200)); - } - - // ------------------------------------------------------------------------ - - public function test_days_in_month() - { - $this->assertEquals(30, days_in_month(06, 2005)); - $this->assertEquals(28, days_in_month(02, 2011)); - $this->assertEquals(29, days_in_month(02, 2012)); - } - - // ------------------------------------------------------------------------ - - public function test_local_to_gmt() - { - $this->assertEquals( - mktime( - gmdate('G', $this->time), gmdate('i', $this->time), gmdate('s', $this->time), - gmdate('n', $this->time), gmdate('j', $this->time), gmdate('Y', $this->time) - ), - local_to_gmt($this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_gmt_to_local() - { - $this->assertEquals(1140128493, gmt_to_local('1140153693', 'UM8', TRUE)); - } - - // ------------------------------------------------------------------------ - - public function test_mysql_to_unix() - { - $this->assertEquals($this->time, mysql_to_unix(date('Y-m-d H:i:s', $this->time))); - } - - // ------------------------------------------------------------------------ - - public function test_unix_to_human() - { - $this->assertEquals(date('Y-m-d h:i A', $this->time), unix_to_human($this->time)); - $this->assertEquals(date('Y-m-d h:i:s A', $this->time), unix_to_human($this->time, TRUE, 'us')); - $this->assertEquals(date('Y-m-d H:i:s', $this->time), unix_to_human($this->time, TRUE, 'eu')); - } - - // ------------------------------------------------------------------------ - - public function test_human_to_unix() - { - $date = '2000-12-31 10:00:00 PM'; - $this->assertEquals(strtotime($date), human_to_unix($date)); - $this->assertFalse(human_to_unix()); - } - - // ------------------------------------------------------------------------ - - public function test_timezones() - { - $zones = array( - 'UM12' => -12, - 'UM11' => -11, - 'UM10' => -10, - 'UM95' => -9.5, - 'UM9' => -9, - 'UM8' => -8, - 'UM7' => -7, - 'UM6' => -6, - 'UM5' => -5, - 'UM45' => -4.5, - 'UM4' => -4, - 'UM35' => -3.5, - 'UM3' => -3, - 'UM2' => -2, - 'UM1' => -1, - 'UTC' => 0, - 'UP1' => +1, - 'UP2' => +2, - 'UP3' => +3, - 'UP35' => +3.5, - 'UP4' => +4, - 'UP45' => +4.5, - 'UP5' => +5, - 'UP55' => +5.5, - 'UP575' => +5.75, - 'UP6' => +6, - 'UP65' => +6.5, - 'UP7' => +7, - 'UP8' => +8, - 'UP875' => +8.75, - 'UP9' => +9, - 'UP95' => +9.5, - 'UP10' => +10, - 'UP105' => +10.5, - 'UP11' => +11, - 'UP115' => +11.5, - 'UP12' => +12, - 'UP1275' => +12.75, - 'UP13' => +13, - 'UP14' => +14 - ); - - foreach ($zones AS $test => $expected) - { - $this->assertEquals($expected, timezones($test)); - } - - $this->assertArrayHasKey('UP3', timezones()); - $this->assertEquals(0, timezones('non_existent')); - } - - // ------------------------------------------------------------------------ - - public function test_date_range() - { - $dates = array( - '29-01-2012', '30-01-2012', '31-01-2012', - '01-02-2012', '02-02-2012', '03-02-2012', - '04-02-2012', '05-02-2012', '06-02-2012', - '07-02-2012', '08-02-2012', '09-02-2012', - '10-02-2012', '11-02-2012', '12-02-2012', - '13-02-2012', '14-02-2012', '15-02-2012', - '16-02-2012', '17-02-2012', '18-02-2012', - '19-02-2012', '20-02-2012', '21-02-2012', - '22-02-2012', '23-02-2012', '24-02-2012', - '25-02-2012', '26-02-2012', '27-02-2012', - '28-02-2012', '29-02-2012', '01-03-2012' - ); - - $this->assertEquals($dates, date_range(mktime(12, 0, 0, 1, 29, 2012), mktime(12, 0, 0, 3, 1, 2012), TRUE, 'd-m-Y')); - array_pop($dates); - $this->assertEquals($dates, date_range(mktime(12, 0, 0, 1, 29, 2012), 31, FALSE, 'd-m-Y')); - } - -} diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php deleted file mode 100644 index 253c1e368..000000000 --- a/tests/codeigniter/helpers/directory_helper_test.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php - -class Directory_helper_test extends CI_TestCase { - - public function set_up() - { - $this->helper('directory'); - - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); - - $this->_test_dir = vfsStreamWrapper::getRoot(); - } - - public function test_directory_map() - { - $ds = DIRECTORY_SEPARATOR; - - $structure = array( - 'libraries' => array( - 'benchmark.html' => '', - 'database' => array('active_record.html' => '', 'binds.html' => ''), - 'email.html' => '', - '0' => '', - '.hiddenfile.txt' => '' - ) - ); - - vfsStream::create($structure, $this->_test_dir); - - // is_dir(), opendir(), etc. seem to fail on Windows + vfsStream when there are trailing backslashes in directory names - if ( ! is_dir(vfsStream::url('testDir').DIRECTORY_SEPARATOR)) - { - $this->markTestSkipped("Can't test this under Windows"); - return; - } - - // test default recursive behavior - $expected = array( - 'libraries'.$ds => array( - 'benchmark.html', - 'database'.$ds => array('active_record.html', 'binds.html'), - 'email.html', - '0' - ) - ); - - $this->assertEquals($expected, directory_map(vfsStream::url('testDir'))); - - // test detection of hidden files - $expected['libraries'.$ds][] = '.hiddenfile.txt'; - - $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), 0, TRUE)); - - // test recursion depth behavior - $this->assertEquals(array('libraries'.$ds), directory_map(vfsStream::url('testDir'), 1)); - } - -} diff --git a/tests/codeigniter/helpers/download_helper_test.php b/tests/codeigniter/helpers/download_helper_test.php deleted file mode 100644 index d2b42e46b..000000000 --- a/tests/codeigniter/helpers/download_helper_test.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -class Download_helper_test extends CI_TestCase { - - public function test_force_download() - { - $this->markTestSkipped('Cant easily test'); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/helpers/email_helper_test.php b/tests/codeigniter/helpers/email_helper_test.php deleted file mode 100644 index 529e96910..000000000 --- a/tests/codeigniter/helpers/email_helper_test.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -class Email_helper_test extends CI_TestCase { - - public function set_up() - { - $this->helper('email'); - } - - public function test_valid_email() - { - $this->assertEquals(FALSE, valid_email('test')); - $this->assertEquals(FALSE, valid_email('test@test@test.com')); - $this->assertEquals(TRUE, valid_email('test@test.com')); - $this->assertEquals(TRUE, valid_email('my.test@test.com')); - $this->assertEquals(TRUE, valid_email('my.test@subdomain.test.com')); - } - - public function test_send_mail() - { - $this->markTestSkipped("Can't test"); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php deleted file mode 100644 index 0d7ae96ee..000000000 --- a/tests/codeigniter/helpers/file_helper_test.php +++ /dev/null @@ -1,144 +0,0 @@ -<?php - -class File_helper_Test extends CI_TestCase { - - public function set_up() - { - $this->helper('file'); - - $this->_test_dir = vfsStream::setup(''); - } - - // -------------------------------------------------------------------- - - public function test_read_file() - { - $this->assertFalse(read_file('does_not_exist')); - - $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - - $file = vfsStream::newFile('my_file.txt')->withContent($content)->at($this->_test_dir); - - $this->assertEquals($content, read_file(vfsStream::url('my_file.txt'))); - } - - // -------------------------------------------------------------------- - - public function test_octal_permissions() - { - $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - - $file = vfsStream::newFile('my_file.txt', 0777) - ->withContent($content) - ->lastModified(time() - 86400) - ->at($this->_test_dir); - - $this->assertEquals('777', octal_permissions($file->getPermissions())); - } - - // -------------------------------------------------------------------- - - /** - * More tests should happen here, since I'm not hitting the whole function. - */ - public function test_symbolic_permissions() - { - $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - - $file = vfsStream::newFile('my_file.txt', 0777) - ->withContent($content) - ->lastModified(time() - 86400) - ->at($this->_test_dir); - - $this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions())); - } - - // -------------------------------------------------------------------- - - public function test_get_mime_by_extension() - { - $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - - $file = vfsStream::newFile('my_file.txt', 0777) - ->withContent($content) - ->lastModified(time() - 86400) - ->at($this->_test_dir); - - $this->assertEquals('text/plain', get_mime_by_extension(vfsStream::url('my_file.txt'))); - - // Test a mime with an array, such as png - $file = vfsStream::newFile('foo.png')->at($this->_test_dir); - - $this->assertEquals('image/png', get_mime_by_extension(vfsStream::url('foo.png'))); - - // Test a file not in the mimes array - $file = vfsStream::newFile('foo.blarfengar')->at($this->_test_dir); - - $this->assertFalse(get_mime_by_extension(vfsStream::url('foo.blarfengar'))); - } - - // -------------------------------------------------------------------- - - public function test_get_file_info() - { - // Test Bad File - $this->assertFalse(get_file_info('i_am_bad_boo')); - - // Test the rest - - // First pass in an array - $vals = array( - 'name', 'server_path', 'size', 'date', - 'readable', 'writable', 'executable', 'fileperms' - ); - - $this->_test_get_file_info($vals); - - // Test passing in vals as a string. - $this->_test_get_file_info(implode(', ', $vals)); - } - - private function _test_get_file_info($vals) - { - $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - $last_modified = time() - 86400; - - $file = vfsStream::newFile('my_file.txt', 0777) - ->withContent($content) - ->lastModified($last_modified) - ->at($this->_test_dir); - - $ret_values = array( - 'name' => 'my_file.txt', - 'server_path' => 'vfs://my_file.txt', - 'size' => 57, - 'date' => $last_modified, - 'readable' => TRUE, - 'writable' => TRUE, - 'executable' => TRUE, - 'fileperms' => 33279 - ); - - $info = get_file_info(vfsStream::url('my_file.txt'), $vals); - - foreach ($info as $k => $v) - { - $this->assertEquals($ret_values[$k], $v); - } - } - - // -------------------------------------------------------------------- - - public function test_write_file() - { - $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - - $file = vfsStream::newFile('write.txt', 0777) - ->withContent('') - ->lastModified(time() - 86400) - ->at($this->_test_dir); - - $this->assertTrue(write_file(vfsStream::url('write.txt'), $content)); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php deleted file mode 100644 index b5fe99b96..000000000 --- a/tests/codeigniter/helpers/form_helper_test.php +++ /dev/null @@ -1,290 +0,0 @@ -<?php - -class Form_helper_test extends CI_TestCase -{ - public function set_up() - { - $this->helper('form'); - } - - // ------------------------------------------------------------------------ - - public function test_form_hidden() - { - $expected = <<<EOH - -<input type="hidden" name="username" value="johndoe" /> - -EOH; - - $this->assertEquals($expected, form_hidden('username', 'johndoe')); - } - - // ------------------------------------------------------------------------ - - public function test_form_input() - { - $expected = <<<EOH -<input type="text" name="username" value="johndoe" id="username" maxlength="100" size="50" style="width:50%" /> - -EOH; - - $data = array( - 'name' => 'username', - 'id' => 'username', - 'value' => 'johndoe', - 'maxlength' => '100', - 'size' => '50', - 'style' => 'width:50%', - ); - - $this->assertEquals($expected, form_input($data)); - } - - // ------------------------------------------------------------------------ - - public function test_form_password() - { - $expected = <<<EOH -<input type="password" name="password" value="" /> - -EOH; - - $this->assertEquals($expected, form_password('password')); - } - - // ------------------------------------------------------------------------ - - public function test_form_upload() - { - $expected = <<<EOH -<input type="file" name="attachment" /> - -EOH; - - $this->assertEquals($expected, form_upload('attachment')); - } - - // ------------------------------------------------------------------------ - - public function test_form_textarea() - { - $expected = <<<EOH -<textarea name="notes" cols="40" rows="10" >Notes</textarea> - -EOH; - - $this->assertEquals($expected, form_textarea('notes', 'Notes')); - } - - // ------------------------------------------------------------------------ - - public function test_form_dropdown() - { - $expected = <<<EOH -<select name="shirts"> -<option value="small">Small Shirt</option> -<option value="med">Medium Shirt</option> -<option value="large" selected="selected">Large Shirt</option> -<option value="xlarge">Extra Large Shirt</option> -</select> - -EOH; - - $options = array( - 'small' => 'Small Shirt', - 'med' => 'Medium Shirt', - 'large' => 'Large Shirt', - 'xlarge' => 'Extra Large Shirt', - ); - - $this->assertEquals($expected, form_dropdown('shirts', $options, 'large')); - - $expected = <<<EOH -<select name="shirts" multiple="multiple"> -<option value="small" selected="selected">Small Shirt</option> -<option value="med">Medium Shirt</option> -<option value="large" selected="selected">Large Shirt</option> -<option value="xlarge">Extra Large Shirt</option> -</select> - -EOH; - - $shirts_on_sale = array('small', 'large'); - - $this->assertEquals($expected, form_dropdown('shirts', $options, $shirts_on_sale)); - - $options = array( - 'Swedish Cars' => array( - 'volvo' => 'Volvo', - 'saab' => 'Saab' - ), - 'German Cars' => array( - 'mercedes' => 'Mercedes', - 'audi' => 'Audi' - ) - ); - - $expected = <<<EOH -<select name="cars" multiple="multiple"> -<optgroup label="Swedish Cars"> -<option value="volvo" selected="selected">Volvo</option> -<option value="saab">Saab</option> -</optgroup> -<optgroup label="German Cars"> -<option value="mercedes">Mercedes</option> -<option value="audi" selected="selected">Audi</option> -</optgroup> -</select> - -EOH; - - $this->assertEquals($expected, form_dropdown('cars', $options, array('volvo', 'audi'))); - } - - // ------------------------------------------------------------------------ - - public function test_form_multiselect() - { - $expected = <<<EOH -<select name="shirts[]" multiple="multiple"> -<option value="small">Small Shirt</option> -<option value="med" selected="selected">Medium Shirt</option> -<option value="large" selected="selected">Large Shirt</option> -<option value="xlarge">Extra Large Shirt</option> -</select> - -EOH; - - $options = array( - 'small' => 'Small Shirt', - 'med' => 'Medium Shirt', - 'large' => 'Large Shirt', - 'xlarge' => 'Extra Large Shirt', - ); - - $this->assertEquals($expected, form_multiselect('shirts[]', $options, array('med', 'large'))); - } - - // ------------------------------------------------------------------------ - - public function test_form_fieldset() - { - $expected = <<<EOH -<fieldset> -<legend>Address Information</legend> - -EOH; - - $this->assertEquals($expected, form_fieldset('Address Information')); - } - - // ------------------------------------------------------------------------ - - public function test_form_fieldset_close() - { - $expected = <<<EOH -</fieldset></div></div> -EOH; - - $this->assertEquals($expected, form_fieldset_close('</div></div>')); - } - - // ------------------------------------------------------------------------ - - public function test_form_checkbox() - { - $expected = <<<EOH -<input type="checkbox" name="newsletter" value="accept" checked="checked" /> - -EOH; - - $this->assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE)); - } - - // ------------------------------------------------------------------------ - - public function test_form_radio() - { - $expected = <<<EOH -<input type="radio" name="newsletter" value="accept" checked="checked" /> - -EOH; - - $this->assertEquals($expected, form_radio('newsletter', 'accept', TRUE)); - } - - // ------------------------------------------------------------------------ - - public function test_form_submit() - { - $expected = <<<EOH -<input type="submit" name="mysubmit" value="Submit Post!" /> - -EOH; - - $this->assertEquals($expected, form_submit('mysubmit', 'Submit Post!')); - } - - // ------------------------------------------------------------------------ - - public function test_form_label() - { - $expected = <<<EOH -<label for="username">What is your Name</label> -EOH; - - $this->assertEquals($expected, form_label('What is your Name', 'username')); - } - - // ------------------------------------------------------------------------ - - public function test_form_reset() - { - $expected = <<<EOH -<input type="reset" name="myreset" value="Reset" /> - -EOH; - - $this->assertEquals($expected, form_reset('myreset', 'Reset')); - } - - // ------------------------------------------------------------------------ - - public function test_form_button() - { - $expected = <<<EOH -<button name="name" type="button" >content</button> - -EOH; - - $this->assertEquals($expected, form_button('name', 'content')); - } - - // ------------------------------------------------------------------------ - - public function test_form_close() - { - $expected = <<<EOH -</form></div></div> -EOH; - - $this->assertEquals($expected, form_close('</div></div>')); - } - - // ------------------------------------------------------------------------ - - public function test_form_prep() - { - $this->assertEquals( - 'Here is a string containing "quoted" text.', - form_prep('Here is a string containing "quoted" text.') - ); - - $this->assertEquals( - 'Here is a string containing a <tag>.', - form_prep('Here is a string containing a <tag>.', TRUE) - ); - } - -} diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php deleted file mode 100644 index 3cf1016ec..000000000 --- a/tests/codeigniter/helpers/html_helper_test.php +++ /dev/null @@ -1,106 +0,0 @@ -<?php - -class Html_helper_test extends CI_TestCase { - - public function set_up() - { - $this->helper('html'); - } - - // ------------------------------------------------------------------------ - - public function test_br() - { - $this->assertEquals('<br /><br />', br(2)); - } - - // ------------------------------------------------------------------------ - - public function test_heading() - { - $this->assertEquals('<h1>foobar</h1>', heading('foobar')); - $this->assertEquals('<h2 class="bar">foobar</h2>', heading('foobar', 2, 'class="bar"')); - } - - public function test_heading_array_attributes() - { - // Test array of attributes - $this->assertEquals('<h2 class="bar" id="foo">foobar</h2>', heading('foobar', 2, array('class' => 'bar', 'id' => 'foo'))); - } - - public function test_heading_object_attributes() - { - // Test array of attributes - $this->assertEquals('<h2 class="bar" id="foo">foobar</h2>', heading('foobar', 2, array('class' => 'bar', 'id' => 'foo'))); - $test = new stdClass; - $test->class = "bar"; - $test->id = "foo"; - $this->assertEquals('<h2 class="bar" id="foo">foobar</h2>', heading('foobar', 2, $test)); - } - - // ------------------------------------------------------------------------ - - public function test_img() - { - $this->ci_set_config('base_url', 'http://localhost/'); - $this->assertEquals('<img src="http://localhost/test" alt="" />', img("test")); - $this->assertEquals('<img src="data:foo/bar,baz" alt="" />', img("data:foo/bar,baz")); - $this->assertEquals('<img src="http://localhost/data://foo" alt="" />', img("data://foo")); - $this->assertEquals('<img src="//foo.bar/baz" alt="" />', img("//foo.bar/baz")); - $this->assertEquals('<img src="http://foo.bar/baz" alt="" />', img("http://foo.bar/baz")); - $this->assertEquals('<img src="https://foo.bar/baz" alt="" />', img("https://foo.bar/baz")); - $this->assertEquals('<img src="ftp://foo.bar/baz" alt="" />', img("ftp://foo.bar/baz")); - } - - // ------------------------------------------------------------------------ - - public function test_Ul() - { - $expect = <<<EOH -<ul> - <li>foo</li> - <li>bar</li> -</ul> - -EOH; - - $expect = ltrim($expect); - $list = array('foo', 'bar'); - - $this->assertEquals(ltrim($expect), ul($list)); - - $expect = <<<EOH -<ul class="test"> - <li>foo</li> - <li>bar</li> -</ul> - -EOH; - - $expect = ltrim($expect); - - $this->assertEquals($expect, ul($list, 'class="test"')); - - $this->assertEquals($expect, ul($list, array('class' => 'test'))); - } - - // ------------------------------------------------------------------------ - - public function test_NBS() - { - $this->assertEquals(' ', nbs(3)); - } - - // ------------------------------------------------------------------------ - - public function test_meta() - { - $this->assertEquals("<meta name=\"test\" content=\"foo\" />\n", meta('test', 'foo')); - - $expect = "<meta name=\"foo\" content=\"\" />\n"; - - $this->assertEquals($expect, meta(array('name' => 'foo'))); - - } - -} diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php deleted file mode 100644 index 3ec681bcd..000000000 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ /dev/null @@ -1,96 +0,0 @@ -<?php - -class Inflector_helper_test extends CI_TestCase { - - public function set_up() - { - $this->helper('inflector'); - } - - public function test_singular() - { - $strs = array( - 'tellies' => 'telly', - 'smellies' => 'smelly', - 'abjectnesses' => 'abjectness', - 'smells' => 'smell', - 'equipment' => 'equipment' - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, singular($str)); - } - } - - // -------------------------------------------------------------------- - - public function test_plural() - { - $strs = array( - 'telly' => 'tellies', - 'smelly' => 'smellies', - 'abjectness' => 'abjectnesses', // ref : http://en.wiktionary.org/wiki/abjectnesses - 'smell' => 'smells', - 'witch' => 'witches', - 'equipment' => 'equipment' - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, plural($str)); - } - } - - // -------------------------------------------------------------------- - - public function test_camelize() - { - $strs = array( - 'this is the string' => 'thisIsTheString', - 'this is another one' => 'thisIsAnotherOne', - 'i-am-playing-a-trick' => 'i-am-playing-a-trick', - 'what_do_you_think-yo?' => 'whatDoYouThink-yo?', - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, camelize($str)); - } - } - - // -------------------------------------------------------------------- - - public function test_underscore() - { - $strs = array( - 'this is the string' => 'this_is_the_string', - 'this is another one' => 'this_is_another_one', - 'i-am-playing-a-trick' => 'i-am-playing-a-trick', - 'what_do_you_think-yo?' => 'what_do_you_think-yo?', - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, underscore($str)); - } - } - - // -------------------------------------------------------------------- - - public function test_humanize() - { - $strs = array( - 'this_is_the_string' => 'This Is The String', - 'this_is_another_one' => 'This Is Another One', - 'i-am-playing-a-trick' => 'I-am-playing-a-trick', - 'what_do_you_think-yo?' => 'What Do You Think-yo?', - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, humanize($str)); - } - } - -} diff --git a/tests/codeigniter/helpers/language_helper_test.php b/tests/codeigniter/helpers/language_helper_test.php deleted file mode 100644 index 1ddabea3d..000000000 --- a/tests/codeigniter/helpers/language_helper_test.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -class Language_helper_test extends CI_TestCase { - - public function test_lang() - { - $this->helper('language'); - $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('line'))->getMock(); - $lang->expects($this->any())->method('line')->will($this->returnValue(FALSE)); - $this->ci_instance_var('lang', $lang); - - $this->assertFalse(lang(1)); - $this->assertEquals('<label for="foo" class="bar"></label>', lang(1, 'foo', array('class' => 'bar'))); - } - -} diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php deleted file mode 100644 index 663e354fe..000000000 --- a/tests/codeigniter/helpers/number_helper_test.php +++ /dev/null @@ -1,63 +0,0 @@ -<?php - -class Number_helper_test extends CI_TestCase { - - public function set_up() - { - $this->helper('number'); - - // Grab the core lang class - $lang_cls = $this->ci_core_class('lang'); - - // Mock away load, too much going on in there, - // we'll just check for the expected parameter - $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock(); - $lang->expects($this->once()) - ->method('load') - ->with($this->equalTo('number')); - - // Assign the proper language array - $lang->language = $this->lang('number'); - - // We don't have a controller, so just create - // a cheap class to act as our super object. - // Make sure it has a lang attribute. - $this->ci_instance_var('lang', $lang); - } - - public function test_byte_format() - { - $this->assertEquals('456 Bytes', byte_format(456)); - } - - public function test_kb_format() - { - $this->assertEquals('4.5 KB', byte_format(4567)); - } - - public function test_kb_format_medium() - { - $this->assertEquals('44.6 KB', byte_format(45678)); - } - - public function test_kb_format_large() - { - $this->assertEquals('446.1 KB', byte_format(456789)); - } - - public function test_mb_format() - { - $this->assertEquals('3.3 MB', byte_format(3456789)); - } - - public function test_gb_format() - { - $this->assertEquals('1.8 GB', byte_format(1932735283.2)); - } - - public function test_tb_format() - { - $this->assertEquals('112,283.3 TB', byte_format(123456789123456789)); - } - -} diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php deleted file mode 100644 index 9d325e70d..000000000 --- a/tests/codeigniter/helpers/path_helper_test.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php - -class Path_helper_test extends CI_TestCase { - - public function set_up() - { - $this->helper('path'); - } - - public function test_set_realpath() - { - $this->assertEquals(getcwd().DIRECTORY_SEPARATOR, set_realpath(getcwd())); - } - - public function test_set_realpath_nonexistent_directory() - { - $expected = '/path/to/nowhere'; - $this->assertEquals($expected, set_realpath('/path/to/nowhere', FALSE)); - } - - public function test_set_realpath_error_trigger() - { - $this->setExpectedException( - 'RuntimeException', 'CI Error: Not a valid path: /path/to/nowhere' - ); - - set_realpath('/path/to/nowhere', TRUE); - } - -} diff --git a/tests/codeigniter/helpers/security_helper_test.php b/tests/codeigniter/helpers/security_helper_test.php deleted file mode 100644 index effd3ec02..000000000 --- a/tests/codeigniter/helpers/security_helper_test.php +++ /dev/null @@ -1,64 +0,0 @@ -<?php - -class Security_helper_tests extends CI_TestCase { - - function setUp() - { - $this->helper('security'); - $obj = new stdClass; - $obj->security = new Mock_Core_Security(); - $this->ci_instance($obj); - } - - function test_xss_clean() - { - $this->assertEquals('foo', xss_clean('foo')); - - $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", xss_clean("Hello, i try to <script>alert('Hack');</script> your site")); - } - - function test_sanitize_filename() - { - $this->assertEquals('hello.doc', sanitize_filename('hello.doc')); - - $filename = './<!--foo-->'; - $this->assertEquals('foo', sanitize_filename($filename)); - } - - function test_do_hash() - { - $md5 = md5('foo'); - $sha1 = sha1('foo'); - - $algos = hash_algos(); - $algo_results = array(); - foreach ($algos as $k => $v) - { - $algo_results[$v] = hash($v, 'foo'); - } - - $this->assertEquals($sha1, do_hash('foo')); - $this->assertEquals($sha1, do_hash('foo', 'sha1')); - $this->assertEquals($md5, do_hash('foo', 'md5')); - $this->assertEquals($md5, do_hash('foo', 'foobar')); - - // Test each algorithm available to PHP - foreach ($algo_results as $algo => $result) - { - $this->assertEquals($result, do_hash('foo', $algo)); - } - } - - function test_strip_image_tags() - { - $this->assertEquals('http://example.com/spacer.gif', strip_image_tags('http://example.com/spacer.gif')); - - $this->assertEquals('http://example.com/spacer.gif', strip_image_tags('<img src="http://example.com/spacer.gif" alt="Who needs CSS when you have a spacer.gif?" />')); - } - - function test_encode_php_tags() - { - $this->assertEquals('<? echo $foo; ?>', encode_php_tags('<? echo $foo; ?>')); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php deleted file mode 100644 index 9bd1ea816..000000000 --- a/tests/codeigniter/helpers/string_helper_test.php +++ /dev/null @@ -1,148 +0,0 @@ -<?php - -class String_helper_test extends CI_TestCase { - - public function set_up() - { - $this->helper('string'); - } - - public function test_strip_slashes() - { - $expected = array( - "Is your name O'reilly?", - "No, my name is O'connor." - ); - - $str = array( - "Is your name O\'reilly?", - "No, my name is O\'connor." - ); - - $this->assertEquals($expected, strip_slashes($str)); - } - - public function test_trim_slashes() - { - $strs = array( - '//Slashes//\/' => 'Slashes//\\', - '/var/www/html/' => 'var/www/html' - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, trim_slashes($str)); - } - } - - // -------------------------------------------------------------------- - - public function test_strip_quotes() - { - $strs = array( - '"me oh my!"' => 'me oh my!', - "it's a winner!" => 'its a winner!', - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, strip_quotes($str)); - } - } - - // -------------------------------------------------------------------- - - public function test_quotes_to_entities() - { - $strs = array( - '"me oh my!"' => '"me oh my!"', - "it's a winner!" => 'it's a winner!', - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, quotes_to_entities($str)); - } - } - - // -------------------------------------------------------------------- - - public function test_reduce_double_slashes() - { - $strs = array( - 'http://codeigniter.com' => 'http://codeigniter.com', - '//var/www/html/example.com/' => '/var/www/html/example.com/', - '/var/www/html//index.php' => '/var/www/html/index.php' - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, reduce_double_slashes($str)); - } - } - - // -------------------------------------------------------------------- - - public function test_reduce_multiples() - { - $strs = array( - 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy', - 'Ringo, John, Paul,,' => 'Ringo, John, Paul,' - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, reduce_multiples($str)); - } - - $strs = array( - 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy', - 'Ringo, John, Paul,,' => 'Ringo, John, Paul' - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, reduce_multiples($str, ',', TRUE)); - } - } - - // -------------------------------------------------------------------- - - public function test_repeater() - { - $strs = array( - 'a' => 'aaaaaaaaaa', - ' ' => ' ', - '<br>' => '<br><br><br><br><br><br><br><br><br><br>' - - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, repeater($str, 10)); - } - } - - // -------------------------------------------------------------------- - - public function test_random_string() - { - $this->assertEquals(16, strlen(random_string('alnum', 16))); - $this->assertEquals(32, strlen(random_string('unique', 16))); - $this->assertEquals('string', gettype(random_string('numeric', 16))); - } - - // -------------------------------------------------------------------- - - public function test_increment_string() - { - $this->assertEquals('my-test_1', increment_string('my-test')); - $this->assertEquals('my-test-1', increment_string('my-test', '-')); - $this->assertEquals('file_5', increment_string('file_4')); - $this->assertEquals('file-5', increment_string('file-4', '-')); - $this->assertEquals('file-5', increment_string('file-4', '-')); - $this->assertEquals('file-1', increment_string('file', '-', '1')); - $this->assertEquals(124, increment_string('123', '')); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php deleted file mode 100644 index 5be1837b8..000000000 --- a/tests/codeigniter/helpers/text_helper_test.php +++ /dev/null @@ -1,179 +0,0 @@ -<?php - -class Text_helper_test extends CI_TestCase { - - private $_long_string; - - public function set_up() - { - $this->helper('text'); - - $this->_long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.'; - } - - // ------------------------------------------------------------------------ - - public function test_word_limiter() - { - $this->assertEquals('Once upon a time,…', word_limiter($this->_long_string, 4)); - $this->assertEquals('Once upon a time,…', word_limiter($this->_long_string, 4, '…')); - $this->assertEquals('', word_limiter('', 4)); - } - - // ------------------------------------------------------------------------ - - public function test_character_limiter() - { - $this->assertEquals('Once upon a time, a…', character_limiter($this->_long_string, 20)); - $this->assertEquals('Once upon a time, a…', character_limiter($this->_long_string, 20, '…')); - $this->assertEquals('Short', character_limiter('Short', 20)); - $this->assertEquals('Short', character_limiter('Short', 5)); - } - - // ------------------------------------------------------------------------ - - public function test_ascii_to_entities() - { - $strs = array( - '“‘ “testâ€' => '“‘ “test”', - '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '†¥¨ˆøåß∂ƒ©˙∆˚¬' - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, ascii_to_entities($str)); - } - } - - // ------------------------------------------------------------------------ - - public function test_entities_to_ascii() - { - $strs = array( - '“‘ “test”' => '“‘ “testâ€', - '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '†¥¨ˆøåß∂ƒ©˙∆˚¬' - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, entities_to_ascii($str)); - } - } - - // ------------------------------------------------------------------------ - - public function test_convert_accented_characters() - { - if (substr(PHP_VERSION, 0, 3) === '7.4') - { - return $this->markTestSkipped('For some reason all PHP 7.4 instances on GitHub Actions trigger a parse error when foreign_chars.php is loaded'); - } - - $this->ci_vfs_clone('application/config/foreign_chars.php'); - $this->assertEquals('AAAeEEEIIOOEUUUeY', convert_accented_characters('ÀÂÄÈÊËÎÃÔŒÙÛÜŸ')); - $this->assertEquals('a e i o u n ue', convert_accented_characters('á é à ó ú ñ ü')); - } - - // ------------------------------------------------------------------------ - - public function test_censored_words() - { - $censored = array('boob', 'nerd', 'ass', 'fart'); - - $strs = array( - 'Ted bobbled the ball' => 'Ted bobbled the ball', - 'Jake is a nerdo' => 'Jake is a nerdo', - 'The borg will assimilate you' => 'The borg will assimilate you', - 'Did Mary Fart?' => 'Did Mary $*#?', - 'Jake is really a boob' => 'Jake is really a $*#' - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, word_censor($str, $censored, '$*#')); - } - - // test censored words being sent as a string - $this->assertEquals('test', word_censor('test', 'test')); - } - - // ------------------------------------------------------------------------ - - public function test_highlight_code() - { - $expect = "<code><span style=\"color: #000000\">\n<span style=\"color: #0000BB\"><?php var_dump</span><span style=\"color: #007700\">(</span><span style=\"color: #0000BB\">\$this</span><span style=\"color: #007700\">); </span><span style=\"color: #0000BB\">?> </span>\n</span>\n</code>"; - - $this->assertEquals($expect, highlight_code('<?php var_dump($this); ?>')); - } - - // ------------------------------------------------------------------------ - - public function test_highlight_phrase() - { - $strs = array( - 'this is a phrase' => '<mark>this is</mark> a phrase', - 'this is another' => '<mark>this is</mark> another', - 'Gimme a test, Sally' => 'Gimme a test, Sally', - 'Or tell me what this is' => 'Or tell me what <mark>this is</mark>', - '' => '' - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, highlight_phrase($str, 'this is')); - } - - $this->assertEquals('<strong>this is</strong> a strong test', highlight_phrase('this is a strong test', 'this is', '<strong>', '</strong>')); - } - - // ------------------------------------------------------------------------ - - public function test_ellipsize() - { - $strs = array( - '0' => array( - 'this is my string' => '… my string', - "here's another one" => '…nother one', - 'this one is just a bit longer' => '…bit longer', - 'short' => 'short' - ), - '.5' => array( - 'this is my string' => 'this …tring', - "here's another one" => "here'…r one", - 'this one is just a bit longer' => 'this …onger', - 'short' => 'short' - ), - '1' => array( - 'this is my string' => 'this is my…', - "here's another one" => "here's ano…", - 'this one is just a bit longer' => 'this one i…', - 'short' => 'short' - ), - ); - - foreach ($strs as $pos => $s) - { - foreach ($s as $str => $expect) - { - $this->assertEquals($expect, ellipsize($str, 10, $pos)); - } - } - } - - // ------------------------------------------------------------------------ - - public function test_word_wrap() - { - $string = 'Here is a simple string of text that will help us demonstrate this function.'; - $this->assertEquals(substr_count(word_wrap($string, 25), "\n"), 4); - } - - // ------------------------------------------------------------------------ - - public function test_default_word_wrap_charlim() - { - $string = "Here is a longer string of text that will help us demonstrate the default charlim of this function."; - $this->assertEquals(strpos(word_wrap($string), "\n"), 73); - } - -} diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php deleted file mode 100644 index 83a8c0ec2..000000000 --- a/tests/codeigniter/helpers/url_helper_test.php +++ /dev/null @@ -1,89 +0,0 @@ -<?php - -class Url_helper_test extends CI_TestCase { - - public function set_up() - { - $this->helper('url'); - } - - public function test_url_title() - { - $words = array( - 'foo bar /' => 'foo-bar', - '\ testing 12' => 'testing-12' - ); - - foreach ($words as $in => $out) - { - $this->assertEquals($out, url_title($in, 'dash', TRUE)); - } - } - - // -------------------------------------------------------------------- - - public function test_url_title_extra_dashes() - { - $words = array( - '_foo bar_' => 'foo_bar', - '_What\'s wrong with CSS?_' => 'Whats_wrong_with_CSS' - ); - - foreach ($words as $in => $out) - { - $this->assertEquals($out, url_title($in, 'underscore')); - } - } - - // -------------------------------------------------------------------- - - public function test_prep_url() - { - $this->assertEquals('http://codeigniter.com', prep_url('codeigniter.com')); - $this->assertEquals('http://www.codeigniter.com', prep_url('www.codeigniter.com')); - } - - // -------------------------------------------------------------------- - - public function test_auto_link_url() - { - $strings = array( - 'www.codeigniter.com test' => '<a href="http://www.codeigniter.com">www.codeigniter.com</a> test', - 'This is my noreply@codeigniter.com test' => 'This is my noreply@codeigniter.com test', - '<br />www.google.com' => '<br /><a href="http://www.google.com">www.google.com</a>', - 'Download CodeIgniter at www.codeigniter.com. Period test.' => 'Download CodeIgniter at <a href="http://www.codeigniter.com">www.codeigniter.com</a>. Period test.', - 'Download CodeIgniter at www.codeigniter.com, comma test' => 'Download CodeIgniter at <a href="http://www.codeigniter.com">www.codeigniter.com</a>, comma test', - 'This one: ://codeigniter.com must not break this one: http://codeigniter.com' => 'This one: <a href="://codeigniter.com">://codeigniter.com</a> must not break this one: <a href="http://codeigniter.com">http://codeigniter.com</a>', - 'Trailing slash: https://codeigniter.com/ fubar' => 'Trailing slash: <a href="https://codeigniter.com/">https://codeigniter.com/</a> fubar' - ); - - foreach ($strings as $in => $out) - { - $this->assertEquals($out, auto_link($in, 'url')); - } - } - - // -------------------------------------------------------------------- - - public function test_pull_675() - { - $strings = array( - '<br />www.google.com' => '<br /><a href="http://www.google.com">www.google.com</a>', - ); - - foreach ($strings as $in => $out) - { - $this->assertEquals($out, auto_link($in, 'url')); - } - } - - // -------------------------------------------------------------------- - - public function test_issue_5331() - { - $this->assertEquals( - 'this is some text that includes '.safe_mailto('www.email@domain.com').' which is causing an issue', - auto_link('this is some text that includes www.email@domain.com which is causing an issue') - ); - } -} diff --git a/tests/codeigniter/helpers/xml_helper_test.php b/tests/codeigniter/helpers/xml_helper_test.php deleted file mode 100644 index e8cf411da..000000000 --- a/tests/codeigniter/helpers/xml_helper_test.php +++ /dev/null @@ -1,15 +0,0 @@ -<?php - -class Xml_helper_test extends CI_TestCase { - - public function set_up() - { - $this->helper('xml'); - } - - public function test_xml_convert() - { - $this->assertEquals('<tag>my & test - </tag>', xml_convert('<tag>my & test - </tag>')); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/libraries/Calendar_test.php b/tests/codeigniter/libraries/Calendar_test.php deleted file mode 100644 index ad1f45e8c..000000000 --- a/tests/codeigniter/libraries/Calendar_test.php +++ /dev/null @@ -1,222 +0,0 @@ -<?php - -class Calendar_test extends CI_TestCase { - - public function set_up() - { - // Required for get_total_days() - $this->ci_instance_var('load', $this->getMockBuilder('CI_Loader')->setMethods(array('helper'))->getMock()); - - $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load', 'line'))->getMock(); - $lang->expects($this->any())->method('line')->will($this->returnValue(FALSE)); - $this->ci_instance_var('lang', $lang); - - $this->calendar = new CI_Calendar(); - } - - // -------------------------------------------------------------------- - - public function test_initialize() - { - $this->calendar->initialize(array( - 'month_type' => 'short', - 'start_day' => 'monday' - )); - $this->assertEquals('short', $this->calendar->month_type); - $this->assertEquals('monday', $this->calendar->start_day); - } - - // -------------------------------------------------------------------- - - public function test_generate() - { - $no_events = '<table border="0" cellpadding="4" cellspacing="0"> - -<tr> -<th colspan="7">September 2011</th> - -</tr> - -<tr> -<td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td> -</tr> - -<tr> -<td> </td><td> </td><td> </td><td> </td><td>1</td><td>2</td><td>3</td> -</tr> - -<tr> -<td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td> -</tr> - -<tr> -<td>11</td><td>12</td><td>13</td><td>14</td><td>15</td><td>16</td><td>17</td> -</tr> - -<tr> -<td>18</td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td> -</tr> - -<tr> -<td>25</td><td>26</td><td>27</td><td>28</td><td>29</td><td>30</td><td> </td> -</tr> - -</table>'; - - $this->assertEquals($no_events, $this->calendar->generate(2011, 9)); - - $data = array( - 3 => 'http://example.com/news/article/2006/03/', - 7 => 'http://example.com/news/article/2006/07/', - 13 => 'http://example.com/news/article/2006/13/', - 26 => 'http://example.com/news/article/2006/26/' - ); - - $events = '<table border="0" cellpadding="4" cellspacing="0"> - -<tr> -<th colspan="7">September 2011</th> - -</tr> - -<tr> -<td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td> -</tr> - -<tr> -<td> </td><td> </td><td> </td><td> </td><td>1</td><td>2</td><td><a href="http://example.com/news/article/2006/03/">3</a></td> -</tr> - -<tr> -<td>4</td><td>5</td><td>6</td><td><a href="http://example.com/news/article/2006/07/">7</a></td><td>8</td><td>9</td><td>10</td> -</tr> - -<tr> -<td>11</td><td>12</td><td><a href="http://example.com/news/article/2006/13/">13</a></td><td>14</td><td>15</td><td>16</td><td>17</td> -</tr> - -<tr> -<td>18</td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td> -</tr> - -<tr> -<td>25</td><td><a href="http://example.com/news/article/2006/26/">26</a></td><td>27</td><td>28</td><td>29</td><td>30</td><td> </td> -</tr> - -</table>'; - - $this->assertEquals($events, $this->calendar->generate(2011, 9, $data)); - } - - // -------------------------------------------------------------------- - - public function test_get_month_name() - { - $this->calendar->month_type = NULL; - $this->assertEquals('January', $this->calendar->get_month_name('01')); - - $this->calendar->month_type = 'short'; - $this->assertEquals('Jan', $this->calendar->get_month_name('01')); - } - - // -------------------------------------------------------------------- - - public function test_get_day_names() - { - $this->assertEquals(array( - 'Sunday', - 'Monday', - 'Tuesday', - 'Wednesday', - 'Thursday', - 'Friday', - 'Saturday' - ), $this->calendar->get_day_names('long')); - - $this->assertEquals(array( - 'Sun', - 'Mon', - 'Tue', - 'Wed', - 'Thu', - 'Fri', - 'Sat' - ), $this->calendar->get_day_names('short')); - - $this->calendar->day_type = NULL; - - $this->assertEquals(array( - 'Su', - 'Mo', - 'Tu', - 'We', - 'Th', - 'Fr', - 'Sa' - ), $this->calendar->get_day_names()); - } - - // -------------------------------------------------------------------- - - public function test_adjust_date() - { - $this->assertEquals(array('month' => 8, 'year' => 2012), $this->calendar->adjust_date(8, 2012)); - $this->assertEquals(array('month' => 1, 'year' => 2013), $this->calendar->adjust_date(13, 2012)); - } - - // -------------------------------------------------------------------- - - public function test_get_total_days() - { - $this->assertEquals(0, $this->calendar->get_total_days(13, 2012)); - - $this->assertEquals(31, $this->calendar->get_total_days(1, 2012)); - $this->assertEquals(28, $this->calendar->get_total_days(2, 2011)); - $this->assertEquals(29, $this->calendar->get_total_days(2, 2012)); - $this->assertEquals(31, $this->calendar->get_total_days(3, 2012)); - $this->assertEquals(30, $this->calendar->get_total_days(4, 2012)); - $this->assertEquals(31, $this->calendar->get_total_days(5, 2012)); - $this->assertEquals(30, $this->calendar->get_total_days(6, 2012)); - $this->assertEquals(31, $this->calendar->get_total_days(7, 2012)); - $this->assertEquals(31, $this->calendar->get_total_days(8, 2012)); - $this->assertEquals(30, $this->calendar->get_total_days(9, 2012)); - $this->assertEquals(31, $this->calendar->get_total_days(10, 2012)); - $this->assertEquals(30, $this->calendar->get_total_days(11, 2012)); - $this->assertEquals(31, $this->calendar->get_total_days(12, 2012)); - } - - // -------------------------------------------------------------------- - - public function test_default_template() - { - $array = array( - 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">', - 'heading_row_start' => '<tr>', - 'heading_previous_cell' => '<th><a href="{previous_url}"><<</a></th>', - 'heading_title_cell' => '<th colspan="{colspan}">{heading}</th>', - 'heading_next_cell' => '<th><a href="{next_url}">>></a></th>', - 'heading_row_end' => '</tr>', - 'week_row_start' => '<tr>', - 'week_day_cell' => '<td>{week_day}</td>', - 'week_row_end' => '</tr>', - 'cal_row_start' => '<tr>', - 'cal_cell_start' => '<td>', - 'cal_cell_start_today' => '<td>', - 'cal_cell_content' => '<a href="{content}">{day}</a>', - 'cal_cell_content_today' => '<a href="{content}"><strong>{day}</strong></a>', - 'cal_cell_no_content' => '{day}', - 'cal_cell_no_content_today' => '<strong>{day}</strong>', - 'cal_cell_blank' => ' ', - 'cal_cell_end' => '</td>', - 'cal_cell_end_today' => '</td>', - 'cal_row_end' => '</tr>', - 'table_close' => '</table>', - 'cal_cell_start_other' => '<td style="color: #666;">', - 'cal_cell_other' => '{day}', - 'cal_cell_end_other' => '</td>' - ); - - $this->assertEquals($array, $this->calendar->default_template()); - } - -} diff --git a/tests/codeigniter/libraries/Driver_test.php b/tests/codeigniter/libraries/Driver_test.php deleted file mode 100644 index ea5cfa235..000000000 --- a/tests/codeigniter/libraries/Driver_test.php +++ /dev/null @@ -1,180 +0,0 @@ -<?php - -/** - * Driver library base class unit test - */ -class Driver_test extends CI_TestCase { - - private $name; - - /** - * Set up test framework - */ - public function set_up() - { - // Set our subclass prefix - $this->subclass = 'Mock_Libraries_'; - $this->ci_set_config('subclass_prefix', $this->subclass); - - // Mock Loader->get_package_paths - $paths = 'get_package_paths'; - $ldr = $this->getMockBuilder('CI_Loader')->setMethods(array($paths))->getMock(); - $ldr->expects($this->any())->method($paths)->will($this->returnValue(array(APPPATH, BASEPATH))); - $this->ci_instance_var('load', $ldr); - - // Create mock driver library - $this->name = 'Driver'; - $this->lib = new Mock_Libraries_Driver(); - } - - /** - * Test driver child loading - */ - public function test_load_driver() - { - // Create driver file - $driver = 'basic'; - $file = $this->name.'_'.$driver; - $class = 'CI_'.$file; - $prop = 'called'; - $content = '<?php class '.$class.' extends CI_Driver { public $'.$prop.' = FALSE; '. - 'public function decorate($parent) { $this->'.$prop.' = TRUE; } }'; - $this->ci_vfs_create($file, $content, $this->ci_base_root, array('libraries', $this->name, 'drivers')); - - // Make driver valid - $this->lib->driver_list($driver); - - // Load driver - $this->assertNotNull($this->lib->load_driver($driver)); - - // Did lib name get set? - $this->assertEquals($this->name, $this->lib->get_name()); - - // Was driver loaded? - $this->assertObjectHasAttribute($driver, $this->lib); - $this->assertInstanceOf($class, $this->lib->$driver); - $this->assertInstanceOf('CI_Driver', $this->lib->$driver); - - // Was decorate called? - $this->assertObjectHasAttribute($prop, $this->lib->$driver); - $this->assertTrue($this->lib->$driver->$prop); - - // Do we get an error for an invalid driver? - $driver = 'unlisted'; - $this->setExpectedException('RuntimeException', 'CI Error: Invalid driver requested: '.$this->name.'_'.$driver); - $this->lib->load_driver($driver); - } - - /** - * Test loading lowercase from app path - */ - public function test_load_app_driver() - { - // Create driver file - $driver = 'lowpack'; - $file = $this->name.'_'.$driver; - $class = 'CI_'.$file; - $content = '<?php class '.$class.' extends CI_Driver { }'; - $this->ci_vfs_create($file, $content, $this->ci_app_root, - array('libraries', $this->name, 'drivers')); - - // Make valid list - $nodriver = 'absent'; - $this->lib->driver_list(array($driver, $nodriver)); - - // Load driver - $this->assertNotNull($this->lib->load_driver($driver)); - - // Was driver loaded? - $this->assertObjectHasAttribute($driver, $this->lib); - $this->assertInstanceOf($class, $this->lib->$driver); - $this->assertInstanceOf('CI_Driver', $this->lib->$driver); - - // Do we get an error for a non-existent driver? - $this->setExpectedException('RuntimeException', 'CI Error: Unable to load the requested driver: CI_'. - $this->name.'_'.$nodriver); - $this->lib->load_driver($nodriver); - } - - /** - * Test loading driver extension - */ - public function test_load_driver_ext() - { - // Create base file - $driver = 'extend'; - $base = $this->name.'_'.$driver; - $baseclass = 'CI_'.$base; - $content = '<?php class '.$baseclass.' extends CI_Driver { }'; - $this->ci_vfs_create($base, $content, $this->ci_base_root, array('libraries', $this->name, 'drivers')); - - // Create driver file - $class = $this->subclass.$base; - $content = '<?php class '.$class.' extends '.$baseclass.' { }'; - $this->ci_vfs_create($class, $content, $this->ci_app_root, array('libraries', $this->name, 'drivers')); - - // Make valid list - $this->lib->driver_list($driver); - - // Load driver - $this->assertNotNull($this->lib->load_driver($driver)); - - // Was driver loaded? - $this->assertObjectHasAttribute($driver, $this->lib); - $this->assertInstanceOf($class, $this->lib->$driver); - $this->assertInstanceOf($baseclass, $this->lib->$driver); - $this->assertInstanceOf('CI_Driver', $this->lib->$driver); - - // Create driver extension without base - $driver = 'baseless'; - $base = $this->name.'_'.$driver; - $class = $this->subclass.$base; - $content = '<?php class '.$class.' extends CI_Driver { }'; - $this->ci_vfs_create($class, $content, $this->ci_app_root, array('libraries', $this->name, 'drivers')); - $this->lib->driver_list($driver); - - // Do we get an error when base class isn't found? - $this->setExpectedException('RuntimeException', 'CI Error: Unable to load the requested class: CI_'.$base); - $this->lib->load_driver($driver); - } - - /** - * Test decorating driver with parent attributes - */ - public function test_decorate() - { - // Create parent with a method and property to access - $pclass = 'Test_Parent'; - $prop = 'parent_prop'; - $value = 'initial'; - $method = 'parent_func'; - $return = 'func return'; - $code = 'class '.$pclass.' { public $'.$prop.' = \''.$value.'\'; '. - 'public function '.$method.'() { return \''.$return.'\'; } }'; - eval($code); - $parent = new $pclass(); - - // Create child driver to decorate - $class = 'Test_Driver'; - eval('class '.$class.' extends CI_Driver { }'); - $child = new $class(); - - // Decorate child - $child->decorate($parent); - - // Do we get the initial parent property value? - $this->assertEquals($value, $child->$prop); - - // Can we change the parent property? - $newval = 'changed'; - $child->$prop = $newval; - $this->assertEquals($newval, $parent->$prop); - - // Do we get back the updated value? - $this->assertEquals($newval, $child->$prop); - - // Can we call the parent method? - $this->assertEquals($return, $child->$method()); - } - -} diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php deleted file mode 100644 index adbca31b2..000000000 --- a/tests/codeigniter/libraries/Encrypt_test.php +++ /dev/null @@ -1,79 +0,0 @@ -<?php -/** - * @requires extension mcrypt - */ -class Encrypt_test extends CI_TestCase { - - public function set_up() - { - if ( ! extension_loaded('mcrypt')) - { - return; - } - elseif (version_compare(PHP_VERSION, '7.1.0-alpha', '>=')) - { - return $this->markTestSkipped('ext/mcrypt is deprecated since PHP 7.1 and will generate notices here.'); - } - - $this->encrypt = new Mock_Libraries_Encrypt(); - $this->ci_instance_var('encrypt', $this->encrypt); - - $this->ci_set_config('encryption_key', "Encryptin'glike@boss!"); - $this->msg = 'My secret message'; - } - - // -------------------------------------------------------------------- - - public function test_encode() - { - $this->assertNotEquals($this->msg, $this->encrypt->encode($this->msg)); - } - - // -------------------------------------------------------------------- - - public function test_decode() - { - $encoded_msg = $this->encrypt->encode($this->msg); - $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg)); - } - - // -------------------------------------------------------------------- - - public function test_optional_key() - { - $key = 'Ohai!ù0129°03182%HD1892P0'; - $encoded_msg = $this->encrypt->encode($this->msg, $key); - $this->assertEquals($this->msg, $this->encrypt->decode($encoded_msg, $key)); - } - - // -------------------------------------------------------------------- - - public function test_default_cipher() - { - $this->assertEquals('rijndael-256', $this->encrypt->get_cipher()); - } - - // -------------------------------------------------------------------- - - public function test_set_cipher() - { - $this->encrypt->set_cipher(MCRYPT_BLOWFISH); - $this->assertEquals('blowfish', $this->encrypt->get_cipher()); - } - - // -------------------------------------------------------------------- - - public function test_default_mode() - { - $this->assertEquals('cbc', $this->encrypt->get_mode()); - } - - // -------------------------------------------------------------------- - - public function test_set_mode() - { - $this->encrypt->set_mode(MCRYPT_MODE_CFB); - $this->assertEquals('cfb', $this->encrypt->get_mode()); - } - -} diff --git a/tests/codeigniter/libraries/Encryption_test.php b/tests/codeigniter/libraries/Encryption_test.php deleted file mode 100644 index 68bc3d804..000000000 --- a/tests/codeigniter/libraries/Encryption_test.php +++ /dev/null @@ -1,400 +0,0 @@ -<?php - -class Encryption_test extends CI_TestCase { - - public function set_up() - { - $this->encryption = new Mock_Libraries_Encryption(); - } - - // -------------------------------------------------------------------- - - /** - * __construct test - * - * Covers behavior with $config['encryption_key'] set or not - */ - public function test___construct() - { - // Assume no configuration from set_up() - $this->assertNull($this->encryption->get_key()); - - // Try with an empty value - $this->ci_set_config('encryption_key'); - $this->encrypt = new Mock_Libraries_Encryption(); - $this->assertNull($this->encrypt->get_key()); - - $this->ci_set_config('encryption_key', str_repeat("\x0", 16)); - $this->encrypt = new Mock_Libraries_Encryption(); - $this->assertEquals(str_repeat("\x0", 16), $this->encrypt->get_key()); - } - - // -------------------------------------------------------------------- - - /** - * hkdf() test - * - * Applies test vectors described in Appendix A(1-3) RFC5869. - * Described vectors 4-7 SHA-1, which we don't support and are - * therefore excluded. - * - * Because our implementation is a single method instead of being - * split into hkdf_extract() and hkdf_expand(), we cannot test for - * the PRK value. As long as the OKM is correct though, it's fine. - * - * @link https://tools.ietf.org/rfc/rfc5869.txt - */ - public function test_hkdf() - { - $vectors = array( - // A.1: Basic test case with SHA-256 - array( - 'digest' => 'sha256', - 'ikm' => "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", - 'salt' => "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c", - 'length' => 42, - 'info' => "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9", - // 'prk' => "\x07\x77\x09\x36\x2c\x2e\x32\xdf\x0d\xdc\x3f\x0d\xc4\x7b\xba\x63\x90\xb6\xc7\x3b\xb5\x0f\x9c\x31\x22\xec\x84\x4a\xd7\xc2\xb3\xe5", - 'okm' => "\x3c\xb2\x5f\x25\xfa\xac\xd5\x7a\x90\x43\x4f\x64\xd0\x36\x2f\x2a\x2d\x2d\x0a\x90\xcf\x1a\x5a\x4c\x5d\xb0\x2d\x56\xec\xc4\xc5\xbf\x34\x00\x72\x08\xd5\xb8\x87\x18\x58\x65" - ), - // A.2: Test with SHA-256 and longer inputs/outputs - array( - 'digest' => 'sha256', - 'ikm' => "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f", - 'salt' => "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf", - 'length' => 82, - 'info' => "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", - // 'prk' => "\x06\xa6\xb8\x8c\x58\x53\x36\x1a\x06\x10\x4c\x9c\xeb\x35\xb4\x5c\xef\x76\x00\x14\x90\x46\x71\x01\x4a\x19\x3f\x40\xc1\x5f\xc2\x44", - 'okm' => "\xb1\x1e\x39\x8d\xc8\x03\x27\xa1\xc8\xe7\xf7\x8c\x59\x6a\x49\x34\x4f\x01\x2e\xda\x2d\x4e\xfa\xd8\xa0\x50\xcc\x4c\x19\xaf\xa9\x7c\x59\x04\x5a\x99\xca\xc7\x82\x72\x71\xcb\x41\xc6\x5e\x59\x0e\x09\xda\x32\x75\x60\x0c\x2f\x09\xb8\x36\x77\x93\xa9\xac\xa3\xdb\x71\xcc\x30\xc5\x81\x79\xec\x3e\x87\xc1\x4c\x01\xd5\xc1\xf3\x43\x4f\x1d\x87", - ), - // A.3: Test with SHA-256 and zero-length salt/info - array( - 'digest' => 'sha256', - 'ikm' => "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", - 'salt' => '', - 'length' => 42, - 'info' => '', - // 'prk' => "\x19\xef\x24\xa3\x2c\x71\x7b\x16\x7f\x33\xa9\x1d\x6f\x64\x8b\xdf\x96\x59\x67\x76\xaf\xdb\x63\x77\xac\x43\x4c\x1c\x29\x3c\xcb\x04", - 'okm' => "\x8d\xa4\xe7\x75\xa5\x63\xc1\x8f\x71\x5f\x80\x2a\x06\x3c\x5a\x31\xb8\xa1\x1f\x5c\x5e\xe1\x87\x9e\xc3\x45\x4e\x5f\x3c\x73\x8d\x2d\x9d\x20\x13\x95\xfa\xa4\xb6\x1a\x96\xc8", - ) - ); - - foreach ($vectors as $test) - { - $this->assertEquals( - $test['okm'], - $this->encryption->hkdf( - $test['ikm'], - $test['digest'], - $test['salt'], - $test['length'], - $test['info'] - ) - ); - } - - // Test default length, it must match the digest size - $hkdf_result = $this->encryption->hkdf('foobar', 'sha512'); - $this->assertEquals( - 64, - defined('MB_OVERLOAD_STRING') - ? mb_strlen($hkdf_result, '8bit') - : strlen($hkdf_result) - ); - - // Test maximum length (RFC5869 says that it must be up to 255 times the digest size) - $hkdf_result = $this->encryption->hkdf('foobar', 'sha384', NULL, 48 * 255); - $this->assertEquals( - 12240, - defined('MB_OVERLOAD_STRING') - ? mb_strlen($hkdf_result, '8bit') - : strlen($hkdf_result) - ); - $this->assertFalse($this->encryption->hkdf('foobar', 'sha224', NULL, 28 * 255 + 1)); - - // CI-specific test for an invalid digest - $this->assertFalse($this->encryption->hkdf('fobar', 'sha1')); - } - - // -------------------------------------------------------------------- - - /** - * _get_params() test - */ - public function test__get_params() - { - $key = str_repeat("\x0", 16); - - // Invalid custom parameters - $params = array( - // No cipher, mode or key - array('cipher' => 'aes-128', 'mode' => 'cbc'), - array('cipher' => 'aes-128', 'key' => $key), - array('mode' => 'cbc', 'key' => $key), - // No HMAC key or not a valid digest - array('cipher' => 'aes-128', 'mode' => 'cbc', 'key' => $key), - array('cipher' => 'aes-128', 'mode' => 'cbc', 'key' => $key, 'hmac_digest' => 'sha1', 'hmac_key' => $key), - // Invalid mode - array('cipher' => 'aes-128', 'mode' => 'foo', 'key' => $key, 'hmac_digest' => 'sha256', 'hmac_key' => $key) - ); - - for ($i = 0, $c = count($params); $i < $c; $i++) - { - $this->assertFalse($this->encryption->__get_params($params[$i])); - } - - // Valid parameters - $params = array( - 'cipher' => 'aes-128', - 'mode' => 'cbc', - 'key' => str_repeat("\x0", 16), - 'hmac_key' => str_repeat("\x0", 16) - ); - - $this->assertEquals('array', gettype($this->encryption->__get_params($params))); - - $params['base64'] = TRUE; - $params['hmac_digest'] = 'sha512'; - - // Including all parameters - $params = array( - 'cipher' => 'aes-128', - 'mode' => 'cbc', - 'key' => str_repeat("\x0", 16), - 'raw_data' => TRUE, - 'hmac_key' => str_repeat("\x0", 16), - 'hmac_digest' => 'sha256' - ); - - $output = $this->encryption->__get_params($params); - unset($output['handle'], $output['cipher'], $params['raw_data'], $params['cipher']); - $params['base64'] = FALSE; - $this->assertEquals($params, $output); - - // HMAC disabled - unset($params['hmac_key'], $params['hmac_digest']); - $params['hmac'] = $params['raw_data'] = FALSE; - $params['cipher'] = 'aes-128'; - $output = $this->encryption->__get_params($params); - unset($output['handle'], $output['cipher'], $params['hmac'], $params['raw_data'], $params['cipher']); - $params['base64'] = TRUE; - $params['hmac_digest'] = $params['hmac_key'] = NULL; - $this->assertEquals($params, $output); - } - - // -------------------------------------------------------------------- - - /** - * initialize(), encrypt(), decrypt() test - * - * Testing the three methods separately is not realistic as they are - * designed to work together. A more thorough test for initialize() - * though is the OpenSSL/MCrypt compatibility test. - * - * @depends test_hkdf - * @depends test__get_params - */ - public function test_initialize_encrypt_decrypt() - { - $message = 'This is a plain-text message.'; - $key = "\xd0\xc9\x08\xc4\xde\x52\x12\x6e\xf8\xcc\xdb\x03\xea\xa0\x3a\x5c"; - - // Default state (AES-128/Rijndael-128 in CBC mode) - $this->encryption->initialize(array('key' => $key)); - - // Was the key properly set? - $this->assertEquals($key, $this->encryption->get_key()); - - $this->assertEquals($message, $this->encryption->decrypt($this->encryption->encrypt($message))); - - // Try DES in ECB mode, just for the sake of changing stuff - $this->encryption->initialize(array('cipher' => 'des', 'mode' => 'ecb', 'key' => substr($key, 0, 8))); - $this->assertEquals($message, $this->encryption->decrypt($this->encryption->encrypt($message))); - } - - // -------------------------------------------------------------------- - - /** - * encrypt(), decrypt test with custom parameters - * - * @depends test__get_params - */ - public function test_encrypt_decrypt_custom() - { - $message = 'Another plain-text message.'; - - // A random invalid parameter - $this->assertFalse($this->encryption->encrypt($message, array('foo'))); - $this->assertFalse($this->encryption->decrypt($message, array('foo'))); - - // No HMAC, binary output - $params = array( - 'cipher' => 'tripledes', - 'mode' => 'cfb', - 'key' => str_repeat("\x1", 16), - 'base64' => FALSE, - 'hmac' => FALSE - ); - - $ciphertext = $this->encryption->encrypt($message, $params); - - $this->assertEquals($message, $this->encryption->decrypt($ciphertext, $params)); - } - - // -------------------------------------------------------------------- - - /** - * _mcrypt_get_handle() test - */ - public function test__mcrypt_get_handle() - { - if ($this->encryption->drivers['mcrypt'] === FALSE) - { - return $this->markTestSkipped('Cannot test MCrypt because it is not available.'); - } - elseif (version_compare(PHP_VERSION, '7.1.0-alpha', '>=')) - { - return $this->markTestSkipped('ext/mcrypt is deprecated since PHP 7.1 and will generate notices here.'); - } - - $this->assertInternalType('resource', $this->encryption->__driver_get_handle('mcrypt', 'rijndael-128', 'cbc')); - } - - // -------------------------------------------------------------------- - - /** - * _openssl_get_handle() test - */ - public function test__openssl_mcrypt_get_handle() - { - if ($this->encryption->drivers['openssl'] === FALSE) - { - return $this->markTestSkipped('Cannot test OpenSSL because it is not available.'); - } - - $this->assertEquals('aes-128-cbc', $this->encryption->__driver_get_handle('openssl', 'aes-128', 'cbc')); - $this->assertEquals('rc4-40', $this->encryption->__driver_get_handle('openssl', 'rc4-40', 'stream')); - } - - // -------------------------------------------------------------------- - - /** - * OpenSSL/MCrypt portability test - * - * Amongst the obvious stuff, _cipher_alias() is also tested here. - */ - public function test_portability() - { - if ( ! $this->encryption->drivers['mcrypt'] OR ! $this->encryption->drivers['openssl']) - { - $this->markTestSkipped('Both MCrypt and OpenSSL support are required for portability tests.'); - return; - } - elseif (version_compare(PHP_VERSION, '7.1.0-alpha', '>=')) - { - return $this->markTestSkipped('ext/mcrypt is deprecated since PHP 7.1 and will generate notices here.'); - } - - $message = 'This is a message encrypted via MCrypt and decrypted via OpenSSL, or vice-versa.'; - - // Format is: <Cipher name>, <Cipher mode>, <Key size> - $portable = array( - array('aes-128', 'cbc', 16), - array('aes-128', 'cfb', 16), - array('aes-128', 'cfb8', 16), - array('aes-128', 'ofb', 16), - array('aes-128', 'ecb', 16), - array('aes-128', 'ctr', 16), - array('aes-192', 'cbc', 24), - array('aes-192', 'cfb', 24), - array('aes-192', 'cfb8', 24), - array('aes-192', 'ofb', 24), - array('aes-192', 'ecb', 24), - array('aes-192', 'ctr', 24), - array('aes-256', 'cbc', 32), - array('aes-256', 'cfb', 32), - array('aes-256', 'cfb8', 32), - array('aes-256', 'ofb', 32), - array('aes-256', 'ecb', 32), - array('aes-256', 'ctr', 32), - array('des', 'cbc', 7), - array('des', 'cfb', 7), - array('des', 'cfb8', 7), - array('des', 'ofb', 7), - array('des', 'ecb', 7), - array('tripledes', 'cbc', 7), - array('tripledes', 'cfb', 7), - array('tripledes', 'cfb8', 7), - array('tripledes', 'ofb', 7), - array('tripledes', 'cbc', 14), - array('tripledes', 'cfb', 14), - array('tripledes', 'cfb8', 14), - array('tripledes', 'ofb', 14), - array('tripledes', 'cbc', 21), - array('tripledes', 'cfb', 21), - array('tripledes', 'cfb8', 21), - array('tripledes', 'ofb', 21), - array('blowfish', 'cbc', 16), - array('blowfish', 'cfb', 16), - array('blowfish', 'ofb', 16), - array('blowfish', 'ecb', 16), - array('blowfish', 'cbc', 56), - array('blowfish', 'cfb', 56), - array('blowfish', 'ofb', 56), - array('blowfish', 'ecb', 56), - array('cast5', 'cbc', 11), - array('cast5', 'cfb', 11), - array('cast5', 'ofb', 11), - array('cast5', 'ecb', 11), - array('cast5', 'cbc', 16), - array('cast5', 'cfb', 16), - array('cast5', 'ofb', 16), - array('cast5', 'ecb', 16), - array('rc4', 'stream', 5), - array('rc4', 'stream', 8), - array('rc4', 'stream', 16), - array('rc4', 'stream', 32), - array('rc4', 'stream', 64), - array('rc4', 'stream', 128), - array('rc4', 'stream', 256) - ); - $driver_index = array('mcrypt', 'openssl'); - - foreach ($portable as &$test) - { - // Add some randomness to the selected driver - $driver = mt_rand(0,1); - $params = array( - 'driver' => $driver_index[$driver], - 'cipher' => $test[0], - 'mode' => $test[1], - 'key' => openssl_random_pseudo_bytes($test[2]) - ); - - $this->encryption->initialize($params); - $ciphertext = $this->encryption->encrypt($message); - - $driver = (int) ! $driver; - $params['driver'] = $driver_index[$driver]; - - $this->encryption->initialize($params); - $this->assertEquals($message, $this->encryption->decrypt($ciphertext)); - } - } - - // -------------------------------------------------------------------- - - /** - * __get() test - */ - public function test_magic_get() - { - $this->assertNull($this->encryption->foo); - $this->assertEquals(array('mcrypt', 'openssl'), array_keys($this->encryption->drivers)); - - // 'stream' mode is translated into an empty string for OpenSSL - $this->encryption->initialize(array('cipher' => 'rc4', 'mode' => 'stream')); - $this->assertEquals('stream', $this->encryption->mode); - } - -} diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php deleted file mode 100644 index 6872b3abd..000000000 --- a/tests/codeigniter/libraries/Form_validation_test.php +++ /dev/null @@ -1,629 +0,0 @@ -<?php - -class Form_validation_test extends CI_TestCase { - - public function set_up() - { - $_SERVER['REQUEST_METHOD'] = 'POST'; - - // Create a mock loader since load->helper() looks in the wrong directories for unit tests, - // We'll use CI_TestCase->helper() instead - $loader = $this->getMockBuilder('CI_Loader')->setMethods(array('helper'))->getMock(); - - // Same applies for lang - $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock(); - - $this->ci_set_config('charset', 'UTF-8'); - $utf8 = new Mock_Core_Utf8(); - $security = new Mock_Core_Security(); - $input = new Mock_Core_Input($security, $utf8); - - $this->ci_instance_var('lang', $lang); - $this->ci_instance_var('load', $loader); - $this->ci_instance_var('input', $input); - - $this->lang('form_validation'); - $this->helper('form'); - - $this->form_validation = new CI_Form_validation(); - } - - public function test_empty_array_input() - { - $this->assertFalse( - $this->run_rules( - array(array('field' => 'foo', 'label' => 'Foo Label', 'rules' => 'required')), - array('foo' => array()) - ) - ); - } - - public function test_rule_required() - { - $rules = array(array('field' => 'foo', 'label' => 'Foo', 'rules' => 'is_numeric')); - - // Empty, not required - $this->assertTrue($this->run_rules($rules, array('foo' => ''))); - - - // Not required, but also not empty - $this->assertTrue($this->run_rules($rules, array('foo' => '123'))); - $this->assertFalse($this->run_rules($rules, array('foo' => 'bar'))); - - // Required variations - $rules[0]['rules'] .= '|required'; - $this->assertTrue($this->run_rules($rules, array('foo' => '123'))); - $this->assertFalse($this->run_rules($rules, array('foo' => ''))); - $this->assertFalse($this->run_rules($rules, array('foo' => ' '))); - $this->assertFalse($this->run_rules($rules, array('foo' => 'bar'))); - } - - public function test_rule_matches() - { - $rules = array( - array('field' => 'foo', 'label' => 'label', 'rules' => 'required'), - array('field' => 'bar', 'label' => 'label2', 'rules' => 'matches[foo]') - ); - $values_base = array('foo' => 'sample'); - - $this->assertTrue($this->run_rules($rules, array_merge($values_base, array('bar' => 'sample')))); - - $this->assertFalse($this->run_rules($rules, array_merge($values_base, array('bar' => '')))); - $this->assertFalse($this->run_rules($rules, array_merge($values_base, array('bar' => 'Sample')))); - $this->assertFalse($this->run_rules($rules, array_merge($values_base, array('bar' => ' sample')))); - } - - public function test_rule_differs() - { - $rules = array( - array('field' => 'foo', 'label' => 'label', 'rules' => 'required'), - array('field' => 'bar', 'label' => 'label2', 'rules' => 'differs[foo]') - ); - $values_base = array('foo' => 'sample'); - - $this->assertTrue($this->run_rules($rules, array_merge($values_base, array('bar' => 'does_not_match')))); - $this->assertTrue($this->run_rules($rules, array_merge($values_base, array('bar' => 'Sample')))); - $this->assertTrue($this->run_rules($rules, array_merge($values_base, array('bar' => ' sample')))); - - $this->assertFalse($this->run_rules($rules, array_merge($values_base, array('bar' => 'sample')))); - } - - public function test_rule_min_length() - { - $this->assertTrue($this->form_validation->min_length('12345', '5')); - $this->assertTrue($this->form_validation->min_length('test', '0')); - - $this->assertFalse($this->form_validation->min_length('123', '4')); - $this->assertFalse($this->form_validation->min_length('should_fail', 'A')); - $this->assertFalse($this->form_validation->min_length('', '4')); - } - - public function test_rule_max_length() - { - $this->assertTrue($this->form_validation->max_length('', '4')); - $this->assertTrue($this->form_validation->max_length('1234', '4')); - - $this->assertFalse($this->form_validation->max_length('12345', '4')); - $this->assertFalse($this->form_validation->max_length('should_fail', 'A')); - } - - public function test_rule_exact_length() - { - $this->assertTrue($this->form_validation->exact_length('1234', '4')); - - $this->assertFalse($this->form_validation->exact_length('', '3')); - $this->assertFalse($this->form_validation->exact_length('12345', '4')); - $this->assertFalse($this->form_validation->exact_length('123', '4')); - $this->assertFalse($this->form_validation->exact_length('should_fail', 'A')); - } - - public function test_rule_greater_than() - { - $this->assertTrue($this->form_validation->greater_than('-10', '-11')); - $this->assertTrue($this->form_validation->greater_than('10', '9')); - - $this->assertFalse($this->form_validation->greater_than('10', '10')); - $this->assertFalse($this->form_validation->greater_than('10', 'a')); - $this->assertFalse($this->form_validation->greater_than('10a', '10')); - } - - public function test_rule_greater_than_equal_to() - { - $this->assertTrue($this->form_validation->greater_than_equal_to('0', '0')); - $this->assertTrue($this->form_validation->greater_than_equal_to('1', '0')); - - $this->assertFalse($this->form_validation->greater_than_equal_to('-1', '0')); - $this->assertFalse($this->form_validation->greater_than_equal_to('10a', '0')); - } - - public function test_rule_less_than() - { - $this->assertTrue($this->form_validation->less_than('4', '5')); - $this->assertTrue($this->form_validation->less_than('-1', '0')); - - $this->assertFalse($this->form_validation->less_than('4', '4')); - $this->assertFalse($this->form_validation->less_than('10a', '5')); - } - - public function test_rule_less_than_equal_to() - { - $this->assertTrue($this->form_validation->less_than_equal_to('-1', '0')); - $this->assertTrue($this->form_validation->less_than_equal_to('-1', '-1')); - $this->assertTrue($this->form_validation->less_than_equal_to('4', '4')); - - $this->assertFalse($this->form_validation->less_than_equal_to('0', '-1')); - $this->assertFalse($this->form_validation->less_than_equal_to('10a', '0')); - } - - public function test_rule_in_list() - { - $this->assertTrue($this->form_validation->in_list('red', 'red,Blue,123')); - $this->assertTrue($this->form_validation->in_list('Blue', 'red,Blue,123')); - $this->assertTrue($this->form_validation->in_list('123', 'red,Blue,123')); - - $this->assertFalse($this->form_validation->in_list('Red', 'red,Blue,123')); - $this->assertFalse($this->form_validation->in_list(' red', 'red,Blue,123')); - $this->assertFalse($this->form_validation->in_list('1234', 'red,Blue,123')); - } - - public function test_rule_alpha() - { - $this->assertTrue($this->form_validation->alpha('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ')); - - $this->assertFalse($this->form_validation->alpha('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ ')); - $this->assertFalse($this->form_validation->alpha('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ1')); - $this->assertFalse($this->form_validation->alpha('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ*')); - } - - public function test_rule_alpha_numeric() - { - $this->assertTrue($this->form_validation->alpha_numeric('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ0123456789')); - - $this->assertFalse($this->form_validation->alpha_numeric('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ0123456789\ ')); - $this->assertFalse($this->form_validation->alpha_numeric('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ0123456789_')); - } - - public function test_rule_alpha_numeric_spaces() - { - $this->assertTrue($this->form_validation->alpha_numeric_spaces(' abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ0123456789')); - - $this->assertFalse($this->form_validation->alpha_numeric_spaces(' abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ0123456789_')); - } - - public function test_rule_alpha_dash() - { - $this->assertTrue($this->form_validation->alpha_dash('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ0123456789-_')); - - $this->assertFalse($this->form_validation->alpha_dash('abcdefghijklmnopqrstuvwxyzABCDEFGHLIJKLMNOPQRSTUVWXYZ0123456789-_\ ')); - } - - public function test_rule_numeric() - { - $this->assertTrue($this->form_validation->numeric('0')); - $this->assertTrue($this->form_validation->numeric('12314')); - $this->assertTrue($this->form_validation->numeric('-42')); - - $this->assertFalse($this->form_validation->numeric('123a')); - $this->assertFalse($this->form_validation->numeric('--1')); - } - - public function test_rule_integer() - { - $this->assertTrue($this->form_validation->integer('0')); - $this->assertTrue($this->form_validation->integer('42')); - $this->assertTrue($this->form_validation->integer('-1')); - - $this->assertFalse($this->form_validation->integer('124a')); - $this->assertFalse($this->form_validation->integer('1.9')); - $this->assertFalse($this->form_validation->integer('--1')); - } - - public function test_rule_decimal() - { - $this->assertTrue($this->form_validation->decimal('1.0')); - $this->assertTrue($this->form_validation->decimal('-0.98')); - - $this->assertFalse($this->form_validation->decimal('0')); - $this->assertFalse($this->form_validation->decimal('1.0a')); - $this->assertFalse($this->form_validation->decimal('-i')); - $this->assertFalse($this->form_validation->decimal('--1')); - } - - public function test_rule_is_natural() - { - $this->assertTrue($this->form_validation->is_natural('0')); - $this->assertTrue($this->form_validation->is_natural('12')); - - $this->assertFalse($this->form_validation->is_natural('42a')); - $this->assertFalse($this->form_validation->is_natural('-1')); - } - - public function test_rule_is_natural_no_zero() - { - $this->assertTrue($this->form_validation->is_natural_no_zero('42')); - - $this->assertFalse($this->form_validation->is_natural_no_zero('0')); - $this->assertFalse($this->form_validation->is_natural_no_zero('42a')); - $this->assertFalse($this->form_validation->is_natural_no_zero('-1')); - } - - public function test_rule_valid_url() - { - $this->assertTrue($this->form_validation->valid_url('www.codeigniter.com')); - $this->assertTrue($this->form_validation->valid_url('http://codeigniter.com')); - - // https://bugs.php.net/bug.php?id=51192 - $this->assertTrue($this->form_validation->valid_url('http://accept-dashes.tld')); - $this->assertFalse($this->form_validation->valid_url('http://reject_underscores.tld')); - - // https://github.com/bcit-ci/CodeIgniter/issues/4415 - $this->assertTrue($this->form_validation->valid_url('http://[::1]/ipv6')); - - // URI scheme case-sensitivity: https://github.com/bcit-ci/CodeIgniter/pull/4758 - $this->assertTrue($this->form_validation->valid_url('HtTp://127.0.0.1/')); - - // https://github.com/bcit-ci/CodeIgniter/issues/5755 - $this->assertFalse($this->form_validation->valid_url('1')); - - $this->assertFalse($this->form_validation->valid_url('htt://www.codeIgniter.com')); - $this->assertFalse($this->form_validation->valid_url('')); - $this->assertFalse($this->form_validation->valid_url('code igniter')); - } - - public function test_rule_valid_email() - { - $this->assertTrue($this->form_validation->valid_email('email@sample.com')); - $this->assertFalse($this->form_validation->valid_email('email@sample.com foo bar')); - $this->assertFalse($this->form_validation->valid_email('valid_email', '@sample.com')); - } - - public function test_rule_valid_emails() - { - $this->assertTrue($this->form_validation->valid_emails('1@sample.com,2@sample.com')); - $this->assertTrue($this->form_validation->valid_emails('email@sample.com')); - - $this->assertFalse($this->form_validation->valid_emails('valid_email', '@sample.com')); - $this->assertFalse($this->form_validation->valid_emails('@sample.com,2@sample.com,validemail@email.ca')); - } - - public function test_rule_valid_ip() - { - $this->assertTrue($this->form_validation->valid_ip('127.0.0.1')); - $this->assertTrue($this->form_validation->valid_ip('127.0.0.1', 'ipv4')); - $this->assertTrue($this->form_validation->valid_ip('2001:0db8:85a3:0000:0000:8a2e:0370:7334')); - $this->assertTrue($this->form_validation->valid_ip('2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'ipv6')); - - $this->assertFalse($this->form_validation->valid_ip('2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'ipv4')); - $this->assertFalse($this->form_validation->valid_ip('127.0.0.1', 'ipv6')); - $this->assertFalse($this->form_validation->valid_ip('H001:0db8:85a3:0000:0000:8a2e:0370:7334')); - $this->assertFalse($this->form_validation->valid_ip('127.0.0.259')); - } - - public function test_rule_valid_base64() - { - $this->assertTrue($this->form_validation->valid_base64(base64_encode('string'))); - - $this->assertFalse($this->form_validation->valid_base64('FA08GG')); - } - - public function test_set_data() - { - $data = array('field' => 'some_data'); - $this->form_validation->set_data($data); - $this->form_validation->set_rules('field', 'label', 'required'); - $this->assertTrue($this->form_validation->run()); - - // Test with empty array - $_POST = array(); - $this->form_validation->reset_validation(); - $data = array('field' => 'some_data'); - $this->form_validation->set_data($data); - // This should do nothing. Old data will still be used - $this->form_validation->set_data(array()); - $this->form_validation->set_rules('field', 'label', 'required'); - $this->assertTrue($this->form_validation->run()); - } - - public function test_set_message() - { - $err_message = 'What a terrible error!'; - $rules = array( - array( - 'field' => 'req_field', - 'label' => 'label', - 'rules' => 'required' - ) - ); - $errorless_data = array('req_field' => 'some text'); - $erroneous_data = array('req_field' => ''); - - $this->form_validation->set_message('required', $err_message); - $this->form_validation->set_data($erroneous_data); - $this->form_validation->set_rules($rules); - $this->form_validation->run(); - $this->assertEquals('<p>'.$err_message.'</p>', $this->form_validation->error('req_field')); - - $this->form_validation->reset_validation(); - $this->form_validation->set_message('required', $err_message); - $this->form_validation->set_data($errorless_data); - $this->form_validation->set_rules($rules); - $this->form_validation->run(); - $this->assertEquals('', $this->form_validation->error('req_field')); - } - - public function test_set_error_delimiters() - { - $prefix = '<div class="error">'; - $suffix = '</div>'; - $this->form_validation->set_error_delimiters($prefix, $suffix); - $this->form_validation->set_rules('foo', 'label', 'required'); - $_POST = array('foo' => ''); - $this->form_validation->run(); - $error_msg = $this->form_validation->error('foo'); - - $this->assertStringStartsWith($prefix, $error_msg); - $this->assertTrue(strrpos($error_msg, $suffix, -strlen($suffix)) === (strlen($error_msg) - strlen($suffix))); - - $_POST = array(); - } - - public function test_error_array() - { - $error_message = 'What a terrible error!'; - $this->form_validation->set_message('required', $error_message); - $this->form_validation->set_rules('foo', 'label', 'required'); - $_POST = array('foo' => ''); - $this->form_validation->run(); - $error_array = $this->form_validation->error_array(); - $this->assertEquals($error_message, $error_array['foo']); - - $_POST = array(); - } - - public function test_error_string() - { - $error_message = 'What a terrible error!'; - $prefix_default = '<foo>'; - $suffix_default = '</foo>'; - $prefix_test = '<bar>'; - $suffix_test = '</bar>'; - $this->form_validation->set_error_delimiters($prefix_default, $suffix_default); - $this->form_validation->set_message('required', $error_message); - $this->form_validation->set_rules('foo', 'label', 'required'); - $_POST = array('foo' => ''); - $this->form_validation->run(); - - $this->assertEquals($prefix_default.$error_message.$suffix_default."\n", $this->form_validation->error_string()); - $this->assertEquals($prefix_test.$error_message.$suffix_default."\n", $this->form_validation->error_string($prefix_test, '')); - $this->assertEquals($prefix_default.$error_message.$suffix_test."\n", $this->form_validation->error_string('', $suffix_test)); - $this->assertEquals($prefix_test.$error_message.$suffix_test."\n", $this->form_validation->error_string($prefix_test, $suffix_test)); - - $this->form_validation->reset_validation(); - $this->form_validation->set_rules('foo', 'label', 'required'); - $_POST = array('foo' => 'bar'); - $this->form_validation->run(); - $this->assertEquals('', $this->form_validation->error_string()); - - $_POST = array(); - } - - public function test_run() - { - // form_validation->run() is tested in many of the other unit tests - // This test will only test run(group='') when group is not empty - $config = array( - 'pass' => array( - array( - 'field' => 'username', - 'label' => 'user', - 'rules' => 'alpha_numeric' - ) - ), - 'fail' => array( - array( - 'field' => 'username', - 'label' => 'user', - 'rules' => 'alpha' - ) - ) - ); - $_POST = array('username' => 'foo42'); - $form_validation = new CI_Form_validation($config); - $this->assertTrue($form_validation->run('pass')); - - $form_validation = new CI_Form_validation($config); - $this->assertFalse($form_validation->run('fail')); - - $_POST = array(); - } - - public function test_has_rule() - { - $this->form_validation->set_rules('foo', 'label', 'required'); - - $this->assertTrue($this->form_validation->has_rule('foo')); - $this->assertFalse($this->form_validation->has_rule('bar')); - } - - public function test_set_value() - { - $default = 'default'; - $this->form_validation->set_rules('foo', 'label', 'required'); - $this->form_validation->set_rules('bar[]', 'label', 'required'); - - // No post data yet: should return the default value provided - $this->assertEquals($default, $this->form_validation->set_value('foo', $default)); - $_POST = array('foo' => 'foo', 'bar' => array('bar1', 'bar2')); - $this->form_validation->run(); - $this->assertEquals('foo', $this->form_validation->set_value('foo', $default)); - $this->assertEquals('bar1', $this->form_validation->set_value('bar[]', $default)); - $this->assertEquals('bar2', $this->form_validation->set_value('bar[]', $default)); - - $_POST = array(); - } - - public function test_set_select() - { - // Test 1: No options selected - $this->form_validation->run(); - - $this->assertEquals('', $this->form_validation->set_select('select', 'foo')); - $this->assertEquals(' selected="selected"', $this->form_validation->set_select('select', 'bar', TRUE)); - - // Test 2: 1 option selected - $this->form_validation->reset_validation(); - $this->form_validation->set_rules('select', 'label', 'alpha_numeric'); - $_POST = array('select' => 'foo'); - $this->form_validation->run(); - - $this->assertEquals(' selected="selected"', $this->form_validation->set_select('select', 'foo')); - $this->assertEquals(' selected="selected"', $this->form_validation->set_select('select', 'foo', TRUE)); - $this->assertEquals('', $this->form_validation->set_select('select', 'bar')); - $this->assertEquals('', $this->form_validation->set_select('select', 'bar', TRUE)); - - // Test 3: Multiple options selected - $this->form_validation->reset_validation(); - $this->form_validation->set_rules('select[]', 'label', 'alpha_numeric'); - $_POST = array('select' => array('foo', 'bar')); - $this->form_validation->run(); - - $this->assertEquals(' selected="selected"', $this->form_validation->set_select('select[]', 'foo')); - $this->assertEquals(' selected="selected"', $this->form_validation->set_select('select[]', 'foo', TRUE)); - $this->assertEquals(' selected="selected"', $this->form_validation->set_select('select[]', 'bar')); - $this->assertEquals(' selected="selected"', $this->form_validation->set_select('select[]', 'bar', TRUE)); - $this->assertEquals('', $this->form_validation->set_select('select[]', 'foobar')); - $this->assertEquals('', $this->form_validation->set_select('select[]', 'foobar', TRUE)); - - $_POST = array(); - } - - public function test_set_radio() - { - // Test 1: No options selected - $this->form_validation->run(); - - $this->assertEquals('', $this->form_validation->set_radio('select', 'foo')); - // Default should only work when no rules are set - $this->assertEquals(' checked="checked"', $this->form_validation->set_radio('select', 'bar', TRUE)); - - // Test 2: 1 option selected - $this->form_validation->reset_validation(); - $this->form_validation->set_rules('select', 'label', 'alpha_numeric'); - $_POST = array('select' => 'foo'); - $this->form_validation->run(); - - $this->assertEquals(' checked="checked"', $this->form_validation->set_radio('select', 'foo')); - $this->assertEquals(' checked="checked"', $this->form_validation->set_radio('select', 'foo', TRUE)); - $this->assertEquals('', $this->form_validation->set_radio('select', 'bar')); - $this->assertEquals('', $this->form_validation->set_radio('select', 'bar', TRUE)); - - // Test 3: Multiple options checked - $this->form_validation->reset_validation(); - $this->form_validation->set_rules('select[]', 'label', 'alpha_numeric'); - $_POST = array('select' => array('foo', 'bar')); - $this->form_validation->run(); - - $this->assertEquals(' checked="checked"', $this->form_validation->set_radio('select[]', 'foo')); - $this->assertEquals(' checked="checked"', $this->form_validation->set_radio('select[]', 'foo', TRUE)); - $this->assertEquals(' checked="checked"', $this->form_validation->set_radio('select[]', 'bar')); - $this->assertEquals(' checked="checked"', $this->form_validation->set_radio('select[]', 'bar', TRUE)); - $this->assertEquals('', $this->form_validation->set_radio('select[]', 'foobar')); - $this->assertEquals('', $this->form_validation->set_radio('select[]', 'foobar', TRUE)); - - $_POST = array(); - } - - public function test_set_checkbox() - { - // Test 1: No options selected - $this->form_validation->run(); - - $this->assertEquals('', $this->form_validation->set_checkbox('select', 'foo')); - $this->assertEquals(' checked="checked"', $this->form_validation->set_checkbox('select', 'bar', TRUE)); - - // Test 2: 1 option selected - $this->form_validation->reset_validation(); - $this->form_validation->set_rules('select', 'label', 'alpha_numeric'); - $_POST = array('select' => 'foo'); - $this->form_validation->run(); - - $this->assertEquals(' checked="checked"', $this->form_validation->set_checkbox('select', 'foo')); - $this->assertEquals(' checked="checked"', $this->form_validation->set_checkbox('select', 'foo', TRUE)); - $this->assertEquals('', $this->form_validation->set_checkbox('select', 'bar')); - $this->assertEquals('', $this->form_validation->set_checkbox('select', 'bar', TRUE)); - - // Test 3: Multiple options selected - $this->form_validation->reset_validation(); - $this->form_validation->set_rules('select[]', 'label', 'alpha_numeric'); - $_POST = array('select' => array('foo', 'bar')); - $this->form_validation->run(); - - $this->assertEquals(' checked="checked"', $this->form_validation->set_checkbox('select[]', 'foo')); - $this->assertEquals(' checked="checked"', $this->form_validation->set_checkbox('select[]', 'foo', TRUE)); - $this->assertEquals(' checked="checked"', $this->form_validation->set_checkbox('select[]', 'bar')); - $this->assertEquals(' checked="checked"', $this->form_validation->set_checkbox('select[]', 'bar', TRUE)); - $this->assertEquals('', $this->form_validation->set_checkbox('select[]', 'foobar')); - $this->assertEquals('', $this->form_validation->set_checkbox('select[]', 'foobar', TRUE)); - - $_POST = array(); - } - - public function test_regex_match() - { - $regex = '/f[a-zA-Z]+/'; - $this->assertTrue($this->form_validation->regex_match('foo', $regex)); - $this->assertFalse($this->form_validation->regex_match('bar', $regex)); - } - - public function test_prep_for_form() - { - $this->form_validation->reset_validation(); - $error_msg_unprepped = '<error =\'foobar\'">'; - $error_msg_prepped = '<error ='foobar'">'; - $this->form_validation->set_rules('foo', 'label', 'required', array('required' => $error_msg_unprepped)); - $_POST = array('foo' => ''); - $this->form_validation->run(); - $error_arr = $this->form_validation->error_array(); - - $this->assertEquals('', $this->form_validation->prep_for_form('')); - $this->assertEquals(array('foo' => $error_msg_prepped), $this->form_validation->prep_for_form($error_arr)); - } - - public function test_prep_url() - { - $this->assertEquals('', $this->form_validation->prep_url('')); - $this->assertEquals('http://codeigniter.com', $this->form_validation->prep_url('codeigniter.com')); - $this->assertEquals('https://codeigniter.com', $this->form_validation->prep_url('https://codeigniter.com')); - $this->assertEquals('http://codeigniter.com', $this->form_validation->prep_url('http://codeigniter.com')); - $this->assertEquals('http://www.codeigniter.com', $this->form_validation->prep_url('www.codeigniter.com')); - } - - public function test_encode_php_tags() - { - $this->assertEquals("<?php", $this->form_validation->encode_php_tags('<?php')); - $this->assertEquals('?>', $this->form_validation->encode_php_tags('?>')); - } - - /** - * Run rules - * - * Helper method to set rules and run them at once, not - * an actual test case. - */ - public function run_rules($rules, $values) - { - $this->form_validation->reset_validation(); - $_POST = array(); - $this->form_validation->set_rules($rules); - - foreach ($values as $field => $value) - { - $_POST[$field] = $value; - } - - $valid = $this->form_validation->run(); - $_POST = array(); - - return $valid; - } -} diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php deleted file mode 100644 index 2a2348793..000000000 --- a/tests/codeigniter/libraries/Parser_test.php +++ /dev/null @@ -1,95 +0,0 @@ -<?php - -class Parser_test extends CI_TestCase { - - public function set_up() - { - $this->parser = new CI_Parser(); - $this->ci_instance_var('parser', $this->parser); - } - - // -------------------------------------------------------------------- - - public function test_set_delimiters() - { - // Make sure default delimiters are there - $this->assertEquals('{', $this->parser->l_delim); - $this->assertEquals('}', $this->parser->r_delim); - - // Change them to square brackets - $this->parser->set_delimiters('[', ']'); - - // Make sure they changed - $this->assertEquals('[', $this->parser->l_delim); - $this->assertEquals(']', $this->parser->r_delim); - - // Reset them - $this->parser->set_delimiters(); - - // Make sure default delimiters are there - $this->assertEquals('{', $this->parser->l_delim); - $this->assertEquals('}', $this->parser->r_delim); - } - - // -------------------------------------------------------------------- - - public function test_parse_string() - { - $data = array( - 'title' => 'Page Title', - 'body' => 'Lorem ipsum dolor sit amet.' - ); - - $template = "{title}\n{body}"; - - $result = implode("\n", $data); - - $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE)); - } - - // -------------------------------------------------------------------- - - public function test_parse() - { - $this->_parse_no_template(); - $this->_parse_var_pair(); - $this->_mismatched_var_pair(); - } - - // -------------------------------------------------------------------- - - private function _parse_no_template() - { - $this->assertFalse($this->parser->parse_string('', '', TRUE)); - } - - // -------------------------------------------------------------------- - - private function _parse_var_pair() - { - $data = array( - 'title' => 'Super Heroes', - 'powers' => array(array('invisibility' => 'yes', 'flying' => 'no')) - ); - - $template = "{title}\n{powers}{invisibility}\n{flying}{/powers}\nsecond:{powers} {invisibility} {flying}{/powers}"; - - $this->assertEquals("Super Heroes\nyes\nno\nsecond: yes no", $this->parser->parse_string($template, $data, TRUE)); - } - - // -------------------------------------------------------------------- - - private function _mismatched_var_pair() - { - $data = array( - 'title' => 'Super Heroes', - 'powers' => array(array('invisibility' => 'yes', 'flying' => 'no')) - ); - - $template = "{title}\n{powers}{invisibility}\n{flying}"; - $result = "Super Heroes\n{powers}{invisibility}\n{flying}"; - - $this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE)); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php deleted file mode 100644 index 76a4fcc98..000000000 --- a/tests/codeigniter/libraries/Session_test.php +++ /dev/null @@ -1,440 +0,0 @@ -<?php - -/** - * Session driver library unit test - */ -class Session_test extends CI_TestCase { - - protected $settings = array( - 'use_cookies' => 0, - 'use_only_cookies' => 0, - 'cache_limiter' => FALSE - ); - protected $setting_vals = array(); - protected $cookie_vals; - protected $session; - - /** - * Set up test framework - */ - public function set_up() - { -return; - // Override settings - foreach ($this->settings as $name => $value) { - $this->setting_vals[$name] = ini_get('session.'.$name); - ini_set('session.'.$name, $value); - } - - // Start with clean environment - $this->cookie_vals = $_COOKIE; - $_COOKIE = array(); - - // Set subclass prefix to match our mock - $this->ci_set_config('subclass_prefix', 'Mock_Libraries_'); - - // Establish necessary support classes - $ci = $this->ci_instance(); - $ldr = $this->ci_core_class('load'); - $ci->load = new $ldr(); - $ci->input = new Mock_Core_Input(NULL, NULL); - - // Make sure string helper is available - $this->ci_vfs_clone('system/helpers/string_helper.php'); - - // Attach session instance locally - $config = array( - 'sess_encrypt_cookie' => FALSE, - 'sess_use_database' => FALSE, - 'sess_table_name' => '', - 'sess_expiration' => 7200, - 'sess_expire_on_close' => FALSE, - 'sess_match_ip' => FALSE, - 'sess_match_useragent' => TRUE, - 'sess_cookie_name' => 'ci_session', - 'cookie_path' => '', - 'cookie_domain' => '', - 'cookie_secure' => FALSE, - 'cookie_httponly' => FALSE, - 'sess_time_to_update' => 300, - 'time_reference' => 'local', - 'cookie_prefix' => '', - 'encryption_key' => 'foobar' - ); - $this->session = new Mock_Libraries_Session($config); - } - - /** - * Tear down test framework - */ - public function tear_down() - { -return; - // Restore environment - if (session_id()) session_destroy(); - $_SESSION = array(); - $_COOKIE = $this->cookie_vals; - - // Restore settings - foreach ($this->settings as $name => $value) { - ini_set('session.'.$name, $this->setting_vals[$name]); - } - } - - /** - * Test set_userdata() function - */ - public function test_set_userdata() - { -return; - // Set userdata values for each driver - $key1 = 'test1'; - $ckey2 = 'test2'; - $nkey2 = 'test3'; - $cmsg1 = 'Some test data'; - $cmsg2 = 42; - $nmsg1 = 'Other test data'; - $nmsg2 = TRUE; - $this->session->cookie->set_userdata($key1, $cmsg1); - $this->session->set_userdata($ckey2, $cmsg2); - $this->session->native->set_userdata($key1, $nmsg1); - $this->session->set_userdata($nkey2, $nmsg2); - - // Verify independent messages - $this->assertEquals($cmsg1, $this->session->cookie->userdata($key1)); - $this->assertEquals($nmsg1, $this->session->native->userdata($key1)); - - // Verify pre-selected driver sets - $this->assertEquals($cmsg2, $this->session->cookie->userdata($ckey2)); - $this->assertEquals($nmsg2, $this->session->native->userdata($nkey2)); - - // Verify no crossover - $this->assertNull($this->session->cookie->userdata($nkey2)); - $this->assertNull($this->session->native->userdata($ckey2)); - } - - /** - * Test the has_userdata() function - */ - public function test_has_userdata() - { -return; - // Set a userdata value for each driver - $key = 'hastest'; - $cmsg = 'My test data'; - $this->session->cookie->set_userdata($key, $cmsg); - $nmsg = 'Your test data'; - $this->session->native->set_userdata($key, $nmsg); - - // Verify values exist - $this->assertTrue($this->session->cookie->has_userdata($key)); - $this->assertTrue($this->session->native->has_userdata($key)); - - // Verify non-existent values - $nokey = 'hasnot'; - $this->assertFalse($this->session->cookie->has_userdata($nokey)); - $this->assertFalse($this->session->native->has_userdata($nokey)); - } - - /** - * Test the all_userdata() function - */ - public function test_all_userdata() - { -return; - // Set a specific series of data for each driver - $cdata = array( - 'one' => 'first', - 'two' => 'second', - 'three' => 'third', - 'foo' => 'bar', - 'bar' => 'baz' - ); - $ndata = array( - 'one' => 'gold', - 'two' => 'silver', - 'three' => 'bronze', - 'foo' => 'baz', - 'bar' => 'foo' - ); - $this->session->cookie->set_userdata($cdata); - $this->session->native->set_userdata($ndata); - - // Make sure all values are present - $call = $this->session->cookie->userdata(); - foreach ($cdata as $key => $value) { - $this->assertEquals($value, $call[$key]); - } - $nall = $this->session->native->userdata(); - foreach ($ndata as $key => $value) { - $this->assertEquals($value, $nall[$key]); - } - } - - /** - * Test the unset_userdata() function - */ - public function test_unset_userdata() - { -return; - // Set a userdata message for each driver - $key = 'untest'; - $cmsg = 'Other test data'; - $this->session->cookie->set_userdata($key, $cmsg); - $nmsg = 'Sundry test data'; - $this->session->native->set_userdata($key, $nmsg); - - // Verify independent messages - $this->assertEquals($this->session->cookie->userdata($key), $cmsg); - $this->assertEquals($this->session->native->userdata($key), $nmsg); - - // Unset them and verify absence - $this->session->cookie->unset_userdata($key); - $this->session->native->unset_userdata($key); - $this->assertNull($this->session->cookie->userdata($key)); - $this->assertNull($this->session->native->userdata($key)); - } - - /** - * Test the flashdata() functions - */ - public function test_flashdata() - { -return; - // Set flashdata message for each driver - $key = 'fltest'; - $cmsg = 'Some flash data'; - $this->session->cookie->set_flashdata($key, $cmsg); - $nmsg = 'Other flash data'; - $this->session->native->set_flashdata($key, $nmsg); - - // Simulate page reload - $this->session->cookie->reload(); - $this->session->native->reload(); - - // Verify independent messages - $this->assertEquals($cmsg, $this->session->cookie->flashdata($key)); - $this->assertEquals($nmsg, $this->session->native->flashdata($key)); - - // Simulate next page reload - $this->session->cookie->reload(); - $this->session->native->reload(); - - // Verify absence of messages - $this->assertNull($this->session->cookie->flashdata($key)); - $this->assertNull($this->session->native->flashdata($key)); - } - - /** - * Test the keep_flashdata() function - */ - public function test_keep_flashdata() - { -return; - // Set flashdata message for each driver - $key = 'kfltest'; - $cmsg = 'My flash data'; - $this->session->cookie->set_flashdata($key, $cmsg); - $nmsg = 'Your flash data'; - $this->session->native->set_flashdata($key, $nmsg); - - // Simulate page reload and verify independent messages - $this->session->cookie->reload(); - $this->session->native->reload(); - $this->assertEquals($cmsg, $this->session->cookie->flashdata($key)); - $this->assertEquals($nmsg, $this->session->native->flashdata($key)); - - // Keep messages - $this->session->cookie->keep_flashdata($key); - $this->session->native->keep_flashdata($key); - - // Simulate next page reload and verify message persistence - $this->session->cookie->reload(); - $this->session->native->reload(); - $this->assertEquals($cmsg, $this->session->cookie->flashdata($key)); - $this->assertEquals($nmsg, $this->session->native->flashdata($key)); - - // Simulate next page reload and verify absence of messages - $this->session->cookie->reload(); - $this->session->native->reload(); - $this->assertNull($this->session->cookie->flashdata($key)); - $this->assertNull($this->session->native->flashdata($key)); - } - - public function test_keep_flashdata_with_array() - { -return; - // Set flashdata array for each driver - $cdata = array( - 'one' => 'first', - 'two' => 'second', - 'three' => 'third', - 'foo' => 'bar', - 'bar' => 'baz' - ); - $ndata = array( - 'one' => 'gold', - 'two' => 'silver', - 'three' => 'bronze', - 'foo' => 'baz', - 'bar' => 'foo' - ); - $kdata = array( - 'one', - 'two', - 'three', - 'foo', - 'bar' - ); - $this->session->cookie->set_flashdata($cdata); - $this->session->native->set_flashdata($ndata); - - // Simulate page reload and verify independent messages - $this->session->cookie->reload(); - $this->session->native->reload(); - $this->assertEquals($cdata, $this->session->cookie->flashdata()); - $this->assertEquals($ndata, $this->session->native->flashdata()); - - // Keep messages - $this->session->cookie->keep_flashdata($kdata); - $this->session->native->keep_flashdata($kdata); - - // Simulate next page reload and verify message persistence - $this->session->cookie->reload(); - $this->session->native->reload(); - $this->assertEquals($cdata, $this->session->cookie->flashdata()); - $this->assertEquals($ndata, $this->session->native->flashdata()); - - // Simulate next page reload and verify absence of messages - $this->session->cookie->reload(); - $this->session->native->reload(); - $this->assertEmpty($this->session->cookie->flashdata()); - $this->assertEmpty($this->session->native->flashdata()); - } - - /** - * Test the all_flashdata() function - */ - public function test_all_flashdata() - { -return; - // Set a specific series of data for each driver - $cdata = array( - 'one' => 'first', - 'two' => 'second', - 'three' => 'third', - 'foo' => 'bar', - 'bar' => 'baz' - ); - $ndata = array( - 'one' => 'gold', - 'two' => 'silver', - 'three' => 'bronze', - 'foo' => 'baz', - 'bar' => 'foo' - ); - $this->session->cookie->set_flashdata($cdata); - $this->session->native->set_flashdata($ndata); - - // Simulate page reload and make sure all values are present - $this->session->cookie->reload(); - $this->session->native->reload(); - $this->assertEquals($cdata, $this->session->cookie->flashdata()); - $this->assertEquals($ndata, $this->session->native->flashdata()); - } - - /** - * Test the tempdata() functions - */ - public function test_set_tempdata() - { -return; - // Set tempdata message for each driver - 1 second timeout - $key = 'tmptest'; - $cmsg = 'Some temp data'; - $this->session->cookie->set_tempdata($key, $cmsg, 1); - $nmsg = 'Other temp data'; - $this->session->native->set_tempdata($key, $nmsg, 1); - - // Simulate page reload and verify independent messages - $this->session->cookie->reload(); - $this->session->native->reload(); - $this->assertEquals($cmsg, $this->session->cookie->tempdata($key)); - $this->assertEquals($nmsg, $this->session->native->tempdata($key)); - - // Wait 2 seconds, simulate page reload and verify message absence - sleep(2); - $this->session->cookie->reload(); - $this->session->native->reload(); - $this->assertNull($this->session->cookie->tempdata($key)); - $this->assertNull($this->session->native->tempdata($key)); - } - - /** - * Test the unset_tempdata() function - */ - public function test_unset_tempdata() - { -return; - // Set tempdata message for each driver - 1 second timeout - $key = 'utmptest'; - $cmsg = 'My temp data'; - $this->session->cookie->set_tempdata($key, $cmsg, 1); - $nmsg = 'Your temp data'; - $this->session->native->set_tempdata($key, $nmsg, 1); - - // Verify independent messages - $this->assertEquals($cmsg, $this->session->cookie->tempdata($key)); - $this->assertEquals($nmsg, $this->session->native->tempdata($key)); - - // Unset data and verify message absence - $this->session->cookie->unset_tempdata($key); - $this->session->native->unset_tempdata($key); - $this->assertNull($this->session->cookie->tempdata($key)); - $this->assertNull($this->session->native->tempdata($key)); - } - - /** - * Test the sess_regenerate() function - */ - public function test_sess_regenerate() - { -return; - // Get current session id, regenerate, and compare - // Cookie driver - $oldid = $this->session->cookie->userdata('session_id'); - $this->session->cookie->sess_regenerate(); - $newid = $this->session->cookie->userdata('session_id'); - $this->assertNotEquals($oldid, $newid); - - // Native driver - bug #55267 (https://bugs.php.net/bug.php?id=55267) prevents testing this - // $oldid = session_id(); - // $this->session->native->sess_regenerate(); - // $oldid = session_id(); - // $this->assertNotEquals($oldid, $newid); - } - - /** - * Test the sess_destroy() function - */ - public function test_sess_destroy() - { -return; - // Set a userdata message, destroy session, and verify absence - $key = 'dsttest'; - $msg = 'More test data'; - - // Cookie driver - $this->session->cookie->set_userdata($key, $msg); - $this->assertEquals($msg, $this->session->cookie->userdata($key)); - $this->session->cookie->sess_destroy(); - $this->assertNull($this->session->cookie->userdata($key)); - - // Native driver - $this->session->native->set_userdata($key, $msg); - $this->assertEquals($msg, $this->session->native->userdata($key)); - $this->session->native->sess_destroy(); - $this->assertNull($this->session->native->userdata($key)); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php deleted file mode 100644 index 6efae5d18..000000000 --- a/tests/codeigniter/libraries/Table_test.php +++ /dev/null @@ -1,300 +0,0 @@ -<?php - -class Table_test extends CI_TestCase { - - public function set_up() - { - $this->table = new Mock_Libraries_Table(); - $this->ci_instance_var('table', $this->table); - } - - // Setter Methods - // -------------------------------------------------------------------- - - public function test_set_template() - { - $this->assertFalse($this->table->set_template('not an array')); - - $template = array('a' => 'b'); - - $this->table->set_template($template); - $this->assertEquals($template, $this->table->template); - } - - public function test_set_empty() - { - $this->table->set_empty('nada'); - $this->assertEquals('nada', $this->table->empty_cells); - } - - public function test_set_caption() - { - $this->table->set_caption('awesome cap'); - $this->assertEquals('awesome cap', $this->table->caption); - } - - /* - * @depends test_prep_args - */ - public function test_set_heading() - { - // uses _prep_args internally, so we'll just do a quick - // check to verify that func_get_args and prep_args are - // being called. - - $this->table->set_heading('name', 'color', 'size'); - - $this->assertEquals( - array( - array('data' => 'name'), - array('data' => 'color'), - array('data' => 'size') - ), - $this->table->heading - ); - } - - /* - * @depends test_prep_args - */ - public function test_add_row() - { - // uses _prep_args internally, so we'll just do a quick - // check to verify that func_get_args and prep_args are - // being called. - - $this->table->add_row('my', 'pony', 'sings'); - $this->table->add_row('your', 'pony', 'stinks'); - $this->table->add_row('my pony', '>', 'your pony'); - - $this->assertCount(3, $this->table->rows); - - $this->assertEquals( - array( - array('data' => 'your'), - array('data' => 'pony'), - array('data' => 'stinks') - ), - $this->table->rows[1] - ); - } - - // Uility Methods - // -------------------------------------------------------------------- - - public function test_prep_args() - { - $expected = array( - array('data' => 'name'), - array('data' => 'color'), - array('data' => 'size') - ); - - $this->assertEquals( - $expected, - $this->table->prep_args(array('name', 'color', 'size')) - ); - - // with cell attributes - // need to add that new argument row to our expected outcome - $expected[] = array('data' => 'weight', 'class' => 'awesome'); - - $this->assertEquals( - $expected, - $this->table->prep_args(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome'))) - ); - } - - public function test_default_template_keys() - { - $keys = array( - 'table_open', - 'thead_open', 'thead_close', - 'heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', - 'tbody_open', 'tbody_close', - 'row_start', 'row_end', 'cell_start', 'cell_end', - 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', - 'table_close' - ); - - foreach ($keys as $key) - { - $this->assertArrayHasKey($key, $this->table->default_template()); - } - } - - public function test_compile_template() - { - $this->assertFalse($this->table->set_template('invalid_junk')); - - // non default key - $this->table->set_template(array('nonsense' => 'foo')); - $this->table->compile_template(); - - $this->assertArrayHasKey('nonsense', $this->table->template); - $this->assertEquals('foo', $this->table->template['nonsense']); - - // override default - $this->table->set_template(array('table_close' => '</table junk>')); - $this->table->compile_template(); - - $this->assertArrayHasKey('table_close', $this->table->template); - $this->assertEquals('</table junk>', $this->table->template['table_close']); - } - - public function test_make_columns() - { - // Test bogus parameters - $this->assertFalse($this->table->make_columns('invalid_junk')); - $this->assertFalse($this->table->make_columns(array())); - $this->assertFalse($this->table->make_columns(array('one', 'two'), '2.5')); - - // Now on to the actual column creation - - $five_values = array( - 'Laura', 'Red', '15', - 'Katie', 'Blue' - ); - - // No column count - no changes to the array - $this->assertEquals( - $five_values, - $this->table->make_columns($five_values) - ); - - // Column count of 3 leaves us with one - $this->assertEquals( - array( - array('Laura', 'Red', '15'), - array('Katie', 'Blue', ' ') - ), - $this->table->make_columns($five_values, 3) - ); - } - - public function test_clear() - { - $this->table->set_heading('Name', 'Color', 'Size'); - - // Make columns changes auto_heading - $rows = $this->table->make_columns(array( - 'Laura', 'Red', '15', - 'Katie', 'Blue' - ), 3); - - foreach ($rows as $row) - { - $this->table->add_row($row); - } - - $this->assertFalse($this->table->auto_heading); - $this->assertCount(3, $this->table->heading); - $this->assertCount(2, $this->table->rows); - - $this->table->clear(); - - $this->assertTrue($this->table->auto_heading); - $this->assertEmpty($this->table->heading); - $this->assertEmpty($this->table->rows); - } - - public function test_set_from_array() - { - $data = array( - array('name', 'color', 'number'), - array('Laura', 'Red', '22'), - array('Katie', 'Blue') - ); - - $this->table->auto_heading = FALSE; - $this->table->set_from_array($data); - $this->assertEmpty($this->table->heading); - - $this->table->clear(); - - $this->table->set_from_array($data); - $this->assertCount(2, $this->table->rows); - - $expected = array( - array('data' => 'name'), - array('data' => 'color'), - array('data' => 'number') - ); - - $this->assertEquals($expected, $this->table->heading); - - $expected = array( - array('data' => 'Katie'), - array('data' => 'Blue'), - ); - - $this->assertEquals($expected, $this->table->rows[1]); - } - - public function test_set_from_object() - { - // This needs to be passed by reference to CI_DB_result::__construct() - $dummy = new stdClass(); - $dummy->conn_id = NULL; - $dummy->result_id = NULL; - - $db_result = new DB_result_dummy($dummy); - - $this->table->set_from_db_result($db_result); - - $expected = array( - array('data' => 'name'), - array('data' => 'email') - ); - - $this->assertEquals($expected, $this->table->heading); - - $expected = array( - 'name' => array('data' => 'Foo Bar'), - 'email' => array('data' => 'foo@bar.com'), - ); - - $this->assertEquals($expected, $this->table->rows[1]); - } - - public function test_generate() - { - // Prepare the data - $data = array( - array('Name', 'Color', 'Size'), - array('Fred', 'Blue', 'Small'), - array('Mary', 'Red', 'Large'), - array('John', 'Green', 'Medium') - ); - - $table = $this->table->generate($data); - - // Test the table header - $this->assertEquals(1, substr_count($table, '<th>Name</th>')); - $this->assertEquals(1, substr_count($table, '<th>Color</th>')); - $this->assertEquals(1, substr_count($table, '<th>Size</th>')); - - // Test the first entry - $this->assertEquals(1, substr_count($table, '<td>Fred</td>')); - $this->assertEquals(1, substr_count($table, '<td>Blue</td>')); - $this->assertEquals(1, substr_count($table, '<td>Small</td>')); - } - -} - -// We need this for the _set_from_db_result() test -class DB_result_dummy extends CI_DB_result -{ - public function list_fields() - { - return array('name', 'email'); - } - - public function result_array() - { - return array( - array('name' => 'John Doe', 'email' => 'john@doe.com'), - array('name' => 'Foo Bar', 'email' => 'foo@bar.com') - ); - } -} diff --git a/tests/codeigniter/libraries/Typography_test.php b/tests/codeigniter/libraries/Typography_test.php deleted file mode 100644 index e6ee7b05c..000000000 --- a/tests/codeigniter/libraries/Typography_test.php +++ /dev/null @@ -1,182 +0,0 @@ -<?php - -class Typography_test extends CI_TestCase { - - public function set_up() - { - $this->type = new CI_Typography(); - $this->ci_instance('type', $this->type); - } - - // -------------------------------------------------------------------- - - /** - * Tests the format_characters() function. - * - * this can and should grow. - */ - public function test_format_characters() - { - $strs = array( - '"double quotes"' => '“double quotes”', - '"testing" in "theory" that is' => '“testing” in “theory” that is', - "Here's what I'm" => 'Here’s what I’m', - '&' => '&', - '&' => '&', - ' ' => ' ', - '--' => '—', - 'foo...' => 'foo…', - 'foo..' => 'foo..', - 'foo...bar.' => 'foo…bar.', - 'test. new' => 'test. new', - ); - - foreach ($strs as $str => $expected) - { - $this->assertEquals($expected, $this->type->format_characters($str)); - } - } - - // -------------------------------------------------------------------- - - public function test_nl2br_except_pre() - { - $str = <<<EOH -Hello, I'm a happy string with some new lines. - -I like to skip. - -Jump - -and sing. - -<pre> -I am inside a pre tag. Please don't mess with me. - -k? -</pre> - -That's my story and I'm sticking to it. - -The End. -EOH; - - $expected = <<<EOH -Hello, I'm a happy string with some new lines. <br /> -<br /> -I like to skip.<br /> -<br /> -Jump<br /> -<br /> -and sing.<br /> -<br /> -<pre> -I am inside a pre tag. Please don't mess with me. - -k? -</pre><br /> -<br /> -That's my story and I'm sticking to it.<br /> -<br /> -The End. -EOH; - - $this->assertEquals($expected, $this->type->nl2br_except_pre($str)); - } - - // -------------------------------------------------------------------- - - public function test_auto_typography() - { - $this->_blank_string(); - $this->_standardize_new_lines(); - $this->_reduce_linebreaks(); - $this->_remove_comments(); - $this->_protect_pre(); - $this->_no_opening_block(); - $this->_protect_braced_quotes(); - } - - // -------------------------------------------------------------------- - - private function _blank_string() - { - // Test blank string - $this->assertEquals('', $this->type->auto_typography('')); - } - - // -------------------------------------------------------------------- - - private function _standardize_new_lines() - { - $strs = array( - "My string\rhas return characters" => "<p>My string<br />\nhas return characters</p>", - 'This one does not!' => '<p>This one does not!</p>' - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, $this->type->auto_typography($str)); - } - } - - // -------------------------------------------------------------------- - - private function _reduce_linebreaks() - { - $str = "This has way too many linebreaks.\n\n\n\nSee?"; - $expect = "<p>This has way too many linebreaks.</p>\n\n<p>See?</p>"; - - $this->assertEquals($expect, $this->type->auto_typography($str, TRUE)); - } - - // -------------------------------------------------------------------- - - private function _remove_comments() - { - $str = '<!-- I can haz comments? --> But no!'; - $expect = '<p><!-- I can haz comments? --> But no!</p>'; - - $this->assertEquals($expect, $this->type->auto_typography($str)); - } - - // -------------------------------------------------------------------- - - private function _protect_pre() - { - $str = '<p>My Sentence</p><pre>var_dump($this);</pre>'; - $expect = '<p>My Sentence</p><pre>var_dump($this);</pre>'; - - $this->assertEquals($expect, $this->type->auto_typography($str)); - } - - // -------------------------------------------------------------------- - - private function _no_opening_block() - { - $str = 'My Sentence<pre>var_dump($this);</pre>'; - $expect = '<p>My Sentence</p><pre>var_dump($this);</pre>'; - - $this->assertEquals($expect, $this->type->auto_typography($str)); - } - - // -------------------------------------------------------------------- - - public function _protect_braced_quotes() - { - $this->type->protect_braced_quotes = TRUE; - - $str = 'Test {parse="foobar"}'; - $expect = '<p>Test {parse="foobar"}</p>'; - - $this->assertEquals($expect, $this->type->auto_typography($str)); - - $this->type->protect_braced_quotes = FALSE; - - $str = 'Test {parse="foobar"}'; - $expect = '<p>Test {parse=“foobar”}</p>'; - - $this->assertEquals($expect, $this->type->auto_typography($str)); - } - -}
\ No newline at end of file diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php deleted file mode 100644 index 8bac597b3..000000000 --- a/tests/codeigniter/libraries/Upload_test.php +++ /dev/null @@ -1,299 +0,0 @@ -<?php - -class Upload_test extends CI_TestCase { - - public function set_up() - { - $ci = $this->ci_instance(); - $ci->upload = new CI_Upload(); - $ci->security = new Mock_Core_Security(); - $ci->lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load', 'line'))->getMock(); - $ci->lang->expects($this->any())->method('line')->will($this->returnValue(FALSE)); - $this->upload = $ci->upload; - } - - // -------------------------------------------------------------------- - - public function test___construct_initialize() - { - // via __construct - - $upload = new CI_Upload( - array( - 'file_name' => 'foo', - 'file_ext_tolower' => TRUE - ) - ); - - $reflection = new ReflectionClass($upload); - $reflection = $reflection->getProperty('_file_name_override'); - $reflection->setAccessible(TRUE); - $this->assertEquals('foo', $reflection->getValue($upload)); - - $this->assertTrue($upload->file_ext_tolower); - - // reset (defaults to true) - - $upload->initialize(array('file_name' => 'bar')); - $this->assertEquals('bar', $upload->file_name); - $this->assertFalse($upload->file_ext_tolower); - - // no reset - - $upload->initialize(array('file_ext_tolower' => TRUE), FALSE); - $this->assertTrue($upload->file_ext_tolower); - $this->assertEquals('bar', $upload->file_name); - } - - // -------------------------------------------------------------------- - - public function test_do_upload() - { - $this->markTestSkipped("We can't test this at the moment because of the call to is_uploaded_file() in do_upload() which isn't supported by vfsStream."); - } - - // -------------------------------------------------------------------- - - function test_data() - { - $data = array( - 'file_name' => 'hello.txt', - 'file_type' => 'text/plain', - 'file_path' => '/tmp/', - 'full_path' => '/tmp/hello.txt', - 'raw_name' => 'hello', - 'orig_name' => 'hello.txt', - 'client_name' => '', - 'file_ext' => '.txt', - 'file_size' => 100, - 'is_image' => FALSE, - 'image_width' => '', - 'image_height' => '', - 'image_type' => '', - 'image_size_str' => '' - ); - - $this->upload->set_upload_path('/tmp/'); - - foreach ($data as $k => $v) - { - $this->upload->{$k} = $v; - } - - $this->assertEquals('hello.txt', $this->upload->data('file_name')); - $this->assertEquals($data, $this->upload->data()); - } - - function test_set_upload_path() - { - $this->upload->set_upload_path('/tmp/'); - $this->assertEquals('/tmp/', $this->upload->upload_path); - - $this->upload->set_upload_path('/tmp'); - $this->assertEquals('/tmp/', $this->upload->upload_path); - } - - function test_set_filename() - { - $dir = 'uploads'; - $isnew = 'helloworld.txt'; - $exists = 'hello-world.txt'; - $this->ci_vfs_create($exists, 'Hello world.', $this->ci_app_root, $dir); - $path = $this->ci_vfs_path($dir.'/', APPPATH); - $this->upload->file_ext = '.txt'; - - $this->assertEquals($isnew, $this->upload->set_filename($path, $isnew)); - $this->assertEquals('hello-world1.txt', $this->upload->set_filename($path, $exists)); - } - - function test_set_max_filesize() - { - $this->upload->set_max_filesize(100); - $this->assertEquals(100, $this->upload->max_size); - } - - function test_set_max_filename() - { - $this->upload->set_max_filename(100); - $this->assertEquals(100, $this->upload->max_filename); - } - - function test_set_max_width() - { - $this->upload->set_max_width(100); - $this->assertEquals(100, $this->upload->max_width); - } - - function test_set_max_height() - { - $this->upload->set_max_height(100); - $this->assertEquals(100, $this->upload->max_height); - } - - function test_set_allowed_types() - { - $this->upload->set_allowed_types('*'); - $this->assertEquals('*', $this->upload->allowed_types); - - $this->upload->set_allowed_types('foo|bar'); - $this->assertEquals(array('foo', 'bar'), $this->upload->allowed_types); - } - - function test_set_image_properties() - { - $this->upload->file_type = 'image/gif'; - $this->upload->file_temp = realpath(PROJECT_BASE.'tests/mocks/uploads/ci_logo.gif'); - - $props = array( - 'image_width' => 170, - 'image_height' => 73, - 'image_type' => 'gif', - 'image_size_str' => 'width="170" height="73"' - ); - - $this->upload->set_image_properties($this->upload->file_temp); - - $this->assertEquals($props['image_width'], $this->upload->image_width); - $this->assertEquals($props['image_height'], $this->upload->image_height); - $this->assertEquals($props['image_type'], $this->upload->image_type); - $this->assertEquals($props['image_size_str'], $this->upload->image_size_str); - } - - function test_set_xss_clean() - { - $this->upload->set_xss_clean(TRUE); - $this->assertTrue($this->upload->xss_clean); - - $this->upload->set_xss_clean(FALSE); - $this->assertFalse($this->upload->xss_clean); - } - - function test_is_image() - { - $this->upload->file_type = 'image/x-png'; - $this->assertTrue($this->upload->is_image()); - - $this->upload->file_type = 'text/plain'; - $this->assertFalse($this->upload->is_image()); - } - - function test_is_allowed_filetype() - { - $this->upload->allowed_types = array('html', 'gif'); - - $this->upload->file_ext = '.txt'; - $this->upload->file_type = 'text/plain'; - $this->assertFalse($this->upload->is_allowed_filetype(FALSE)); - $this->assertFalse($this->upload->is_allowed_filetype(TRUE)); - - $this->upload->file_ext = '.html'; - $this->upload->file_type = 'text/html'; - $this->assertTrue($this->upload->is_allowed_filetype(FALSE)); - $this->assertTrue($this->upload->is_allowed_filetype(TRUE)); - - $this->upload->file_temp = realpath(PROJECT_BASE.'tests/mocks/uploads/ci_logo.gif'); - $this->upload->file_ext = '.gif'; - $this->upload->file_type = 'image/gif'; - $this->assertTrue($this->upload->is_allowed_filetype()); - } - - function test_is_allowed_filesize() - { - $this->upload->max_size = 100; - $this->upload->file_size = 99; - - $this->assertTrue($this->upload->is_allowed_filesize()); - - $this->upload->file_size = 101; - $this->assertFalse($this->upload->is_allowed_filesize()); - } - - function test_is_allowed_dimensions() - { - $this->upload->file_type = 'text/plain'; - $this->assertTrue($this->upload->is_allowed_dimensions()); - - $this->upload->file_type = 'image/gif'; - $this->upload->file_temp = realpath(PROJECT_BASE.'tests/mocks/uploads/ci_logo.gif'); - - $this->upload->max_width = 10; - $this->assertFalse($this->upload->is_allowed_dimensions()); - - $this->upload->max_width = 170; - $this->upload->max_height = 10; - $this->assertFalse($this->upload->is_allowed_dimensions()); - - $this->upload->max_height = 73; - $this->assertTrue($this->upload->is_allowed_dimensions()); - } - - function test_validate_upload_path() - { - $this->upload->upload_path = ''; - $this->assertFalse($this->upload->validate_upload_path()); - - $dir = 'uploads'; - $this->ci_vfs_mkdir($dir); - $this->upload->upload_path = $this->ci_vfs_path($dir); - $this->assertTrue($this->upload->validate_upload_path()); - } - - function test_get_extension() - { - $this->assertEquals('.txt', $this->upload->get_extension('hello.txt')); - $this->assertEquals('.htaccess', $this->upload->get_extension('.htaccess')); - $this->assertEquals('', $this->upload->get_extension('hello')); - } - - function test_limit_filename_length() - { - $this->assertEquals('hello.txt', $this->upload->limit_filename_length('hello.txt', 10)); - $this->assertEquals('hello.txt', $this->upload->limit_filename_length('hello-world.txt', 9)); - } - - function test_do_xss_clean() - { - $dir = 'uploads'; - $file1 = 'file1.txt'; - $file2 = 'file2.txt'; - $file3 = 'file3.txt'; - $this->ci_vfs_create($file1, 'The billy goat was waiting for them.', $this->ci_vfs_root, $dir); - $this->ci_vfs_create($file2, '', $this->ci_vfs_root, $dir); - $this->ci_vfs_create($file3, '<script type="text/javascript">alert("Boo! said the billy goat")</script>', $this->ci_vfs_root, $dir); - - $this->upload->file_temp = $this->ci_vfs_path($file1, $dir); - $this->assertTrue($this->upload->do_xss_clean()); - - $this->upload->file_temp = $this->ci_vfs_path($file2, $dir); - $this->assertFalse($this->upload->do_xss_clean()); - - $this->upload->file_temp = $this->ci_vfs_path($file3, $dir); - $this->assertFalse($this->upload->do_xss_clean()); - - $this->upload->file_temp = realpath(PROJECT_BASE.'tests/mocks/uploads/ci_logo.gif'); - $this->assertTrue($this->upload->do_xss_clean()); - } - - function test_set_error() - { - $errors = array( - 'An error!' - ); - - $another = 'Another error!'; - - $this->upload->set_error($errors); - $this->assertEquals($errors, $this->upload->error_msg); - - $errors[] = $another; - $this->upload->set_error($another); - $this->assertEquals($errors, $this->upload->error_msg); - } - - function test_display_errors() - { - $this->upload->error_msg[] = 'Error test'; - $this->assertEquals('<p>Error test</p>', $this->upload->display_errors()); - } - -} diff --git a/tests/codeigniter/libraries/Useragent_test.php b/tests/codeigniter/libraries/Useragent_test.php deleted file mode 100644 index 087544a1a..000000000 --- a/tests/codeigniter/libraries/Useragent_test.php +++ /dev/null @@ -1,125 +0,0 @@ -<?php - -class UserAgent_test extends CI_TestCase { - - protected $_user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27'; - protected $_mobile_ua = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7'; - - public function set_up() - { - // set a baseline user agent - $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent; - - $this->ci_vfs_clone('application/config/user_agents.php'); - $this->agent = new CI_User_agent(); - $this->ci_instance_var('agent', $this->agent); - } - - // -------------------------------------------------------------------- - - public function test_accept_lang() - { - $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en'; - $this->assertTrue($this->agent->accept_lang()); - unset($_SERVER['HTTP_ACCEPT_LANGUAGE']); - $this->assertTrue($this->agent->accept_lang('en')); - $this->assertFalse($this->agent->accept_lang('fr')); - } - - // -------------------------------------------------------------------- - - public function test_mobile() - { - // Mobile Not Set - $_SERVER['HTTP_USER_AGENT'] = $this->_mobile_ua; - $this->assertEquals('', $this->agent->mobile()); - unset($_SERVER['HTTP_USER_AGENT']); - } - - // -------------------------------------------------------------------- - - public function test_is_functions() - { - $this->assertTrue($this->agent->is_browser()); - $this->assertTrue($this->agent->is_browser('Safari')); - $this->assertFalse($this->agent->is_browser('Firefox')); - $this->assertFalse($this->agent->is_robot()); - $this->assertFalse($this->agent->is_mobile()); - } - - // -------------------------------------------------------------------- - - public function test_referrer() - { - $_SERVER['HTTP_REFERER'] = 'http://codeigniter.com/userguide3/'; - $this->assertTrue($this->agent->is_referral()); - $this->assertEquals('http://codeigniter.com/userguide3/', $this->agent->referrer()); - - $this->agent->referer = NULL; - unset($_SERVER['HTTP_REFERER']); - $this->assertFalse($this->agent->is_referral()); - $this->assertEquals('', $this->agent->referrer()); - } - - // -------------------------------------------------------------------- - - public function test_agent_string() - { - $this->assertEquals($this->_user_agent, $this->agent->agent_string()); - } - - // -------------------------------------------------------------------- - - public function test_browser_info() - { - $this->assertEquals('Mac OS X', $this->agent->platform()); - $this->assertEquals('Safari', $this->agent->browser()); - $this->assertEquals('533.20.27', $this->agent->version()); - $this->assertEquals('', $this->agent->robot()); - } - - // -------------------------------------------------------------------- - - public function test_charsets() - { - $_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf8'; - $this->agent->charsets = array(); - $this->agent->charsets(); - $this->assertTrue($this->agent->accept_charset('utf8')); - $this->assertFalse($this->agent->accept_charset('foo')); - $this->assertEquals('utf8', $this->agent->charsets[0]); - - $_SERVER['HTTP_ACCEPT_CHARSET'] = ''; - $this->agent->charsets = array(); - $this->assertFalse($this->agent->accept_charset()); - $this->assertEquals('Undefined', $this->agent->charsets[0]); - - $_SERVER['HTTP_ACCEPT_CHARSET'] = 'iso-8859-5, unicode-1-1; q=0.8'; - $this->agent->charsets = array(); - $this->assertTrue($this->agent->accept_charset('iso-8859-5')); - $this->assertTrue($this->agent->accept_charset('unicode-1-1')); - $this->assertFalse($this->agent->accept_charset('foo')); - $this->assertEquals('iso-8859-5', $this->agent->charsets[0]); - $this->assertEquals('unicode-1-1', $this->agent->charsets[1]); - - unset($_SERVER['HTTP_ACCEPT_CHARSET']); - } - - public function test_parse() - { - $new_agent = 'Mozilla/5.0 (Android; Mobile; rv:13.0) Gecko/13.0 Firefox/13.0'; - $this->agent->parse($new_agent); - - $this->assertEquals('Android', $this->agent->platform()); - $this->assertEquals('Firefox', $this->agent->browser()); - $this->assertEquals('13.0', $this->agent->version()); - $this->assertEquals('', $this->agent->robot()); - $this->assertEquals('Android', $this->agent->mobile()); - $this->assertEquals($new_agent, $this->agent->agent_string()); - $this->assertTrue($this->agent->is_browser()); - $this->assertFalse($this->agent->is_robot()); - $this->assertTrue($this->agent->is_mobile()); - $this->assertTrue($this->agent->is_mobile('android')); - } - -}
\ No newline at end of file |