2 namespace TYPO3\CMS\Fluid\Tests\Unit\View;
14 include_once(__DIR__ .
'/Fixtures/TransparentSyntaxTreeNode.php');
15 include_once(__DIR__ .
'/Fixtures/TemplateViewFixture.php');
17 use org\bovigo\vfs\vfsStreamWrapper;
20 use TYPO3\CMS\Core\Tests\AccessibleObjectInterface;
21 use TYPO3\CMS\Core\Tests\UnitTestCase;
48 $templateView = $this->getAccessibleMock(TemplateView::class, array(
'dummy'), array(),
'',
false);
49 $templateView->_set(
'controllerContext', $mockControllerContext);
51 $actual = $templateView->_call(
'expandGenericPathPattern',
'@templateRoot/@subpackage/@controller/@action.@format',
false,
false);
52 $this->assertEquals($expected, $actual);
63 $templateView = $this->getAccessibleMock(TemplateView::class, array(
'dummy'), array(),
'',
false);
64 $templateView->_set(
'controllerContext', $mockControllerContext);
66 $actual = $templateView->_call(
'expandGenericPathPattern',
'@templateRoot/@subpackage/@controller/@action.@format',
false,
false);
67 $this->assertEquals($expected, $actual);
81 $controllerObjectName =
"TYPO3\\$packageKey\\" . ($subPackageKey != $subPackageKey .
'\\' ? :
'') .
'Controller\\' . $controllerName .
'Controller';
82 $mockRequest = $this->getMock(WebRequest::class);
83 $mockRequest->expects($this->any())->method(
'getControllerExtensionKey')->will($this->returnValue(
'frontend'));
84 $mockRequest->expects($this->any())->method(
'getControllerPackageKey')->will($this->returnValue($packageKey));
85 $mockRequest->expects($this->any())->method(
'getControllerSubPackageKey')->will($this->returnValue($subPackageKey));
86 $mockRequest->expects($this->any())->method(
'getControllerName')->will($this->returnValue($controllerName));
87 $mockRequest->expects($this->any())->method(
'getControllerObjectName')->will($this->returnValue($controllerObjectName));
88 $mockRequest->expects($this->any())->method(
'getFormat')->will($this->returnValue($format));
90 $mockControllerContext = $this->getMock(ControllerContext::class, array(
'getRequest'), array(),
'',
false);
91 $mockControllerContext->expects($this->any())->method(
'getRequest')->will($this->returnValue($mockRequest));
93 return $mockControllerContext;
104 'package' =>
'Some.Package',
105 'subPackage' =>
'Some\\Sub\\Package',
106 'controller' =>
'SomeController',
108 'templateRootPath' =>
'Resources/Private/Templates',
109 'templateRootPaths' => null,
110 'partialRootPath' =>
'Resources/Private/Partials',
111 'partialRootPaths' => null,
112 'layoutRootPath' =>
'Resources/Private/Layouts',
113 'layoutRootPaths' => null,
114 'bubbleControllerAndSubpackage' =>
true,
115 'formatIsOptional' =>
true,
116 'pattern' =>
'@templateRoot/@subpackage/@controller/@action.@format',
117 'expectedResult' => array(
118 'Resources/Private/Templates/Some/Sub/Package/SomeController/@action.html',
119 'Resources/Private/Templates/Some/Sub/Package/SomeController/@action',
120 'Resources/Private/Templates/Some/Sub/Package/@action.html',
121 'Resources/Private/Templates/Some/Sub/Package/@action',
122 'Resources/Private/Templates/Sub/Package/@action.html',
123 'Resources/Private/Templates/Sub/Package/@action',
124 'Resources/Private/Templates/Package/@action.html',
125 'Resources/Private/Templates/Package/@action',
126 'Resources/Private/Templates/@action.html',
127 'Resources/Private/Templates/@action',
132 'package' =>
'Some.Package',
133 'subPackage' =>
'Some\\Sub\\Package',
134 'controller' =>
'SomeController',
136 'templateRootPath' =>
'Resources/Private/Templates/',
137 'templateRootPaths' => null,
138 'partialRootPath' =>
'Resources/Private/Partials',
139 'partialRootPaths' => null,
140 'layoutRootPath' =>
'Resources/Private/Layouts',
141 'layoutRootPaths' => null,
142 'bubbleControllerAndSubpackage' =>
false,
143 'formatIsOptional' =>
true,
144 'pattern' =>
'@templateRoot/@subpackage/@controller/@action.@format',
145 'expectedResult' => array(
146 'Resources/Private/Templates/Some/Sub/Package/SomeController/@action.html',
147 'Resources/Private/Templates/Some/Sub/Package/SomeController/@action',
152 'package' =>
'Some.Package',
153 'subPackage' =>
'Some\\Sub\\Package',
154 'controller' =>
'SomeController',
156 'templateRootPath' =>
'Resources/Private/Templates',
157 'templateRootPaths' => null,
158 'partialRootPath' =>
'Resources/Private/Partials',
159 'partialRootPaths' => null,
160 'layoutRootPath' =>
'Resources/Private/Layouts',
161 'layoutRootPaths' => null,
162 'bubbleControllerAndSubpackage' =>
true,
163 'formatIsOptional' =>
false,
164 'pattern' =>
'@partialRoot/@subpackage/@controller/@action.@format',
165 'expectedResult' => array(
166 'Resources/Private/Partials/Some/Sub/Package/SomeController/@action.json',
167 'Resources/Private/Partials/Some/Sub/Package/@action.json',
168 'Resources/Private/Partials/Sub/Package/@action.json',
169 'Resources/Private/Partials/Package/@action.json',
170 'Resources/Private/Partials/@action.json',
175 'package' =>
'Some.Package',
176 'subPackage' => null,
177 'controller' => null,
179 'templateRootPath' =>
'Resources/Private/Templates',
180 'templateRootPaths' => null,
181 'partialRootPath' =>
'Resources/Private/Partials',
182 'partialRootPaths' => null,
183 'layoutRootPath' =>
'Resources/Private/Layouts',
184 'layoutRootPaths' => null,
185 'bubbleControllerAndSubpackage' =>
true,
186 'formatIsOptional' =>
true,
187 'pattern' =>
'@layoutRoot/@subpackage/@controller/@action.@format',
188 'expectedResult' => array(
189 'Resources/Private/Layouts/@action.xml',
190 'Resources/Private/Layouts/@action',
195 'package' =>
'Some.Package',
196 'subPackage' =>
'Some\\Sub\\Package',
197 'controller' => null,
199 'templateRootPath' =>
'Resources/Private/Templates',
200 'templateRootPaths' => null,
201 'partialRootPath' =>
'Resources/Private/Partials',
202 'partialRootPaths' => null,
203 'layoutRootPath' =>
'Resources/Private/Layouts',
204 'layoutRootPaths' => null,
205 'bubbleControllerAndSubpackage' =>
true,
206 'formatIsOptional' =>
true,
207 'pattern' =>
'@templateRoot/@subpackage/@controller/@action.@format',
208 'expectedResult' => array(
209 'Resources/Private/Templates/Some/Sub/Package/@action.html',
210 'Resources/Private/Templates/Some/Sub/Package/@action',
211 'Resources/Private/Templates/Sub/Package/@action.html',
212 'Resources/Private/Templates/Sub/Package/@action',
213 'Resources/Private/Templates/Package/@action.html',
214 'Resources/Private/Templates/Package/@action',
215 'Resources/Private/Templates/@action.html',
216 'Resources/Private/Templates/@action',
221 'package' =>
'Some.Package',
222 'subPackage' =>
'Some\\Sub\\Package',
223 'controller' =>
'SomeController',
225 'templateRootPath' =>
'Resources/Private/Templates_@format',
226 'templateRootPaths' => null,
227 'partialRootPath' =>
'Resources/Private/Partials',
228 'partialRootPaths' => null,
229 'layoutRootPath' =>
'Resources/Private/Layouts',
230 'layoutRootPaths' => null,
231 'bubbleControllerAndSubpackage' =>
false,
232 'formatIsOptional' =>
true,
233 'pattern' =>
'@templateRoot/@subpackage/@controller/@action',
234 'expectedResult' => array(
235 'Resources/Private/Templates_xml/Some/Sub/Package/SomeController/@action',
236 'Resources/Private/Templates_/Some/Sub/Package/SomeController/@action',
241 'package' =>
'Some.Package',
242 'subPackage' =>
'Some\\Sub\\Package',
243 'controller' =>
'SomeController',
245 'templateRootPath' =>
'Resources/Private/Templates_@format',
246 'templateRootPaths' => null,
247 'partialRootPath' =>
'Resources/Private/Partials',
248 'partialRootPaths' => null,
249 'layoutRootPath' =>
'Resources/Private/Layouts',
250 'layoutRootPaths' => null,
251 'bubbleControllerAndSubpackage' =>
false,
252 'formatIsOptional' =>
false,
253 'pattern' =>
'@templateRoot/@subpackage/@controller/@action',
254 'expectedResult' => array(
255 'Resources/Private/Templates_json/Some/Sub/Package/SomeController/@action',
260 'package' =>
'Some.Package',
261 'subPackage' => null,
262 'controller' =>
'SomeController',
264 'templateRootPath' =>
'Resources/Private/Templates',
265 'templateRootPaths' => null,
266 'partialRootPath' =>
'Resources/Private/Partials',
267 'partialRootPaths' => null,
268 'layoutRootPath' =>
'Some/Root/Path/',
269 'layoutRootPaths' => null,
270 'bubbleControllerAndSubpackage' =>
true,
271 'formatIsOptional' =>
true,
272 'pattern' =>
'@layoutRoot/@subpackage/@controller/@action.@format',
273 'expectedResult' => array(
274 'Some/Root/Path/SomeController/@action.html',
275 'Some/Root/Path/SomeController/@action',
276 'Some/Root/Path/@action.html',
277 'Some/Root/Path/@action',
282 'package' =>
'Some.Package',
283 'subPackage' =>
'Some\\Sub\\Package',
284 'controller' =>
'SomeController',
286 'templateRootPath' =>
'Resources/Private/Templates',
287 'templateRootPaths' => null,
288 'partialRootPath' =>
'Resources/Private/Partials',
289 'partialRootPaths' => null,
290 'layoutRootPath' =>
'Resources/Private/Layouts',
291 'layoutRootPaths' => null,
292 'bubbleControllerAndSubpackage' =>
true,
293 'formatIsOptional' =>
false,
295 'expectedResult' => array(
301 'package' =>
'Some.Package',
302 'subPackage' =>
'Some\\Sub\\Package',
303 'controller' =>
'SomeController',
305 'templateRootPath' =>
'Resources/Private/Templates',
306 'templateRootPaths' => array(
'Resources/Private/Templates',
'Some/Fallback/Path'),
307 'partialRootPath' =>
'Resources/Private/Partials',
308 'partialRootPaths' => null,
309 'layoutRootPath' =>
'Resources/Private/Layouts',
310 'layoutRootPaths' => null,
311 'bubbleControllerAndSubpackage' =>
false,
312 'formatIsOptional' =>
true,
313 'pattern' =>
'@templateRoot/@subpackage/@controller/@action.@format',
314 'expectedResult' => array(
315 'Resources/Private/Templates/Some/Sub/Package/SomeController/@action.html',
316 'Resources/Private/Templates/Some/Sub/Package/SomeController/@action',
317 'Some/Fallback/Path/Some/Sub/Package/SomeController/@action.html',
318 'Some/Fallback/Path/Some/Sub/Package/SomeController/@action',
323 'package' =>
'Some.Package',
324 'subPackage' =>
'Some\\Sub\\Package',
325 'controller' =>
'SomeController',
327 'templateRootPath' =>
'Resources/Private/Templates',
328 'templateRootPaths' => array(
'Resources/Private/Templates',
'Some/Fallback/Path'),
329 'partialRootPath' =>
'Resources/Private/Partials',
330 'partialRootPaths' => null,
331 'layoutRootPath' =>
'Resources/Private/Layouts',
332 'layoutRootPaths' => null,
333 'bubbleControllerAndSubpackage' =>
true,
334 'formatIsOptional' =>
false,
335 'pattern' =>
'@templateRoot/@subpackage/@controller/@action.@format',
336 'expectedResult' => array(
337 'Resources/Private/Templates/Some/Sub/Package/SomeController/@action.html',
338 'Resources/Private/Templates/Some/Sub/Package/@action.html',
339 'Resources/Private/Templates/Sub/Package/@action.html',
340 'Resources/Private/Templates/Package/@action.html',
341 'Resources/Private/Templates/@action.html',
342 'Some/Fallback/Path/Some/Sub/Package/SomeController/@action.html',
343 'Some/Fallback/Path/Some/Sub/Package/@action.html',
344 'Some/Fallback/Path/Sub/Package/@action.html',
345 'Some/Fallback/Path/Package/@action.html',
346 'Some/Fallback/Path/@action.html',
351 'package' =>
'Some.Package',
352 'subPackage' =>
'Some\\Sub\\Package',
353 'controller' =>
'SomeController',
355 'templateRootPath' =>
'Resources/Private/Templates',
356 'templateRootPaths' => null,
357 'partialRootPath' =>
'Resources/Private/Partials',
358 'partialRootPaths' => array(
'Default/Resources/Path',
'Fallback/'),
359 'layoutRootPath' =>
'Resources/Private/Layouts',
360 'layoutRootPaths' => null,
361 'bubbleControllerAndSubpackage' =>
false,
362 'formatIsOptional' =>
true,
363 'pattern' =>
'@partialRoot/@subpackage/@controller/@partial.@format',
364 'expectedResult' => array(
365 'Default/Resources/Path/Some/Sub/Package/SomeController/@partial.html',
366 'Default/Resources/Path/Some/Sub/Package/SomeController/@partial',
367 'Fallback/Some/Sub/Package/SomeController/@partial.html',
368 'Fallback/Some/Sub/Package/SomeController/@partial',
373 'package' =>
'Some.Package',
374 'subPackage' =>
'Some\\Sub\\Package',
375 'controller' =>
'SomeController',
377 'templateRootPath' =>
'Resources/Private/Templates',
378 'templateRootPaths' => array(
'Resources/Private/Templates',
'Some/Fallback/Path'),
379 'partialRootPath' =>
'Resources/Private/Partials',
380 'partialRootPaths' => array(
'Default/Resources/Path',
'Fallback1/',
'Fallback2'),
381 'layoutRootPath' =>
'Resources/Private/Layouts',
382 'layoutRootPaths' => null,
383 'bubbleControllerAndSubpackage' =>
true,
384 'formatIsOptional' =>
true,
385 'pattern' =>
'@partialRoot/@controller/@subpackage/@partial',
386 'expectedResult' => array(
387 'Default/Resources/Path/SomeController/Some/Sub/Package/@partial',
388 'Default/Resources/Path/Some/Sub/Package/@partial',
389 'Default/Resources/Path/Sub/Package/@partial',
390 'Default/Resources/Path/Package/@partial',
391 'Default/Resources/Path/@partial',
392 'Fallback1/SomeController/Some/Sub/Package/@partial',
393 'Fallback1/Some/Sub/Package/@partial',
394 'Fallback1/Sub/Package/@partial',
395 'Fallback1/Package/@partial',
396 'Fallback1/@partial',
397 'Fallback2/SomeController/Some/Sub/Package/@partial',
398 'Fallback2/Some/Sub/Package/@partial',
399 'Fallback2/Sub/Package/@partial',
400 'Fallback2/Package/@partial',
401 'Fallback2/@partial',
406 'package' =>
'Some.Package',
407 'subPackage' =>
'Some\\Sub\\Package',
408 'controller' =>
'SomeController',
410 'templateRootPath' =>
'Resources/Private/Templates',
411 'templateRootPaths' => array(
'Resources/Private/Templates',
'Some/Fallback/Path'),
412 'partialRootPath' =>
'Resources/Private/Partials',
413 'partialRootPaths' => array(
'foo',
'bar'),
414 'layoutRootPath' =>
'Resources/Private/Layouts',
415 'layoutRootPaths' => array(
'Default/Layout/Path',
'Fallback/Path'),
416 'bubbleControllerAndSubpackage' =>
false,
417 'formatIsOptional' =>
false,
418 'pattern' =>
'@layoutRoot/@subpackage/@controller/@layout.@format',
419 'expectedResult' => array(
420 'Default/Layout/Path/Some/Sub/Package/SomeController/@layout.html',
421 'Fallback/Path/Some/Sub/Package/SomeController/@layout.html',
426 'package' =>
'Some.Package',
427 'subPackage' =>
'Some\\Sub\\Package',
428 'controller' =>
'SomeController',
430 'templateRootPath' =>
'Resources/Private/Templates',
431 'templateRootPaths' => null,
432 'partialRootPath' =>
'Resources/Private/Partials',
433 'partialRootPaths' => null,
434 'layoutRootPath' =>
'Resources/Private/Layouts',
435 'layoutRootPaths' => array(
'Resources/Layouts',
'Some/Fallback/Path'),
436 'bubbleControllerAndSubpackage' =>
true,
437 'formatIsOptional' =>
true,
438 'pattern' =>
'Static/@layoutRoot/@subpackage/@controller/@layout.@format',
439 'expectedResult' => array(
440 'Static/Resources/Layouts/Some/Sub/Package/SomeController/@layout.html',
441 'Static/Resources/Layouts/Some/Sub/Package/SomeController/@layout',
442 'Static/Resources/Layouts/Some/Sub/Package/@layout.html',
443 'Static/Resources/Layouts/Some/Sub/Package/@layout',
444 'Static/Resources/Layouts/Sub/Package/@layout.html',
445 'Static/Resources/Layouts/Sub/Package/@layout',
446 'Static/Resources/Layouts/Package/@layout.html',
447 'Static/Resources/Layouts/Package/@layout',
448 'Static/Resources/Layouts/@layout.html',
449 'Static/Resources/Layouts/@layout',
450 'Static/Some/Fallback/Path/Some/Sub/Package/SomeController/@layout.html',
451 'Static/Some/Fallback/Path/Some/Sub/Package/SomeController/@layout',
452 'Static/Some/Fallback/Path/Some/Sub/Package/@layout.html',
453 'Static/Some/Fallback/Path/Some/Sub/Package/@layout',
454 'Static/Some/Fallback/Path/Sub/Package/@layout.html',
455 'Static/Some/Fallback/Path/Sub/Package/@layout',
456 'Static/Some/Fallback/Path/Package/@layout.html',
457 'Static/Some/Fallback/Path/Package/@layout',
458 'Static/Some/Fallback/Path/@layout.html',
459 'Static/Some/Fallback/Path/@layout',
464 'package' =>
'Some.Package',
465 'subPackage' =>
'Some\\Sub\\Package',
466 'controller' =>
'SomeController',
468 'templateRootPath' =>
'Resources/Private/Templates',
469 'templateRootPaths' => array(
'Resources/Templates',
'Templates/Fallback1',
'Templates/Fallback2'),
470 'partialRootPath' =>
'Resources/Private/Partials',
471 'partialRootPaths' => array(
'Resources/Partials'),
472 'layoutRootPath' =>
'Resources/Private/Layouts',
473 'layoutRootPaths' => array(
'Resources/Layouts',
'Layouts/Fallback1'),
474 'bubbleControllerAndSubpackage' =>
false,
475 'formatIsOptional' =>
true,
476 'pattern' =>
'@layoutRoot/@templateRoot/@partialRoot/@subpackage/@controller/foo',
477 'expectedResult' => array(
478 'Resources/Layouts/Resources/Templates/Resources/Partials/Some/Sub/Package/SomeController/foo',
479 'Layouts/Fallback1/Resources/Templates/Resources/Partials/Some/Sub/Package/SomeController/foo',
480 'Resources/Layouts/Templates/Fallback1/Resources/Partials/Some/Sub/Package/SomeController/foo',
481 'Layouts/Fallback1/Templates/Fallback1/Resources/Partials/Some/Sub/Package/SomeController/foo',
482 'Resources/Layouts/Templates/Fallback2/Resources/Partials/Some/Sub/Package/SomeController/foo',
483 'Layouts/Fallback1/Templates/Fallback2/Resources/Partials/Some/Sub/Package/SomeController/foo',
508 public function expandGenericPathPatternTests($package, $subPackage, $controller, $format, $templateRootPath, array $templateRootPaths = null, $partialRootPath, array $partialRootPaths = null, $layoutRootPath, array $layoutRootPaths = null, $bubbleControllerAndSubpackage, $formatIsOptional, $pattern, $expectedResult)
513 $templateView = $this->getAccessibleMock(TemplateView::class, array(
'dummy'), array(),
'',
false);
514 $templateView->setControllerContext($mockControllerContext);
515 if ($templateRootPath !== null) {
516 $templateView->setTemplateRootPath($templateRootPath);
518 if ($templateRootPaths !== null) {
519 $templateView->setTemplateRootPaths($templateRootPaths);
522 if ($partialRootPath !== null) {
523 $templateView->setPartialRootPath($partialRootPath);
525 if ($partialRootPaths !== null) {
526 $templateView->setPartialRootPaths($partialRootPaths);
529 if ($layoutRootPath !== null) {
530 $templateView->setLayoutRootPath($layoutRootPath);
532 if ($layoutRootPaths !== null) {
533 $templateView->setLayoutRootPaths($layoutRootPaths);
536 $actualResult = $templateView->_call(
'expandGenericPathPattern', $pattern, $bubbleControllerAndSubpackage, $formatIsOptional);
537 $this->assertEquals($expectedResult, $actualResult);
547 $templateView = $this->getAccessibleMock(TemplateView::class, array(
'getTemplateRootPaths'), array(),
'',
false);
548 $templateView->_set(
'controllerContext', $mockControllerContext);
549 $templateView->expects($this->any())->method(
'getTemplateRootPaths')->will($this->returnValue(array(
'Resources/Private/')));
551 $expected = array(
'Resources/Private/Templates/My/@action.html');
552 $actual = $templateView->_call(
'expandGenericPathPattern',
'@templateRoot/Templates/@subpackage/@controller/@action.@format',
false,
false);
553 $this->assertEquals($expected, $actual);
564 $templateView = $this->getAccessibleMock(TemplateView::class, array(
'getTemplateRootPaths'), array(),
'',
false);
565 $templateView->_set(
'controllerContext', $mockControllerContext);
566 $templateView->expects($this->any())->method(
'getTemplateRootPaths')->will($this->returnValue(array(
'Resources/Private/')));
567 $actual = $templateView->_call(
'expandGenericPathPattern',
'@templateRoot/Templates/@subpackage/@controller/@action.@format',
false,
false);
570 'Resources/Private/Templates/MySubPackage/My/@action.html'
572 $this->assertEquals($expected, $actual);
582 $templateView = $this->getAccessibleMock(TemplateView::class, array(
'getTemplateRootPaths'), array(),
'',
false);
583 $templateView->_set(
'controllerContext', $mockControllerContext);
584 $templateView->expects($this->any())->method(
'getTemplateRootPaths')->will($this->returnValue(array(
'Resources/Private/')));
585 $actual = $templateView->_call(
'expandGenericPathPattern',
'@templateRoot/Templates/@subpackage/@controller/@action.@format',
false,
true);
588 'Resources/Private/Templates/MySubPackage/My/@action.html',
589 'Resources/Private/Templates/MySubPackage/My/@action'
591 $this->assertEquals($expected, $actual);
601 $templateView = $this->getAccessibleMock(TemplateView::class, array(
'getTemplateRootPaths'), array(),
'',
false);
602 $templateView->_set(
'controllerContext', $mockControllerContext);
603 $templateView->expects($this->any())->method(
'getTemplateRootPaths')->will($this->returnValue(array(
'Resources/Private/')));
604 $actual = $templateView->_call(
'expandGenericPathPattern',
'@templateRoot/Templates/@subpackage/@controller/@action.@format',
true,
true);
607 'Resources/Private/Templates/MySubPackage/My/@action.html',
608 'Resources/Private/Templates/MySubPackage/My/@action',
609 'Resources/Private/Templates/MySubPackage/@action.html',
610 'Resources/Private/Templates/MySubPackage/@action',
611 'Resources/Private/Templates/@action.html',
612 'Resources/Private/Templates/@action'
614 $this->assertEquals($expected, $actual);
620 public function getTemplateRootPathsReturnsUserSpecifiedTemplatePaths()
623 $templateView = $this->getAccessibleMock(TemplateView::class, array(
'dummy'), array(),
'',
false);
624 $templateView->setTemplateRootPath(
'/foo/bar');
625 $expected = array(
'/foo/bar');
626 $actual = $templateView->_call(
'getTemplateRootPaths');
627 $this->assertEquals($expected, $actual,
'A set template root path was not returned correctly.');
633 public function setTemplateRootPathOverrulesSetTemplateRootPaths()
636 $templateView = $this->getAccessibleMock(TemplateView::class, array(
'dummy'), array(),
'',
false);
637 $templateView->setTemplateRootPath(
'/foo/bar');
638 $templateView->setTemplateRootPaths(array(
'/overruled/path'));
639 $expected = array(
'/overruled/path');
640 $actual = $templateView->_call(
'getTemplateRootPaths');
641 $this->assertEquals($expected, $actual,
'A set template root path was not returned correctly.');
647 public function getPartialRootPathsReturnsUserSpecifiedPartialPath()
650 $templateView = $this->getAccessibleMock(TemplateView::class, array(
'dummy'), array(),
'',
false);
651 $templateView->setPartialRootPath(
'/foo/bar');
652 $expected = array(
'/foo/bar');
653 $actual = $templateView->_call(
'getPartialRootPaths');
654 $this->assertEquals($expected, $actual,
'A set partial root path was not returned correctly.');
660 public function getLayoutRootPathsReturnsUserSpecifiedPartialPath()
663 $templateView = $this->getAccessibleMock(TemplateView::class, array(
'dummy'), array(),
'',
false);
664 $templateView->setLayoutRootPath(
'/foo/bar');
665 $expected = array(
'/foo/bar');
666 $actual = $templateView->_call(
'getLayoutRootPaths');
667 $this->assertEquals($expected, $actual,
'A set partial root path was not returned correctly.');
673 public function pathToPartialIsResolvedCorrectly()
675 vfsStreamWrapper::register();
676 mkdir(
'vfs://MyPartials');
677 \file_put_contents(
'vfs://MyPartials/SomePartial',
'contentsOfSomePartial');
680 'vfs://NonExistentDir/UnknowFile.html',
681 'vfs://MyPartials/SomePartial.html',
682 'vfs://MyPartials/SomePartial'
686 $templateView = $this->getAccessibleMock(TemplateView::class, array(
'expandGenericPathPattern',
'resolveFileNamePath'), array(),
'',
false);
687 $templateView->expects($this->once())->method(
'expandGenericPathPattern')->with(
'@partialRoot/@subpackage/@partial.@format',
true,
true)->will($this->returnValue($paths));
688 $templateView->expects($this->any())->method(
'resolveFileNamePath')->will($this->onConsecutiveCalls(
694 $templateView->setTemplateRootPath(
'MyTemplates');
695 $templateView->setPartialRootPath(
'MyPartials');
696 $templateView->setLayoutRootPath(
'MyLayouts');
698 $this->assertSame(
'contentsOfSomePartial', $templateView->_call(
'getPartialSource',
'SomePartial'));
704 public function resolveTemplatePathAndFilenameChecksDifferentPathPatternsAndReturnsTheFirstPathWhichExists()
706 vfsStreamWrapper::register();
707 mkdir(
'vfs://MyTemplates');
708 \file_put_contents(
'vfs://MyTemplates/MyCoolAction.html',
'contentsOfMyCoolAction');
711 'vfs://NonExistentDir/UnknownFile.html',
712 'vfs://MyTemplates/@action.html'
716 $templateView = $this->getAccessibleMock(TemplateView::class, array(
'expandGenericPathPattern',
'resolveFileNamePath'), array(),
'',
false);
717 $templateView->expects($this->once())->method(
'expandGenericPathPattern')->with(
'@templateRoot/@subpackage/@controller/@action.@format',
false,
false)->will($this->returnValue($paths));
718 $templateView->expects($this->any())->method(
'resolveFileNamePath')->will($this->onConsecutiveCalls(
720 'vfs://MyTemplates/MyCoolAction.html'
723 $templateView->setTemplateRootPath(
'MyTemplates');
724 $templateView->setPartialRootPath(
'MyPartials');
725 $templateView->setLayoutRootPath(
'MyLayouts');
727 $this->assertSame(
'contentsOfMyCoolAction', $templateView->_call(
'getTemplateSource',
'myCoolAction'));
735 vfsStreamWrapper::register();
736 mkdir(
'vfs://MyTemplates');
737 \file_put_contents(
'vfs://MyTemplates/MyCoolAction.html',
'contentsOfMyCoolAction');
739 $templateView = $this->getAccessibleMock(TemplateView::class, array(
'resolveFileNamePath'), array(),
'',
false);
740 $templateView->expects($this->any())->method(
'resolveFileNamePath')->willReturnArgument(0);
741 $templateView->_set(
'templatePathAndFilename',
'vfs://MyTemplates/MyCoolAction.html');
743 $this->assertSame(
'contentsOfMyCoolAction', $templateView->_call(
'getTemplateSource'));
749 public function getLayoutPathAndFilenameRespectsCasingOfLayoutName()
753 $mockParsedTemplate = $this->getMock(ParsedTemplateInterface::class);
754 $mockTemplateParser = $this->getMock(TemplateParser::class);
755 $mockTemplateParser->expects($this->any())->method(
'parse')->will($this->returnValue($mockParsedTemplate));
758 $mockObjectManager = $this->getMock(ObjectManager::class);
759 $mockObjectManager->expects($this->any())->method(
'get')->will($this->returnCallback(array($this,
'objectManagerCallback')));
761 $mockRequest = $this->getMock(WebRequest::class);
762 $mockControllerContext = $this->getMock(ControllerContext::class);
763 $mockControllerContext->expects($this->any())->method(
'getRequest')->will($this->returnValue($mockRequest));
765 $mockViewHelperVariableContainer = $this->getMock(ViewHelperVariableContainer::class);
767 $mockRenderingContext = $this->getMock(RenderingContext::class);
768 $mockRenderingContext->expects($this->any())->method(
'getControllerContext')->will($this->returnValue($mockControllerContext));
769 $mockRenderingContext->expects($this->any())->method(
'getViewHelperVariableContainer')->will($this->returnValue($mockViewHelperVariableContainer));
772 $view = $this->getAccessibleMock(TemplateView::class, array(
'testFileExistence',
'buildParserConfiguration'), array(),
'',
false);
773 $view->_set(
'templateParser', $mockTemplateParser);
774 $view->_set(
'objectManager', $mockObjectManager);
775 $view->setRenderingContext($mockRenderingContext);
777 $mockTemplateCompiler = $this->getMock(TemplateCompiler::class);
778 $view->_set(
'templateCompiler', $mockTemplateCompiler);
780 $mockContentObject = $this->getMock(ContentObjectRenderer::class);
784 $mockCacheManager = $this->getMock(CacheManager::class, array(), array(),
'',
false);
785 $mockCache = $this->getMock(PhpFrontend::class, array(), array(),
'',
false);
786 $mockCacheManager->expects($this->any())->method(
'getCache')->will($this->returnValue($mockCache));
789 $mockRequest->expects($this->any())->method(
'getFormat')->will($this->returnValue(
'html'));
790 $view->setLayoutRootPaths(array(
'some/Default/Directory'));
791 $view->setTemplateRootPaths(array(
'some/Default/Directory'));
792 $view->setPartialRootPaths(array(
'some/Default/Directory'));
793 $view->expects($this->at(0))->method(
'testFileExistence')->with(PATH_site .
'some/Default/Directory/LayoutName.html')->willReturn(
false);
794 $view->expects($this->at(1))->method(
'testFileExistence')->with(PATH_site .
'some/Default/Directory/layoutName.html')->willReturn(
true);
795 $this->assertSame(PATH_site .
'some/Default/Directory/layoutName.html', $view->_call(
'getLayoutPathAndFilename',
'layoutName'));