[CLEANUP] Improve the @param/@return/@var PHPDoc
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / View / StandaloneViewTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\View;
3
4 /* *
5 * This script is backported from the FLOW3 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 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
22 * */
23
24 use TYPO3\CMS\Core\Tests\UnitTestCase;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
27 use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
28 use TYPO3\CMS\Extbase\Mvc\Web\Request;
29 use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
30 use TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler;
31 use TYPO3\CMS\Fluid\Core\Parser\TemplateParser;
32 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
33 use TYPO3\CMS\Fluid\View\StandaloneView;
34
35 /**
36 * Test case
37 */
38 class StandaloneViewTest extends UnitTestCase {
39
40 /**
41 * @var array A backup of registered singleton instances
42 */
43 protected $singletonInstances = array();
44
45 /**
46 * @var StandaloneView|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject
47 */
48 protected $view;
49
50 /**
51 * @var \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface|\PHPUnit_Framework_MockObject_MockObject
52 */
53 protected $mockRenderingContext;
54
55 /**
56 * @var \TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer|\PHPUnit_Framework_MockObject_MockObject
57 */
58 protected $mockViewHelperVariableContainer;
59
60 /**
61 * @var ControllerContext|\PHPUnit_Framework_MockObject_MockObject
62 */
63 protected $mockControllerContext;
64
65 /**
66 * @var TemplateParser|\PHPUnit_Framework_MockObject_MockObject
67 */
68 protected $mockTemplateParser;
69
70 /**
71 * @var \TYPO3\CMS\Extbase\Object\ObjectManager|\PHPUnit_Framework_MockObject_MockObject
72 */
73 protected $mockObjectManager;
74
75 /**
76 * @var Request|\PHPUnit_Framework_MockObject_MockObject
77 */
78 protected $mockRequest;
79
80 /**
81 * @var UriBuilder|\PHPUnit_Framework_MockObject_MockObject
82 */
83 protected $mockUriBuilder;
84
85 /**
86 * @var \TYPO3\CMS\Fluid\Core\Parser\ParsedTemplateInterface|\PHPUnit_Framework_MockObject_MockObject
87 */
88 protected $mockParsedTemplate;
89
90 /**
91 * @var ConfigurationManagerInterface|\PHPUnit_Framework_MockObject_MockObject
92 */
93 protected $mockConfigurationManager;
94
95 /**
96 * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer|\PHPUnit_Framework_MockObject_MockObject
97 */
98 protected $mockContentObject;
99
100 /**
101 * @var TemplateCompiler|\PHPUnit_Framework_MockObject_MockObject
102 */
103 protected $mockTemplateCompiler;
104
105 /**
106 * Sets up this test case
107 *
108 * @return void
109 */
110 public function setUp() {
111 $this->singletonInstances = GeneralUtility::getSingletonInstances();
112 $this->view = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\StandaloneView::class, array('testFileExistence', 'buildParserConfiguration'), array(), '', FALSE);
113 $this->mockTemplateParser = $this->getMock(TemplateParser::class);
114 $this->mockParsedTemplate = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\ParsedTemplateInterface::class);
115 $this->mockTemplateParser->expects($this->any())->method('parse')->will($this->returnValue($this->mockParsedTemplate));
116 $this->mockConfigurationManager = $this->getMock(ConfigurationManagerInterface::class);
117 $this->mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
118 $this->mockObjectManager->expects($this->any())->method('get')->will($this->returnCallback(array($this, 'objectManagerCallback')));
119 $this->mockRequest = $this->getMock(Request::class);
120 $this->mockUriBuilder = $this->getMock(UriBuilder::class);
121 $this->mockContentObject = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
122 $this->mockControllerContext = $this->getMock(ControllerContext::class);
123 $this->mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->mockRequest));
124 $this->mockViewHelperVariableContainer = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer::class);
125 $this->mockRenderingContext = $this->getMock(RenderingContext::class);
126 $this->mockRenderingContext->expects($this->any())->method('getControllerContext')->will($this->returnValue($this->mockControllerContext));
127 $this->mockRenderingContext->expects($this->any())->method('getViewHelperVariableContainer')->will($this->returnValue($this->mockViewHelperVariableContainer));
128 $this->view->_set('templateParser', $this->mockTemplateParser);
129 $this->view->_set('objectManager', $this->mockObjectManager);
130 $this->view->setRenderingContext($this->mockRenderingContext);
131 $this->mockTemplateCompiler = $this->getMock(TemplateCompiler::class);
132 $this->view->_set('templateCompiler', $this->mockTemplateCompiler);
133 GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class, $this->mockObjectManager);
134 GeneralUtility::addInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, $this->mockContentObject);
135
136 $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager::class, array(), array(), '', FALSE);
137 $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class, array(), array(), '', FALSE);
138 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
139 GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $mockCacheManager);
140 }
141
142 /**
143 * @return void
144 */
145 public function tearDown() {
146 GeneralUtility::purgeInstances();
147 GeneralUtility::resetSingletonInstances($this->singletonInstances);
148 parent::tearDown();
149 }
150
151 /**
152 * @param string $className
153 * @return ConfigurationManagerInterface|TemplateParser|RenderingContext|Request|UriBuilder|ControllerContext|TemplateCompiler
154 */
155 public function objectManagerCallback($className) {
156 switch ($className) {
157 case ConfigurationManagerInterface::class:
158 return $this->mockConfigurationManager;
159 case TemplateParser::class:
160 return $this->mockTemplateParser;
161 case RenderingContext::class:
162 return $this->mockRenderingContext;
163 case Request::class:
164 return $this->mockRequest;
165 case UriBuilder::class:
166 return $this->mockUriBuilder;
167 case ControllerContext::class:
168 return $this->mockControllerContext;
169 case TemplateCompiler::class:
170 return $this->mockTemplateCompiler;
171 }
172 throw new \InvalidArgumentException('objectManagerCallback cannot handle class "' . $className . '". Looks like incomplete mocking in the tests.', 1417105493);
173 }
174
175 /**
176 * @test
177 */
178 public function constructorSetsSpecifiedContentObject() {
179 $mockContentObject = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
180 $this->mockConfigurationManager->expects($this->once())->method('setContentObject')->with($this->identicalTo($mockContentObject));
181 new StandaloneView($mockContentObject);
182 }
183
184 /**
185 * @test
186 */
187 public function constructorCreatesContentObjectIfItIsNotSpecified() {
188 $this->mockConfigurationManager->expects($this->once())->method('setContentObject')->with($this->identicalTo($this->mockContentObject));
189 new StandaloneView();
190 }
191
192 /**
193 * @test
194 */
195 public function constructorSetsRequestUri() {
196 $expectedRequestUri = GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
197 $this->mockRequest->expects($this->once())->method('setRequestURI')->with($expectedRequestUri);
198 new StandaloneView();
199 }
200
201 /**
202 * @test
203 */
204 public function constructorSetsBaseUri() {
205 $expectedBaseUri = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
206 $this->mockRequest->expects($this->once())->method('setBaseURI')->with($expectedBaseUri);
207 new StandaloneView();
208 }
209
210 /**
211 * @test
212 */
213 public function constructorInjectsRequestToUriBuilder() {
214 $this->mockUriBuilder->expects($this->once())->method('setRequest')->with($this->mockRequest);
215 new StandaloneView();
216 }
217
218 /**
219 * @test
220 */
221 public function constructorInjectsRequestToControllerContext() {
222 $this->mockControllerContext->expects($this->once())->method('setRequest')->with($this->mockRequest);
223 new StandaloneView();
224 }
225
226 /**
227 * @test
228 */
229 public function constructorInjectsUriBuilderToControllerContext() {
230 $this->mockControllerContext->expects($this->once())->method('setUriBuilder')->with($this->mockUriBuilder);
231 new StandaloneView();
232 }
233
234 /**
235 * @test
236 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
237 */
238 public function renderThrowsExceptionIfTemplateIsNotSpecified() {
239 $this->view->render();
240 }
241
242 /**
243 * @test
244 */
245 public function renderPassesSpecifiedTemplateSourceToTemplateParser() {
246 $this->view->setTemplateSource('The Template Source');
247 $this->mockTemplateParser->expects($this->once())->method('parse')->with('The Template Source');
248 $this->view->render();
249 }
250
251 /**
252 * @test
253 */
254 public function renderLoadsSpecifiedTemplateFileAndPassesSourceToTemplateParser() {
255 $templatePathAndFilename = __DIR__ . '/Fixtures/StandaloneViewFixture.html';
256 $expectedResult = file_get_contents($templatePathAndFilename);
257 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
258 $this->view->expects($this->once())->method('testFileExistence')->with($templatePathAndFilename)->will($this->returnValue(TRUE));
259 $this->mockTemplateParser->expects($this->once())->method('parse')->with($expectedResult);
260 $this->view->render();
261 }
262
263 /**
264 * @test
265 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
266 */
267 public function renderThrowsExceptionIfSpecifiedTemplateFileDoesNotExist() {
268 $this->view->setTemplatePathAndFilename('NonExistingTemplatePath');
269 @$this->view->render();
270 }
271
272 /**
273 * @test
274 */
275 public function setFormatSetsRequestFormat() {
276 $this->mockRequest->expects($this->once())->method('setFormat')->with('xml');
277 $this->view->setFormat('xml');
278 }
279
280 /**
281 * @test
282 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
283 */
284 public function getLayoutRootPathThrowsExceptionIfLayoutRootPathAndTemplatePathAreNotSpecified() {
285 $this->view->getLayoutRootPath();
286 }
287
288 /**
289 * @test
290 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
291 */
292 public function getLayoutRootPathsThrowsExceptionIfLayoutRootPathAndTemplatePathAreNotSpecified() {
293 $this->view->getLayoutRootPaths();
294 }
295
296 /**
297 * @test
298 */
299 public function getLayoutRootPathReturnsSpecifiedLayoutRootPathByDefault() {
300 $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
301 $layoutRootPath = 'some/layout/RootPath';
302 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
303 $this->view->setLayoutRootPath($layoutRootPath);
304 $actualResult = $this->view->getLayoutRootPath();
305 $this->assertEquals($layoutRootPath, $actualResult);
306 }
307
308 /**
309 * @test
310 */
311 public function getLayoutRootPathsReturnsSpecifiedLayoutRootPathByDefault() {
312 $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
313 $layoutRootPaths = array(
314 'some/layout/RootPath'
315 );
316 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
317 $this->view->setLayoutRootPaths($layoutRootPaths);
318 $actualResult = $this->view->getLayoutRootPaths();
319 $this->assertEquals($layoutRootPaths, $actualResult);
320 }
321
322 /**
323 * @test
324 */
325 public function getLayoutRootPathReturnsDefaultPathIfNoLayoutRootPathIsSpecified() {
326 $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
327 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
328 $expectedResult = 'some/template/RootPath/Layouts';
329 $actualResult = $this->view->getLayoutRootPath();
330 $this->assertEquals($expectedResult, $actualResult);
331 }
332
333 /**
334 * @test
335 */
336 public function getLayoutRootPathsReturnsDefaultPathIfNoLayoutRootPathIsSpecified() {
337 $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
338 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
339 $expectedResult = array('some/template/RootPath/Layouts');
340 $actualResult = $this->view->getLayoutRootPaths();
341 $this->assertEquals($expectedResult, $actualResult);
342 }
343
344 /**
345 * @test
346 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
347 */
348 public function getLayoutSourceThrowsExceptionIfLayoutRootPathDoesNotExist() {
349 $this->view->setLayoutRootPath('some/non/existing/Path');
350 $this->view->_call('getLayoutSource');
351 }
352
353 /**
354 * @test
355 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
356 */
357 public function getLayoutSourceThrowsExceptionIfLayoutRootPathsDoesNotExist() {
358 $this->view->setLayoutRootPaths(array('some/non/existing/Path'));
359 $this->view->_call('getLayoutSource');
360 }
361
362 /**
363 * @test
364 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
365 */
366 public function getLayoutSourceThrowsExceptionIfLayoutFileDoesNotExist() {
367 $layoutRootPath = __DIR__ . '/Fixtures';
368 $this->view->setLayoutRootPaths(array($layoutRootPath));
369 $this->view->_call('getLayoutSource', 'NonExistingLayout');
370 }
371
372 /**
373 * @test
374 */
375 public function getLayoutSourceReturnsContentOfLayoutFileForTheDefaultFormat() {
376 $layoutRootPath = __DIR__ . '/Fixtures';
377 $this->view->setLayoutRootPath($layoutRootPath);
378 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('html'));
379 $this->view->expects($this->once())->method('testFileExistence')->with($layoutRootPath . '/LayoutFixture.html')->will($this->returnValue(TRUE));
380 $expectedResult = file_get_contents($layoutRootPath . '/LayoutFixture.html');
381 $actualResult = $this->view->_call('getLayoutSource', 'LayoutFixture');
382 $this->assertEquals($expectedResult, $actualResult);
383 }
384
385 /**
386 * @test
387 */
388 public function getLayoutSourceReturnsContentOfLayoutFileForTheSpecifiedFormat() {
389 $layoutRootPath = __DIR__ . '/Fixtures';
390 $this->view->setLayoutRootPath($layoutRootPath);
391 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('xml'));
392 $this->view->expects($this->once())->method('testFileExistence')->with($layoutRootPath . '/LayoutFixture.xml')->will($this->returnValue(TRUE));
393 $expectedResult = file_get_contents($layoutRootPath . '/LayoutFixture.xml');
394 $actualResult = $this->view->_call('getLayoutSource', 'LayoutFixture');
395 $this->assertEquals($expectedResult, $actualResult);
396 }
397
398 /**
399 * @test
400 */
401 public function getLayoutSourceReturnsContentOfDefaultLayoutFileIfNoLayoutExistsForTheSpecifiedFormat() {
402 $layoutRootPath = __DIR__ . '/Fixtures';
403 $this->view->setLayoutRootPath($layoutRootPath);
404 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('foo'));
405 $this->view->expects($this->at(0))->method('testFileExistence')->with($layoutRootPath . '/LayoutFixture.foo')->will($this->returnValue(FALSE));
406 $this->view->expects($this->at(1))->method('testFileExistence')->with($layoutRootPath . '/LayoutFixture')->will($this->returnValue(TRUE));
407 $expectedResult = file_get_contents($layoutRootPath . '/LayoutFixture');
408 $actualResult = $this->view->_call('getLayoutSource', 'LayoutFixture');
409 $this->assertEquals($expectedResult, $actualResult);
410 }
411
412 /**
413 * @test
414 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
415 */
416 public function getPartialRootPathThrowsExceptionIfPartialRootPathAndTemplatePathAreNotSpecified() {
417 $this->view->getPartialRootPath();
418 }
419
420 /**
421 * @test
422 */
423 public function getPartialRootPathReturnsSpecifiedPartialRootPathByDefault() {
424 $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
425 $partialRootPath = 'some/partial/RootPath';
426 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
427 $this->view->setPartialRootPath($partialRootPath);
428 $actualResult = $this->view->getPartialRootPath();
429 $this->assertEquals($partialRootPath, $actualResult);
430 }
431
432 /**
433 * @test
434 */
435 public function getPartialRootPathReturnsDefaultPathIfNoPartialRootPathIsSpecified() {
436 $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
437 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
438 $expectedResult = 'some/template/RootPath/Partials';
439 $actualResult = $this->view->getPartialRootPath();
440 $this->assertEquals($expectedResult, $actualResult);
441 }
442
443 /**
444 * @test
445 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
446 */
447 public function getPartialSourceThrowsExceptionIfPartialRootPathDoesNotExist() {
448 $this->view->setPartialRootPath('some/non/existing/Path');
449 $this->view->_call('getPartialSource', 'SomePartial');
450 }
451
452 /**
453 * @test
454 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
455 */
456 public function getPartialSourceThrowsExceptionIfPartialFileDoesNotExist() {
457 $partialRootPath = __DIR__ . '/Fixtures';
458 $this->view->setPartialRootPath($partialRootPath);
459 $this->view->_call('getPartialSource', 'NonExistingPartial');
460 }
461
462 /**
463 * @test
464 */
465 public function getPartialSourceReturnsContentOfPartialFileForTheDefaultFormat() {
466 $partialRootPath = __DIR__ . '/Fixtures';
467 $this->view->setPartialRootPath($partialRootPath);
468 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('html'));
469 $this->view->expects($this->once())->method('testFileExistence')->will($this->returnValue(TRUE));
470 $expectedResult = file_get_contents($partialRootPath . '/LayoutFixture.html');
471 $actualResult = $this->view->_call('getPartialSource', 'LayoutFixture');
472 $this->assertEquals($expectedResult, $actualResult);
473 }
474
475 /**
476 * @test
477 */
478 public function getPartialSourceReturnsContentOfPartialFileForTheSpecifiedFormat() {
479 $partialRootPath = __DIR__ . '/Fixtures';
480 $this->view->setPartialRootPath($partialRootPath);
481 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('xml'));
482 $this->view->expects($this->once())->method('testFileExistence')->will($this->returnValue(TRUE));
483 $expectedResult = file_get_contents($partialRootPath . '/LayoutFixture.xml');
484 $actualResult = $this->view->_call('getPartialSource', 'LayoutFixture');
485 $this->assertEquals($expectedResult, $actualResult);
486 }
487
488 /**
489 * @test
490 */
491 public function getPartialSourceReturnsContentOfDefaultPartialFileIfNoPartialExistsForTheSpecifiedFormat() {
492 $partialRootPath = __DIR__ . '/Fixtures';
493 $this->view->setPartialRootPath($partialRootPath);
494 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('foo'));
495 $this->view->expects($this->at(1))->method('testFileExistence')->will($this->returnValue(TRUE));
496 $expectedResult = file_get_contents($partialRootPath . '/LayoutFixture');
497 $actualResult = $this->view->_call('getPartialSource', 'LayoutFixture');
498 $this->assertEquals($expectedResult, $actualResult);
499 }
500
501 /**
502 * @test
503 */
504 public function setPartialRootPathsOverridesValueSetBySetPartialRootPath() {
505 $this->view->setPartialRootPath('/foo/bar');
506 $this->view->setPartialRootPaths(array('/overruled/path'));
507 $expected = array('/overruled/path');
508 $actual = $this->view->_call('getPartialRootPaths');
509 $this->assertEquals($expected, $actual, 'A set partial root path was not returned correctly.');
510 }
511
512 /**
513 * @test
514 */
515 public function setLayoutRootPathsOverridesValuesSetBySetLayoutRootPath() {
516 $this->view->setLayoutRootPath('/foo/bar');
517 $this->view->setLayoutRootPaths(array('/overruled/path'));
518 $expected = array('/overruled/path');
519 $actual = $this->view->_call('getLayoutRootPaths');
520 $this->assertEquals($expected, $actual, 'A set layout root path was not returned correctly.');
521 }
522
523 /**
524 * @test
525 */
526 public function getLayoutPathAndFilenameRespectsCasingOfLayoutName() {
527 $this->view->setLayoutRootPaths(array('some/Default/Directory'));
528 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
529 $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/LayoutName.html')->willReturn(FALSE);
530 $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/LayoutName')->willReturn(FALSE);
531 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/layoutName.html')->willReturn(TRUE);
532 $this->assertSame(PATH_site . 'some/Default/Directory/layoutName.html', $this->view->_call('getLayoutPathAndFilename', 'layoutName'));
533 }
534
535 /**
536 * @test
537 */
538 public function getLayoutPathAndFilenameFindsUpperCasedLayoutName() {
539 $this->view->setLayoutRootPaths(array('some/Default/Directory'));
540 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
541 $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/LayoutName.html')->willReturn(TRUE);
542 $this->assertSame(PATH_site . 'some/Default/Directory/LayoutName.html', $this->view->_call('getLayoutPathAndFilename', 'layoutName'));
543 }
544
545 /**
546 * @test
547 */
548 public function getLayoutPathAndFilenameResolvesTheSpecificFile() {
549 $this->view->setLayoutRootPaths(array(
550 'default' => 'some/Default/Directory',
551 'specific' => 'specific/Layouts',
552 ));
553 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
554 $this->view->expects($this->once())->method('testFileExistence')->with(PATH_site . 'specific/Layouts/Default.html')->will($this->returnValue(TRUE));
555 $this->assertEquals(PATH_site . 'specific/Layouts/Default.html', $this->view->_call('getLayoutPathAndFilename'));
556 }
557
558 /**
559 * @test
560 */
561 public function getLayoutPathAndFilenameResolvesTheDefaultFile() {
562 $this->view->setLayoutRootPaths(array(
563 'default' => 'some/Default/Directory',
564 'specific' => 'specific/Layouts',
565 ));
566 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
567 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default.html')->will($this->returnValue(TRUE));
568 $this->assertEquals(PATH_site . 'some/Default/Directory/Default.html', $this->view->_call('getLayoutPathAndFilename'));
569 }
570
571 /**
572 * @test
573 */
574 public function getLayoutPathAndFilenameResolvesTheSpecificFileWithNumericIndices() {
575 $this->view->setLayoutRootPaths(array(
576 '10' => 'some/Default/Directory',
577 '25' => 'evenMore/Specific/Layouts',
578 '17' => 'specific/Layouts',
579 ));
580 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
581 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Layouts/Default.html')->will($this->returnValue(TRUE));
582 $this->assertEquals(PATH_site . 'specific/Layouts/Default.html', $this->view->_call('getLayoutPathAndFilename'));
583 }
584
585 /**
586 * @test
587 */
588 public function getLayoutPathAndFilenameResolvesTheDefaultFileWithNumericIndices() {
589 $this->view->setLayoutRootPaths(array(
590 '10' => 'some/Default/Directory',
591 '25' => 'evenMore/Specific/Layouts',
592 '17' => 'specific/Layouts',
593 ));
594 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
595 $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default.html')->will($this->returnValue(TRUE));
596 $this->assertEquals(PATH_site . 'some/Default/Directory/Default.html', $this->view->_call('getLayoutPathAndFilename'));
597 }
598
599 /**
600 * @test
601 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
602 * @expectedExceptionCode 1288092555
603 */
604 public function getLayoutPathAndFilenameThrowsExceptionIfNoFileWasFound() {
605 $this->view->setLayoutRootPaths(array(
606 '10' => 'some/Default/Directory',
607 '25' => 'evenMore/Specific/Layouts',
608 '17' => 'specific/Layouts',
609 ));
610 $this->view->expects($this->any())->method('testFileExistence')->will($this->returnValue(FALSE));
611 $this->view->_call('getLayoutPathAndFilename');
612 }
613
614 /**
615 * @test
616 */
617 public function getPartialPathAndFilenameRespectsCasingOfPartialName() {
618 $this->view->setPartialRootPaths(array('some/Default/Directory'));
619 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
620 $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/PartialName.html')->willReturn(FALSE);
621 $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/PartialName')->willReturn(FALSE);
622 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/partialName.html')->willReturn(TRUE);
623 $this->assertSame(PATH_site . 'some/Default/Directory/partialName.html', $this->view->_call('getPartialPathAndFilename', 'partialName'));
624 }
625
626 /**
627 * @test
628 */
629 public function getPartialPathAndFilenameFindsUpperCasedPartialName() {
630 $this->view->setPartialRootPaths(array('some/Default/Directory'));
631 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
632 $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/PartialName.html')->willReturn(TRUE);
633 $this->assertSame(PATH_site . 'some/Default/Directory/PartialName.html', $this->view->_call('getPartialPathAndFilename', 'partialName'));
634 }
635
636 /**
637 * @test
638 */
639 public function getPartialPathAndFilenameResolvesTheSpecificFile() {
640 $this->view->setPartialRootPaths(array(
641 'default' => 'some/Default/Directory',
642 'specific' => 'specific/Partials',
643 ));
644 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
645 $this->view->expects($this->once())->method('testFileExistence')->with(PATH_site . 'specific/Partials/Partial.html')->will($this->returnValue(TRUE));
646 $this->assertEquals(PATH_site . 'specific/Partials/Partial.html', $this->view->_call('getPartialPathAndFilename', 'Partial'));
647 }
648
649 /**
650 * @test
651 */
652 public function getPartialPathAndFilenameResolvesTheDefaultFile() {
653 $this->view->setPartialRootPaths(array(
654 'default' => 'some/Default/Directory',
655 'specific' => 'specific/Partials',
656 ));
657 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
658 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Partial.html')->will($this->returnValue(TRUE));
659 $this->assertEquals(PATH_site . 'some/Default/Directory/Partial.html', $this->view->_call('getPartialPathAndFilename', 'Partial'));
660 }
661
662 /**
663 * @test
664 */
665 public function getPartialPathAndFilenameResolvesTheSpecificFileWithNumericIndices() {
666 $this->view->setPartialRootPaths(array(
667 '10' => 'some/Default/Directory',
668 '25' => 'evenMore/Specific/Partials',
669 '17' => 'specific/Partials',
670 ));
671 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
672 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Partials/Partial.html')->will($this->returnValue(TRUE));
673 $this->assertEquals(PATH_site . 'specific/Partials/Partial.html', $this->view->_call('getPartialPathAndFilename', 'Partial'));
674 }
675
676 /**
677 * @test
678 */
679 public function getPartialPathAndFilenameResolvesTheDefaultFileWithNumericIndices() {
680 $this->view->setPartialRootPaths(array(
681 '10' => 'some/Default/Directory',
682 '25' => 'evenMore/Specific/Partials',
683 '17' => 'specific/Partials',
684 ));
685 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
686 $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Partial.html')->will($this->returnValue(TRUE));
687 $this->assertEquals(PATH_site . 'some/Default/Directory/Partial.html', $this->view->_call('getPartialPathAndFilename', 'Partial'));
688 }
689
690 /**
691 * @test
692 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
693 * @expectedExceptionCode 1288092556
694 */
695 public function getPartialPathAndFilenameThrowsExceptionIfNoFileWasFound() {
696 $this->view->setPartialRootPaths(array(
697 '10' => 'some/Default/Directory',
698 '25' => 'evenMore/Specific/Partials',
699 '17' => 'specific/Partials',
700 ));
701 $this->view->expects($this->any())->method('testFileExistence')->will($this->returnValue(FALSE));
702 $this->view->_call('getPartialPathAndFilename', 'Partial');
703 }
704
705 /**
706 * @test
707 */
708 public function getPartialPathAndFilenameWalksNumericalIndicesInDescendingOrder() {
709 $this->view->setPartialRootPaths(array(
710 '10' => 'some/Default/Directory',
711 '25' => 'evenMore/Specific/Partials',
712 '17' => 'specific/Partials',
713 ));
714 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
715 $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Partials/Partial.html')->will($this->returnValue(FALSE));
716 $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Partials/Partial')->will($this->returnValue(FALSE));
717 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Partials/Partial.html')->will($this->returnValue(FALSE));
718 $this->view->expects($this->at(3))->method('testFileExistence')->with(PATH_site . 'specific/Partials/Partial')->will($this->returnValue(FALSE));
719 $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Partial.html')->will($this->returnValue(FALSE));
720 $this->view->expects($this->at(5))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Partial')->will($this->returnValue(TRUE));
721 $this->assertEquals(PATH_site . 'some/Default/Directory/Partial', $this->view->_call('getPartialPathAndFilename', 'Partial'));
722 }
723
724 /**
725 * @test
726 */
727 public function getLayoutPathAndFilenameWalksNumericalIndicesInDescendingOrder() {
728 $this->view->setLayoutRootPaths(array(
729 '10' => 'some/Default/Directory',
730 '25' => 'evenMore/Specific/Layouts',
731 '17' => 'specific/Layouts',
732 ));
733 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
734 $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Layouts/Default.html')->will($this->returnValue(FALSE));
735 $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Layouts/Default')->will($this->returnValue(FALSE));
736 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Layouts/Default.html')->will($this->returnValue(FALSE));
737 $this->view->expects($this->at(3))->method('testFileExistence')->with(PATH_site . 'specific/Layouts/Default')->will($this->returnValue(FALSE));
738 $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default.html')->will($this->returnValue(FALSE));
739 $this->view->expects($this->at(5))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default')->will($this->returnValue(TRUE));
740 $this->assertEquals(PATH_site . 'some/Default/Directory/Default', $this->view->_call('getLayoutPathAndFilename'));
741 }
742
743 /**
744 * @test
745 */
746 public function getPartialPathAndFilenameWalksStringKeysInReversedOrder() {
747 $this->view->setPartialRootPaths(array(
748 'default' => 'some/Default/Directory',
749 'specific' => 'specific/Partials',
750 'verySpecific' => 'evenMore/Specific/Partials',
751 ));
752 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
753 $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Partials/Partial.html')->will($this->returnValue(FALSE));
754 $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Partials/Partial')->will($this->returnValue(FALSE));
755 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Partials/Partial.html')->will($this->returnValue(FALSE));
756 $this->view->expects($this->at(3))->method('testFileExistence')->with(PATH_site . 'specific/Partials/Partial')->will($this->returnValue(FALSE));
757 $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Partial.html')->will($this->returnValue(FALSE));
758 $this->view->expects($this->at(5))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Partial')->will($this->returnValue(TRUE));
759 $this->assertEquals(PATH_site . 'some/Default/Directory/Partial', $this->view->_call('getPartialPathAndFilename', 'Partial'));
760 }
761
762 /**
763 * @test
764 */
765 public function getLayoutPathAndFilenameWalksStringKeysInReversedOrder() {
766 $this->view->setLayoutRootPaths(array(
767 'default' => 'some/Default/Directory',
768 'specific' => 'specific/Layout',
769 'verySpecific' => 'evenMore/Specific/Layout',
770 ));
771 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
772 $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Layout/Default.html')->will($this->returnValue(FALSE));
773 $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Layout/Default')->will($this->returnValue(FALSE));
774 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Layout/Default.html')->will($this->returnValue(FALSE));
775 $this->view->expects($this->at(3))->method('testFileExistence')->with(PATH_site . 'specific/Layout/Default')->will($this->returnValue(FALSE));
776 $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default.html')->will($this->returnValue(FALSE));
777 $this->view->expects($this->at(5))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default')->will($this->returnValue(TRUE));
778 $this->assertEquals(PATH_site . 'some/Default/Directory/Default', $this->view->_call('getLayoutPathAndFilename'));
779 }
780
781 }