5e566e5437640c336eb838576cbe9f079dd43e77
[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->view->expects($this->once())->method('testFileExistence')->with($templatePathAndFilename)->will($this->returnValue(TRUE));
252 $this->mockTemplateParser->expects($this->once())->method('parse')->with($expectedResult);
253 $this->view->render();
254 }
255
256 /**
257 * @test
258 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
259 */
260 public function renderThrowsExceptionIfSpecifiedTemplateFileDoesNotExist() {
261 $this->view->setTemplatePathAndFilename('NonExistingTemplatePath');
262 @$this->view->render();
263 }
264
265 /**
266 * @test
267 */
268 public function setFormatSetsRequestFormat() {
269 $this->mockRequest->expects($this->once())->method('setFormat')->with('xml');
270 $this->view->setFormat('xml');
271 }
272
273 /**
274 * @test
275 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
276 */
277 public function getLayoutRootPathThrowsExceptionIfLayoutRootPathAndTemplatePathAreNotSpecified() {
278 $this->view->getLayoutRootPath();
279 }
280
281 /**
282 * @test
283 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
284 */
285 public function getLayoutRootPathsThrowsExceptionIfLayoutRootPathAndTemplatePathAreNotSpecified() {
286 $this->view->getLayoutRootPaths();
287 }
288
289 /**
290 * @test
291 */
292 public function getLayoutRootPathReturnsSpecifiedLayoutRootPathByDefault() {
293 $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
294 $layoutRootPath = 'some/layout/RootPath';
295 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
296 $this->view->setLayoutRootPath($layoutRootPath);
297 $actualResult = $this->view->getLayoutRootPath();
298 $this->assertEquals($layoutRootPath, $actualResult);
299 }
300
301 /**
302 * @test
303 */
304 public function getLayoutRootPathsReturnsSpecifiedLayoutRootPathByDefault() {
305 $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
306 $layoutRootPaths = array(
307 'some/layout/RootPath'
308 );
309 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
310 $this->view->setLayoutRootPaths($layoutRootPaths);
311 $actualResult = $this->view->getLayoutRootPaths();
312 $this->assertEquals($layoutRootPaths, $actualResult);
313 }
314
315 /**
316 * @test
317 */
318 public function getLayoutRootPathReturnsDefaultPathIfNoLayoutRootPathIsSpecified() {
319 $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
320 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
321 $expectedResult = 'some/template/RootPath/Layouts';
322 $actualResult = $this->view->getLayoutRootPath();
323 $this->assertEquals($expectedResult, $actualResult);
324 }
325
326 /**
327 * @test
328 */
329 public function getLayoutRootPathsReturnsDefaultPathIfNoLayoutRootPathIsSpecified() {
330 $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
331 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
332 $expectedResult = array('some/template/RootPath/Layouts');
333 $actualResult = $this->view->getLayoutRootPaths();
334 $this->assertEquals($expectedResult, $actualResult);
335 }
336
337 /**
338 * @test
339 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
340 */
341 public function getLayoutSourceThrowsExceptionIfLayoutRootPathDoesNotExist() {
342 $this->view->setLayoutRootPath('some/non/existing/Path');
343 $this->view->_call('getLayoutSource');
344 }
345
346 /**
347 * @test
348 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
349 */
350 public function getLayoutSourceThrowsExceptionIfLayoutRootPathsDoesNotExist() {
351 $this->view->setLayoutRootPaths(array('some/non/existing/Path'));
352 $this->view->_call('getLayoutSource');
353 }
354
355 /**
356 * @test
357 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
358 */
359 public function getLayoutSourceThrowsExceptionIfLayoutFileDoesNotExist() {
360 $layoutRootPath = __DIR__ . '/Fixtures';
361 $this->view->setLayoutRootPaths(array($layoutRootPath));
362 $this->view->_call('getLayoutSource', 'NonExistingLayout');
363 }
364
365 /**
366 * @test
367 */
368 public function getLayoutSourceReturnsContentOfLayoutFileForTheDefaultFormat() {
369 $layoutRootPath = __DIR__ . '/Fixtures';
370 $this->view->setLayoutRootPath($layoutRootPath);
371 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('html'));
372 $this->view->expects($this->once())->method('testFileExistence')->with($layoutRootPath . '/LayoutFixture.html')->will($this->returnValue(TRUE));
373 $expectedResult = file_get_contents($layoutRootPath . '/LayoutFixture.html');
374 $actualResult = $this->view->_call('getLayoutSource', 'LayoutFixture');
375 $this->assertEquals($expectedResult, $actualResult);
376 }
377
378 /**
379 * @test
380 */
381 public function getLayoutSourceReturnsContentOfLayoutFileForTheSpecifiedFormat() {
382 $layoutRootPath = __DIR__ . '/Fixtures';
383 $this->view->setLayoutRootPath($layoutRootPath);
384 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('xml'));
385 $this->view->expects($this->once())->method('testFileExistence')->with($layoutRootPath . '/LayoutFixture.xml')->will($this->returnValue(TRUE));
386 $expectedResult = file_get_contents($layoutRootPath . '/LayoutFixture.xml');
387 $actualResult = $this->view->_call('getLayoutSource', 'LayoutFixture');
388 $this->assertEquals($expectedResult, $actualResult);
389 }
390
391 /**
392 * @test
393 */
394 public function getLayoutSourceReturnsContentOfDefaultLayoutFileIfNoLayoutExistsForTheSpecifiedFormat() {
395 $layoutRootPath = __DIR__ . '/Fixtures';
396 $this->view->setLayoutRootPath($layoutRootPath);
397 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('foo'));
398 $this->view->expects($this->at(0))->method('testFileExistence')->with($layoutRootPath . '/LayoutFixture.foo')->will($this->returnValue(FALSE));
399 $this->view->expects($this->at(1))->method('testFileExistence')->with($layoutRootPath . '/LayoutFixture')->will($this->returnValue(TRUE));
400 $expectedResult = file_get_contents($layoutRootPath . '/LayoutFixture');
401 $actualResult = $this->view->_call('getLayoutSource', 'LayoutFixture');
402 $this->assertEquals($expectedResult, $actualResult);
403 }
404
405 /**
406 * @test
407 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
408 */
409 public function getPartialRootPathThrowsExceptionIfPartialRootPathAndTemplatePathAreNotSpecified() {
410 $this->view->getPartialRootPath();
411 }
412
413 /**
414 * @test
415 */
416 public function getPartialRootPathReturnsSpecifiedPartialRootPathByDefault() {
417 $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
418 $partialRootPath = 'some/partial/RootPath';
419 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
420 $this->view->setPartialRootPath($partialRootPath);
421 $actualResult = $this->view->getPartialRootPath();
422 $this->assertEquals($partialRootPath, $actualResult);
423 }
424
425 /**
426 * @test
427 */
428 public function getPartialRootPathReturnsDefaultPathIfNoPartialRootPathIsSpecified() {
429 $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
430 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
431 $expectedResult = 'some/template/RootPath/Partials';
432 $actualResult = $this->view->getPartialRootPath();
433 $this->assertEquals($expectedResult, $actualResult);
434 }
435
436 /**
437 * @test
438 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
439 */
440 public function getPartialSourceThrowsExceptionIfPartialRootPathDoesNotExist() {
441 $this->view->setPartialRootPath('some/non/existing/Path');
442 $this->view->_call('getPartialSource', 'SomePartial');
443 }
444
445 /**
446 * @test
447 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
448 */
449 public function getPartialSourceThrowsExceptionIfPartialFileDoesNotExist() {
450 $partialRootPath = __DIR__ . '/Fixtures';
451 $this->view->setPartialRootPath($partialRootPath);
452 $this->view->_call('getPartialSource', 'NonExistingPartial');
453 }
454
455 /**
456 * @test
457 */
458 public function getPartialSourceReturnsContentOfPartialFileForTheDefaultFormat() {
459 $partialRootPath = __DIR__ . '/Fixtures';
460 $this->view->setPartialRootPath($partialRootPath);
461 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('html'));
462 $this->view->expects($this->once())->method('testFileExistence')->will($this->returnValue(TRUE));
463 $expectedResult = file_get_contents($partialRootPath . '/LayoutFixture.html');
464 $actualResult = $this->view->_call('getPartialSource', 'LayoutFixture');
465 $this->assertEquals($expectedResult, $actualResult);
466 }
467
468 /**
469 * @test
470 */
471 public function getPartialSourceReturnsContentOfPartialFileForTheSpecifiedFormat() {
472 $partialRootPath = __DIR__ . '/Fixtures';
473 $this->view->setPartialRootPath($partialRootPath);
474 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('xml'));
475 $this->view->expects($this->once())->method('testFileExistence')->will($this->returnValue(TRUE));
476 $expectedResult = file_get_contents($partialRootPath . '/LayoutFixture.xml');
477 $actualResult = $this->view->_call('getPartialSource', 'LayoutFixture');
478 $this->assertEquals($expectedResult, $actualResult);
479 }
480
481 /**
482 * @test
483 */
484 public function getPartialSourceReturnsContentOfDefaultPartialFileIfNoPartialExistsForTheSpecifiedFormat() {
485 $partialRootPath = __DIR__ . '/Fixtures';
486 $this->view->setPartialRootPath($partialRootPath);
487 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('foo'));
488 $this->view->expects($this->at(1))->method('testFileExistence')->will($this->returnValue(TRUE));
489 $expectedResult = file_get_contents($partialRootPath . '/LayoutFixture');
490 $actualResult = $this->view->_call('getPartialSource', 'LayoutFixture');
491 $this->assertEquals($expectedResult, $actualResult);
492 }
493
494 /**
495 * @test
496 */
497 public function setPartialRootPathsOverridesValueSetBySetPartialRootPath() {
498 $this->view->setPartialRootPath('/foo/bar');
499 $this->view->setPartialRootPaths(array('/overruled/path'));
500 $expected = array('/overruled/path');
501 $actual = $this->view->_call('getPartialRootPaths');
502 $this->assertEquals($expected, $actual, 'A set partial root path was not returned correctly.');
503 }
504
505 /**
506 * @test
507 */
508 public function setLayoutRootPathsOverridesValuesSetBySetLayoutRootPath() {
509 $this->view->setLayoutRootPath('/foo/bar');
510 $this->view->setLayoutRootPaths(array('/overruled/path'));
511 $expected = array('/overruled/path');
512 $actual = $this->view->_call('getLayoutRootPaths');
513 $this->assertEquals($expected, $actual, 'A set layout root path was not returned correctly.');
514 }
515
516 /**
517 * @test
518 */
519 public function getLayoutPathAndFilenameRespectsCasingOfLayoutName() {
520 $this->view->setLayoutRootPaths(array('some/Default/Directory'));
521 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
522 $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/LayoutName.html')->willReturn(FALSE);
523 $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/LayoutName')->willReturn(FALSE);
524 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/layoutName.html')->willReturn(TRUE);
525 $this->assertSame(PATH_site . 'some/Default/Directory/layoutName.html', $this->view->_call('getLayoutPathAndFilename', 'layoutName'));
526 }
527
528 /**
529 * @test
530 */
531 public function getLayoutPathAndFilenameFindsUpperCasedLayoutName() {
532 $this->view->setLayoutRootPaths(array('some/Default/Directory'));
533 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
534 $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/LayoutName.html')->willReturn(TRUE);
535 $this->assertSame(PATH_site . 'some/Default/Directory/LayoutName.html', $this->view->_call('getLayoutPathAndFilename', 'layoutName'));
536 }
537
538 /**
539 * @test
540 */
541 public function getLayoutPathAndFilenameResolvesTheSpecificFile() {
542 $this->view->setLayoutRootPaths(array(
543 'default' => 'some/Default/Directory',
544 'specific' => 'specific/Layouts',
545 ));
546 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
547 $this->view->expects($this->once())->method('testFileExistence')->with(PATH_site . 'specific/Layouts/Default.html')->will($this->returnValue(TRUE));
548 $this->assertEquals(PATH_site . 'specific/Layouts/Default.html', $this->view->_call('getLayoutPathAndFilename'));
549 }
550
551 /**
552 * @test
553 */
554 public function getLayoutPathAndFilenameResolvesTheDefaultFile() {
555 $this->view->setLayoutRootPaths(array(
556 'default' => 'some/Default/Directory',
557 'specific' => 'specific/Layouts',
558 ));
559 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
560 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default.html')->will($this->returnValue(TRUE));
561 $this->assertEquals(PATH_site . 'some/Default/Directory/Default.html', $this->view->_call('getLayoutPathAndFilename'));
562 }
563
564 /**
565 * @test
566 */
567 public function getLayoutPathAndFilenameResolvesTheSpecificFileWithNumericIndices() {
568 $this->view->setLayoutRootPaths(array(
569 '10' => 'some/Default/Directory',
570 '25' => 'evenMore/Specific/Layouts',
571 '17' => 'specific/Layouts',
572 ));
573 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
574 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Layouts/Default.html')->will($this->returnValue(TRUE));
575 $this->assertEquals(PATH_site . 'specific/Layouts/Default.html', $this->view->_call('getLayoutPathAndFilename'));
576 }
577
578 /**
579 * @test
580 */
581 public function getLayoutPathAndFilenameResolvesTheDefaultFileWithNumericIndices() {
582 $this->view->setLayoutRootPaths(array(
583 '10' => 'some/Default/Directory',
584 '25' => 'evenMore/Specific/Layouts',
585 '17' => 'specific/Layouts',
586 ));
587 $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
588 $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default.html')->will($this->returnValue(TRUE));
589 $this->assertEquals(PATH_site . 'some/Default/Directory/Default.html', $this->view->_call('getLayoutPathAndFilename'));
590 }
591
592 /**
593 * @test
594 * @expectedException \TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException
595 * @expectedExceptionCode 1288092555
596 */
597 public function getLayoutPathAndFilenameThrowsExceptionIfNoFileWasFound() {
598 $this->view->setLayoutRootPaths(array(
599 '10' => 'some/Default/Directory',
600 '25' => 'evenMore/Specific/Layouts',
601 '17' => 'specific/Layouts',
602 ));
603 $this->view->expects($this->any())->method('testFileExistence')->will($this->returnValue(FALSE));
604 $this->view->_call('getLayoutPathAndFilename');
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(PATH_site . 'some/Default/Directory/PartialName.html')->willReturn(FALSE);
614 $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/PartialName')->willReturn(FALSE);
615 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/partialName.html')->willReturn(TRUE);
616 $this->assertSame(PATH_site . '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(PATH_site . 'some/Default/Directory/PartialName.html')->willReturn(TRUE);
626 $this->assertSame(PATH_site . '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(PATH_site . 'specific/Partials/Partial.html')->will($this->returnValue(TRUE));
639 $this->assertEquals(PATH_site . '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(PATH_site . 'some/Default/Directory/Partial.html')->will($this->returnValue(TRUE));
652 $this->assertEquals(PATH_site . '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(PATH_site . 'specific/Partials/Partial.html')->will($this->returnValue(TRUE));
666 $this->assertEquals(PATH_site . '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(PATH_site . 'some/Default/Directory/Partial.html')->will($this->returnValue(TRUE));
680 $this->assertEquals(PATH_site . '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(PATH_site . 'evenMore/Specific/Partials/Partial.html')->will($this->returnValue(FALSE));
709 $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Partials/Partial')->will($this->returnValue(FALSE));
710 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Partials/Partial.html')->will($this->returnValue(FALSE));
711 $this->view->expects($this->at(3))->method('testFileExistence')->with(PATH_site . 'specific/Partials/Partial')->will($this->returnValue(FALSE));
712 $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Partial.html')->will($this->returnValue(FALSE));
713 $this->view->expects($this->at(5))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Partial')->will($this->returnValue(TRUE));
714 $this->assertEquals(PATH_site . '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(PATH_site . 'evenMore/Specific/Layouts/Default.html')->will($this->returnValue(FALSE));
728 $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Layouts/Default')->will($this->returnValue(FALSE));
729 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Layouts/Default.html')->will($this->returnValue(FALSE));
730 $this->view->expects($this->at(3))->method('testFileExistence')->with(PATH_site . 'specific/Layouts/Default')->will($this->returnValue(FALSE));
731 $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default.html')->will($this->returnValue(FALSE));
732 $this->view->expects($this->at(5))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default')->will($this->returnValue(TRUE));
733 $this->assertEquals(PATH_site . '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(PATH_site . 'evenMore/Specific/Partials/Partial.html')->will($this->returnValue(FALSE));
747 $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Partials/Partial')->will($this->returnValue(FALSE));
748 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Partials/Partial.html')->will($this->returnValue(FALSE));
749 $this->view->expects($this->at(3))->method('testFileExistence')->with(PATH_site . 'specific/Partials/Partial')->will($this->returnValue(FALSE));
750 $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Partial.html')->will($this->returnValue(FALSE));
751 $this->view->expects($this->at(5))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Partial')->will($this->returnValue(TRUE));
752 $this->assertEquals(PATH_site . '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(PATH_site . 'evenMore/Specific/Layout/Default.html')->will($this->returnValue(FALSE));
766 $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Layout/Default')->will($this->returnValue(FALSE));
767 $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Layout/Default.html')->will($this->returnValue(FALSE));
768 $this->view->expects($this->at(3))->method('testFileExistence')->with(PATH_site . 'specific/Layout/Default')->will($this->returnValue(FALSE));
769 $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default.html')->will($this->returnValue(FALSE));
770 $this->view->expects($this->at(5))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default')->will($this->returnValue(TRUE));
771 $this->assertEquals(PATH_site . 'some/Default/Directory/Default', $this->view->_call('getLayoutPathAndFilename'));
772 }
773
774 }