diff options
author | Jonatas Miguel <jonatas.df.miguel@gmail.com> | 2012-10-24 19:30:36 +0200 |
---|---|---|
committer | Jonatas Miguel <jonatas.df.miguel@gmail.com> | 2012-10-24 19:30:36 +0200 |
commit | b51823dde5fbae508b8ebf99258d2f514a8bece8 (patch) | |
tree | 4db09a22f85e0ddf151c940cd3e6fbaa799b8513 /tests/codeigniter/helpers | |
parent | a53f402b78ad07fb0f6da19cff0c7bec3a09a4c0 (diff) | |
parent | a7001e968a4791312391eb245ad84888893cda8f (diff) |
Merge branch 'develop' of git://github.com/EllisLab/CodeIgniter into develop
Conflicts:
user_guide_src/source/changelog.rst
Diffstat (limited to 'tests/codeigniter/helpers')
-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/date_helper_test.php | 25 | ||||
-rw-r--r-- | tests/codeigniter/helpers/directory_helper_test.php | 4 | ||||
-rw-r--r-- | tests/codeigniter/helpers/download_helper_test.php | 10 | ||||
-rw-r--r-- | tests/codeigniter/helpers/form_helper_test.php | 8 | ||||
-rw-r--r-- | tests/codeigniter/helpers/html_helper_test.php | 17 | ||||
-rw-r--r-- | tests/codeigniter/helpers/language_helper_test.php | 14 | ||||
-rw-r--r-- | tests/codeigniter/helpers/number_helper_test.php | 17 | ||||
-rw-r--r-- | tests/codeigniter/helpers/security_helper_test.php | 64 | ||||
-rw-r--r-- | tests/codeigniter/helpers/text_helper_test.php | 1 | ||||
-rw-r--r-- | tests/codeigniter/helpers/url_helper_test.php | 2 |
12 files changed, 211 insertions, 20 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/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 1b79b9480..1458acd3e 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -168,6 +168,8 @@ class Date_helper_test extends CI_TestCase { 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); @@ -290,6 +292,29 @@ class Date_helper_test extends CI_TestCase { $this->assertEquals(0, timezones('non_existant')); } + // ------------------------------------------------------------------------ + + 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')); + } + } /* End of file date_helper_test.php */
\ No newline at end of file diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php index 176ff1d78..c39ccd8d0 100644 --- a/tests/codeigniter/helpers/directory_helper_test.php +++ b/tests/codeigniter/helpers/directory_helper_test.php @@ -19,6 +19,7 @@ class Directory_helper_test extends CI_TestCase { 'benchmark.html' => '', 'database' => array('active_record.html' => '', 'binds.html' => ''), 'email.html' => '', + '0' => '', '.hiddenfile.txt' => '' ) ); @@ -30,7 +31,8 @@ class Directory_helper_test extends CI_TestCase { 'libraries' => array( 'benchmark.html', 'database' => array('active_record.html', 'binds.html'), - 'email.html' + 'email.html', + '0' ) ); 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/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php index 1a30ed993..48628d2e5 100644 --- a/tests/codeigniter/helpers/form_helper_test.php +++ b/tests/codeigniter/helpers/form_helper_test.php @@ -1,10 +1,12 @@ <?php -require BASEPATH . 'core/Common.php'; -require BASEPATH . 'helpers/form_helper.php'; - class Form_helper_test extends CI_TestCase { + public function set_up() + { + $this->helper('form'); + } + public function test_form_hidden() { $expected = <<<EOH diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index 9a7bb48bf..4dd717ff7 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -22,6 +22,22 @@ class Html_helper_test extends CI_TestCase { $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_Ul() @@ -72,5 +88,4 @@ EOH; $this->assertEquals($expect, meta(array('name' => 'foo'))); } - }
\ 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/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php index ef6aae138..817db2c7e 100644 --- a/tests/codeigniter/helpers/number_helper_test.php +++ b/tests/codeigniter/helpers/number_helper_test.php @@ -11,31 +11,18 @@ class Number_helper_test extends CI_TestCase { // Mock away load, too much going on in there, // we'll just check for the expected parameter - $lang = $this->getMock($lang_cls, array('load')); $lang->expects($this->once()) ->method('load') ->with($this->equalTo('number')); // Assign the proper language array - - $lang->language = $this->_get_lang('number'); + $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. - - $obj = new stdClass; - $obj->lang = $lang; - $this->ci_instance($obj); - } - - // Quick helper to actually grab the language - // file. Consider moving this to ci_testcase? - public function _get_lang($name) - { - require BASEPATH.'language/english/'.$name.'_lang.php'; - return $lang; + $this->ci_instance_var('lang', $lang); } public function test_byte_format() 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/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index f131469cb..d75d26208 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -64,6 +64,7 @@ class Text_helper_test extends CI_TestCase { public function test_convert_accented_characters() { + $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('á é í ó ú ñ ü')); } 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) |