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 --- .../codeigniter/helpers/inflector_helper_test.php | 91 ++++++++++++++++ tests/codeigniter/helpers/string_helper_test.php | 117 +++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 tests/codeigniter/helpers/inflector_helper_test.php create mode 100644 tests/codeigniter/helpers/string_helper_test.php (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php new file mode 100644 index 000000000..5e2fae9fd --- /dev/null +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -0,0 +1,91 @@ + 'telly', + 'smellies' => 'smelly', + 'abjectnesses' => 'abjectness', + 'smells' => 'smell' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, singular($str)); + } + } + + // -------------------------------------------------------------------- + + public function testPlural() + { + $strs = array( + 'telly' => 'tellies', + 'smelly' => 'smellies', + 'abjectness' => 'abjectness', + 'smell' => 'smells', + 'witch' => 'witches' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, plural($str)); + } + } + + // -------------------------------------------------------------------- + + public function testCamelize() + { + $strs = array( + 'this is the string' => 'thisIsTheString', + 'this is another one' => 'thisIsAnotherOne', + 'i-am-playing-a-trick' => 'i-am-playing-a-trick', + 'what_do_you_think-yo?' => 'whatDoYouThink-yo?', + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, camelize($str)); + } + } + + // -------------------------------------------------------------------- + + public function testUnderscore() + { + $strs = array( + 'this is the string' => 'this_is_the_string', + 'this is another one' => 'this_is_another_one', + 'i-am-playing-a-trick' => 'i-am-playing-a-trick', + 'what_do_you_think-yo?' => 'what_do_you_think-yo?', + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, underscore($str)); + } + } + + // -------------------------------------------------------------------- + + public function testHumanize() + { + $strs = array( + 'this_is_the_string' => 'This Is The String', + 'this_is_another_one' => 'This Is Another One', + 'i-am-playing-a-trick' => 'I-am-playing-a-trick', + 'what_do_you_think-yo?' => 'What Do You Think-yo?', + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, humanize($str)); + } + } +} \ No newline at end of file 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