Phalcon\Test\Unit\Mvc\View\Engine\Volt\CompilerTest::testVoltUsersFunctions PHP Method

testVoltUsersFunctions() public method

    public function testVoltUsersFunctions()
    {
        $this->specify("Custom functions should work", function () {
            $volt = new Compiler();
            //Single string function
            $volt->addFunction('random', 'mt_rand');
            //Function with closure
            $volt->addFunction('shuffle', function ($arguments, $exprArguments) {
                return 'str_shuffle(' . $arguments . ')';
            });
            $volt->addFunction('strtotime', 'strtotime');
            $compilation = $volt->compileString('{{ random() }}');
            expect($compilation)->equals('<?= mt_rand() ?>');
            $compilation = $volt->compileString('{{ shuffle("hello") }}');
            expect($compilation)->equals('<?= str_shuffle(\'hello\') ?>');
            $compilation = $volt->compileString('{{ strtotime("now") }}');
            expect($compilation)->equals("<?= strtotime('now') ?>");
        });
    }