mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Add tests
This commit is contained in:
parent
e6a9b511bd
commit
97838eb0b9
@ -8,6 +8,8 @@ php:
|
||||
|
||||
before_script:
|
||||
- composer install --dev
|
||||
- phpunit --help
|
||||
- coveralls --help
|
||||
|
||||
script:
|
||||
- phpunit
|
||||
|
@ -139,6 +139,7 @@ class Fenom
|
||||
"split" => 'Fenom\Modifier::split',
|
||||
"esplit" => 'Fenom\Modifier::esplit',
|
||||
"join" => 'Fenom\Modifier::join',
|
||||
"in" => 'Fenom\Modifier::in',
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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!'),
|
||||
|
Loading…
Reference in New Issue
Block a user