[!!!][CLEANUP] Remove deprecated code in sysext fluid
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / View / TemplateViewTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\View;
3
4 /* *
5 * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13
14 include_once(__DIR__ . '/Fixtures/TransparentSyntaxTreeNode.php');
15 include_once(__DIR__ . '/Fixtures/TemplateViewFixture.php');
16
17 use org\bovigo\vfs\vfsStreamWrapper;
18 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
19 use TYPO3\CMS\Fluid\View\TemplateView;
20
21 /**
22 * Test case
23 */
24 class TemplateViewTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
25
26 /**
27 * Test for #42123
28 * "Widgets with underscores in class names do not work because the subpackage key is not handled correctly."
29 * @test
30 */
31 public function expandGenericPathPatternWorksWithOldNamingSchemeOfSubPackage() {
32 $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', 'ViewHelpers_Widget', 'Paginate', 'html');
33 $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('dummy'), array(), '', FALSE);
34 $templateView->_set('controllerContext', $mockControllerContext);
35 $expected = array(ExtensionManagementUtility::extPath('frontend') . 'Resources/Private/Templates/ViewHelpers/Widget/Paginate/@action.html');
36 $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/@subpackage/@controller/@action.@format', FALSE, FALSE);
37 $this->assertEquals($expected, $actual);
38 }
39
40 /**
41 * Test for #42123
42 * "Widgets with underscores in class names do not work because the subpackage key is not handled correctly."
43 * @test
44 */
45 public function expandGenericPathPatternWorksWithNewNamingSchemeOfSubPackage() {
46 $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', 'ViewHelpers\\Widget', 'Paginate', 'html');
47 $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('dummy'), array(), '', FALSE);
48 $templateView->_set('controllerContext', $mockControllerContext);
49 $expected = array(ExtensionManagementUtility::extPath('frontend') . 'Resources/Private/Templates/ViewHelpers/Widget/Paginate/@action.html');
50 $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/@subpackage/@controller/@action.@format', FALSE, FALSE);
51 $this->assertEquals($expected, $actual);
52 }
53
54 /**
55 * Helper to build mock controller context needed to test expandGenericPathPattern.
56 *
57 * @param string $packageKey
58 * @param string $subPackageKey
59 * @param string $controllerName
60 * @param string $format
61 * @return \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
62 */
63 protected function setupMockControllerContextForPathResolving($packageKey, $subPackageKey, $controllerName, $format) {
64 $controllerObjectName = "TYPO3\\$packageKey\\" . ($subPackageKey != $subPackageKey . '\\' ? : '') . 'Controller\\' . $controllerName . 'Controller';
65 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request');
66 $mockRequest->expects($this->any())->method('getControllerExtensionKey')->will($this->returnValue('frontend'));
67 $mockRequest->expects($this->any())->method('getControllerPackageKey')->will($this->returnValue($packageKey));
68 $mockRequest->expects($this->any())->method('getControllerSubPackageKey')->will($this->returnValue($subPackageKey));
69 $mockRequest->expects($this->any())->method('getControllerName')->will($this->returnValue($controllerName));
70 $mockRequest->expects($this->any())->method('getControllerObjectName')->will($this->returnValue($controllerObjectName));
71 $mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue($format));
72
73 $mockControllerContext = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext', array('getRequest'), array(), '', FALSE);
74 $mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($mockRequest));
75
76 return $mockControllerContext;
77 }
78
79 /**
80 * @return array
81 */
82 public function expandGenericPathPatternDataProvider() {
83 return array(
84 // bubbling controller & subpackage parts and optional format
85 array(
86 'package' => 'Some.Package',
87 'subPackage' => 'Some\\Sub\\Package',
88 'controller' => 'SomeController',
89 'format' => 'html',
90 'templateRootPath' => 'Resources/Private/Templates',
91 'templateRootPaths' => NULL,
92 'partialRootPath' => 'Resources/Private/Partials',
93 'partialRootPaths' => NULL,
94 'layoutRootPath' => 'Resources/Private/Layouts',
95 'layoutRootPaths' => NULL,
96 'bubbleControllerAndSubpackage' => TRUE,
97 'formatIsOptional' => TRUE,
98 'pattern' => '@templateRoot/@subpackage/@controller/@action.@format',
99 'expectedResult' => array(
100 'Resources/Private/Templates/Some/Sub/Package/SomeController/@action.html',
101 'Resources/Private/Templates/Some/Sub/Package/SomeController/@action',
102 'Resources/Private/Templates/Some/Sub/Package/@action.html',
103 'Resources/Private/Templates/Some/Sub/Package/@action',
104 'Resources/Private/Templates/Sub/Package/@action.html',
105 'Resources/Private/Templates/Sub/Package/@action',
106 'Resources/Private/Templates/Package/@action.html',
107 'Resources/Private/Templates/Package/@action',
108 'Resources/Private/Templates/@action.html',
109 'Resources/Private/Templates/@action',
110 )
111 ),
112 // just optional format
113 array(
114 'package' => 'Some.Package',
115 'subPackage' => 'Some\\Sub\\Package',
116 'controller' => 'SomeController',
117 'format' => 'html',
118 'templateRootPath' => 'Resources/Private/Templates/',
119 'templateRootPaths' => NULL,
120 'partialRootPath' => 'Resources/Private/Partials',
121 'partialRootPaths' => NULL,
122 'layoutRootPath' => 'Resources/Private/Layouts',
123 'layoutRootPaths' => NULL,
124 'bubbleControllerAndSubpackage' => FALSE,
125 'formatIsOptional' => TRUE,
126 'pattern' => '@templateRoot/@subpackage/@controller/@action.@format',
127 'expectedResult' => array(
128 'Resources/Private/Templates/Some/Sub/Package/SomeController/@action.html',
129 'Resources/Private/Templates/Some/Sub/Package/SomeController/@action',
130 )
131 ),
132 // just bubbling controller & subpackage parts
133 array(
134 'package' => 'Some.Package',
135 'subPackage' => 'Some\\Sub\\Package',
136 'controller' => 'SomeController',
137 'format' => 'json',
138 'templateRootPath' => 'Resources/Private/Templates',
139 'templateRootPaths' => NULL,
140 'partialRootPath' => 'Resources/Private/Partials',
141 'partialRootPaths' => NULL,
142 'layoutRootPath' => 'Resources/Private/Layouts',
143 'layoutRootPaths' => NULL,
144 'bubbleControllerAndSubpackage' => TRUE,
145 'formatIsOptional' => FALSE,
146 'pattern' => '@partialRoot/@subpackage/@controller/@action.@format',
147 'expectedResult' => array(
148 'Resources/Private/Partials/Some/Sub/Package/SomeController/@action.json',
149 'Resources/Private/Partials/Some/Sub/Package/@action.json',
150 'Resources/Private/Partials/Sub/Package/@action.json',
151 'Resources/Private/Partials/Package/@action.json',
152 'Resources/Private/Partials/@action.json',
153 )
154 ),
155 // layoutRootPath
156 array(
157 'package' => 'Some.Package',
158 'subPackage' => NULL,
159 'controller' => NULL,
160 'format' => 'xml',
161 'templateRootPath' => 'Resources/Private/Templates',
162 'templateRootPaths' => NULL,
163 'partialRootPath' => 'Resources/Private/Partials',
164 'partialRootPaths' => NULL,
165 'layoutRootPath' => 'Resources/Private/Layouts',
166 'layoutRootPaths' => NULL,
167 'bubbleControllerAndSubpackage' => TRUE,
168 'formatIsOptional' => TRUE,
169 'pattern' => '@layoutRoot/@subpackage/@controller/@action.@format',
170 'expectedResult' => array(
171 'Resources/Private/Layouts/@action.xml',
172 'Resources/Private/Layouts/@action',
173 )
174 ),
175 // partialRootPath
176 array(
177 'package' => 'Some.Package',
178 'subPackage' => 'Some\\Sub\\Package',
179 'controller' => NULL,
180 'format' => 'html',
181 'templateRootPath' => 'Resources/Private/Templates',
182 'templateRootPaths' => NULL,
183 'partialRootPath' => 'Resources/Private/Partials',
184 'partialRootPaths' => NULL,
185 'layoutRootPath' => 'Resources/Private/Layouts',
186 'layoutRootPaths' => NULL,
187 'bubbleControllerAndSubpackage' => TRUE,
188 'formatIsOptional' => TRUE,
189 'pattern' => '@templateRoot/@subpackage/@controller/@action.@format',
190 'expectedResult' => array(
191 'Resources/Private/Templates/Some/Sub/Package/@action.html',
192 'Resources/Private/Templates/Some/Sub/Package/@action',
193 'Resources/Private/Templates/Sub/Package/@action.html',
194 'Resources/Private/Templates/Sub/Package/@action',
195 'Resources/Private/Templates/Package/@action.html',
196 'Resources/Private/Templates/Package/@action',
197 'Resources/Private/Templates/@action.html',
198 'Resources/Private/Templates/@action',
199 )
200 ),
201 // optional format as directory name
202 array(
203 'package' => 'Some.Package',
204 'subPackage' => 'Some\\Sub\\Package',
205 'controller' => 'SomeController',
206 'format' => 'xml',
207 'templateRootPath' => 'Resources/Private/Templates_@format',
208 'templateRootPaths' => NULL,
209 'partialRootPath' => 'Resources/Private/Partials',
210 'partialRootPaths' => NULL,
211 'layoutRootPath' => 'Resources/Private/Layouts',
212 'layoutRootPaths' => NULL,
213 'bubbleControllerAndSubpackage' => FALSE,
214 'formatIsOptional' => TRUE,
215 'pattern' => '@templateRoot/@subpackage/@controller/@action',
216 'expectedResult' => array(
217 'Resources/Private/Templates_xml/Some/Sub/Package/SomeController/@action',
218 'Resources/Private/Templates_/Some/Sub/Package/SomeController/@action',
219 )
220 ),
221 // mandatory format as directory name
222 array(
223 'package' => 'Some.Package',
224 'subPackage' => 'Some\\Sub\\Package',
225 'controller' => 'SomeController',
226 'format' => 'json',
227 'templateRootPath' => 'Resources/Private/Templates_@format',
228 'templateRootPaths' => NULL,
229 'partialRootPath' => 'Resources/Private/Partials',
230 'partialRootPaths' => NULL,
231 'layoutRootPath' => 'Resources/Private/Layouts',
232 'layoutRootPaths' => NULL,
233 'bubbleControllerAndSubpackage' => FALSE,
234 'formatIsOptional' => FALSE,
235 'pattern' => '@templateRoot/@subpackage/@controller/@action',
236 'expectedResult' => array(
237 'Resources/Private/Templates_json/Some/Sub/Package/SomeController/@action',
238 )
239 ),
240 // paths must not contain double slashes
241 array(
242 'package' => 'Some.Package',
243 'subPackage' => NULL,
244 'controller' => 'SomeController',
245 'format' => 'html',
246 'templateRootPath' => 'Resources/Private/Templates',
247 'templateRootPaths' => NULL,
248 'partialRootPath' => 'Resources/Private/Partials',
249 'partialRootPaths' => NULL,
250 'layoutRootPath' => 'Some/Root/Path/',
251 'layoutRootPaths' => NULL,
252 'bubbleControllerAndSubpackage' => TRUE,
253 'formatIsOptional' => TRUE,
254 'pattern' => '@layoutRoot/@subpackage/@controller/@action.@format',
255 'expectedResult' => array(
256 'Some/Root/Path/SomeController/@action.html',
257 'Some/Root/Path/SomeController/@action',
258 'Some/Root/Path/@action.html',
259 'Some/Root/Path/@action',
260 )
261 ),
262 // paths must be unique
263 array(
264 'package' => 'Some.Package',
265 'subPackage' => 'Some\\Sub\\Package',
266 'controller' => 'SomeController',
267 'format' => 'json',
268 'templateRootPath' => 'Resources/Private/Templates',
269 'templateRootPaths' => NULL,
270 'partialRootPath' => 'Resources/Private/Partials',
271 'partialRootPaths' => NULL,
272 'layoutRootPath' => 'Resources/Private/Layouts',
273 'layoutRootPaths' => NULL,
274 'bubbleControllerAndSubpackage' => TRUE,
275 'formatIsOptional' => FALSE,
276 'pattern' => 'foo',
277 'expectedResult' => array(
278 'foo',
279 )
280 ),
281 // template fallback paths
282 array(
283 'package' => 'Some.Package',
284 'subPackage' => 'Some\\Sub\\Package',
285 'controller' => 'SomeController',
286 'format' => 'html',
287 'templateRootPath' => 'Resources/Private/Templates',
288 'templateRootPaths' => array('Resources/Private/Templates', 'Some/Fallback/Path'),
289 'partialRootPath' => 'Resources/Private/Partials',
290 'partialRootPaths' => NULL,
291 'layoutRootPath' => 'Resources/Private/Layouts',
292 'layoutRootPaths' => NULL,
293 'bubbleControllerAndSubpackage' => FALSE,
294 'formatIsOptional' => TRUE,
295 'pattern' => '@templateRoot/@subpackage/@controller/@action.@format',
296 'expectedResult' => array(
297 'Resources/Private/Templates/Some/Sub/Package/SomeController/@action.html',
298 'Resources/Private/Templates/Some/Sub/Package/SomeController/@action',
299 'Some/Fallback/Path/Some/Sub/Package/SomeController/@action.html',
300 'Some/Fallback/Path/Some/Sub/Package/SomeController/@action',
301 )
302 ),
303 // template fallback paths with bubbleControllerAndSubpackage
304 array(
305 'package' => 'Some.Package',
306 'subPackage' => 'Some\\Sub\\Package',
307 'controller' => 'SomeController',
308 'format' => 'html',
309 'templateRootPath' => 'Resources/Private/Templates',
310 'templateRootPaths' => array('Resources/Private/Templates', 'Some/Fallback/Path'),
311 'partialRootPath' => 'Resources/Private/Partials',
312 'partialRootPaths' => NULL,
313 'layoutRootPath' => 'Resources/Private/Layouts',
314 'layoutRootPaths' => NULL,
315 'bubbleControllerAndSubpackage' => TRUE,
316 'formatIsOptional' => FALSE,
317 'pattern' => '@templateRoot/@subpackage/@controller/@action.@format',
318 'expectedResult' => array(
319 'Resources/Private/Templates/Some/Sub/Package/SomeController/@action.html',
320 'Resources/Private/Templates/Some/Sub/Package/@action.html',
321 'Resources/Private/Templates/Sub/Package/@action.html',
322 'Resources/Private/Templates/Package/@action.html',
323 'Resources/Private/Templates/@action.html',
324 'Some/Fallback/Path/Some/Sub/Package/SomeController/@action.html',
325 'Some/Fallback/Path/Some/Sub/Package/@action.html',
326 'Some/Fallback/Path/Sub/Package/@action.html',
327 'Some/Fallback/Path/Package/@action.html',
328 'Some/Fallback/Path/@action.html',
329 )
330 ),
331 // partial fallback paths
332 array(
333 'package' => 'Some.Package',
334 'subPackage' => 'Some\\Sub\\Package',
335 'controller' => 'SomeController',
336 'format' => 'html',
337 'templateRootPath' => 'Resources/Private/Templates',
338 'templateRootPaths' => NULL,
339 'partialRootPath' => 'Resources/Private/Partials',
340 'partialRootPaths' => array('Default/Resources/Path', 'Fallback/'),
341 'layoutRootPath' => 'Resources/Private/Layouts',
342 'layoutRootPaths' => NULL,
343 'bubbleControllerAndSubpackage' => FALSE,
344 'formatIsOptional' => TRUE,
345 'pattern' => '@partialRoot/@subpackage/@controller/@partial.@format',
346 'expectedResult' => array(
347 'Default/Resources/Path/Some/Sub/Package/SomeController/@partial.html',
348 'Default/Resources/Path/Some/Sub/Package/SomeController/@partial',
349 'Fallback/Some/Sub/Package/SomeController/@partial.html',
350 'Fallback/Some/Sub/Package/SomeController/@partial',
351 )
352 ),
353 // partial fallback paths with bubbleControllerAndSubpackage
354 array(
355 'package' => 'Some.Package',
356 'subPackage' => 'Some\\Sub\\Package',
357 'controller' => 'SomeController',
358 'format' => 'html',
359 'templateRootPath' => 'Resources/Private/Templates',
360 'templateRootPaths' => array('Resources/Private/Templates', 'Some/Fallback/Path'),
361 'partialRootPath' => 'Resources/Private/Partials',
362 'partialRootPaths' => array('Default/Resources/Path', 'Fallback1/', 'Fallback2'),
363 'layoutRootPath' => 'Resources/Private/Layouts',
364 'layoutRootPaths' => NULL,
365 'bubbleControllerAndSubpackage' => TRUE,
366 'formatIsOptional' => TRUE,
367 'pattern' => '@partialRoot/@controller/@subpackage/@partial',
368 'expectedResult' => array(
369 'Default/Resources/Path/SomeController/Some/Sub/Package/@partial',
370 'Default/Resources/Path/Some/Sub/Package/@partial',
371 'Default/Resources/Path/Sub/Package/@partial',
372 'Default/Resources/Path/Package/@partial',
373 'Default/Resources/Path/@partial',
374 'Fallback1/SomeController/Some/Sub/Package/@partial',
375 'Fallback1/Some/Sub/Package/@partial',
376 'Fallback1/Sub/Package/@partial',
377 'Fallback1/Package/@partial',
378 'Fallback1/@partial',
379 'Fallback2/SomeController/Some/Sub/Package/@partial',
380 'Fallback2/Some/Sub/Package/@partial',
381 'Fallback2/Sub/Package/@partial',
382 'Fallback2/Package/@partial',
383 'Fallback2/@partial',
384 )
385 ),
386 // layout fallback paths
387 array(
388 'package' => 'Some.Package',
389 'subPackage' => 'Some\\Sub\\Package',
390 'controller' => 'SomeController',
391 'format' => 'html',
392 'templateRootPath' => 'Resources/Private/Templates',
393 'templateRootPaths' => array('Resources/Private/Templates', 'Some/Fallback/Path'),
394 'partialRootPath' => 'Resources/Private/Partials',
395 'partialRootPaths' => array('foo', 'bar'),
396 'layoutRootPath' => 'Resources/Private/Layouts',
397 'layoutRootPaths' => array('Default/Layout/Path', 'Fallback/Path'),
398 'bubbleControllerAndSubpackage' => FALSE,
399 'formatIsOptional' => FALSE,
400 'pattern' => '@layoutRoot/@subpackage/@controller/@layout.@format',
401 'expectedResult' => array(
402 'Default/Layout/Path/Some/Sub/Package/SomeController/@layout.html',
403 'Fallback/Path/Some/Sub/Package/SomeController/@layout.html',
404 )
405 ),
406 // layout fallback paths with bubbleControllerAndSubpackage
407 array(
408 'package' => 'Some.Package',
409 'subPackage' => 'Some\\Sub\\Package',
410 'controller' => 'SomeController',
411 'format' => 'html',
412 'templateRootPath' => 'Resources/Private/Templates',
413 'templateRootPaths' => NULL,
414 'partialRootPath' => 'Resources/Private/Partials',
415 'partialRootPaths' => NULL,
416 'layoutRootPath' => 'Resources/Private/Layouts',
417 'layoutRootPaths' => array('Resources/Layouts', 'Some/Fallback/Path'),
418 'bubbleControllerAndSubpackage' => TRUE,
419 'formatIsOptional' => TRUE,
420 'pattern' => 'Static/@layoutRoot/@subpackage/@controller/@layout.@format',
421 'expectedResult' => array(
422 'Static/Resources/Layouts/Some/Sub/Package/SomeController/@layout.html',
423 'Static/Resources/Layouts/Some/Sub/Package/SomeController/@layout',
424 'Static/Resources/Layouts/Some/Sub/Package/@layout.html',
425 'Static/Resources/Layouts/Some/Sub/Package/@layout',
426 'Static/Resources/Layouts/Sub/Package/@layout.html',
427 'Static/Resources/Layouts/Sub/Package/@layout',
428 'Static/Resources/Layouts/Package/@layout.html',
429 'Static/Resources/Layouts/Package/@layout',
430 'Static/Resources/Layouts/@layout.html',
431 'Static/Resources/Layouts/@layout',
432 'Static/Some/Fallback/Path/Some/Sub/Package/SomeController/@layout.html',
433 'Static/Some/Fallback/Path/Some/Sub/Package/SomeController/@layout',
434 'Static/Some/Fallback/Path/Some/Sub/Package/@layout.html',
435 'Static/Some/Fallback/Path/Some/Sub/Package/@layout',
436 'Static/Some/Fallback/Path/Sub/Package/@layout.html',
437 'Static/Some/Fallback/Path/Sub/Package/@layout',
438 'Static/Some/Fallback/Path/Package/@layout.html',
439 'Static/Some/Fallback/Path/Package/@layout',
440 'Static/Some/Fallback/Path/@layout.html',
441 'Static/Some/Fallback/Path/@layout',
442 )
443 ),
444 // combined fallback paths
445 array(
446 'package' => 'Some.Package',
447 'subPackage' => 'Some\\Sub\\Package',
448 'controller' => 'SomeController',
449 'format' => 'html',
450 'templateRootPath' => 'Resources/Private/Templates',
451 'templateRootPaths' => array('Resources/Templates', 'Templates/Fallback1', 'Templates/Fallback2'),
452 'partialRootPath' => 'Resources/Private/Partials',
453 'partialRootPaths' => array('Resources/Partials'),
454 'layoutRootPath' => 'Resources/Private/Layouts',
455 'layoutRootPaths' => array('Resources/Layouts', 'Layouts/Fallback1'),
456 'bubbleControllerAndSubpackage' => FALSE,
457 'formatIsOptional' => TRUE,
458 'pattern' => '@layoutRoot/@templateRoot/@partialRoot/@subpackage/@controller/foo',
459 'expectedResult' => array(
460 'Resources/Layouts/Resources/Templates/Resources/Partials/Some/Sub/Package/SomeController/foo',
461 'Layouts/Fallback1/Resources/Templates/Resources/Partials/Some/Sub/Package/SomeController/foo',
462 'Resources/Layouts/Templates/Fallback1/Resources/Partials/Some/Sub/Package/SomeController/foo',
463 'Layouts/Fallback1/Templates/Fallback1/Resources/Partials/Some/Sub/Package/SomeController/foo',
464 'Resources/Layouts/Templates/Fallback2/Resources/Partials/Some/Sub/Package/SomeController/foo',
465 'Layouts/Fallback1/Templates/Fallback2/Resources/Partials/Some/Sub/Package/SomeController/foo',
466 )
467 ),
468 );
469 }
470
471 /**
472 * @test
473 * @dataProvider expandGenericPathPatternDataProvider()
474 *
475 * @param string $package
476 * @param string $subPackage
477 * @param string $controller
478 * @param string $format
479 * @param string $templateRootPath
480 * @param array $templateRootPaths
481 * @param string $partialRootPath
482 * @param array $partialRootPaths
483 * @param string $layoutRootPath
484 * @param array $layoutRootPaths
485 * @param bool $bubbleControllerAndSubpackage
486 * @param bool $formatIsOptional
487 * @param string $pattern
488 * @param string $expectedResult
489 */
490 public function expandGenericPathPatternTests($package, $subPackage, $controller, $format, $templateRootPath, array $templateRootPaths = NULL, $partialRootPath, array $partialRootPaths = NULL, $layoutRootPath, array $layoutRootPaths = NULL, $bubbleControllerAndSubpackage, $formatIsOptional, $pattern, $expectedResult) {
491 $mockControllerContext = $this->setupMockControllerContextForPathResolving($package, $subPackage, $controller, $format);
492
493 /** @var TemplateView|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $templateView */
494 $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('dummy'), array(), '', FALSE);
495 $templateView->setControllerContext($mockControllerContext);
496 if ($templateRootPath !== NULL) {
497 $templateView->setTemplateRootPath($templateRootPath);
498 }
499 if ($templateRootPaths !== NULL) {
500 $templateView->setTemplateRootPaths($templateRootPaths);
501 }
502
503 if ($partialRootPath !== NULL) {
504 $templateView->setPartialRootPath($partialRootPath);
505 }
506 if ($partialRootPaths !== NULL) {
507 $templateView->setPartialRootPaths($partialRootPaths);
508 }
509
510 if ($layoutRootPath !== NULL) {
511 $templateView->setLayoutRootPath($layoutRootPath);
512 }
513 if ($layoutRootPaths !== NULL) {
514 $templateView->setLayoutRootPaths($layoutRootPaths);
515 }
516
517 $actualResult = $templateView->_call('expandGenericPathPattern', $pattern, $bubbleControllerAndSubpackage, $formatIsOptional);
518 $this->assertEquals($expectedResult, $actualResult);
519 }
520
521 /**
522 * @test
523 */
524 public function expandGenericPathPatternWorksWithBubblingDisabledAndFormatNotOptional() {
525 $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', NULL, 'My', 'html');
526
527 $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('getTemplateRootPaths'), array(), '', FALSE);
528 $templateView->_set('controllerContext', $mockControllerContext);
529 $templateView->expects($this->any())->method('getTemplateRootPaths')->will($this->returnValue(array('Resources/Private/')));
530
531 $expected = array('Resources/Private/Templates/My/@action.html');
532 $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/Templates/@subpackage/@controller/@action.@format', FALSE, FALSE);
533 $this->assertEquals($expected, $actual);
534 }
535
536
537 /**
538 * @test
539 */
540 public function expandGenericPathPatternWorksWithSubpackageAndBubblingDisabledAndFormatNotOptional() {
541 $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', 'MySubPackage', 'My', 'html');
542
543 $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('getTemplateRootPaths'), array(), '', FALSE);
544 $templateView->_set('controllerContext', $mockControllerContext);
545 $templateView->expects($this->any())->method('getTemplateRootPaths')->will($this->returnValue(array('Resources/Private/')));
546 $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/Templates/@subpackage/@controller/@action.@format', FALSE, FALSE);
547
548 $expected = array(
549 'Resources/Private/Templates/MySubPackage/My/@action.html'
550 );
551 $this->assertEquals($expected, $actual);
552 }
553
554 /**
555 * @test
556 */
557 public function expandGenericPathPatternWorksWithSubpackageAndBubblingDisabledAndFormatOptional() {
558 $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', 'MySubPackage', 'My', 'html');
559
560 $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('getTemplateRootPaths'), array(), '', FALSE);
561 $templateView->_set('controllerContext', $mockControllerContext);
562 $templateView->expects($this->any())->method('getTemplateRootPaths')->will($this->returnValue(array('Resources/Private/')));
563 $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/Templates/@subpackage/@controller/@action.@format', FALSE, TRUE);
564
565 $expected = array(
566 'Resources/Private/Templates/MySubPackage/My/@action.html',
567 'Resources/Private/Templates/MySubPackage/My/@action'
568 );
569 $this->assertEquals($expected, $actual);
570 }
571
572 /**
573 * @test
574 */
575 public function expandGenericPathPatternWorksWithSubpackageAndBubblingEnabledAndFormatOptional() {
576 $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', 'MySubPackage', 'My', 'html');
577
578 $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('getTemplateRootPaths'), array(), '', FALSE);
579 $templateView->_set('controllerContext', $mockControllerContext);
580 $templateView->expects($this->any())->method('getTemplateRootPaths')->will($this->returnValue(array('Resources/Private/')));
581 $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/Templates/@subpackage/@controller/@action.@format', TRUE, TRUE);
582
583 $expected = array(
584 'Resources/Private/Templates/MySubPackage/My/@action.html',
585 'Resources/Private/Templates/MySubPackage/My/@action',
586 'Resources/Private/Templates/MySubPackage/@action.html',
587 'Resources/Private/Templates/MySubPackage/@action',
588 'Resources/Private/Templates/@action.html',
589 'Resources/Private/Templates/@action'
590 );
591 $this->assertEquals($expected, $actual);
592 }
593
594 /**
595 * @test
596 */
597 public function getTemplateRootPathsReturnsUserSpecifiedTemplatePaths() {
598 /** @var TemplateView|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $templateView */
599 $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('dummy'), array(), '', FALSE);
600 $templateView->setTemplateRootPath('/foo/bar');
601 $expected = array('/foo/bar');
602 $actual = $templateView->_call('getTemplateRootPaths');
603 $this->assertEquals($expected, $actual, 'A set template root path was not returned correctly.');
604 }
605
606 /**
607 * @test
608 */
609 public function setTemplateRootPathOverrulesSetTemplateRootPaths() {
610 /** @var TemplateView|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $templateView */
611 $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('dummy'), array(), '', FALSE);
612 $templateView->setTemplateRootPath('/foo/bar');
613 $templateView->setTemplateRootPaths(array('/overruled/path'));
614 $expected = array('/overruled/path');
615 $actual = $templateView->_call('getTemplateRootPaths');
616 $this->assertEquals($expected, $actual, 'A set template root path was not returned correctly.');
617 }
618
619 /**
620 * @test
621 */
622 public function getPartialRootPathsReturnsUserSpecifiedPartialPath() {
623 /** @var TemplateView|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $templateView */
624 $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('dummy'), array(), '', FALSE);
625 $templateView->setPartialRootPath('/foo/bar');
626 $expected = array('/foo/bar');
627 $actual = $templateView->_call('getPartialRootPaths');
628 $this->assertEquals($expected, $actual, 'A set partial root path was not returned correctly.');
629 }
630
631 /**
632 * @test
633 */
634 public function getLayoutRootPathsReturnsUserSpecifiedPartialPath() {
635 /** @var TemplateView|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $templateView */
636 $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('dummy'), array(), '', FALSE);
637 $templateView->setLayoutRootPath('/foo/bar');
638 $expected = array('/foo/bar');
639 $actual = $templateView->_call('getLayoutRootPaths');
640 $this->assertEquals($expected, $actual, 'A set partial root path was not returned correctly.');
641 }
642
643 /**
644 * @test
645 */
646 public function pathToPartialIsResolvedCorrectly() {
647 vfsStreamWrapper::register();
648 mkdir('vfs://MyPartials');
649 \file_put_contents('vfs://MyPartials/SomePartial', 'contentsOfSomePartial');
650
651 $paths = array(
652 'vfs://NonExistantDir/UnknowFile.html',
653 'vfs://MyPartials/SomePartial.html',
654 'vfs://MyPartials/SomePartial'
655 );
656
657 /** @var TemplateView|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $templateView */
658 $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('expandGenericPathPattern', 'resolveFileNamePath'), array(), '', FALSE);
659 $templateView->expects($this->once())->method('expandGenericPathPattern')->with('@partialRoot/@subpackage/@partial.@format', TRUE, TRUE)->will($this->returnValue($paths));
660 $templateView->expects($this->any())->method('resolveFileNamePath')->will($this->onConsecutiveCalls(
661 $paths[0],
662 $paths[1],
663 $paths[2]
664 ));
665
666 $templateView->setTemplateRootPath('MyTemplates');
667 $templateView->setPartialRootPath('MyPartials');
668 $templateView->setLayoutRootPath('MyLayouts');
669
670 $this->assertSame('contentsOfSomePartial', $templateView->_call('getPartialSource', 'SomePartial'));
671 }
672
673 /**
674 * @test
675 */
676 public function resolveTemplatePathAndFilenameChecksDifferentPathPatternsAndReturnsTheFirstPathWhichExists() {
677 vfsStreamWrapper::register();
678 mkdir('vfs://MyTemplates');
679 \file_put_contents('vfs://MyTemplates/MyCoolAction.html', 'contentsOfMyCoolAction');
680
681 $paths = array(
682 'vfs://NonExistantDir/UnknownFile.html',
683 'vfs://MyTemplates/@action.html'
684 );
685
686 /** @var TemplateView|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $templateView */
687 $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('expandGenericPathPattern', 'resolveFileNamePath'), array(), '', FALSE);
688 $templateView->expects($this->once())->method('expandGenericPathPattern')->with('@templateRoot/@subpackage/@controller/@action.@format', FALSE, FALSE)->will($this->returnValue($paths));
689 $templateView->expects($this->any())->method('resolveFileNamePath')->will($this->onConsecutiveCalls(
690 $paths[0],
691 'vfs://MyTemplates/MyCoolAction.html'
692 ));
693
694 $templateView->setTemplateRootPath('MyTemplates');
695 $templateView->setPartialRootPath('MyPartials');
696 $templateView->setLayoutRootPath('MyLayouts');
697
698 $this->assertSame('contentsOfMyCoolAction', $templateView->_call('getTemplateSource', 'myCoolAction'));
699
700 }
701
702 /**
703 * @test
704 */
705 public function resolveTemplatePathAndFilenameReturnsTheExplicitlyConfiguredTemplatePathAndFilename() {
706 vfsStreamWrapper::register();
707 mkdir('vfs://MyTemplates');
708 \file_put_contents('vfs://MyTemplates/MyCoolAction.html', 'contentsOfMyCoolAction');
709
710 $templateView = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\TemplateView', array('dummy'), array(), '', FALSE);
711 $templateView->_set('templatePathAndFilename', 'vfs://MyTemplates/MyCoolAction.html');
712
713 $this->assertSame('contentsOfMyCoolAction', $templateView->_call('getTemplateSource'));
714 }
715 }