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