diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3c403ab3c87..3be37c2e578 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,5 @@
# [2.0.12](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.12) (????-??-??)
+- Fixed regression changes for `Phalcon\Mvc\View\Engine\Volt::callMacro` [#11745](https://github.com/phalcon/cphalcon/issues/11745)
# [2.0.11](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.11) (2016-05-04)
- Fix Model magic set functionality to maintain variable visibility and utilize setter methods.[#11286](https://github.com/phalcon/cphalcon/issues/11286)
diff --git a/phalcon/mvc/view/engine/volt.zep b/phalcon/mvc/view/engine/volt.zep
index a42d7f6bbea..6bf49d5f649 100644
--- a/phalcon/mvc/view/engine/volt.zep
+++ b/phalcon/mvc/view/engine/volt.zep
@@ -3,7 +3,7 @@
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
- | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) |
+ | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
@@ -121,7 +121,6 @@ class Volt extends Engine implements EngineInterface
if mustClean {
this->_view->setContent(ob_get_contents());
- //ob_clean();
}
}
@@ -285,7 +284,7 @@ class Volt extends Engine implements EngineInterface
/**
* Checks if a macro is defined and calls it
*/
- public function callMacro(string! name, array arguments)
+ public function callMacro(string! name, array arguments = []) -> var
{
var macro;
@@ -293,6 +292,6 @@ class Volt extends Engine implements EngineInterface
throw new Exception("Macro '" . name . "' does not exist");
}
- return call_user_func_array(macro, arguments);
+ return call_user_func(macro, arguments);
}
}
diff --git a/unit-tests/TODO.txt b/unit-tests/TODO.txt
index 3b6ae6fd4da..06e6013fd19 100644
--- a/unit-tests/TODO.txt
+++ b/unit-tests/TODO.txt
@@ -1,4 +1,3 @@
- Tests for foreign keys cascade in the ORM
- Tests for many-to-many relations
-- Tests for macros in Volt
- Tests for +=, -=, *=, /=, ++, -- in Volt
diff --git a/unit-tests/ViewEnginesVoltTest.php b/unit-tests/ViewEnginesVoltTest.php
index 4238deccbfa..834d8483bef 100644
--- a/unit-tests/ViewEnginesVoltTest.php
+++ b/unit-tests/ViewEnginesVoltTest.php
@@ -4,7 +4,7 @@
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
- | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) |
+ | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
@@ -19,6 +19,12 @@
*/
use Phalcon\Mvc\View\Engine\Volt\Compiler;
+use Phalcon\Mvc\View\Engine\Volt;
+use Phalcon\Mvc\View;
+use Phalcon\Escaper;
+use Phalcon\Mvc\Url;
+use Phalcon\Tag;
+use Phalcon\Di;
class SomeObject implements Iterator, Countable
{
@@ -1120,12 +1126,17 @@ public function testVoltUsersFunctions()
return 'str_shuffle(' . $arguments . ')';
});
+ $volt->addFunction('strtotime', 'strtotime');
+
$compilation = $volt->compileString('{{ random() }}');
$this->assertEquals($compilation, '');
$compilation = $volt->compileString('{{ shuffle("hello") }}');
$this->assertEquals($compilation, '');
+ $compilation = $volt->compileString('{{ strtotime("now") }}');
+ $this->assertEquals("", $compilation);
+
}
public function testVoltUsersFilters()
@@ -1379,4 +1390,105 @@ public function testVoltEngineBuiltInFunctions()
$this->assertEquals($view->getContent(), 'Length Array: 4Length Object: 4Length String: 5Length No String: 4Slice Array: 1,2,3,4Slice Array: 2,3Slice Array: 1,2,3Slice Object: 2,3,4Slice Object: 2,3Slice Object: 1,2Slice String: helSlice String: elSlice String: lloSlice No String: 123Slice No String: 23Slice No String: 34');
}
+
+ public function testVoltMacros()
+ {
+ $this->removeFiles([
+ 'unit-tests/views/macro/hello.volt.php',
+ 'unit-tests/views/macro/conditionaldate.volt.php',
+ 'unit-tests/views/macro/my_input.volt.php',
+ 'unit-tests/views/macro/error_messages.volt.php',
+ 'unit-tests/views/macro/related_links.volt.php',
+ 'unit-tests/views/macro/strtotime.volt.php',
+ ]);
+
+ Di::reset();
+
+ $view = new View;
+ $di = new Di;
+
+ $di->set('escaper', function() { return new Escaper; });
+ $di->set('tag', function() { return new Tag; });
+ $di->set('url', function() { return (new Url)->setBaseUri('/'); });
+
+ $view->setDI($di);
+ $view->setViewsDir('unit-tests/views/');
+ $view->registerEngines(array(
+ '.volt' => function ($view, $di) {
+ $volt = new Volt($view, $di);
+ $compiler = $volt->getCompiler();
+ $compiler->addFunction('strtotime', 'strtotime');
+
+ return $volt;
+ }
+ ));
+
+ $view->start();
+ $view->render('macro', 'hello');
+ $view->finish();
+
+ $this->assertEquals('Hello World', $view->getContent());
+
+ $view->start();
+ $view->render('macro', 'conditionaldate');
+ $view->finish();
+
+ $this->assertEquals(sprintf('from
%s, %s UTC', date('Y-m-d'), date('H:i')), $view->getContent());
+
+ $view->start();
+ $view->render('macro', 'my_input');
+ $view->finish();
+
+ $this->assertEquals('
' ~ my_input('name') ~ '
' -}} diff --git a/unit-tests/views/macro/related_links.volt b/unit-tests/views/macro/related_links.volt new file mode 100644 index 00000000000..cd5ec9f8f57 --- /dev/null +++ b/unit-tests/views/macro/related_links.volt @@ -0,0 +1,9 @@ +{%- macro related_bar(related_links) -%} +