mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 20:06:31 +00:00
fixed tests where macros were not used properly
This commit is contained in:
@@ -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 }}☃
|
||||
|
||||
Reference in New Issue
Block a user