1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
<?php
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,…', 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_ellipsize()
{
$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));
}
}
}
// ------------------------------------------------------------------------
public function test_word_wrap()
{
$string = "Here is a simple string of text that will help us demonstrate this function.";
$word_wraped = word_wrap($string, 25);
preg_match_all("/\r\n|\n/", $word_wraped, $matches);
$this->assertEquals(count($matches[0]), 4);
}
}
|