diff options
Diffstat (limited to 'tests/codeigniter')
-rw-r--r-- | tests/codeigniter/helpers/captcha_helper_test.php | 10 | ||||
-rw-r--r-- | tests/codeigniter/helpers/cookie_helper_test.php | 59 | ||||
-rw-r--r-- | tests/codeigniter/helpers/download_helper_test.php | 10 | ||||
-rw-r--r-- | tests/codeigniter/helpers/language_helper_test.php | 14 | ||||
-rw-r--r-- | tests/codeigniter/helpers/security_helper_test.php | 64 | ||||
-rw-r--r-- | tests/codeigniter/helpers/url_helper_test.php | 2 | ||||
-rw-r--r-- | tests/codeigniter/libraries/Upload_test.php | 10 |
7 files changed, 164 insertions, 5 deletions
diff --git a/tests/codeigniter/helpers/captcha_helper_test.php b/tests/codeigniter/helpers/captcha_helper_test.php new file mode 100644 index 000000000..fc86305e3 --- /dev/null +++ b/tests/codeigniter/helpers/captcha_helper_test.php @@ -0,0 +1,10 @@ +<?php + +class Captcha_helper_test extends CI_TestCase { + + public function test_create_captcha() + { + $this->markTestSkipped('Cant easily 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 new file mode 100644 index 000000000..fba68f20f --- /dev/null +++ b/tests/codeigniter/helpers/cookie_helper_test.php @@ -0,0 +1,59 @@ +<?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/download_helper_test.php b/tests/codeigniter/helpers/download_helper_test.php new file mode 100644 index 000000000..d2b42e46b --- /dev/null +++ b/tests/codeigniter/helpers/download_helper_test.php @@ -0,0 +1,10 @@ +<?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/language_helper_test.php b/tests/codeigniter/helpers/language_helper_test.php new file mode 100644 index 000000000..06932b9fd --- /dev/null +++ b/tests/codeigniter/helpers/language_helper_test.php @@ -0,0 +1,14 @@ +<?php + +class Language_helper_test extends CI_TestCase { + + public function test_lang() + { + $this->helper('language'); + $this->ci_instance_var('lang', new Mock_Core_Lang()); + + $this->assertFalse(lang(1)); + $this->assertEquals('<label for="foo"></label>', lang(1, 'foo')); + } + +}
\ No newline at end of file diff --git a/tests/codeigniter/helpers/security_helper_test.php b/tests/codeigniter/helpers/security_helper_test.php new file mode 100644 index 000000000..effd3ec02 --- /dev/null +++ b/tests/codeigniter/helpers/security_helper_test.php @@ -0,0 +1,64 @@ +<?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/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php index c81c5f1b8..5fc364238 100644 --- a/tests/codeigniter/helpers/url_helper_test.php +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -51,6 +51,8 @@ class Url_helper_test extends CI_TestCase { 'www.codeigniter.com test' => '<a href="http://www.codeigniter.com">http://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">http://www.google.com</a>', + 'Download CodeIgniter at www.codeigniter.com. Period test.' => 'Download CodeIgniter at <a href="http://www.codeigniter.com">http://www.codeigniter.com</a>. Period test.', + 'Download CodeIgniter at www.codeigniter.com, comma test' => 'Download CodeIgniter at <a href="http://www.codeigniter.com">http://www.codeigniter.com</a>, comma test' ); foreach ($strings as $in => $out) diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php index 827942773..546cebc59 100644 --- a/tests/codeigniter/libraries/Upload_test.php +++ b/tests/codeigniter/libraries/Upload_test.php @@ -11,9 +11,9 @@ class Upload_test extends CI_TestCase { $this->upload = $ci->upload; } - function test_do_upload() + function test_do_upload() { - $this->markTestIncomplete('We can\'t really test this at the moment because of the call to `is_uploaded_file` in do_upload which isn\'t supported by vfsStream'); + $this->markTestSkipped('We can\'t really 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() @@ -72,7 +72,7 @@ class Upload_test extends CI_TestCase { { $this->upload->set_max_filesize(100); $this->assertEquals(100, $this->upload->max_size); - } + } function test_set_max_filename() { @@ -84,7 +84,7 @@ class Upload_test extends CI_TestCase { { $this->upload->set_max_width(100); $this->assertEquals(100, $this->upload->max_width); - } + } function test_set_max_height() { @@ -178,7 +178,7 @@ class Upload_test extends CI_TestCase { $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->upload->max_width = 10; $this->assertFalse($this->upload->is_allowed_dimensions()); $this->upload->max_width = 170; |