2b54e6f4bb7323037387738b8d2130fe9e3a5642
[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 getLayoutPathAndFilenameResolvesTheSpecificFile() {
519 $this->view->setLayoutRootPaths(array(
520 'default' => 'some/Default/Directory',
521 'specific' => 'specific/Layouts',
522 ));
523 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
524 $this->view->expects($this->once())->method('testFileExistence')->with('specific/Layouts/Default.html')->will($this->returnValue(TRUE));
525 $this->assertEquals('specific/Layouts/Default.html', $this->view->_call('getLayoutPathAndFilename'));
526 }
527
528 /**
529 * @test
530 */
531 public function getLayoutPathAndFilenameResolvesTheDefaultFile() {
532 $this->view->setLayoutRootPaths(array(
533 'default' => 'some/Default/Directory',
534 'specific' => 'specific/Layouts',
535 ));
536 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
537 $this->view->expects($this->at(2))->method('testFileExistence')->with('some/Default/Directory/Default.html')->will($this->returnValue(TRUE));
538 $this->assertEquals('some/Default/Directory/Default.html', $this->view->_call('getLayoutPathAndFilename'));
539 }
540
541 /**
542 * @test
543 */
544 public function getLayoutPathAndFilenameResolvesTheSpecificFileWithNumericIndices() {
545 $this->view->setLayoutRootPaths(array(
546 '10' => 'some/Default/Directory',
547 '25' => 'evenMore/Specific/Layouts',
548 '17' => 'specific/Layouts',
549 ));
550 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
551 $this->view->expects($this->at(2))->method('testFileExistence')->with('specific/Layouts/Default.html')->will($this->returnValue(TRUE));
552 $this->assertEquals('specific/Layouts/Default.html', $this->view->_call('getLayoutPathAndFilename'));
553 }
554
555 /**
556 * @test
557 */
558 public function getLayoutPathAndFilenameResolvesTheDefaultFileWithNumericIndices() {
559 $this->view->setLayoutRootPaths(array(
560 '10' => 'some/Default/Directory',
561 '25' => 'evenMore/Specific/Layouts',
562 '17' => 'specific/Layouts',
563 ));
564 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
565 $this->view->expects($this->at(4))->method('testFileExistence')->with('some/Default/Directory/Default.html')->will($this->returnValue(TRUE));
566 $this->assertEquals('some/Default/Directory/Default.html', $this->view->_call('getLayoutPathAndFilename'));
567 }
568
569 /**
570 * @test
571 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
572 * @expectedExceptionCode 1288092555
573 */
574 public function getLayoutPathAndFilenameThrowsExceptionIfNoFileWasFound() {
575 $this->view->setLayoutRootPaths(array(
576 '10' => 'some/Default/Directory',
577 '25' => 'evenMore/Specific/Layouts',
578 '17' => 'specific/Layouts',
579 ));
580 $this->view->expects($this->any())->method('testFileExistence')->will($this->returnValue(FALSE));
581 $this->view->_call('getLayoutPathAndFilename');
582
583 }
584
585 /**
586 * @test
587 */
588 public function getPartialPathAndFilenameResolvesTheSpecificFile() {
589 $this->view->setPartialRootPaths(array(
590 'default' => 'some/Default/Directory',
591 'specific' => 'specific/Partials',
592 ));
593 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
594 $this->view->expects($this->once())->method('testFileExistence')->with('specific/Partials/Partial.html')->will($this->returnValue(TRUE));
595 $this->assertEquals('specific/Partials/Partial.html', $this->view->_call('getPartialPathAndFilename', 'Partial'));
596 }
597
598 /**
599 * @test
600 */
601 public function getPartialPathAndFilenameResolvesTheDefaultFile() {
602 $this->view->setPartialRootPaths(array(
603 'default' => 'some/Default/Directory',
604 'specific' => 'specific/Partials',
605 ));
606 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
607 $this->view->expects($this->at(2))->method('testFileExistence')->with('some/Default/Directory/Partial.html')->will($this->returnValue(TRUE));
608 $this->assertEquals('some/Default/Directory/Partial.html', $this->view->_call('getPartialPathAndFilename', 'Partial'));
609 }
610
611 /**
612 * @test
613 */
614 public function getPartialPathAndFilenameResolvesTheSpecificFileWithNumericIndices() {
615 $this->view->setPartialRootPaths(array(
616 '10' => 'some/Default/Directory',
617 '25' => 'evenMore/Specific/Partials',
618 '17' => 'specific/Partials',
619 ));
620 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
621 $this->view->expects($this->at(2))->method('testFileExistence')->with('specific/Partials/Partial.html')->will($this->returnValue(TRUE));
622 $this->assertEquals('specific/Partials/Partial.html', $this->view->_call('getPartialPathAndFilename', 'Partial'));
623 }
624
625 /**
626 * @test
627 */
628 public function getPartialPathAndFilenameResolvesTheDefaultFileWithNumericIndices() {
629 $this->view->setPartialRootPaths(array(
630 '10' => 'some/Default/Directory',
631 '25' => 'evenMore/Specific/Partials',
632 '17' => 'specific/Partials',
633 ));
634 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
635 $this->view->expects($this->at(4))->method('testFileExistence')->with('some/Default/Directory/Partial.html')->will($this->returnValue(TRUE));
636 $this->assertEquals('some/Default/Directory/Partial.html', $this->view->_call('getPartialPathAndFilename', 'Partial'));
637 }
638
639 /**
640 * @test
641 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
642 * @expectedExceptionCode 1288092556
643 */
644 public function getPartialPathAndFilenameThrowsExceptionIfNoFileWasFound() {
645 $this->view->setPartialRootPaths(array(
646 '10' => 'some/Default/Directory',
647 '25' => 'evenMore/Specific/Partials',
648 '17' => 'specific/Partials',
649 ));
650 $this->view->expects($this->any())->method('testFileExistence')->will($this->returnValue(FALSE));
651 $this->view->_call('getPartialPathAndFilename', 'Partial');
652 }
653
654 /**
655 * @test
656 */
657 public function getPartialPathAndFilenameWalksNumericalIndicesInDescendingOrder() {
658 $this->view->setPartialRootPaths(array(
659 '10' => 'some/Default/Directory',
660 '25' => 'evenMore/Specific/Partials',
661 '17' => 'specific/Partials',
662 ));
663 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
664 $this->view->expects($this->at(0))->method('testFileExistence')->with('evenMore/Specific/Partials/Partial.html')->will($this->returnValue(FALSE));
665 $this->view->expects($this->at(1))->method('testFileExistence')->with('evenMore/Specific/Partials/Partial')->will($this->returnValue(FALSE));
666 $this->view->expects($this->at(2))->method('testFileExistence')->with('specific/Partials/Partial.html')->will($this->returnValue(FALSE));
667 $this->view->expects($this->at(3))->method('testFileExistence')->with('specific/Partials/Partial')->will($this->returnValue(FALSE));
668 $this->view->expects($this->at(4))->method('testFileExistence')->with('some/Default/Directory/Partial.html')->will($this->returnValue(FALSE));
669 $this->view->expects($this->at(5))->method('testFileExistence')->with('some/Default/Directory/Partial')->will($this->returnValue(TRUE));
670 $this->assertEquals('some/Default/Directory/Partial', $this->view->_call('getPartialPathAndFilename', 'Partial'));
671 }
672
673 /**
674 * @test
675 */
676 public function getLayoutPathAndFilenameWalksNumericalIndicesInDescendingOrder() {
677 $this->view->setLayoutRootPaths(array(
678 '10' => 'some/Default/Directory',
679 '25' => 'evenMore/Specific/Layouts',
680 '17' => 'specific/Layouts',
681 ));
682 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
683 $this->view->expects($this->at(0))->method('testFileExistence')->with('evenMore/Specific/Layouts/Default.html')->will($this->returnValue(FALSE));
684 $this->view->expects($this->at(1))->method('testFileExistence')->with('evenMore/Specific/Layouts/Default')->will($this->returnValue(FALSE));
685 $this->view->expects($this->at(2))->method('testFileExistence')->with('specific/Layouts/Default.html')->will($this->returnValue(FALSE));
686 $this->view->expects($this->at(3))->method('testFileExistence')->with('specific/Layouts/Default')->will($this->returnValue(FALSE));
687 $this->view->expects($this->at(4))->method('testFileExistence')->with('some/Default/Directory/Default.html')->will($this->returnValue(FALSE));
688 $this->view->expects($this->at(5))->method('testFileExistence')->with('some/Default/Directory/Default')->will($this->returnValue(TRUE));
689 $this->assertEquals('some/Default/Directory/Default', $this->view->_call('getLayoutPathAndFilename'));
690 }
691
692 /**
693 * @test
694 */
695 public function getPartialPathAndFilenameWalksStringKeysInReversedOrder() {
696 $this->view->setPartialRootPaths(array(
697 'default' => 'some/Default/Directory',
698 'specific' => 'specific/Partials',
699 'verySpecific' => 'evenMore/Specific/Partials',
700 ));
701 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
702 $this->view->expects($this->at(0))->method('testFileExistence')->with('evenMore/Specific/Partials/Partial.html')->will($this->returnValue(FALSE));
703 $this->view->expects($this->at(1))->method('testFileExistence')->with('evenMore/Specific/Partials/Partial')->will($this->returnValue(FALSE));
704 $this->view->expects($this->at(2))->method('testFileExistence')->with('specific/Partials/Partial.html')->will($this->returnValue(FALSE));
705 $this->view->expects($this->at(3))->method('testFileExistence')->with('specific/Partials/Partial')->will($this->returnValue(FALSE));
706 $this->view->expects($this->at(4))->method('testFileExistence')->with('some/Default/Directory/Partial.html')->will($this->returnValue(FALSE));
707 $this->view->expects($this->at(5))->method('testFileExistence')->with('some/Default/Directory/Partial')->will($this->returnValue(TRUE));
708 $this->assertEquals('some/Default/Directory/Partial', $this->view->_call('getPartialPathAndFilename', 'Partial'));
709 }
710
711 /**
712 * @test
713 */
714 public function getLayoutPathAndFilenameWalksStringKeysInReversedOrder() {
715 $this->view->setLayoutRootPaths(array(
716 'default' => 'some/Default/Directory',
717 'specific' => 'specific/Layout',
718 'verySpecific' => 'evenMore/Specific/Layout',
719 ));
720 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
721 $this->view->expects($this->at(0))->method('testFileExistence')->with('evenMore/Specific/Layout/Default.html')->will($this->returnValue(FALSE));
722 $this->view->expects($this->at(1))->method('testFileExistence')->with('evenMore/Specific/Layout/Default')->will($this->returnValue(FALSE));
723 $this->view->expects($this->at(2))->method('testFileExistence')->with('specific/Layout/Default.html')->will($this->returnValue(FALSE));
724 $this->view->expects($this->at(3))->method('testFileExistence')->with('specific/Layout/Default')->will($this->returnValue(FALSE));
725 $this->view->expects($this->at(4))->method('testFileExistence')->with('some/Default/Directory/Default.html')->will($this->returnValue(FALSE));
726 $this->view->expects($this->at(5))->method('testFileExistence')->with('some/Default/Directory/Default')->will($this->returnValue(TRUE));
727 $this->assertEquals('some/Default/Directory/Default', $this->view->_call('getLayoutPathAndFilename'));
728 }
729
730 }