From 9071573bc510f127fa22ddd367b2ff46a60242cc Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 14:36:26 -0500 Subject: Adding text_helper_test --- tests/codeigniter/helpers/text_helper_test.php | 151 +++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 tests/codeigniter/helpers/text_helper_test.php (limited to 'tests/codeigniter/helpers/text_helper_test.php') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php new file mode 100644 index 000000000..aa6660ea0 --- /dev/null +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -0,0 +1,151 @@ +_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 = ''; + $expect = "\n<?php var_dump(\$this); ?> \n\n"; + + $this->assertEquals($expect, highlight_code($code)); + } + + // ------------------------------------------------------------------------ + + public function testHighlightPhrase() + { + $strs = array( + 'this is a phrase' => 'this is a phrase', + 'this is another' => 'this is another', + 'Gimme a test, Sally' => 'Gimme a test, Sally', + 'Or tell me what this is' => 'Or tell me what this is', + '' => '' + ); + + 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 -- 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/text_helper_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter/helpers/text_helper_test.php') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index aa6660ea0..22c834bcf 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -2,7 +2,7 @@ require_once(BASEPATH.'helpers/text_helper.php'); -class Text_helper_test extends PHPUnit_Framework_TestCase +class Text_helper_test extends CI_TestCase { private $_long_string; -- 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/text_helper_test.php | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'tests/codeigniter/helpers/text_helper_test.php') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 22c834bcf..a0866e638 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -6,14 +6,14 @@ class Text_helper_test extends CI_TestCase { private $_long_string; - public function setUp() + 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 testWordLimiter() + 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, '…')); @@ -22,7 +22,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testCharacterLimiter() + 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, '…')); @@ -32,7 +32,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testAsciiToEntities() + public function test_ascii_to_entities() { $strs = array( '“‘ “test”' => '“‘ “test”', @@ -47,7 +47,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testEntitiesToAscii() + public function test_entities_to_ascii() { $strs = array( '“‘ “test”' => '“‘ “test”', @@ -59,10 +59,18 @@ class Text_helper_test extends CI_TestCase $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 testCensoredWords() + public function test_censored_words() { $censored = array('boob', 'nerd', 'ass', 'fart'); @@ -86,7 +94,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testHighlightCode() + public function test_highlight_code() { $code = ''; $expect = "\n<?php var_dump(\$this); ?> \n\n"; @@ -96,7 +104,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testHighlightPhrase() + public function test_highlight_phrase() { $strs = array( 'this is a phrase' => 'this is a phrase', @@ -114,7 +122,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testEllipsizing() + public function test_ellipsizing() { $strs = array( '0' => array( -- cgit v1.2.3-24-g4f1b