_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));
}
}
}
// ------------------------------------------------------------------------
}