2013-03-15 14:53:19 +04:00
|
|
|
<?php
|
2013-04-04 10:56:44 +04:00
|
|
|
namespace Cytro;
|
2013-03-15 14:53:19 +04:00
|
|
|
|
|
|
|
|
|
|
|
class ModifiersTest extends TestCase {
|
|
|
|
|
|
|
|
public static function providerTruncate() {
|
|
|
|
$lorem = 'Lorem ipsum dolor sit amet';
|
|
|
|
$uni = 'Лорем ипсум долор сит амет';
|
|
|
|
return array(
|
|
|
|
// ascii chars
|
|
|
|
array($lorem, 'Lorem ip...', 8),
|
|
|
|
array($lorem, 'Lorem ip!!!', 8, '!!!'),
|
|
|
|
array($lorem, 'Lorem...', 8, '...', true),
|
|
|
|
array($lorem, 'Lorem ip...sit amet', 8, '...', false, true),
|
|
|
|
array($lorem, 'Lorem...amet', 8, '...', true, true),
|
|
|
|
// unicode
|
|
|
|
array($uni, 'Лорем ип...', 8),
|
|
|
|
array($uni, 'Лорем ип!!!', 8, '!!!'),
|
|
|
|
array($uni, 'Лорем...', 8, '...', true),
|
|
|
|
array($uni, 'Лорем ип...сит амет', 8, '...', false, true),
|
|
|
|
array($uni, 'Лорем...амет', 8, '...', true, true),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTruncate
|
|
|
|
* @param $in
|
|
|
|
* @param $out
|
|
|
|
* @param $count
|
|
|
|
* @param string $delim
|
|
|
|
* @param bool $by_word
|
|
|
|
*/
|
|
|
|
public function testTruncate($in, $out, $count, $delim = '...', $by_words = false, $middle = false) {
|
2013-04-04 10:56:44 +04:00
|
|
|
$tpl = $this->cytro->compileCode('{$text|truncate:$count:$delim:$by_words:$middle}');
|
2013-03-15 14:53:19 +04:00
|
|
|
$this->assertEquals($out, $tpl->fetch(array(
|
|
|
|
"text" => $in,
|
|
|
|
"count" => $count,
|
|
|
|
"delim" => $delim,
|
|
|
|
"by_words" => $by_words,
|
|
|
|
"middle" => $middle
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
}
|