summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/helpers/string_helper_test.php
diff options
context:
space:
mode:
authorEric Barnes <eric@ericlbarnes.com>2011-11-27 06:48:56 +0100
committerEric Barnes <eric@ericlbarnes.com>2011-11-27 06:48:56 +0100
commit78ec0603601001b6f0b4d0c4ef6087d32a133a63 (patch)
tree3aa82d75320298514fbb0480ac82f532225d9ca7 /tests/codeigniter/helpers/string_helper_test.php
parent7e66dda705743cbfe1d522ddb73e5694006ec42c (diff)
Added tests for new increment_string
Diffstat (limited to 'tests/codeigniter/helpers/string_helper_test.php')
-rw-r--r--tests/codeigniter/helpers/string_helper_test.php65
1 files changed, 38 insertions, 27 deletions
diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php
index 5e0ee45de..2d7f96aa5 100644
--- a/tests/codeigniter/helpers/string_helper_test.php
+++ b/tests/codeigniter/helpers/string_helper_test.php
@@ -10,14 +10,14 @@ class String_helper_test extends CI_TestCase
'//Slashes//\/' => 'Slashes//\\',
'/var/www/html/' => 'var/www/html'
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, trim_slashes($str));
}
}
-
- // --------------------------------------------------------------------
+
+ // --------------------------------------------------------------------
public function test_strip_quotes()
{
@@ -25,30 +25,30 @@ class String_helper_test extends CI_TestCase
'"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!"' => '&quot;me oh my!&quot;',
"it's a winner!" => 'it&#39;s a winner!',
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, quotes_to_entities($str));
- }
+ }
}
- // --------------------------------------------------------------------
-
+ // --------------------------------------------------------------------
+
public function test_reduce_double_slashes()
{
$strs = array(
@@ -56,57 +56,56 @@ class String_helper_test extends CI_TestCase
'//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',
'&nbsp;' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'<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()
{
@@ -114,5 +113,17 @@ class String_helper_test extends CI_TestCase
$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