Permalink
Browse files

fixed tests where macros were not used properly

  • Loading branch information...
1 parent 9728a5d commit e1e9802c562aa4e8f8d5a8d3faaed6f235a38d2f @fabpot committed Oct 12, 2012
@@ -156,10 +156,13 @@ public function testSandboxLocallySetForAnInclude()
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,15 +1,16 @@
--TEST--
Twig parses postfix expressions
--TEMPLATE--
+{% import _self as macros %}
{% macro foo() %}foo{% endmacro %}
{{ 'a' }}
{{ '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 }}☃

0 comments on commit e1e9802

Please sign in to comment.