added tests for block() when using a template argument

This commit is contained in:
Fabien Potencier
2016-11-18 15:51:55 -05:00
parent a5526f32fb
commit 8c090a7cc4
4 changed files with 44 additions and 11 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
* 1.28.1 (2016-XX-XX)
* n/a
* fixed block() function when used with a template argument
* 1.28.0 (2016-11-17)
+4 -10
View File
@@ -39,23 +39,16 @@ class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
public function compile(Twig_Compiler $compiler)
{
if ($this->getAttribute('is_defined_test')) {
$this
->compileTemplateCall($compiler, 'hasBlock')
->compileBlockArguments($compiler)
;
$this->compileTemplateCall($compiler, 'hasBlock');
} else {
if ($this->getAttribute('output')) {
$compiler->addDebugInfo($this);
$this
->compileTemplateCall($compiler, 'displayBlock')
->compileBlockArguments($compiler)
->raw(";\n");
} else {
$this
->compileTemplateCall($compiler, 'renderBlock')
->compileBlockArguments($compiler)
;
$this->compileTemplateCall($compiler, 'renderBlock');
}
}
}
@@ -77,8 +70,9 @@ class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
}
$compiler->raw(sprintf('->%s', $method));
$this->compileBlockArguments($compiler);
return $this;
return $compiler;
}
private function compileBlockArguments(Twig_Compiler $compiler)
@@ -0,0 +1,22 @@
--TEST--
"block" function with a template argument
--TEMPLATE--
{{ block('foo', 'included.twig') }}
{{ block('foo', included_loaded) }}
{{ block('foo', included_loaded_internal) }}
{% set output = block('foo', 'included.twig') %}
{{ output }}
{% block foo %}NOT FOO{% endblock %}
--TEMPLATE(included.twig)--
{% block foo %}FOO{% endblock %}
--DATA--
return array(
'included_loaded' => $twig->load('included.twig'),
'included_loaded_internal' => $twig->loadTemplate('included.twig'),
)
--EXPECT--
FOO
FOO
FOO
FOO
NOT FOO
@@ -0,0 +1,17 @@
--TEST--
"defined" support for blocks with a template argument
--TEMPLATE--
{{ block('foo', 'included.twig') is defined ? 'ok' : 'ko' }}
{{ block('foo', included_loaded) is defined ? 'ok' : 'ko' }}
{{ block('foo', included_loaded_internal) is defined ? 'ok' : 'ko' }}
--TEMPLATE(included.twig)--
{% block foo %}FOO{% endblock %}
--DATA--
return array(
'included_loaded' => $twig->load('included.twig'),
'included_loaded_internal' => $twig->loadTemplate('included.twig'),
)
--EXPECT--
ok
ok
ok