diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-03-20 21:36:46 +0100 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-03-20 21:36:46 +0100 |
commit | 0d87bae93d5558f03d8194df13020517e3e84364 (patch) | |
tree | 1568d9fc5923c0e8e31ce232e289e67abd48d948 /tests/codeigniter/helpers/text_helper_test.php | |
parent | 1b5a85671bb28cdf87ef1c32c3d926a14a9409de (diff) | |
parent | 2f56fba915e35bcc7a36fbc047503d777decccd5 (diff) |
Merge upstream branch
Diffstat (limited to 'tests/codeigniter/helpers/text_helper_test.php')
-rw-r--r-- | tests/codeigniter/helpers/text_helper_test.php | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php new file mode 100644 index 000000000..a0866e638 --- /dev/null +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -0,0 +1,159 @@ +<?php + +require_once(BASEPATH.'helpers/text_helper.php'); + +class Text_helper_test extends CI_TestCase +{ + private $_long_string; + + public function set_up() + { + $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 test_word_limiter() + { + $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 test_character_limiter() + { + $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 test_ascii_to_entities() + { + $strs = array( + '“‘ “test”' => '“‘ “test”', + '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '†¥¨ˆøåß∂ƒ©˙∆˚¬' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, ascii_to_entities($str)); + } + } + + // ------------------------------------------------------------------------ + + public function test_entities_to_ascii() + { + $strs = array( + '“‘ “test”' => '“‘ “test”', + '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '†¥¨ˆøåß∂ƒ©˙∆˚¬' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, entities_to_ascii($str)); + } + } + + // ------------------------------------------------------------------------ + + function test_convert_accented_characters() + { + $this->assertEquals('AAAeEEEIIOOEUUUeY', convert_accented_characters('ÀÂÄÈÊËÎÏÔŒÙÛÜŸ')); + $this->assertEquals('a e i o u n ue', convert_accented_characters('á é í ó ú ñ ü')); + } + + // ------------------------------------------------------------------------ + + public function test_censored_words() + { + $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 test_highlight_code() + { + $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 test_highlight_phrase() + { + $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 test_ellipsizing() + { + $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 |