2013-03-15 14:53:19 +04:00
|
|
|
<?php
|
2013-06-28 11:53:53 +04:00
|
|
|
namespace Fenom;
|
2013-03-15 14:53:19 +04:00
|
|
|
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
class ModifiersTest extends TestCase
|
|
|
|
{
|
2013-03-15 14:53:19 +04:00
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerTruncate()
|
|
|
|
{
|
2013-05-30 19:00:00 +04:00
|
|
|
$lorem = 'Lorem ipsum dolor sit amet'; // en
|
2014-05-06 14:22:58 +04:00
|
|
|
$uni = 'Лорем ипсум долор сит амет'; // ru
|
2013-03-15 14:53:19 +04:00
|
|
|
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),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-05-30 19:00:00 +04:00
|
|
|
|
2013-03-15 14:53:19 +04:00
|
|
|
/**
|
|
|
|
* @dataProvider providerTruncate
|
|
|
|
* @param $in
|
|
|
|
* @param $out
|
|
|
|
* @param $count
|
|
|
|
* @param string $delim
|
2013-05-30 19:00:00 +04:00
|
|
|
* @param bool $by_words
|
|
|
|
* @param bool $middle
|
2013-03-15 14:53:19 +04:00
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testTruncate($in, $out, $count, $delim = '...', $by_words = false, $middle = false)
|
|
|
|
{
|
2013-06-28 11:53:53 +04:00
|
|
|
$tpl = $this->fenom->compileCode('{$text|truncate:$count:$delim:$by_words:$middle}');
|
2014-05-06 14:22:58 +04:00
|
|
|
$this->assertEquals(
|
|
|
|
$out,
|
|
|
|
$tpl->fetch(
|
|
|
|
array(
|
|
|
|
"text" => $in,
|
|
|
|
"count" => $count,
|
|
|
|
"delim" => $delim,
|
|
|
|
"by_words" => $by_words,
|
|
|
|
"middle" => $middle
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2013-03-15 14:53:19 +04:00
|
|
|
}
|
2013-05-30 19:00:00 +04:00
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerUpLow()
|
|
|
|
{
|
2013-05-30 19:00:00 +04:00
|
|
|
return array(
|
|
|
|
array("up", "lorem", "LOREM"),
|
|
|
|
array("up", "Lorem", "LOREM"),
|
|
|
|
array("up", "loREM", "LOREM"),
|
|
|
|
array("up", "223a", "223A"),
|
|
|
|
array("low", "lorem", "lorem"),
|
|
|
|
array("low", "Lorem", "lorem"),
|
|
|
|
array("low", "loREM", "lorem"),
|
|
|
|
array("low", "223A", "223a"),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerUpLow
|
|
|
|
* @param $modifier
|
|
|
|
* @param $in
|
|
|
|
* @param $out
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testUpLow($modifier, $in, $out)
|
|
|
|
{
|
|
|
|
$tpl = $this->fenom->compileCode('{$text|' . $modifier . '}');
|
2014-05-06 14:22:58 +04:00
|
|
|
$this->assertEquals(
|
|
|
|
$out,
|
|
|
|
$tpl->fetch(
|
|
|
|
array(
|
|
|
|
"text" => $in,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2013-05-30 19:00:00 +04:00
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerLength()
|
|
|
|
{
|
2013-05-30 19:00:00 +04:00
|
|
|
return array(
|
|
|
|
array("length", 6),
|
|
|
|
array("длина", 5),
|
|
|
|
array("length - длина", 14),
|
|
|
|
array(array(1, 33, "c" => 4), 3),
|
|
|
|
array(new \ArrayIterator(array(1, "c" => 4)), 2),
|
|
|
|
array(true, 0),
|
|
|
|
array(new \stdClass(), 0),
|
|
|
|
array(5, 0)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerLength
|
|
|
|
* @param $in
|
|
|
|
* @param $in
|
|
|
|
* @param $out
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testLength($in, $out)
|
|
|
|
{
|
2013-06-28 11:53:53 +04:00
|
|
|
$tpl = $this->fenom->compileCode('{$data|length}');
|
2014-05-06 14:22:58 +04:00
|
|
|
$this->assertEquals(
|
|
|
|
$out,
|
|
|
|
$tpl->fetch(
|
|
|
|
array(
|
|
|
|
"data" => $in,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2013-05-30 19:00:00 +04:00
|
|
|
}
|
|
|
|
|
2013-03-15 14:53:19 +04:00
|
|
|
}
|