diff --git a/.travis.yml b/.travis.yml index c98ca2d..97a4bb1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,8 @@ php: before_script: - composer install --dev + - phpunit --help + - coveralls --help script: - phpunit diff --git a/src/Fenom.php b/src/Fenom.php index 073c002..31f12d9 100644 --- a/src/Fenom.php +++ b/src/Fenom.php @@ -139,6 +139,7 @@ class Fenom "split" => 'Fenom\Modifier::split', "esplit" => 'Fenom\Modifier::esplit', "join" => 'Fenom\Modifier::join', + "in" => 'Fenom\Modifier::in', ); /** diff --git a/tests/cases/Fenom/ModifiersTest.php b/tests/cases/Fenom/ModifiersTest.php index 452bb86..25883f7 100644 --- a/tests/cases/Fenom/ModifiersTest.php +++ b/tests/cases/Fenom/ModifiersTest.php @@ -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() { diff --git a/tests/cases/Fenom/TemplateTest.php b/tests/cases/Fenom/TemplateTest.php index 5503331..a29bab4 100644 --- a/tests/cases/Fenom/TemplateTest.php +++ b/tests/cases/Fenom/TemplateTest.php @@ -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!'),