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