summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/helpers/text_helper_test.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-06-09 21:24:46 +0200
committerAndrey Andreev <narf@bofh.bg>2012-06-09 21:24:46 +0200
commit99b782d8a3d92c4703a059cbd62e2f1e6fea689c (patch)
tree622bd77c72eb812e37d4b3816b93528679d71425 /tests/codeigniter/helpers/text_helper_test.php
parent1b60fda70ff1e1801c133575c530ef0a5a450029 (diff)
Cleanup and optimize helper tests for speed
Diffstat (limited to 'tests/codeigniter/helpers/text_helper_test.php')
-rw-r--r--tests/codeigniter/helpers/text_helper_test.php70
1 files changed, 33 insertions, 37 deletions
diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php
index 73e2b9429..f131469cb 100644
--- a/tests/codeigniter/helpers/text_helper_test.php
+++ b/tests/codeigniter/helpers/text_helper_test.php
@@ -3,16 +3,16 @@
class Text_helper_test extends CI_TestCase {
private $_long_string;
-
+
public function set_up()
{
$this->helper('text');
-
+
$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,&#8230;', word_limiter($this->_long_string, 4));
@@ -20,8 +20,8 @@ class Text_helper_test extends CI_TestCase {
$this->assertEquals('', word_limiter('', 4));
}
- // ------------------------------------------------------------------------
-
+ // ------------------------------------------------------------------------
+
public function test_character_limiter()
{
$this->assertEquals('Once upon a time, a&#8230;', character_limiter($this->_long_string, 20));
@@ -30,22 +30,22 @@ class Text_helper_test extends CI_TestCase {
$this->assertEquals('Short', character_limiter('Short', 5));
}
- // ------------------------------------------------------------------------
-
+ // ------------------------------------------------------------------------
+
public function test_ascii_to_entities()
{
$strs = array(
'“‘ “test”' => '&#8220;&#8216; &#8220;test&#8221;',
'†¥¨ˆøåß∂ƒ©˙∆˚¬' => '&#8224;&#165;&#168;&#710;&#248;&#229;&#223;&#8706;&#402;&#169;&#729;&#8710;&#730;&#172;'
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, ascii_to_entities($str));
}
}
- // ------------------------------------------------------------------------
+ // ------------------------------------------------------------------------
public function test_entities_to_ascii()
{
@@ -53,27 +53,27 @@ class Text_helper_test extends CI_TestCase {
'&#8220;&#8216; &#8220;test&#8221;' => '“‘ “test”',
'&#8224;&#165;&#168;&#710;&#248;&#229;&#223;&#8706;&#402;&#169;&#729;&#8710;&#730;&#172;' => '†¥¨ˆøåß∂ƒ©˙∆˚¬'
);
-
+
foreach ($strs as $str => $expect)
{
$this->assertEquals($expect, entities_to_ascii($str));
- }
+ }
}
-
- // ------------------------------------------------------------------------
-
- function test_convert_accented_characters()
+
+ // ------------------------------------------------------------------------
+
+ public 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',
@@ -81,28 +81,26 @@ class Text_helper_test extends CI_TestCase {
'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\">&lt;?php&nbsp;var_dump</span><span style=\"color: #007700\">(</span><span style=\"color: #0000BB\">\$this</span><span style=\"color: #007700\">);&nbsp;</span><span style=\"color: #0000BB\">?&gt;&nbsp;</span>\n</span>\n</code>";
- $this->assertEquals($expect, highlight_code($code));
+ $this->assertEquals($expect, highlight_code('<?php var_dump($this); ?>'));
}
- // ------------------------------------------------------------------------
+ // ------------------------------------------------------------------------
public function test_highlight_phrase()
{
@@ -113,14 +111,14 @@ class Text_helper_test extends CI_TestCase {
'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_ellipsize()
{
@@ -144,32 +142,30 @@ class Text_helper_test extends CI_TestCase {
'short' => 'short'
),
);
-
+
foreach ($strs as $pos => $s)
{
foreach ($s as $str => $expect)
{
- $this->assertEquals($expect, ellipsize($str, 10, $pos));
+ $this->assertEquals($expect, ellipsize($str, 10, $pos));
}
}
}
- // ------------------------------------------------------------------------
+ // ------------------------------------------------------------------------
public function test_word_wrap()
{
- $string = "Here is a simple string of text that will help us demonstrate this function.";
- $word_wrapped = word_wrap($string, 25);
- $this->assertEquals(substr_count($word_wrapped, "\n"), 4);
+ $string = 'Here is a simple string of text that will help us demonstrate this function.';
+ $this->assertEquals(substr_count(word_wrap($string, 25), "\n"), 4);
}
- // ------------------------------------------------------------------------
+ // ------------------------------------------------------------------------
public function test_default_word_wrap_charlim()
{
$string = "Here is a longer string of text that will help us demonstrate the default charlim of this function.";
- $word_wrapped = word_wrap($string);
- $this->assertEquals(strpos($word_wrapped, "\n"), 73);
+ $this->assertEquals(strpos(word_wrap($string), "\n"), 73);
}
} \ No newline at end of file