Add tests

This commit is contained in:
bzick 2014-07-11 12:11:51 +04:00
parent e6a9b511bd
commit 97838eb0b9
4 changed files with 46 additions and 0 deletions

View File

@ -8,6 +8,8 @@ php:
before_script:
- composer install --dev
- phpunit --help
- coveralls --help
script:
- phpunit

View File

@ -139,6 +139,7 @@ class Fenom
"split" => 'Fenom\Modifier::split',
"esplit" => 'Fenom\Modifier::esplit',
"join" => 'Fenom\Modifier::join',
"in" => 'Fenom\Modifier::in',
);
/**

View File

@ -16,12 +16,16 @@ class ModifiersTest extends TestCase
array($lorem, 'Lorem...', 8, '...', true),
array($lorem, 'Lorem ip...sit amet', 8, '...', false, true),
array($lorem, 'Lorem...amet', 8, '...', true, true),
array($lorem, $lorem, 100, '...', true, true),
array($lorem, $lorem, 100, '...', true, false),
// unicode
array($uni, 'Лорем ип...', 8),
array($uni, 'Лорем ип!!!', 8, '!!!'),
array($uni, 'Лорем...', 8, '...', true),
array($uni, 'Лорем ип...сит амет', 8, '...', false, true),
array($uni, 'Лорем...амет', 8, '...', true, true),
array($uni, $uni, 100, '...', true, true),
array($uni, $uni, 100, '...', true, false),
);
}
@ -119,6 +123,44 @@ class ModifiersTest extends TestCase
);
}
public static function providerIn()
{
return array(
array('"b"|in:["a", "b", "c"]', true),
array('"d"|in:["a", "b", "c"]', false),
array('2|in:["a", "b", "c"]', true),
array('3|in:["a", "b", "c"]', false),
array('"b"|in:"abc"', true),
array('"d"|in:"abc"', false),
);
}
/**
* @dataProvider providerIn
*/
public function testIn($code, $valid)
{
$tpl = $this->fenom->compileCode('{if '.$code.'}valid{else}invalid{/if}');
$this->assertEquals($valid ? "valid" : "invalid", $tpl->fetch(array()));
}
public function testJoin()
{
$tpl = $this->fenom->compileCode('{if "a;b;c" === ["a", "b", "c"]|join:";"}equal{/if}');
$this->assertEquals("equal", $tpl->fetch(array()));
}
public function testJoinString()
{
$tpl = $this->fenom->compileCode('{if "a;b;c" === "a;b;c"|join:","}equal{/if}');
$this->assertEquals("equal", $tpl->fetch(array()));
}
public function testJoinOther()
{
$tpl = $this->fenom->compileCode('{if "" === true|join:","}equal{/if}');
$this->assertEquals("equal", $tpl->fetch(array()));
}
public function testSplit()
{

View File

@ -163,6 +163,7 @@ class TemplateTest extends TestCase
array('Mod: {$rescue|escape:"html"}!', $b, 'Mod: Chip & Dale!'),
array('Mod: {$rescue|escape:"url"}!', $b, 'Mod: Chip+%26+Dale!'),
array('Mod: {$rescue|escape:"unknown"}!', $b, 'Mod: Chip & Dale!'),
array('Mod: {$rescue|escape:"js"}!', $b, 'Mod: "Chip & Dale"!'),
array('Mod: {$rescue_html|unescape}!', $b, 'Mod: Chip & Dale!'),
array('Mod: {$rescue_html|unescape:"html"}!', $b, 'Mod: Chip & Dale!'),
array('Mod: {$rescue_url|unescape:"url"}!', $b, 'Mod: Chip & Dale!'),