diff options
Diffstat (limited to 'vendor/twig/twig/test/Twig/Tests/Node/ModuleTest.php')
-rw-r--r-- | vendor/twig/twig/test/Twig/Tests/Node/ModuleTest.php | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/vendor/twig/twig/test/Twig/Tests/Node/ModuleTest.php b/vendor/twig/twig/test/Twig/Tests/Node/ModuleTest.php new file mode 100644 index 00000000..9411e99e --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/ModuleTest.php | |||
@@ -0,0 +1,196 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of Twig. | ||
5 | * | ||
6 | * (c) Fabien Potencier | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | class Twig_Tests_Node_ModuleTest extends Twig_Test_NodeTestCase | ||
13 | { | ||
14 | /** | ||
15 | * @covers Twig_Node_Module::__construct | ||
16 | */ | ||
17 | public function testConstructor() | ||
18 | { | ||
19 | $body = new Twig_Node_Text('foo', 1); | ||
20 | $parent = new Twig_Node_Expression_Constant('layout.twig', 1); | ||
21 | $blocks = new Twig_Node(); | ||
22 | $macros = new Twig_Node(); | ||
23 | $traits = new Twig_Node(); | ||
24 | $filename = 'foo.twig'; | ||
25 | $node = new Twig_Node_Module($body, $parent, $blocks, $macros, $traits, new Twig_Node(array()), $filename); | ||
26 | |||
27 | $this->assertEquals($body, $node->getNode('body')); | ||
28 | $this->assertEquals($blocks, $node->getNode('blocks')); | ||
29 | $this->assertEquals($macros, $node->getNode('macros')); | ||
30 | $this->assertEquals($parent, $node->getNode('parent')); | ||
31 | $this->assertEquals($filename, $node->getAttribute('filename')); | ||
32 | } | ||
33 | |||
34 | /** | ||
35 | * @covers Twig_Node_Module::compile | ||
36 | * @covers Twig_Node_Module::compileTemplate | ||
37 | * @covers Twig_Node_Module::compileMacros | ||
38 | * @covers Twig_Node_Module::compileClassHeader | ||
39 | * @covers Twig_Node_Module::compileDisplayHeader | ||
40 | * @covers Twig_Node_Module::compileDisplayBody | ||
41 | * @covers Twig_Node_Module::compileDisplayFooter | ||
42 | * @covers Twig_Node_Module::compileClassFooter | ||
43 | * @dataProvider getTests | ||
44 | */ | ||
45 | public function testCompile($node, $source, $environment = null) | ||
46 | { | ||
47 | parent::testCompile($node, $source, $environment); | ||
48 | } | ||
49 | |||
50 | public function getTests() | ||
51 | { | ||
52 | $twig = new Twig_Environment(new Twig_Loader_String()); | ||
53 | |||
54 | $tests = array(); | ||
55 | |||
56 | $body = new Twig_Node_Text('foo', 1); | ||
57 | $extends = null; | ||
58 | $blocks = new Twig_Node(); | ||
59 | $macros = new Twig_Node(); | ||
60 | $traits = new Twig_Node(); | ||
61 | $filename = 'foo.twig'; | ||
62 | |||
63 | $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $filename); | ||
64 | $tests[] = array($node, <<<EOF | ||
65 | <?php | ||
66 | |||
67 | /* foo.twig */ | ||
68 | class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template | ||
69 | { | ||
70 | public function __construct(Twig_Environment \$env) | ||
71 | { | ||
72 | parent::__construct(\$env); | ||
73 | |||
74 | \$this->parent = false; | ||
75 | |||
76 | \$this->blocks = array( | ||
77 | ); | ||
78 | } | ||
79 | |||
80 | protected function doDisplay(array \$context, array \$blocks = array()) | ||
81 | { | ||
82 | // line 1 | ||
83 | echo "foo"; | ||
84 | } | ||
85 | |||
86 | public function getTemplateName() | ||
87 | { | ||
88 | return "foo.twig"; | ||
89 | } | ||
90 | |||
91 | public function getDebugInfo() | ||
92 | { | ||
93 | return array ( 19 => 1,); | ||
94 | } | ||
95 | } | ||
96 | EOF | ||
97 | , $twig); | ||
98 | |||
99 | $import = new Twig_Node_Import(new Twig_Node_Expression_Constant('foo.twig', 1), new Twig_Node_Expression_AssignName('macro', 1), 1); | ||
100 | |||
101 | $body = new Twig_Node(array($import)); | ||
102 | $extends = new Twig_Node_Expression_Constant('layout.twig', 1); | ||
103 | |||
104 | $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $filename); | ||
105 | $tests[] = array($node, <<<EOF | ||
106 | <?php | ||
107 | |||
108 | /* foo.twig */ | ||
109 | class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template | ||
110 | { | ||
111 | public function __construct(Twig_Environment \$env) | ||
112 | { | ||
113 | parent::__construct(\$env); | ||
114 | |||
115 | \$this->parent = \$this->env->loadTemplate("layout.twig"); | ||
116 | |||
117 | \$this->blocks = array( | ||
118 | ); | ||
119 | } | ||
120 | |||
121 | protected function doGetParent(array \$context) | ||
122 | { | ||
123 | return "layout.twig"; | ||
124 | } | ||
125 | |||
126 | protected function doDisplay(array \$context, array \$blocks = array()) | ||
127 | { | ||
128 | // line 1 | ||
129 | \$context["macro"] = \$this->env->loadTemplate("foo.twig"); | ||
130 | \$this->parent->display(\$context, array_merge(\$this->blocks, \$blocks)); | ||
131 | } | ||
132 | |||
133 | public function getTemplateName() | ||
134 | { | ||
135 | return "foo.twig"; | ||
136 | } | ||
137 | |||
138 | public function isTraitable() | ||
139 | { | ||
140 | return false; | ||
141 | } | ||
142 | |||
143 | public function getDebugInfo() | ||
144 | { | ||
145 | return array ( 24 => 1,); | ||
146 | } | ||
147 | } | ||
148 | EOF | ||
149 | , $twig); | ||
150 | |||
151 | $body = new Twig_Node(); | ||
152 | $extends = new Twig_Node_Expression_Conditional( | ||
153 | new Twig_Node_Expression_Constant(true, 1), | ||
154 | new Twig_Node_Expression_Constant('foo', 1), | ||
155 | new Twig_Node_Expression_Constant('foo', 1), | ||
156 | 0 | ||
157 | ); | ||
158 | |||
159 | $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $filename); | ||
160 | $tests[] = array($node, <<<EOF | ||
161 | <?php | ||
162 | |||
163 | /* foo.twig */ | ||
164 | class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template | ||
165 | { | ||
166 | protected function doGetParent(array \$context) | ||
167 | { | ||
168 | return \$this->env->resolveTemplate(((true) ? ("foo") : ("foo"))); | ||
169 | } | ||
170 | |||
171 | protected function doDisplay(array \$context, array \$blocks = array()) | ||
172 | { | ||
173 | \$this->getParent(\$context)->display(\$context, array_merge(\$this->blocks, \$blocks)); | ||
174 | } | ||
175 | |||
176 | public function getTemplateName() | ||
177 | { | ||
178 | return "foo.twig"; | ||
179 | } | ||
180 | |||
181 | public function isTraitable() | ||
182 | { | ||
183 | return false; | ||
184 | } | ||
185 | |||
186 | public function getDebugInfo() | ||
187 | { | ||
188 | return array (); | ||
189 | } | ||
190 | } | ||
191 | EOF | ||
192 | , $twig); | ||
193 | |||
194 | return $tests; | ||
195 | } | ||
196 | } | ||