Browse code

added tests for block() when using a template argument

Fabien Potencier authored on 18/11/2016 20:51:55
Showing 4 changed files
... ...
@@ -1,6 +1,6 @@
1 1
 * 1.28.1 (2016-XX-XX)
2 2
 
3
- * n/a
3
+ * fixed block() function when used with a template argument
4 4
 
5 5
 * 1.28.0 (2016-11-17)
6 6
 
... ...
@@ -39,23 +39,16 @@ class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
39 39
     public function compile(Twig_Compiler $compiler)
40 40
     {
41 41
         if ($this->getAttribute('is_defined_test')) {
42
-            $this
43
-                ->compileTemplateCall($compiler, 'hasBlock')
44
-                ->compileBlockArguments($compiler)
45
-            ;
42
+            $this->compileTemplateCall($compiler, 'hasBlock');
46 43
         } else {
47 44
             if ($this->getAttribute('output')) {
48 45
                 $compiler->addDebugInfo($this);
49 46
 
50 47
                 $this
51 48
                     ->compileTemplateCall($compiler, 'displayBlock')
52
-                    ->compileBlockArguments($compiler)
53 49
                     ->raw(";\n");
54 50
             } else {
55
-                $this
56
-                    ->compileTemplateCall($compiler, 'renderBlock')
57
-                    ->compileBlockArguments($compiler)
58
-                ;
51
+                $this->compileTemplateCall($compiler, 'renderBlock');
59 52
             }
60 53
         }
61 54
     }
... ...
@@ -77,8 +70,9 @@ class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
77 70
         }
78 71
 
79 72
         $compiler->raw(sprintf('->%s', $method));
73
+        $this->compileBlockArguments($compiler);
80 74
 
81
-        return $this;
75
+        return $compiler;
82 76
     }
83 77
 
84 78
     private function compileBlockArguments(Twig_Compiler $compiler)
85 79
new file mode 100644
... ...
@@ -0,0 +1,22 @@
1
+--TEST--
2
+"block" function with a template argument
3
+--TEMPLATE--
4
+{{ block('foo', 'included.twig') }}
5
+{{ block('foo', included_loaded) }}
6
+{{ block('foo', included_loaded_internal) }}
7
+{% set output = block('foo', 'included.twig') %}
8
+{{ output }}
9
+{% block foo %}NOT FOO{% endblock %}
10
+--TEMPLATE(included.twig)--
11
+{% block foo %}FOO{% endblock %}
12
+--DATA--
13
+return array(
14
+    'included_loaded' => $twig->load('included.twig'),
15
+    'included_loaded_internal' => $twig->loadTemplate('included.twig'),
16
+)
17
+--EXPECT--
18
+FOO
19
+FOO
20
+FOO
21
+FOO
22
+NOT FOO
0 23
new file mode 100644
... ...
@@ -0,0 +1,17 @@
1
+--TEST--
2
+"defined" support for blocks with a template argument
3
+--TEMPLATE--
4
+{{ block('foo', 'included.twig') is defined ? 'ok' : 'ko' }}
5
+{{ block('foo', included_loaded) is defined ? 'ok' : 'ko' }}
6
+{{ block('foo', included_loaded_internal) is defined ? 'ok' : 'ko' }}
7
+--TEMPLATE(included.twig)--
8
+{% block foo %}FOO{% endblock %}
9
+--DATA--
10
+return array(
11
+    'included_loaded' => $twig->load('included.twig'),
12
+    'included_loaded_internal' => $twig->loadTemplate('included.twig'),
13
+)
14
+--EXPECT--
15
+ok
16
+ok
17
+ok