diff options
author | Greg Aker <greg.aker@ellislab.com> | 2011-04-21 22:19:37 +0200 |
---|---|---|
committer | Greg Aker <greg.aker@ellislab.com> | 2011-04-21 22:19:37 +0200 |
commit | b58aeaca9be4b342bb6d88138005fdc7138828b4 (patch) | |
tree | f986aefeec38cfb6938c93f90596c41631edd7ce /tests/codeigniter/helpers | |
parent | 1d3021a26e3d542137ceddc6c0f4a08a4f80a096 (diff) | |
parent | 9512ab8a22ff14a3789cba6e5ace03aed4196e23 (diff) |
Branch merge
Diffstat (limited to 'tests/codeigniter/helpers')
-rw-r--r-- | tests/codeigniter/helpers/array_helper_test.php | 49 | ||||
-rw-r--r-- | tests/codeigniter/helpers/html_helper_test.php | 67 | ||||
-rw-r--r-- | tests/codeigniter/helpers/inflector_helper_test.php | 91 | ||||
-rw-r--r-- | tests/codeigniter/helpers/string_helper_test.php | 117 | ||||
-rw-r--r-- | tests/codeigniter/helpers/text_helper_test.php | 151 |
5 files changed, 475 insertions, 0 deletions
diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php new file mode 100644 index 000000000..fd306cee8 --- /dev/null +++ b/tests/codeigniter/helpers/array_helper_test.php @@ -0,0 +1,49 @@ +<?php + +// OLD TEST FORMAT: DO NOT COPY + +require_once(BASEPATH.'helpers/array_helper.php'); + +class Array_helper_test extends CI_TestCase +{ + public function setUp() + { + $this->my_array = array( + 'foo' => 'bar', + 'sally' => 'jim', + 'maggie' => 'bessie', + 'herb' => 'cook' + ); + } + + // ------------------------------------------------------------------------ + + public function testElementWithExistingItem() + { + $this->assertEquals(FALSE, element('testing', $this->my_array)); + + $this->assertEquals('not set', element('testing', $this->my_array, 'not set')); + + $this->assertEquals('bar', element('foo', $this->my_array)); + } + + // ------------------------------------------------------------------------ + + public function testRandomElement() + { + // Send a string, not an array to random_element + $this->assertEquals('my string', random_element('my string')); + + // Test sending an array + $this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array)); + } + + // ------------------------------------------------------------------------ + + public function testElements() + { + $this->assertEquals(TRUE, is_array(elements('test', $this->my_array))); + $this->assertEquals(TRUE, is_array(elements('foo', $this->my_array))); + } + +}
\ No newline at end of file diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php new file mode 100644 index 000000000..8c0e53301 --- /dev/null +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -0,0 +1,67 @@ +<?php + +require_once(BASEPATH.'helpers/html_helper.php'); + +class Html_helper_test extends CI_TestCase +{ + public function testHeading() + { + $this->assertEquals('<h1>foobar</h1>', heading('foobar')); + } + + // ------------------------------------------------------------------------ + + public function testUl() + { + $expect = <<<EOH +<ul> + <li>foo</li> + <li>bar</li> +</ul> + +EOH; + + $expect = ltrim($expect); + + $list = array('foo', 'bar'); + + $this->assertEquals($expect, ul($list)); + + + $expect = <<<EOH +<ul class="test"> + <li>foo</li> + <li>bar</li> +</ul> + +EOH; + + $expect = ltrim($expect); + + $list = array('foo', 'bar'); + + $this->assertEquals($expect, ul($list, ' class="test"')); + + $this->assertEquals($expect, ul($list, array('class' => 'test'))); + } + + // ------------------------------------------------------------------------ + + public function testNBS() + { + $this->assertEquals(' ', nbs(3)); + } + + // ------------------------------------------------------------------------ + + public function testMeta() + { + $this->assertEquals("<meta name=\"test\" content=\"foo\" />\n", meta('test', 'foo')); + + $expect = "<meta name=\"foo\" content=\"\" />\n"; + + $this->assertEquals($expect, meta(array('name' => 'foo'))); + + } + +}
\ No newline at end of file diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php new file mode 100644 index 000000000..e59875e4a --- /dev/null +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -0,0 +1,91 @@ +<?php + +require_once(BASEPATH.'helpers/inflector_helper.php'); + +class Inflector_helper_test extends CI_TestCase { + + + public function testSingular() + { + $strs = array( + 'tellies' => '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..00ba5dec7 --- /dev/null +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -0,0 +1,117 @@ +<?php + +require_once(BASEPATH.'helpers/string_helper.php'); + +class String_helper_test extends CI_TestCase +{ + public function testTrimSlashes() + { + $strs = array( + '//Slashes//\/' => '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', + ' ' => ' ', + '<br>' => '<br><br><br><br><br><br><br><br><br><br>' + + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, repeater($str, 10)); + } + } + + // -------------------------------------------------------------------- + +}
\ No newline at end of file diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php new file mode 100644 index 000000000..22c834bcf --- /dev/null +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -0,0 +1,151 @@ +<?php + +require_once(BASEPATH.'helpers/text_helper.php'); + +class Text_helper_test extends CI_TestCase +{ + private $_long_string; + + public function setUp() + { + $this->_long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.'; + } + + // ------------------------------------------------------------------------ + + public function testWordLimiter() + { + $this->assertEquals('Once upon a time,…', word_limiter($this->_long_string, 4)); + $this->assertEquals('Once upon a time,…', word_limiter($this->_long_string, 4, '…')); + $this->assertEquals('', word_limiter('', 4)); + } + + // ------------------------------------------------------------------------ + + public function testCharacterLimiter() + { + $this->assertEquals('Once upon a time, a…', character_limiter($this->_long_string, 20)); + $this->assertEquals('Once upon a time, a…', character_limiter($this->_long_string, 20, '…')); + $this->assertEquals('Short', character_limiter('Short', 20)); + $this->assertEquals('Short', character_limiter('Short', 5)); + } + + // ------------------------------------------------------------------------ + + public function testAsciiToEntities() + { + $strs = array( + '“‘ “test”' => '“‘ “test”', + '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '†¥¨ˆøåß∂ƒ©˙∆˚¬' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, ascii_to_entities($str)); + } + } + + // ------------------------------------------------------------------------ + + public function testEntitiesToAscii() + { + $strs = array( + '“‘ “test”' => '“‘ “test”', + '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '†¥¨ˆøåß∂ƒ©˙∆˚¬' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, entities_to_ascii($str)); + } + } + + // ------------------------------------------------------------------------ + + public function testCensoredWords() + { + $censored = array('boob', 'nerd', 'ass', 'fart'); + + $strs = array( + 'Ted bobbled the ball' => 'Ted bobbled the ball', + 'Jake is a nerdo' => 'Jake is a nerdo', + 'The borg will assimilate you' => 'The borg will assimilate you', + 'Did Mary Fart?' => 'Did Mary $*#?', + 'Jake is really a boob' => 'Jake is really a $*#' + ); + + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, word_censor($str, $censored, '$*#')); + } + + // test censored words being sent as a string + $this->assertEquals('test', word_censor('test', 'test')); + } + + // ------------------------------------------------------------------------ + + public function testHighlightCode() + { + $code = '<?php var_dump($this); ?>'; + $expect = "<code><span style=\"color: #000000\">\n<span style=\"color: #0000BB\"><?php var_dump</span><span style=\"color: #007700\">(</span><span style=\"color: #0000BB\">\$this</span><span style=\"color: #007700\">); </span><span style=\"color: #0000BB\">?> </span>\n</span>\n</code>"; + + $this->assertEquals($expect, highlight_code($code)); + } + + // ------------------------------------------------------------------------ + + public function testHighlightPhrase() + { + $strs = array( + 'this is a phrase' => '<strong>this is</strong> a phrase', + 'this is another' => '<strong>this is</strong> another', + 'Gimme a test, Sally' => 'Gimme a test, Sally', + 'Or tell me what this is' => 'Or tell me what <strong>this is</strong>', + '' => '' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, highlight_phrase($str, 'this is')); + } + } + + // ------------------------------------------------------------------------ + + public function testEllipsizing() + { + $strs = array( + '0' => array( + 'this is my string' => '… my string', + "here's another one" => '…nother one', + 'this one is just a bit longer' => '…bit longer', + 'short' => 'short' + ), + '.5' => array( + 'this is my string' => 'this …tring', + "here's another one" => "here'…r one", + 'this one is just a bit longer' => 'this …onger', + 'short' => 'short' + ), + '1' => array( + 'this is my string' => 'this is my…', + "here's another one" => "here's ano…", + 'this one is just a bit longer' => 'this one i…', + 'short' => 'short' + ), + ); + + foreach ($strs as $pos => $s) + { + foreach ($s as $str => $expect) + { + $this->assertEquals($expect, ellipsize($str, 10, $pos)); + } + } + } + + // ------------------------------------------------------------------------ + +}
\ No newline at end of file |