TYPO3 CMS  TYPO3_7-6
StandaloneViewTest.php
Go to the documentation of this file.
1 <?php
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 
34 
39 {
43  protected $singletonInstances = [];
44 
48  protected $view;
49 
54 
59 
64 
69 
73  protected $mockObjectManager;
74 
78  protected $mockRequest;
79 
83  protected $mockUriBuilder;
84 
89 
94 
98  protected $mockContentObject;
99 
104 
110  protected function setUp()
111  {
112  $this->singletonInstances = GeneralUtility::getSingletonInstances();
113  $this->view = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\StandaloneView::class, ['testFileExistence', 'buildParserConfiguration'], [], '', false);
114  $this->mockTemplateParser = $this->getMock(TemplateParser::class);
115  $this->mockParsedTemplate = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\ParsedTemplateInterface::class);
116  $this->mockTemplateParser->expects($this->any())->method('parse')->will($this->returnValue($this->mockParsedTemplate));
117  $this->mockConfigurationManager = $this->getMock(ConfigurationManagerInterface::class);
118  $this->mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
119  $this->mockObjectManager->expects($this->any())->method('get')->will($this->returnCallback([$this, 'objectManagerCallback']));
120  $this->mockRequest = $this->getMock(Request::class);
121  $this->mockUriBuilder = $this->getMock(UriBuilder::class);
122  $this->mockContentObject = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
123  $this->mockControllerContext = $this->getMock(ControllerContext::class);
124  $this->mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->mockRequest));
125  $this->mockViewHelperVariableContainer = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer::class);
126  $this->mockRenderingContext = $this->getMock(RenderingContext::class);
127  $this->mockRenderingContext->expects($this->any())->method('getControllerContext')->will($this->returnValue($this->mockControllerContext));
128  $this->mockRenderingContext->expects($this->any())->method('getViewHelperVariableContainer')->will($this->returnValue($this->mockViewHelperVariableContainer));
129  $this->view->_set('templateParser', $this->mockTemplateParser);
130  $this->view->_set('objectManager', $this->mockObjectManager);
131  $this->view->setRenderingContext($this->mockRenderingContext);
132  $this->mockTemplateCompiler = $this->getMock(TemplateCompiler::class);
133  $this->view->_set('templateCompiler', $this->mockTemplateCompiler);
134  GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class, $this->mockObjectManager);
135  GeneralUtility::addInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, $this->mockContentObject);
136 
137  $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager::class, [], [], '', false);
138  $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class, [], [], '', false);
139  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
140  GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $mockCacheManager);
141  }
142 
146  protected function tearDown()
147  {
149  GeneralUtility::resetSingletonInstances($this->singletonInstances);
150  parent::tearDown();
151  }
152 
157  public function objectManagerCallback($className)
158  {
159  switch ($className) {
160  case ConfigurationManagerInterface::class:
162  case TemplateParser::class:
164  case RenderingContext::class:
166  case Request::class:
167  return $this->mockRequest;
168  case UriBuilder::class:
169  return $this->mockUriBuilder;
170  case ControllerContext::class:
172  case TemplateCompiler::class:
174  }
175  throw new \InvalidArgumentException('objectManagerCallback cannot handle class "' . $className . '". Looks like incomplete mocking in the tests.', 1417105493);
176  }
177 
182  {
183  $mockContentObject = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
184  $this->mockConfigurationManager->expects($this->once())->method('setContentObject')->with($this->identicalTo($mockContentObject));
186  }
187 
192  {
193  $this->mockConfigurationManager->expects($this->once())->method('setContentObject')->with($this->identicalTo($this->mockContentObject));
194  new StandaloneView();
195  }
196 
200  public function constructorSetsRequestUri()
201  {
202  $expectedRequestUri = GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
203  $this->mockRequest->expects($this->once())->method('setRequestURI')->with($expectedRequestUri);
204  new StandaloneView();
205  }
206 
210  public function constructorSetsBaseUri()
211  {
212  $expectedBaseUri = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
213  $this->mockRequest->expects($this->once())->method('setBaseURI')->with($expectedBaseUri);
214  new StandaloneView();
215  }
216 
221  {
222  $this->mockUriBuilder->expects($this->once())->method('setRequest')->with($this->mockRequest);
223  new StandaloneView();
224  }
225 
230  {
231  $this->mockControllerContext->expects($this->once())->method('setRequest')->with($this->mockRequest);
232  new StandaloneView();
233  }
234 
239  {
240  $this->mockControllerContext->expects($this->once())->method('setUriBuilder')->with($this->mockUriBuilder);
241  new StandaloneView();
242  }
243 
249  {
250  $this->view->render();
251  }
252 
257  {
258  $this->view->setTemplateSource('The Template Source');
259  $this->mockTemplateParser->expects($this->once())->method('parse')->with('The Template Source');
260  $this->view->render();
261  }
262 
267  {
268  $templatePathAndFilename = GeneralUtility::fixWindowsFilePath(__DIR__) . '/Fixtures/StandaloneViewFixture.html';
269  $expectedResult = file_get_contents($templatePathAndFilename);
270  $this->view->setTemplatePathAndFilename($templatePathAndFilename);
271  $this->view->expects($this->once())->method('testFileExistence')->with($templatePathAndFilename)->will($this->returnValue(true));
272  $this->mockTemplateParser->expects($this->once())->method('parse')->with($expectedResult);
273  $this->view->render();
274  }
275 
281  {
282  $this->view->setTemplatePathAndFilename('NonExistingTemplatePath');
283  @$this->view->render();
284  }
285 
289  public function setFormatSetsRequestFormat()
290  {
291  $this->mockRequest->expects($this->once())->method('setFormat')->with('xml');
292  $this->view->setFormat('xml');
293  }
294 
300  {
301  $this->view->getLayoutRootPath();
302  }
303 
309  {
310  $this->view->getLayoutRootPaths();
311  }
312 
317  {
318  $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
319  $layoutRootPath = 'some/layout/RootPath';
320  $this->view->setTemplatePathAndFilename($templatePathAndFilename);
321  $this->view->setLayoutRootPath($layoutRootPath);
322  $actualResult = $this->view->getLayoutRootPath();
323  $this->assertEquals($layoutRootPath, $actualResult);
324  }
325 
330  {
331  $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
332  $layoutRootPaths = [
333  'some/layout/RootPath'
334  ];
335  $this->view->setTemplatePathAndFilename($templatePathAndFilename);
336  $this->view->setLayoutRootPaths($layoutRootPaths);
337  $actualResult = $this->view->getLayoutRootPaths();
338  $this->assertEquals($layoutRootPaths, $actualResult);
339  }
340 
345  {
346  $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
347  $this->view->setTemplatePathAndFilename($templatePathAndFilename);
348  $expectedResult = 'some/template/RootPath/Layouts';
349  $actualResult = $this->view->getLayoutRootPath();
350  $this->assertEquals($expectedResult, $actualResult);
351  }
352 
357  {
358  $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
359  $this->view->setTemplatePathAndFilename($templatePathAndFilename);
360  $expectedResult = ['some/template/RootPath/Layouts'];
361  $actualResult = $this->view->getLayoutRootPaths();
362  $this->assertEquals($expectedResult, $actualResult);
363  }
364 
370  {
371  $this->view->setLayoutRootPath('some/non/existing/Path');
372  $this->view->_call('getLayoutSource');
373  }
374 
380  {
381  $this->view->setLayoutRootPaths(['some/non/existing/Path']);
382  $this->view->_call('getLayoutSource');
383  }
384 
390  {
391  $layoutRootPath = __DIR__ . '/Fixtures';
392  $this->view->setLayoutRootPaths([$layoutRootPath]);
393  $this->view->_call('getLayoutSource', 'NonExistingLayout');
394  }
395 
400  {
401  $layoutRootPath = GeneralUtility::fixWindowsFilePath(__DIR__) . '/Fixtures';
402  $this->view->setLayoutRootPath($layoutRootPath);
403  $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('html'));
404  $this->view->expects($this->once())->method('testFileExistence')->with($layoutRootPath . '/LayoutFixture.html')->will($this->returnValue(true));
405  $expectedResult = file_get_contents($layoutRootPath . '/LayoutFixture.html');
406  $actualResult = $this->view->_call('getLayoutSource', 'LayoutFixture');
407  $this->assertEquals($expectedResult, $actualResult);
408  }
409 
414  {
415  $layoutRootPath = GeneralUtility::fixWindowsFilePath(__DIR__) . '/Fixtures';
416  $this->view->setLayoutRootPath($layoutRootPath);
417  $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('xml'));
418  $this->view->expects($this->once())->method('testFileExistence')->with($layoutRootPath . '/LayoutFixture.xml')->will($this->returnValue(true));
419  $expectedResult = file_get_contents($layoutRootPath . '/LayoutFixture.xml');
420  $actualResult = $this->view->_call('getLayoutSource', 'LayoutFixture');
421  $this->assertEquals($expectedResult, $actualResult);
422  }
423 
428  {
429  $layoutRootPath = GeneralUtility::fixWindowsFilePath(__DIR__) . '/Fixtures';
430  $this->view->setLayoutRootPath($layoutRootPath);
431  $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('foo'));
432  $this->view->expects($this->at(0))->method('testFileExistence')->with($layoutRootPath . '/LayoutFixture.foo')->will($this->returnValue(false));
433  $this->view->expects($this->at(1))->method('testFileExistence')->with($layoutRootPath . '/LayoutFixture')->will($this->returnValue(true));
434  $expectedResult = file_get_contents($layoutRootPath . '/LayoutFixture');
435  $actualResult = $this->view->_call('getLayoutSource', 'LayoutFixture');
436  $this->assertEquals($expectedResult, $actualResult);
437  }
438 
444  {
445  $this->view->getPartialRootPath();
446  }
447 
452  {
453  $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
454  $partialRootPath = 'some/partial/RootPath';
455  $this->view->setTemplatePathAndFilename($templatePathAndFilename);
456  $this->view->setPartialRootPath($partialRootPath);
457  $actualResult = $this->view->getPartialRootPath();
458  $this->assertEquals($partialRootPath, $actualResult);
459  }
460 
465  {
466  $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html';
467  $this->view->setTemplatePathAndFilename($templatePathAndFilename);
468  $expectedResult = 'some/template/RootPath/Partials';
469  $actualResult = $this->view->getPartialRootPath();
470  $this->assertEquals($expectedResult, $actualResult);
471  }
472 
478  {
479  $this->view->setPartialRootPath('some/non/existing/Path');
480  $this->view->_call('getPartialSource', 'SomePartial');
481  }
482 
488  {
489  $partialRootPath = __DIR__ . '/Fixtures';
490  $this->view->setPartialRootPath($partialRootPath);
491  $this->view->_call('getPartialSource', 'NonExistingPartial');
492  }
493 
498  {
499  $partialRootPath = __DIR__ . '/Fixtures';
500  $this->view->setPartialRootPath($partialRootPath);
501  $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('html'));
502  $this->view->expects($this->once())->method('testFileExistence')->will($this->returnValue(true));
503  $expectedResult = file_get_contents($partialRootPath . '/LayoutFixture.html');
504  $actualResult = $this->view->_call('getPartialSource', 'LayoutFixture');
505  $this->assertEquals($expectedResult, $actualResult);
506  }
507 
512  {
513  $partialRootPath = __DIR__ . '/Fixtures';
514  $this->view->setPartialRootPath($partialRootPath);
515  $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('xml'));
516  $this->view->expects($this->once())->method('testFileExistence')->will($this->returnValue(true));
517  $expectedResult = file_get_contents($partialRootPath . '/LayoutFixture.xml');
518  $actualResult = $this->view->_call('getPartialSource', 'LayoutFixture');
519  $this->assertEquals($expectedResult, $actualResult);
520  }
521 
526  {
527  $partialRootPath = __DIR__ . '/Fixtures';
528  $this->view->setPartialRootPath($partialRootPath);
529  $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('foo'));
530  $this->view->expects($this->at(1))->method('testFileExistence')->will($this->returnValue(true));
531  $expectedResult = file_get_contents($partialRootPath . '/LayoutFixture');
532  $actualResult = $this->view->_call('getPartialSource', 'LayoutFixture');
533  $this->assertEquals($expectedResult, $actualResult);
534  }
535 
540  {
541  $this->view->setPartialRootPath('/foo/bar');
542  $this->view->setPartialRootPaths(['/overruled/path']);
543  $expected = ['/overruled/path'];
544  $actual = $this->view->_call('getPartialRootPaths');
545  $this->assertEquals($expected, $actual, 'A set partial root path was not returned correctly.');
546  }
547 
552  {
553  $this->view->setLayoutRootPath('/foo/bar');
554  $this->view->setLayoutRootPaths(['/overruled/path']);
555  $expected = ['/overruled/path'];
556  $actual = $this->view->_call('getLayoutRootPaths');
557  $this->assertEquals($expected, $actual, 'A set layout root path was not returned correctly.');
558  }
559 
564  {
565  $this->view->setLayoutRootPaths(['some/Default/Directory']);
566  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
567  $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/LayoutName.html')->willReturn(false);
568  $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/LayoutName')->willReturn(false);
569  $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/layoutName.html')->willReturn(true);
570  $this->assertSame(PATH_site . 'some/Default/Directory/layoutName.html', $this->view->_call('getLayoutPathAndFilename', 'layoutName'));
571  }
572 
577  {
578  $this->view->setLayoutRootPaths(['some/Default/Directory']);
579  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
580  $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/LayoutName.html')->willReturn(true);
581  $this->assertSame(PATH_site . 'some/Default/Directory/LayoutName.html', $this->view->_call('getLayoutPathAndFilename', 'layoutName'));
582  }
583 
588  {
589  $this->view->setLayoutRootPaths([
590  'default' => 'some/Default/Directory',
591  'specific' => 'specific/Layouts',
592  ]);
593  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
594  $this->view->expects($this->once())->method('testFileExistence')->with(PATH_site . 'specific/Layouts/Default.html')->will($this->returnValue(true));
595  $this->assertEquals(PATH_site . 'specific/Layouts/Default.html', $this->view->_call('getLayoutPathAndFilename'));
596  }
597 
602  {
603  $this->view->setLayoutRootPaths([
604  'default' => 'some/Default/Directory',
605  'specific' => 'specific/Layouts',
606  ]);
607  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
608  $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default.html')->will($this->returnValue(true));
609  $this->assertEquals(PATH_site . 'some/Default/Directory/Default.html', $this->view->_call('getLayoutPathAndFilename'));
610  }
611 
616  {
617  $this->view->setLayoutRootPaths([
618  '10' => 'some/Default/Directory',
619  '25' => 'evenMore/Specific/Layouts',
620  '17' => 'specific/Layouts',
621  ]);
622  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
623  $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Layouts/Default.html')->will($this->returnValue(true));
624  $this->assertEquals(PATH_site . 'specific/Layouts/Default.html', $this->view->_call('getLayoutPathAndFilename'));
625  }
626 
631  {
632  $this->view->setLayoutRootPaths([
633  '10' => 'some/Default/Directory',
634  '25' => 'evenMore/Specific/Layouts',
635  '17' => 'specific/Layouts',
636  ]);
637  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
638  $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default.html')->will($this->returnValue(true));
639  $this->assertEquals(PATH_site . 'some/Default/Directory/Default.html', $this->view->_call('getLayoutPathAndFilename'));
640  }
641 
648  {
649  $this->view->setLayoutRootPaths([
650  '10' => 'some/Default/Directory',
651  '25' => 'evenMore/Specific/Layouts',
652  '17' => 'specific/Layouts',
653  ]);
654  $this->view->expects($this->any())->method('testFileExistence')->will($this->returnValue(false));
655  $this->view->_call('getLayoutPathAndFilename');
656  }
657 
662  {
663  $this->view->setPartialRootPaths(['some/Default/Directory']);
664  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
665  $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/PartialName.html')->willReturn(false);
666  $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/PartialName')->willReturn(false);
667  $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/partialName.html')->willReturn(true);
668  $this->assertSame(PATH_site . 'some/Default/Directory/partialName.html', $this->view->_call('getPartialPathAndFilename', 'partialName'));
669  }
670 
675  {
676  $this->view->setPartialRootPaths(['some/Default/Directory']);
677  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
678  $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/PartialName.html')->willReturn(true);
679  $this->assertSame(PATH_site . 'some/Default/Directory/PartialName.html', $this->view->_call('getPartialPathAndFilename', 'partialName'));
680  }
681 
686  {
687  $this->view->setPartialRootPaths([
688  'default' => 'some/Default/Directory',
689  'specific' => 'specific/Partials',
690  ]);
691  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
692  $this->view->expects($this->once())->method('testFileExistence')->with(PATH_site . 'specific/Partials/Partial.html')->will($this->returnValue(true));
693  $this->assertEquals(PATH_site . 'specific/Partials/Partial.html', $this->view->_call('getPartialPathAndFilename', 'Partial'));
694  }
695 
700  {
701  $this->view->setPartialRootPaths([
702  'default' => 'some/Default/Directory',
703  'specific' => 'specific/Partials',
704  ]);
705  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
706  $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Partial.html')->will($this->returnValue(true));
707  $this->assertEquals(PATH_site . 'some/Default/Directory/Partial.html', $this->view->_call('getPartialPathAndFilename', 'Partial'));
708  }
709 
714  {
715  $this->view->setPartialRootPaths([
716  '10' => 'some/Default/Directory',
717  '25' => 'evenMore/Specific/Partials',
718  '17' => 'specific/Partials',
719  ]);
720  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
721  $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Partials/Partial.html')->will($this->returnValue(true));
722  $this->assertEquals(PATH_site . 'specific/Partials/Partial.html', $this->view->_call('getPartialPathAndFilename', 'Partial'));
723  }
724 
729  {
730  $this->view->setPartialRootPaths([
731  '10' => 'some/Default/Directory',
732  '25' => 'evenMore/Specific/Partials',
733  '17' => 'specific/Partials',
734  ]);
735  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
736  $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Partial.html')->will($this->returnValue(true));
737  $this->assertEquals(PATH_site . 'some/Default/Directory/Partial.html', $this->view->_call('getPartialPathAndFilename', 'Partial'));
738  }
739 
746  {
747  $this->view->setPartialRootPaths([
748  '10' => 'some/Default/Directory',
749  '25' => 'evenMore/Specific/Partials',
750  '17' => 'specific/Partials',
751  ]);
752  $this->view->expects($this->any())->method('testFileExistence')->will($this->returnValue(false));
753  $this->view->_call('getPartialPathAndFilename', 'Partial');
754  }
755 
760  {
761  $this->view->setPartialRootPaths([
762  '10' => 'some/Default/Directory',
763  '25' => 'evenMore/Specific/Partials',
764  '17' => 'specific/Partials',
765  ]);
766  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
767  $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Partials/Partial.html')->will($this->returnValue(false));
768  $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Partials/Partial')->will($this->returnValue(false));
769  $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Partials/Partial.html')->will($this->returnValue(false));
770  $this->view->expects($this->at(3))->method('testFileExistence')->with(PATH_site . 'specific/Partials/Partial')->will($this->returnValue(false));
771  $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Partial.html')->will($this->returnValue(false));
772  $this->view->expects($this->at(5))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Partial')->will($this->returnValue(true));
773  $this->assertEquals(PATH_site . 'some/Default/Directory/Partial', $this->view->_call('getPartialPathAndFilename', 'Partial'));
774  }
775 
780  {
781  $this->view->setLayoutRootPaths([
782  '10' => 'some/Default/Directory',
783  '25' => 'evenMore/Specific/Layouts',
784  '17' => 'specific/Layouts',
785  ]);
786  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
787  $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Layouts/Default.html')->will($this->returnValue(false));
788  $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Layouts/Default')->will($this->returnValue(false));
789  $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Layouts/Default.html')->will($this->returnValue(false));
790  $this->view->expects($this->at(3))->method('testFileExistence')->with(PATH_site . 'specific/Layouts/Default')->will($this->returnValue(false));
791  $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default.html')->will($this->returnValue(false));
792  $this->view->expects($this->at(5))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default')->will($this->returnValue(true));
793  $this->assertEquals(PATH_site . 'some/Default/Directory/Default', $this->view->_call('getLayoutPathAndFilename'));
794  }
795 
800  {
801  $this->view->setPartialRootPaths([
802  'default' => 'some/Default/Directory',
803  'specific' => 'specific/Partials',
804  'verySpecific' => 'evenMore/Specific/Partials',
805  ]);
806  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
807  $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Partials/Partial.html')->will($this->returnValue(false));
808  $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Partials/Partial')->will($this->returnValue(false));
809  $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Partials/Partial.html')->will($this->returnValue(false));
810  $this->view->expects($this->at(3))->method('testFileExistence')->with(PATH_site . 'specific/Partials/Partial')->will($this->returnValue(false));
811  $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Partial.html')->will($this->returnValue(false));
812  $this->view->expects($this->at(5))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Partial')->will($this->returnValue(true));
813  $this->assertEquals(PATH_site . 'some/Default/Directory/Partial', $this->view->_call('getPartialPathAndFilename', 'Partial'));
814  }
815 
820  {
821  $this->view->setLayoutRootPaths([
822  'default' => 'some/Default/Directory',
823  'specific' => 'specific/Layout',
824  'verySpecific' => 'evenMore/Specific/Layout',
825  ]);
826  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
827  $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Layout/Default.html')->will($this->returnValue(false));
828  $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Layout/Default')->will($this->returnValue(false));
829  $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Layout/Default.html')->will($this->returnValue(false));
830  $this->view->expects($this->at(3))->method('testFileExistence')->with(PATH_site . 'specific/Layout/Default')->will($this->returnValue(false));
831  $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default.html')->will($this->returnValue(false));
832  $this->view->expects($this->at(5))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Default')->will($this->returnValue(true));
833  $this->assertEquals(PATH_site . 'some/Default/Directory/Default', $this->view->_call('getLayoutPathAndFilename'));
834  }
835 
841  {
842  $this->view->setTemplate('TemplateName');
843  }
844 
850  {
851  $this->view->setTemplateRootPaths([
852  'Some/Template/Path'
853  ]);
854  $this->view->setTemplate('NonExistingTemplateName');
855  }
856 
861  {
862  $this->view->setTemplateRootPaths(['some/Default/Directory']);
863  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
864  $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/TemplateName.html')->willReturn(false);
865  $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/TemplateName')->willReturn(false);
866  $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/templateName.html')->willReturn(true);
867  $this->view->setTemplate('templateName');
868 
869  $this->assertSame(PATH_site . 'some/Default/Directory/templateName.html', $this->view->getTemplatePathAndFilename());
870  }
871 
876  {
877  $this->view->setTemplateRootPaths(['some/Default/Directory']);
878  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
879  $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/TemplateName.html')->willReturn(true);
880  $this->view->setTemplate('templateName');
881  $this->assertSame(PATH_site . 'some/Default/Directory/TemplateName.html', $this->view->getTemplatePathAndFilename());
882  }
883 
888  {
889  $this->view->setTemplateRootPaths([
890  'default' => 'some/Default/Directory',
891  'specific' => 'specific/Templates',
892  ]);
893  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
894  $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'specific/Templates/Template.html')->will($this->returnValue(true));
895  $this->view->setTemplate('Template');
896  $this->assertEquals(PATH_site . 'specific/Templates/Template.html', $this->view->getTemplatePathAndFilename());
897  }
898 
903  {
904  $this->view->setTemplateRootPaths([
905  'default' => 'some/Default/Directory',
906  'specific' => 'specific/Templates',
907  ]);
908  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
909  $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Template.html')->will($this->returnValue(true));
910  $this->view->setTemplate('Template');
911 
912  $this->assertEquals(PATH_site . 'some/Default/Directory/Template.html', $this->view->getTemplatePathAndFilename());
913  }
914 
919  {
920  $this->view->setTemplateRootPaths([
921  'default' => 'some/Default/Directory',
922  'specific' => 'specific/Templates',
923  ]);
924  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
925  $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'specific/Templates/Email/Template.html')->will($this->returnValue(true));
926  $this->view->setTemplate('Email/Template');
927  $this->assertEquals(PATH_site . 'specific/Templates/Email/Template.html', $this->view->getTemplatePathAndFilename());
928  }
929 
934  {
935  $this->view->setTemplateRootPaths([
936  '10' => 'some/Default/Directory',
937  '25' => 'evenMore/Specific/Templates',
938  '17' => 'specific/Templates',
939  ]);
940  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
941  $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Templates/Template.html')->will($this->returnValue(true));
942  $this->view->setTemplate('Template');
943  $this->assertEquals(PATH_site . 'specific/Templates/Template.html', $this->view->getTemplatePathAndFilename());
944  }
945 
950  {
951  $this->view->setTemplateRootPaths([
952  '10' => 'some/Default/Directory',
953  '25' => 'evenMore/Specific/Templates',
954  '17' => 'specific/Templates',
955  ]);
956  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
957  $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Template.html')->will($this->returnValue(true));
958  $this->view->setTemplate('Template');
959  $this->assertEquals(PATH_site . 'some/Default/Directory/Template.html', $this->view->getTemplatePathAndFilename());
960  }
961 
966  {
967  $this->view->setTemplateRootPaths([
968  '10' => 'some/Default/Directory',
969  '25' => 'evenMore/Specific/Templates',
970  '17' => 'specific/Templates',
971  ]);
972  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
973  $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Templates/Template.html')->will($this->returnValue(false));
974  $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Templates/Template')->will($this->returnValue(false));
975  $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Templates/Template.html')->will($this->returnValue(false));
976  $this->view->expects($this->at(3))->method('testFileExistence')->with(PATH_site . 'specific/Templates/Template')->will($this->returnValue(false));
977  $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Template.html')->will($this->returnValue(false));
978  $this->view->expects($this->at(5))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Template')->will($this->returnValue(true));
979  $this->view->setTemplate('Template');
980  $this->assertEquals(PATH_site . 'some/Default/Directory/Template', $this->view->getTemplatePathAndFilename());
981  }
982 
987  {
988  $this->view->setTemplateRootPaths([
989  'default' => 'some/Default/Directory',
990  'specific' => 'specific/Templates',
991  'verySpecific' => 'evenMore/Specific/Templates',
992  ]);
993  $this->mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
994  $this->view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Templates/Template.html')->will($this->returnValue(false));
995  $this->view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'evenMore/Specific/Templates/Template')->will($this->returnValue(false));
996  $this->view->expects($this->at(2))->method('testFileExistence')->with(PATH_site . 'specific/Templates/Template.html')->will($this->returnValue(false));
997  $this->view->expects($this->at(3))->method('testFileExistence')->with(PATH_site . 'specific/Templates/Template')->will($this->returnValue(false));
998  $this->view->expects($this->at(4))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Template.html')->will($this->returnValue(false));
999  $this->view->expects($this->at(5))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/Template')->will($this->returnValue(true));
1000  $this->view->setTemplate('Template');
1001  $this->assertEquals(PATH_site . 'some/Default/Directory/Template', $this->view->getTemplatePathAndFilename());
1002  }
1003 }
static addInstance($className, $instance)
static setSingletonInstance($className, SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)