|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /* * 00004 * This script belongs to the FLOW3 package "Fluid". * 00005 * * 00006 * It is free software; you can redistribute it and/or modify it under * 00007 * the terms of the GNU Lesser General Public License as published by the * 00008 * Free Software Foundation, either version 3 of the License, or (at your * 00009 * option) any later version. * 00010 * * 00011 * This script is distributed in the hope that it will be useful, but * 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- * 00013 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * 00014 * General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with the script. * 00018 * If not, see http://www.gnu.org/licenses/lgpl.html * 00019 * * 00020 * The TYPO3 project - inspiring people to share! * 00021 * */ 00022 00023 /** 00024 * Testcase for the StandaloneView 00025 * 00026 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later 00027 */ 00028 class Tx_Fluid_Tests_Unit_View_StandaloneViewTest extends Tx_Extbase_Tests_Unit_BaseTestCase { 00029 00030 /** 00031 * @var Tx_Fluid_View_StandaloneView 00032 */ 00033 protected $view; 00034 00035 /** 00036 * @var Tx_Fluid_Core_Rendering_RenderingContextInterface 00037 */ 00038 protected $mockRenderingContext; 00039 00040 /** 00041 * @var Tx_Fluid_Core_ViewHelper_ViewHelperVariableContainer 00042 */ 00043 protected $mockViewHelperVariableContainer; 00044 00045 /** 00046 * @var Tx_Extbase_MVC_Controller_ControllerContext 00047 */ 00048 protected $mockControllerContext; 00049 00050 /** 00051 * @var Tx_Fluid_Core_Parser_TemplateParser 00052 */ 00053 protected $mockTemplateParser; 00054 00055 /** 00056 * @var Tx_Extbase_Object_ObjectManager 00057 */ 00058 protected $mockObjectManager; 00059 00060 /** 00061 * @var Tx_Extbase_MVC_Web_Request 00062 */ 00063 protected $mockRequest; 00064 00065 /** 00066 * @var Tx_Extbase_MVC_Web_Routing_UriBuilder 00067 */ 00068 protected $mockUriBuilder; 00069 00070 /** 00071 * @var Tx_Fluid_Core_Parser_ParsedTemplateInterface 00072 */ 00073 protected $mockParsedTemplate; 00074 00075 /** 00076 * @var Tx_Extbase_Configuration_ConfigurationManagerInterface 00077 */ 00078 protected $mockConfigurationManager; 00079 00080 /** 00081 * @var Tx_Extbase_MVC_Controller_FlashMessages 00082 */ 00083 protected $mockFlashMessages; 00084 00085 /** 00086 * @var tslib_cObj 00087 */ 00088 protected $mockContentObject; 00089 00090 /** 00091 * Sets up this test case 00092 * 00093 * @return void 00094 */ 00095 public function setUp() { 00096 $this->view = $this->getAccessibleMock('Tx_Fluid_View_StandaloneView', array('dummy'), array(), '', FALSE); 00097 00098 $this->mockTemplateParser = $this->getMock('Tx_Fluid_Core_Parser_TemplateParser'); 00099 $this->mockParsedTemplate = $this->getMock('Tx_Fluid_Core_Parser_ParsedTemplateInterface'); 00100 $this->mockTemplateParser->expects($this->any())->method('parse')->will($this->returnValue($this->mockParsedTemplate)); 00101 00102 $this->mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface'); 00103 00104 $this->mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager'); 00105 $this->mockObjectManager->expects($this->any())->method('get')->will($this->returnCallback(array($this, 'objectManagerCallback'))); 00106 $this->mockObjectManager->expects($this->any())->method('create')->will($this->returnCallback(array($this, 'objectManagerCallback'))); 00107 00108 $this->mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request'); 00109 $this->mockUriBuilder = $this->getMock('Tx_Extbase_MVC_Web_Routing_UriBuilder'); 00110 $this->mockFlashMessages = $this->getMock('Tx_Extbase_MVC_Controller_FlashMessages'); 00111 $this->mockContentObject = $this->getMock('tslib_cObj'); 00112 00113 $this->mockControllerContext = $this->getMock('Tx_Extbase_MVC_Controller_ControllerContext'); 00114 $this->mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->mockRequest)); 00115 00116 $this->mockViewHelperVariableContainer = $this->getMock('Tx_Fluid_Core_ViewHelper_ViewHelperVariableContainer'); 00117 00118 $this->mockRenderingContext = $this->getMock('Tx_Fluid_Core_Rendering_RenderingContextInterface'); 00119 $this->mockRenderingContext->expects($this->any())->method('getControllerContext')->will($this->returnValue($this->mockControllerContext)); 00120 $this->mockRenderingContext->expects($this->any())->method('getViewHelperVariableContainer')->will($this->returnValue($this->mockViewHelperVariableContainer)); 00121 00122 $this->view->injectTemplateParser($this->mockTemplateParser); 00123 $this->view->injectObjectManager($this->mockObjectManager); 00124 $this->view->setRenderingContext($this->mockRenderingContext); 00125 00126 t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $this->mockObjectManager); 00127 t3lib_div::addInstance('tslib_cObj', $this->mockContentObject); 00128 } 00129 00130 /** 00131 * @return void 00132 */ 00133 public function tearDown() { 00134 t3lib_div::purgeInstances(); 00135 } 00136 00137 /** 00138 * @param string $className 00139 * @return object 00140 */ 00141 public function objectManagerCallback($className) { 00142 switch($className) { 00143 case 'Tx_Extbase_Configuration_ConfigurationManagerInterface': 00144 return $this->mockConfigurationManager; 00145 case 'Tx_Fluid_Core_Parser_TemplateParser': 00146 return $this->mockTemplateParser; 00147 case 'Tx_Fluid_Core_Rendering_RenderingContext': 00148 return $this->mockRenderingContext; 00149 case 'Tx_Extbase_MVC_Web_Request': 00150 return $this->mockRequest; 00151 case 'Tx_Extbase_MVC_Web_Routing_UriBuilder': 00152 return $this->mockUriBuilder; 00153 case 'Tx_Extbase_MVC_Controller_ControllerContext': 00154 return $this->mockControllerContext; 00155 case 'Tx_Extbase_MVC_Controller_FlashMessages': 00156 return $this->mockFlashMessages; 00157 } 00158 } 00159 00160 /** 00161 * @test 00162 * @author Bastian Waidelich <bastian@typo3.org> 00163 */ 00164 public function constructorSetsSpecifiedContentObject() { 00165 $mockContentObject = $this->getMock('tslib_cObj'); 00166 // FIXME should be compared with identicalTo() - but that does not seem to work 00167 $this->mockConfigurationManager->expects($this->once())->method('setContentObject')->with($this->equalTo($this->mockContentObject)); 00168 00169 new Tx_Fluid_View_StandaloneView($mockContentObject); 00170 } 00171 00172 /** 00173 * @test 00174 * @author Bastian Waidelich <bastian@typo3.org> 00175 */ 00176 public function constructorCreatesContentObjectIfItIsNotSpecified() { 00177 // FIXME should be compared with identicalTo() - but that does not seem to work 00178 $this->mockConfigurationManager->expects($this->once())->method('setContentObject')->with($this->equalTo($this->mockContentObject)); 00179 00180 new Tx_Fluid_View_StandaloneView(); 00181 } 00182 00183 /** 00184 * @test 00185 * @author Bastian Waidelich <bastian@typo3.org> 00186 */ 00187 public function constructorSetsRequestUri() { 00188 $expectedRequestUri = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'); 00189 $this->mockRequest->expects($this->once())->method('setRequestURI')->with($expectedRequestUri); 00190 new Tx_Fluid_View_StandaloneView(); 00191 } 00192 00193 /** 00194 * @test 00195 * @author Bastian Waidelich <bastian@typo3.org> 00196 */ 00197 public function constructorSetsBaseUri() { 00198 $expectedBaseUri = t3lib_div::getIndpEnv('TYPO3_SITE_URL'); 00199 $this->mockRequest->expects($this->once())->method('setBaseURI')->with($expectedBaseUri); 00200 new Tx_Fluid_View_StandaloneView(); 00201 } 00202 00203 /** 00204 * @test 00205 * @author Bastian Waidelich <bastian@typo3.org> 00206 */ 00207 public function constructorInjectsRequestToUriBuilder() { 00208 $this->mockUriBuilder->expects($this->once())->method('setRequest')->with($this->mockRequest); 00209 new Tx_Fluid_View_StandaloneView(); 00210 } 00211 00212 /** 00213 * @test 00214 * @author Bastian Waidelich <bastian@typo3.org> 00215 */ 00216 public function constructorInjectsRequestToControllerContext() { 00217 $this->mockControllerContext->expects($this->once())->method('setRequest')->with($this->mockRequest); 00218 new Tx_Fluid_View_StandaloneView(); 00219 } 00220 00221 /** 00222 * @test 00223 * @author Bastian Waidelich <bastian@typo3.org> 00224 */ 00225 public function constructorInjectsUriBuilderToControllerContext() { 00226 $this->mockControllerContext->expects($this->once())->method('setUriBuilder')->with($this->mockUriBuilder); 00227 new Tx_Fluid_View_StandaloneView(); 00228 } 00229 00230 /** 00231 * @test 00232 * @author Bastian Waidelich <bastian@typo3.org> 00233 */ 00234 public function constructorInjectsFlashMessageContainerToControllerContext() { 00235 $this->mockControllerContext->expects($this->once())->method('setFlashMessageContainer')->with($this->mockFlashMessages); 00236 new Tx_Fluid_View_StandaloneView(); 00237 } 00238 00239 /** 00240 * @test 00241 * @expectedException Tx_Fluid_View_Exception_InvalidTemplateResourceException 00242 * @author Bastian Waidelich <bastian@typo3.org> 00243 */ 00244 public function renderThrowsExceptionIfTemplateIsNotSpecified() { 00245 $this->view->render(); 00246 } 00247 00248 /** 00249 * @test 00250 * @author Bastian Waidelich <bastian@typo3.org> 00251 */ 00252 public function renderPassesSpecifiedTemplateSourceToTemplateParser() { 00253 $this->view->setTemplateSource('The Template Source'); 00254 $this->mockTemplateParser->expects($this->once())->method('parse')->with('The Template Source'); 00255 $this->view->render(); 00256 } 00257 00258 /** 00259 * @test 00260 * @author Bastian Waidelich <bastian@typo3.org> 00261 */ 00262 public function renderLoadsSpecifiedTemplateFileAndPassesSourceToTemplateParser() { 00263 $templatePathAndFilename = dirname(__FILE__) . '/Fixtures/StandaloneViewFixture.html'; 00264 $expectedResult = file_get_contents($templatePathAndFilename); 00265 $this->view->setTemplatePathAndFilename($templatePathAndFilename); 00266 $this->mockTemplateParser->expects($this->once())->method('parse')->with($expectedResult); 00267 $this->view->render(); 00268 } 00269 00270 /** 00271 * @test 00272 * @expectedException Tx_Fluid_View_Exception_InvalidTemplateResourceException 00273 * @author Bastian Waidelich <bastian@typo3.org> 00274 */ 00275 public function renderThrowsExceptionIfSpecifiedTemplateFileDoesNotExist() { 00276 $this->view->setTemplatePathAndFilename('NonExistingTemplatePath'); 00277 $this->view->render(); 00278 } 00279 00280 /** 00281 * @test 00282 * @author Bastian Waidelich <bastian@typo3.org> 00283 */ 00284 public function setFormatSetsRequestFormat() { 00285 $this->mockRequest->expects($this->once())->method('setFormat')->with('xml'); 00286 $this->view->setFormat('xml'); 00287 } 00288 00289 /** 00290 * @test 00291 * @expectedException Tx_Fluid_View_Exception_InvalidTemplateResourceException 00292 * @author Bastian Waidelich <bastian@typo3.org> 00293 */ 00294 public function getLayoutRootPathThrowsExceptionIfLayoutRootPathAndTemplatePathAreNotSpecified() { 00295 $this->view->getLayoutRootPath(); 00296 } 00297 00298 /** 00299 * @test 00300 * @author Bastian Waidelich <bastian@typo3.org> 00301 */ 00302 public function getLayoutRootPathReturnsSpecifiedLayoutRootPathByDefault() { 00303 $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html'; 00304 $layoutRootPath = 'some/layout/RootPath'; 00305 $this->view->setTemplatePathAndFilename($templatePathAndFilename); 00306 $this->view->setLayoutRootPath($layoutRootPath); 00307 $actualResult = $this->view->getLayoutRootPath(); 00308 $this->assertEquals($layoutRootPath, $actualResult); 00309 } 00310 00311 /** 00312 * @test 00313 * @author Bastian Waidelich <bastian@typo3.org> 00314 */ 00315 public function getLayoutRootPathReturnsDefaultPathIfNoLayoutRootPathIsSpecified() { 00316 $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html'; 00317 $this->view->setTemplatePathAndFilename($templatePathAndFilename); 00318 $expectedResult = 'some/template/RootPath/Layouts'; 00319 $actualResult = $this->view->getLayoutRootPath(); 00320 $this->assertEquals($expectedResult, $actualResult); 00321 } 00322 00323 /** 00324 * @test 00325 * @expectedException Tx_Fluid_View_Exception_InvalidTemplateResourceException 00326 * @author Bastian Waidelich <bastian@typo3.org> 00327 */ 00328 public function getLayoutSourceThrowsExceptionIfLayoutRootPathDoesNotExist() { 00329 $this->view->setLayoutRootPath('some/non/existing/Path'); 00330 $this->view->_call('getLayoutSource'); 00331 } 00332 00333 /** 00334 * @test 00335 * @expectedException Tx_Fluid_View_Exception_InvalidTemplateResourceException 00336 * @author Bastian Waidelich <bastian@typo3.org> 00337 */ 00338 public function getLayoutSourceThrowsExceptionIfLayoutFileDoesNotExist() { 00339 $layoutRootPath = dirname(__FILE__) . '/Fixtures'; 00340 $this->view->setLayoutRootPath($layoutRootPath); 00341 $this->view->_call('getLayoutSource', 'NonExistingLayout'); 00342 } 00343 00344 /** 00345 * @test 00346 * @author Bastian Waidelich <bastian@typo3.org> 00347 */ 00348 public function getLayoutSourceReturnsContentOfLayoutFileForTheDefaultFormat() { 00349 $layoutRootPath = dirname(__FILE__) . '/Fixtures'; 00350 $this->view->setLayoutRootPath($layoutRootPath); 00351 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('html')); 00352 $expectedResult = file_get_contents($layoutRootPath . '/LayoutFixture.html'); 00353 $actualResult = $this->view->_call('getLayoutSource', 'LayoutFixture'); 00354 $this->assertEquals($expectedResult, $actualResult); 00355 } 00356 00357 /** 00358 * @test 00359 * @author Bastian Waidelich <bastian@typo3.org> 00360 */ 00361 public function getLayoutSourceReturnsContentOfLayoutFileForTheSpecifiedFormat() { 00362 $layoutRootPath = dirname(__FILE__) . '/Fixtures'; 00363 $this->view->setLayoutRootPath($layoutRootPath); 00364 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('xml')); 00365 $expectedResult = file_get_contents($layoutRootPath . '/LayoutFixture.xml'); 00366 $actualResult = $this->view->_call('getLayoutSource', 'LayoutFixture'); 00367 $this->assertEquals($expectedResult, $actualResult); 00368 } 00369 00370 /** 00371 * @test 00372 * @author Bastian Waidelich <bastian@typo3.org> 00373 */ 00374 public function getLayoutSourceReturnsContentOfDefaultLayoutFileIfNoLayoutExistsForTheSpecifiedFormat() { 00375 $layoutRootPath = dirname(__FILE__) . '/Fixtures'; 00376 $this->view->setLayoutRootPath($layoutRootPath); 00377 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('foo')); 00378 $expectedResult = file_get_contents($layoutRootPath . '/LayoutFixture'); 00379 $actualResult = $this->view->_call('getLayoutSource', 'LayoutFixture'); 00380 $this->assertEquals($expectedResult, $actualResult); 00381 } 00382 00383 /** 00384 * @test 00385 * @expectedException Tx_Fluid_View_Exception_InvalidTemplateResourceException 00386 * @author Bastian Waidelich <bastian@typo3.org> 00387 */ 00388 public function getPartialRootPathThrowsExceptionIfPartialRootPathAndTemplatePathAreNotSpecified() { 00389 $this->view->getPartialRootPath(); 00390 } 00391 00392 /** 00393 * @test 00394 * @author Bastian Waidelich <bastian@typo3.org> 00395 */ 00396 public function getPartialRootPathReturnsSpecifiedPartialRootPathByDefault() { 00397 $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html'; 00398 $partialRootPath = 'some/partial/RootPath'; 00399 $this->view->setTemplatePathAndFilename($templatePathAndFilename); 00400 $this->view->setPartialRootPath($partialRootPath); 00401 $actualResult = $this->view->getPartialRootPath(); 00402 $this->assertEquals($partialRootPath, $actualResult); 00403 } 00404 00405 /** 00406 * @test 00407 * @author Bastian Waidelich <bastian@typo3.org> 00408 */ 00409 public function getPartialRootPathReturnsDefaultPathIfNoPartialRootPathIsSpecified() { 00410 $templatePathAndFilename = 'some/template/RootPath/SomeTemplate.html'; 00411 $this->view->setTemplatePathAndFilename($templatePathAndFilename); 00412 $expectedResult = 'some/template/RootPath/Partials'; 00413 $actualResult = $this->view->getPartialRootPath(); 00414 $this->assertEquals($expectedResult, $actualResult); 00415 } 00416 00417 /** 00418 * @test 00419 * @expectedException Tx_Fluid_View_Exception_InvalidTemplateResourceException 00420 * @author Bastian Waidelich <bastian@typo3.org> 00421 */ 00422 public function getPartialSourceThrowsExceptionIfPartialRootPathDoesNotExist() { 00423 $this->view->setPartialRootPath('some/non/existing/Path'); 00424 $this->view->_call('getPartialSource'); 00425 } 00426 00427 /** 00428 * @test 00429 * @expectedException Tx_Fluid_View_Exception_InvalidTemplateResourceException 00430 * @author Bastian Waidelich <bastian@typo3.org> 00431 */ 00432 public function getPartialSourceThrowsExceptionIfPartialFileDoesNotExist() { 00433 $partialRootPath = dirname(__FILE__) . '/Fixtures'; 00434 $this->view->setPartialRootPath($partialRootPath); 00435 $this->view->_call('getPartialSource', 'NonExistingPartial'); 00436 } 00437 00438 /** 00439 * @test 00440 * @author Bastian Waidelich <bastian@typo3.org> 00441 */ 00442 public function getPartialSourceReturnsContentOfPartialFileForTheDefaultFormat() { 00443 $partialRootPath = dirname(__FILE__) . '/Fixtures'; 00444 $this->view->setPartialRootPath($partialRootPath); 00445 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('html')); 00446 $expectedResult = file_get_contents($partialRootPath . '/LayoutFixture.html'); 00447 $actualResult = $this->view->_call('getPartialSource', 'LayoutFixture'); 00448 $this->assertEquals($expectedResult, $actualResult); 00449 } 00450 00451 /** 00452 * @test 00453 * @author Bastian Waidelich <bastian@typo3.org> 00454 */ 00455 public function getPartialSourceReturnsContentOfPartialFileForTheSpecifiedFormat() { 00456 $partialRootPath = dirname(__FILE__) . '/Fixtures'; 00457 $this->view->setPartialRootPath($partialRootPath); 00458 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('xml')); 00459 $expectedResult = file_get_contents($partialRootPath . '/LayoutFixture.xml'); 00460 $actualResult = $this->view->_call('getPartialSource', 'LayoutFixture'); 00461 $this->assertEquals($expectedResult, $actualResult); 00462 } 00463 00464 /** 00465 * @test 00466 * @author Bastian Waidelich <bastian@typo3.org> 00467 */ 00468 public function getPartialSourceReturnsContentOfDefaultPartialFileIfNoPartialExistsForTheSpecifiedFormat() { 00469 $partialRootPath = dirname(__FILE__) . '/Fixtures'; 00470 $this->view->setPartialRootPath($partialRootPath); 00471 $this->mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('foo')); 00472 $expectedResult = file_get_contents($partialRootPath . '/LayoutFixture'); 00473 $actualResult = $this->view->_call('getPartialSource', 'LayoutFixture'); 00474 $this->assertEquals($expectedResult, $actualResult); 00475 } 00476 } 00477 ?>
1.8.0