public function testVoltUsersFilters() { $volt = new Compiler(); //Single string filter $volt->addFilter('reverse', 'strrev'); //Filter with closure $volt->addFilter('separate', function ($arguments, $exprArguments) { return 'explode(",", ' . $arguments . ')'; }); $compilation = $volt->compileString('{{ "hello"|reverse }}'); $this->assertEquals($compilation, '<?php echo strrev(\'hello\'); ?>'); $compilation = $volt->compileString('{{ "1,2,3,4"|separate }}'); $this->assertEquals($compilation, '<?php echo explode(",", \'1,2,3,4\'); ?>'); }
public function testVoltEngineLoopContext() { $volt = new Compiler(); $compiled = $volt->compileString('{% for i in 1..5 %}{{ loop.self.index }}{% endfor %}'); ob_start(); eval('?>' . $compiled); $result = ob_get_clean(); $this->assertEquals('12345', $result); }
public function testVoltRuntimeError() { $volt = new \Phalcon\Mvc\View\Engine\Volt\Compiler(); try { $volt->compileString('{{ "hello"|unknown }}'); $this->assertTrue(false); } catch (Phalcon\Mvc\View\Exception $e) { $this->assertEquals($e->getMessage(), 'Unknown filter "unknown" in eval code on line 1'); } try { $volt->compileString('{{ "hello"|unknown(1, 2, 3) }}'); $this->assertTrue(false); } catch (Phalcon\Mvc\View\Exception $e) { $this->assertEquals($e->getMessage(), 'Unknown filter "unknown" in eval code on line 1'); } try { $volt->compileString('{{ "hello"|(a-1) }}'); $this->assertTrue(false); } catch (Phalcon\Mvc\View\Exception $e) { $this->assertEquals($e->getMessage(), 'Unknown filter type in eval code on line 1'); } try { $volt->compileString('{{ unknown() }}'); $this->assertTrue(false); } catch (Phalcon\Mvc\View\Exception $e) { $this->assertEquals($e->getMessage(), "Undefined function 'unknown' in eval code on line 1"); } try { $volt->compileString('{{ dump(unknown()) }}'); $this->assertTrue(false); } catch (Phalcon\Mvc\View\Exception $e) { $this->assertEquals($e->getMessage(), "Undefined function 'unknown' in eval code on line 1"); } }
public function testVoltEngineLoopContext() { $this->specify("Volt loops don't work", function () { $volt = new Compiler(); $compiled = $volt->compileString('{% for i in 1..5 %}{{ loop.self.index }}{% endfor %}'); ob_start(); eval('?>' . $compiled); $result = ob_get_clean(); expect($result)->equals('12345'); }); }