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