diff options
author | Jamie Rumbelow <jamie@jamierumbelow.net> | 2012-04-26 14:27:35 +0200 |
---|---|---|
committer | Jamie Rumbelow <jamie@jamierumbelow.net> | 2012-04-26 14:27:35 +0200 |
commit | d6ce1e936d60487ad8ddd099a040fba7d8f88367 (patch) | |
tree | 31dcdda9a24e2ed12135659a4e38cb4f35b0af31 /tests/codeigniter/helpers/string_helper_test.php | |
parent | bcee50ff3247dee71d83bf273e52bc10096cd48c (diff) | |
parent | 9e2d5d130eff40592b49337a8ba4d8c170934de1 (diff) |
Merge branch 'develop' of git://github.com/EllisLab/CodeIgniter into develop
Conflicts:
system/core/Loader.php
system/database/DB_query_builder.php
system/database/drivers/cubrid/cubrid_driver.php
system/database/drivers/mssql/mssql_driver.php
system/database/drivers/mysql/mysql_driver.php
system/database/drivers/mysqli/mysqli_driver.php
system/database/drivers/oci8/oci8_driver.php
system/database/drivers/odbc/odbc_driver.php
system/database/drivers/pdo/pdo_driver.php
system/database/drivers/postgre/postgre_driver.php
system/database/drivers/sqlite/sqlite_driver.php
user_guide_src/source/changelog.rst
user_guide_src/source/database/query_builder.rst
Diffstat (limited to 'tests/codeigniter/helpers/string_helper_test.php')
-rw-r--r-- | tests/codeigniter/helpers/string_helper_test.php | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php new file mode 100644 index 000000000..29c3d6594 --- /dev/null +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -0,0 +1,147 @@ +<?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->assertInternalType('string', 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 |