From 052b01d9398de56e23300242f25d5317afcacf82 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 14:38:03 -0500 Subject: Adding string helper and inflector helper tests --- tests/codeigniter/helpers/string_helper_test.php | 117 +++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 tests/codeigniter/helpers/string_helper_test.php (limited to 'tests/codeigniter/helpers/string_helper_test.php') diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php new file mode 100644 index 000000000..71449f64a --- /dev/null +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -0,0 +1,117 @@ + 'Slashes//\\', + '/var/www/html/' => 'var/www/html' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, trim_slashes($str)); + } + } + + // -------------------------------------------------------------------- + + public function testStripSlashes() + { + $this->assertEquals("This is totally foo bar'd", trim_slashes("This is totally foo bar'd")); + } + + // -------------------------------------------------------------------- + + public function testStripQuotes() + { + $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 testQuotesToEntities() + { + $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 testReduceDoubleSlashes() + { + $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 testReduceMultiples() + { + $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 testRepeater() + { + $strs = array( + 'a' => 'aaaaaaaaaa', + ' ' => '          ', + '
' => '









' + + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, repeater($str, 10)); + } + } + + // -------------------------------------------------------------------- + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b4d93dbab7253f98613ab10e75e0ed20f06eaf19 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 14:42:33 -0500 Subject: Updating helper test classes to extend CI_TestCase --- tests/codeigniter/helpers/string_helper_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter/helpers/string_helper_test.php') diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index 71449f64a..00ba5dec7 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -2,7 +2,7 @@ require_once(BASEPATH.'helpers/string_helper.php'); -class String_helper_test extends PHPUnit_Framework_TestCase +class String_helper_test extends CI_TestCase { public function testTrimSlashes() { -- cgit v1.2.3-24-g4f1b From 68286a4dcc1ed4d904ad992173c1b3621bf6fced Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Thu, 21 Apr 2011 22:00:33 -0400 Subject: Reworked unit tests to match rest of framework and added a few more. --- tests/codeigniter/helpers/string_helper_test.php | 27 ++++++++++++------------ 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'tests/codeigniter/helpers/string_helper_test.php') diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index 00ba5dec7..5e0ee45de 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -4,7 +4,7 @@ require_once(BASEPATH.'helpers/string_helper.php'); class String_helper_test extends CI_TestCase { - public function testTrimSlashes() + public function test_trim_slashes() { $strs = array( '//Slashes//\/' => 'Slashes//\\', @@ -17,16 +17,9 @@ class String_helper_test extends CI_TestCase } } - // -------------------------------------------------------------------- - - public function testStripSlashes() - { - $this->assertEquals("This is totally foo bar'd", trim_slashes("This is totally foo bar'd")); - } - // -------------------------------------------------------------------- - public function testStripQuotes() + public function test_strip_quotes() { $strs = array( '"me oh my!"' => 'me oh my!', @@ -41,7 +34,7 @@ class String_helper_test extends CI_TestCase // -------------------------------------------------------------------- - public function testQuotesToEntities() + public function test_quotes_to_entities() { $strs = array( '"me oh my!"' => '"me oh my!"', @@ -56,7 +49,7 @@ class String_helper_test extends CI_TestCase // -------------------------------------------------------------------- - public function testReduceDoubleSlashes() + public function test_reduce_double_slashes() { $strs = array( 'http://codeigniter.com' => 'http://codeigniter.com', @@ -72,7 +65,7 @@ class String_helper_test extends CI_TestCase // -------------------------------------------------------------------- - public function testReduceMultiples() + public function test_reduce_multiples() { $strs = array( 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy', @@ -97,7 +90,7 @@ class String_helper_test extends CI_TestCase // -------------------------------------------------------------------- - public function testRepeater() + public function test_repeater() { $strs = array( 'a' => 'aaaaaaaaaa', @@ -114,4 +107,12 @@ class String_helper_test extends CI_TestCase // -------------------------------------------------------------------- + + 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)); + } + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 78ec0603601001b6f0b4d0c4ef6087d32a133a63 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 27 Nov 2011 00:48:56 -0500 Subject: Added tests for new increment_string --- tests/codeigniter/helpers/string_helper_test.php | 65 ++++++++++++++---------- 1 file changed, 38 insertions(+), 27 deletions(-) (limited to 'tests/codeigniter/helpers/string_helper_test.php') 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!"' => '"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( @@ -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', ' ' => '          ', '
' => '









' - + ); - + 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 -- cgit v1.2.3-24-g4f1b From 3fb5aa5886de15ef68e40b556a6ea3f1badf962e Mon Sep 17 00:00:00 2001 From: tiyowan Date: Fri, 16 Mar 2012 19:08:34 +0400 Subject: Add unit test for strip_slashes() in string_helper.php --- tests/codeigniter/helpers/string_helper_test.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/codeigniter/helpers/string_helper_test.php') diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index 2d7f96aa5..a884d6284 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -4,6 +4,21 @@ require_once(BASEPATH.'helpers/string_helper.php'); class String_helper_test extends CI_TestCase { + 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( -- cgit v1.2.3-24-g4f1b