summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/helpers/text_helper_test.php
diff options
context:
space:
mode:
authorEric Roberts <eric@cryode.com>2012-12-12 14:02:11 +0100
committerEric Roberts <eric@cryode.com>2012-12-12 14:02:11 +0100
commitb9e35f21e1c70b6aa67c47e9244ed83195abc00a (patch)
tree64f82db362deeac48cc20d1d1afd80651f36f5a5 /tests/codeigniter/helpers/text_helper_test.php
parent0b05705c52c3bca7f9b3aee657c888e8ad1ff422 (diff)
parent545a7c86701875e1412bcde316e9bcc76d9a23a0 (diff)
Merge branch 'refs/heads/develop' into feature/form_error_msgs
Conflicts: system/language/english/form_validation_lang.php user_guide_src/source/libraries/form_validation.rst Signed-off-by: Eric Roberts <eric@cryode.com>
Diffstat (limited to 'tests/codeigniter/helpers/text_helper_test.php')
-rw-r--r--tests/codeigniter/helpers/text_helper_test.php77
1 files changed, 45 insertions, 32 deletions
diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php
index 584066b0c..d75d26208 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,28 @@ 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->ci_vfs_clone('application/config/foreign_chars.php');
$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 +82,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,16 +112,16 @@ 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_ellipsizing()
+ public function test_ellipsize()
{
$strs = array(
'0' => array(
@@ -144,16 +143,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.';
+ $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.";
+ $this->assertEquals(strpos(word_wrap($string), "\n"), 73);
+ }
} \ No newline at end of file