fixed tests where macros were not used properly

This commit is contained in:
Fabien Potencier
2012-10-12 16:42:58 +02:00
parent 9728a5de40
commit e1e9802c56
5 changed files with 20 additions and 10 deletions
+6 -3
View File
@@ -156,10 +156,13 @@ class Twig_Tests_Extension_SandboxTest extends PHPUnit_Framework_TestCase
public function testMacrosInASandbox()
{
$twig = $this->getEnvironment(true, array('autoescape' => true), array('index' => <<<EOF
{% macro test(text) %}<p>{{ text }}</p>{% endmacro %}
{{ _self.test('username') }}
{%- import _self as macros %}
{%- macro test(text) %}<p>{{ text }}</p>{% endmacro %}
{{- macros.test('username') }}
EOF
), array('macro'), array('escape'));
), array('macro', 'import'), array('escape'));
$this->assertEquals('<p>username</p>', $twig->loadTemplate('index')->render(array()));
}
@@ -1,6 +1,7 @@
--TEST--
Twig parses postfix expressions
--TEMPLATE--
{% import _self as macros %}
{% macro foo() %}foo{% endmacro %}
@@ -8,8 +9,8 @@ Twig parses postfix expressions
{{ 'a'|upper }}
{{ ('a')|upper }}
{{ -1|upper }}
{{ _self.foo() }}
{{ (_self).foo() }}
{{ macros.foo() }}
{{ (macros).foo() }}
--DATA--
return array();
--EXPECT--
@@ -1,8 +1,10 @@
--TEST--
"macro" tag
--TEMPLATE--
{{ _self.input('username') }}
{{ _self.input('password', null, 'password', 1) }}
{% import _self as macros %}
{{ macros.input('username') }}
{{ macros.input('password', null, 'password', 1) }}
{% macro input(name, value, type, size) %}
<input type="{{ type|default("text") }}" name="{{ name }}" value="{{ value|e|default('') }}" size="{{ size|default(20) }}">
@@ -1,8 +1,10 @@
--TEST--
"macro" tag supports name for endmacro
--TEMPLATE--
{{ _self.foo() }}
{{ _self.bar() }}
{% import _self as macros %}
{{ macros.foo() }}
{{ macros.bar() }}
{% macro foo() %}foo{% endmacro %}
{% macro bar() %}bar{% endmacro bar %}
@@ -1,7 +1,9 @@
--TEST--
"☃" as a macro name
--TEMPLATE--
{{ _self.☃('foo') }}
{% import _self as macros %}
{{ macros.☃('foo') }}
{% macro ☃(foo) %}
☃{{ foo }}☃