|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de> 00006 * All rights reserved 00007 * 00008 * This class is a backport of the corresponding class of FLOW3. 00009 * All credits go to the v5 team. 00010 * 00011 * This script is part of the TYPO3 project. The TYPO3 project is 00012 * free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License as published by 00014 * the Free Software Foundation; either version 2 of the License, or 00015 * (at your option) any later version. 00016 * 00017 * The GNU General Public License can be found at 00018 * http://www.gnu.org/copyleft/gpl.html. 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 00028 class Tx_Extbase_Tests_Unit_MVC_Controller_ActionControllerTest extends Tx_Extbase_Tests_Unit_BaseTestCase { 00029 00030 /** 00031 * @var Tx_Extbase_MVC_Controller_ActionController 00032 */ 00033 protected $actionController; 00034 00035 /** 00036 * @var Tx_Extbase_Object_ObjectManagerInterface 00037 */ 00038 protected $mockObjectManager; 00039 00040 /** 00041 * @var Tx_Extbase_MVC_Web_Routing_UriBuilder 00042 */ 00043 protected $mockUriBuilder; 00044 00045 public function setUp() { 00046 $this->actionController = $this->getAccessibleMock('Tx_Extbase_MVC_Controller_ActionController'); 00047 //$this->mockUriBuilder = $this->getMock('Tx_Extbase_MVC_Web_Routing_UriBuilder'); 00048 //$this->mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface'); 00049 //$this->mockObjectManager->expects($this->any())->method('create')->with('Tx_Extbase_MVC_Web_Routing_UriBuilder')->will($this->returnValue($this->mockUriBuilder)); 00050 //$this->actionController->_set('objectManager', $this->mockObjectManager); 00051 } 00052 00053 /** 00054 * @test 00055 */ 00056 public function processRequestSticksToSpecifiedSequence() { 00057 $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request', array(), array(), '', FALSE); 00058 $mockRequest->expects($this->once())->method('setDispatched')->with(TRUE); 00059 00060 $mockUriBuilder = $this->getMock('Tx_Extbase_MVC_Web_Routing_UriBuilder'); 00061 $mockUriBuilder->expects($this->once())->method('setRequest')->with($mockRequest); 00062 00063 $mockControllerContext = $this->getMock('Tx_Extbase_MVC_Controller_ControllerContext', array(), array(), '', FALSE); 00064 00065 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface'); 00066 $mockObjectManager->expects($this->once())->method('create')->with('Tx_Extbase_MVC_Web_Routing_UriBuilder')->will($this->returnValue($mockUriBuilder)); 00067 00068 $mockResponse = $this->getMock('Tx_Extbase_MVC_Web_Response', array(), array(), '', FALSE); 00069 00070 $mockView = $this->getMock('Tx_Extbase_MVC_View_ViewInterface'); 00071 00072 $mockController = $this->getAccessibleMock('Tx_Extbase_MVC_Controller_ActionController', array( 00073 'initializeFooAction', 'initializeAction', 'resolveActionMethodName', 'initializeActionMethodArguments', 00074 'initializeActionMethodValidators', 'mapRequestArgumentsToControllerArguments', 'buildControllerContext', 00075 'resolveView', 'initializeView', 'callActionMethod'), 00076 array(), '', FALSE); 00077 00078 $mockController->_set('objectManager', $mockObjectManager); 00079 $mockController->expects($this->at(0))->method('resolveActionMethodName')->will($this->returnValue('fooAction')); 00080 $mockController->expects($this->at(1))->method('initializeActionMethodArguments'); 00081 $mockController->expects($this->at(2))->method('initializeActionMethodValidators'); 00082 $mockController->expects($this->at(3))->method('initializeAction'); 00083 $mockController->expects($this->at(4))->method('initializeFooAction'); 00084 $mockController->expects($this->at(5))->method('mapRequestArgumentsToControllerArguments'); 00085 $mockController->expects($this->at(6))->method('checkRequestHash'); 00086 $mockController->expects($this->at(7))->method('buildControllerContext'); 00087 $mockController->expects($this->at(8))->method('resolveView'); 00088 00089 $mockController->processRequest($mockRequest, $mockResponse); 00090 $this->assertSame($mockRequest, $mockController->_get('request')); 00091 $this->assertSame($mockResponse, $mockController->_get('response')); 00092 } 00093 00094 /** 00095 * @test 00096 * @author Robert Lemke <robert@typo3.org> 00097 */ 00098 public function callActionMethodAppendsStringsReturnedByActionMethodToTheResponseObject() { 00099 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE); 00100 00101 $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface', array(), array(), '', FALSE); 00102 $mockResponse->expects($this->once())->method('appendContent')->with('the returned string'); 00103 00104 $mockArguments = new ArrayObject; 00105 00106 $mockArgumentMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE); 00107 $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE)); 00108 00109 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'initializeAction'), array(), '', FALSE); 00110 $mockController->expects($this->once())->method('fooAction')->will($this->returnValue('the returned string')); 00111 $mockController->_set('request', $mockRequest); 00112 $mockController->_set('response', $mockResponse); 00113 $mockController->_set('arguments', $mockArguments); 00114 $mockController->_set('actionMethodName', 'fooAction'); 00115 $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults); 00116 $mockController->_call('callActionMethod'); 00117 } 00118 00119 /** 00120 * @test 00121 * @author Robert Lemke <robert@typo3.org> 00122 */ 00123 public function callActionMethodRendersTheViewAutomaticallyIfTheActionReturnedNullAndAViewExists() { 00124 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE); 00125 00126 $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface', array(), array(), '', FALSE); 00127 $mockResponse->expects($this->once())->method('appendContent')->with('the view output'); 00128 00129 $mockView = $this->getMock('Tx_Extbase_MVC_View_ViewInterface'); 00130 $mockView->expects($this->once())->method('render')->will($this->returnValue('the view output')); 00131 00132 $mockArguments = new ArrayObject; 00133 00134 $mockArgumentMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE); 00135 $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE)); 00136 00137 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'initializeAction'), array(), '', FALSE); 00138 $mockController->expects($this->once())->method('fooAction'); 00139 $mockController->_set('request', $mockRequest); 00140 $mockController->_set('response', $mockResponse); 00141 $mockController->_set('arguments', $mockArguments); 00142 $mockController->_set('actionMethodName', 'fooAction'); 00143 $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults); 00144 $mockController->_set('view', $mockView); 00145 $mockController->_call('callActionMethod'); 00146 } 00147 00148 /** 00149 * @test 00150 * @author Robert Lemke <robert@typo3.org> 00151 */ 00152 public function callActionMethodCallsTheErrorActionIfTheMappingResultsHaveErrors() { 00153 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE); 00154 00155 $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface', array(), array(), '', FALSE); 00156 $mockResponse->expects($this->once())->method('appendContent')->with('the returned string'); 00157 00158 $mockArguments = new ArrayObject; 00159 00160 $mockArgumentMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE); 00161 $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(TRUE)); 00162 00163 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('barAction', 'initializeAction'), array(), '', FALSE); 00164 $mockController->expects($this->once())->method('barAction')->will($this->returnValue('the returned string')); 00165 $mockController->_set('request', $mockRequest); 00166 $mockController->_set('response', $mockResponse); 00167 $mockController->_set('arguments', $mockArguments); 00168 $mockController->_set('actionMethodName', 'fooAction'); 00169 $mockController->_set('errorMethodName', 'barAction'); 00170 $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults); 00171 $mockController->_call('callActionMethod'); 00172 } 00173 00174 /** 00175 * @test 00176 * @author Sebastian Kurfürst <sebastian@typo3.org> 00177 */ 00178 public function callActionMethodPassesDefaultValuesAsArguments() { 00179 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE); 00180 00181 $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface', array(), array(), '', FALSE); 00182 00183 $arguments = new ArrayObject(); 00184 $optionalArgument = new Tx_Extbase_MVC_Controller_Argument('name1', 'Text'); 00185 $optionalArgument->setDefaultValue('Default value'); 00186 $arguments[] = $optionalArgument; 00187 00188 $mockArgumentMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE); 00189 $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE)); 00190 00191 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'initializeAction'), array(), '', FALSE); 00192 $mockController->expects($this->once())->method('fooAction')->with('Default value'); 00193 $mockController->_set('request', $mockRequest); 00194 $mockController->_set('response', $mockResponse); 00195 $mockController->_set('arguments', $arguments); 00196 $mockController->_set('actionMethodName', 'fooAction'); 00197 $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults); 00198 $mockController->_call('callActionMethod'); 00199 } 00200 00201 /** 00202 * @test 00203 * @author Karsten Dambekalns <karsten@typo3.org> 00204 */ 00205 public function resolveViewUsesFluidTemplateViewIfTemplateIsAvailable() { 00206 $mockSession = $this->getMock('Tx_Extbase_Session_SessionInterface'); 00207 $mockControllerContext = $this->getMock('Tx_Extbase_MVC_Controller_ControllerContext', array(), array(), '', FALSE); 00208 00209 $mockFluidTemplateView = $this->getMock('Tx_Extbase_MVC_View_ViewInterface'); 00210 $mockFluidTemplateView->expects($this->once())->method('setControllerContext')->with($mockControllerContext); 00211 $mockFluidTemplateView->expects($this->once())->method('canRender')->with($mockControllerContext)->will($this->returnValue(TRUE)); 00212 00213 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface', array(), array(), '', FALSE); 00214 $mockObjectManager->expects($this->at(0))->method('create')->with('Tx_Fluid_View_TemplateView')->will($this->returnValue($mockFluidTemplateView)); 00215 00216 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('buildControllerContext', 'resolveViewObjectName', 'setViewConfiguration'), array(), '', FALSE); 00217 $mockController->expects($this->once())->method('resolveViewObjectName')->will($this->returnValue(FALSE)); 00218 $mockController->_set('session', $mockSession); 00219 $mockController->_set('objectManager', $mockObjectManager); 00220 $mockController->_set('controllerContext', $mockControllerContext); 00221 00222 $this->assertSame($mockFluidTemplateView, $mockController->_call('resolveView')); 00223 } 00224 00225 /** 00226 * @test 00227 * @author Bastian Waidelich <bastian@typo3.org> 00228 */ 00229 public function resolveViewObjectNameUsesViewObjectNamePatternToResolveViewObjectName() { 00230 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE); 00231 $mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('MyPackage')); 00232 $mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('MyController')); 00233 $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('MyAction')); 00234 $mockRequest->expects($this->atLeastOnce())->method('getFormat')->will($this->returnValue('MyFormat')); 00235 00236 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface', array(), array(), '', FALSE); 00237 00238 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('dummy'), array(), '', FALSE); 00239 $mockController->_set('request', $mockRequest); 00240 $mockController->_set('objectManager', $mockObjectManager); 00241 $mockController->_set('viewObjectNamePattern', 'RandomViewObjectPattern_@package_@controller_@action_@format'); 00242 00243 $mockController->_call('resolveViewObjectName'); 00244 } 00245 00246 /** 00247 * @test 00248 * @author Robert Lemke <robert@typo3.org> 00249 */ 00250 public function resolveActionMethodNameReturnsTheCurrentActionMethodNameFromTheRequest() { 00251 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE); 00252 $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('fooBar')); 00253 00254 $mockController = $this->getAccessibleMock('Tx_Extbase_MVC_Controller_ActionController', array('fooBarAction'), array(), '', FALSE); 00255 $mockController->_set('request', $mockRequest); 00256 00257 $this->assertEquals('fooBarAction', $mockController->_call('resolveActionMethodName')); 00258 } 00259 00260 /** 00261 * @test 00262 * @expectedException Tx_Extbase_MVC_Exception_NoSuchAction 00263 * @author Robert Lemke <robert@typo3.org> 00264 */ 00265 public function resolveActionMethodNameThrowsAnExceptionIfTheActionDefinedInTheRequestDoesNotExist() { 00266 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE); 00267 $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('fooBar')); 00268 00269 $mockController = $this->getAccessibleMock('Tx_Extbase_MVC_Controller_ActionController', array('otherBarAction'), array(), '', FALSE); 00270 $mockController->_set('request', $mockRequest); 00271 00272 $mockController->_call('resolveActionMethodName'); 00273 } 00274 00275 /** 00276 * @test 00277 * @author Robert Lemke <robert@typo3.org> 00278 */ 00279 public function initializeActionMethodArgumentsRegistersArgumentsFoundInTheSignatureOfTheCurrentActionMethod() { 00280 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE); 00281 00282 $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('addNewArgument', 'removeAll'), array(), '', FALSE); 00283 $mockArguments->expects($this->at(0))->method('addNewArgument')->with('stringArgument', 'string', TRUE); 00284 $mockArguments->expects($this->at(1))->method('addNewArgument')->with('integerArgument', 'integer', TRUE); 00285 $mockArguments->expects($this->at(2))->method('addNewArgument')->with('objectArgument', 'F3_Foo_Bar', TRUE); 00286 00287 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'evaluateDontValidateAnnotations'), array(), '', FALSE); 00288 00289 $methodParameters = array( 00290 'stringArgument' => array( 00291 'position' => 0, 00292 'byReference' => FALSE, 00293 'array' => FALSE, 00294 'optional' => FALSE, 00295 'allowsNull' => FALSE, 00296 'type' => 'string' 00297 ), 00298 'integerArgument' => array( 00299 'position' => 1, 00300 'byReference' => FALSE, 00301 'array' => FALSE, 00302 'optional' => FALSE, 00303 'allowsNull' => FALSE, 00304 'type' => 'integer' 00305 ), 00306 'objectArgument' => array( 00307 'position' => 2, 00308 'byReference' => FALSE, 00309 'array' => FALSE, 00310 'optional' => FALSE, 00311 'allowsNull' => FALSE, 00312 'type' => 'F3_Foo_Bar' 00313 ) 00314 ); 00315 00316 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE); 00317 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters)); 00318 00319 $mockController->injectReflectionService($mockReflectionService); 00320 $mockController->_set('request', $mockRequest); 00321 $mockController->_set('arguments', $mockArguments); 00322 $mockController->_set('actionMethodName', 'fooAction'); 00323 $mockController->_call('initializeActionMethodArguments'); 00324 } 00325 00326 /** 00327 * @test 00328 * @author Robert Lemke <robert@typo3.org> 00329 */ 00330 public function initializeActionMethodArgumentsRegistersOptionalArgumentsAsSuch() { 00331 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE); 00332 00333 $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array(), array(), '', FALSE); 00334 $mockArguments->expects($this->at(0))->method('addNewArgument')->with('arg1', 'string', TRUE); 00335 $mockArguments->expects($this->at(1))->method('addNewArgument')->with('arg2', 'array', FALSE, array(21)); 00336 $mockArguments->expects($this->at(2))->method('addNewArgument')->with('arg3', 'string', FALSE, 42); 00337 00338 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'evaluateDontValidateAnnotations'), array(), '', FALSE); 00339 00340 $methodParameters = array( 00341 'arg1' => array( 00342 'position' => 0, 00343 'byReference' => FALSE, 00344 'array' => FALSE, 00345 'optional' => FALSE, 00346 'allowsNull' => FALSE, 00347 'type' => 'string' 00348 ), 00349 'arg2' => array( 00350 'position' => 1, 00351 'byReference' => FALSE, 00352 'array' => TRUE, 00353 'optional' => TRUE, 00354 'defaultValue' => array(21), 00355 'allowsNull' => FALSE 00356 ), 00357 'arg3' => array( 00358 'position' => 2, 00359 'byReference' => FALSE, 00360 'array' => FALSE, 00361 'optional' => TRUE, 00362 'defaultValue' => 42, 00363 'allowsNull' => FALSE, 00364 'type' => 'string' 00365 ) 00366 ); 00367 00368 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE); 00369 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters)); 00370 00371 $mockController->injectReflectionService($mockReflectionService); 00372 $mockController->_set('request', $mockRequest); 00373 $mockController->_set('arguments', $mockArguments); 00374 $mockController->_set('actionMethodName', 'fooAction'); 00375 $mockController->_call('initializeActionMethodArguments'); 00376 } 00377 00378 /** 00379 * @test 00380 * @author Sebastian Kurfürst <sbastian@typo3.org> 00381 * @expectedException Tx_Extbase_MVC_Exception_InvalidArgumentType 00382 */ 00383 public function initializeActionMethodArgumentsThrowsExceptionIfDataTypeWasNotSpecified() { 00384 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE); 00385 00386 $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array(), array(), '', FALSE); 00387 00388 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction'), array(), '', FALSE); 00389 00390 $methodParameters = array( 00391 'arg1' => array( 00392 'position' => 0, 00393 'byReference' => FALSE, 00394 'array' => FALSE, 00395 'optional' => FALSE, 00396 'allowsNull' => FALSE, 00397 ) 00398 ); 00399 00400 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE); 00401 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters)); 00402 00403 $mockController->injectReflectionService($mockReflectionService); 00404 $mockController->_set('request', $mockRequest); 00405 $mockController->_set('arguments', $mockArguments); 00406 $mockController->_set('actionMethodName', 'fooAction'); 00407 $mockController->_call('initializeActionMethodArguments'); 00408 } 00409 00410 /** 00411 * @test 00412 * @author Sebastian Kurfürst <sbastian@typo3.org> 00413 */ 00414 public function initializeActionMethodValidatorsCorrectlyRegistersValidatorsBasedOnDataType() { 00415 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction'), array(), '', FALSE); 00416 00417 $argument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE); 00418 $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1')); 00419 00420 $arguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('dummy'), array(), '', FALSE); 00421 $arguments->addArgument($argument); 00422 00423 $methodTagsValues = array( 00424 00425 ); 00426 00427 $methodArgumentsValidatorConjunctions = array(); 00428 $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE); 00429 00430 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE); 00431 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues)); 00432 00433 $mockValidatorResolver = $this->getMock('Tx_Extbase_Validation_ValidatorResolver', array(), array(), '', FALSE); 00434 $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions)); 00435 00436 $mockController->injectReflectionService($mockReflectionService); 00437 $mockController->injectValidatorResolver($mockValidatorResolver); 00438 $mockController->_set('arguments', $arguments); 00439 $mockController->_set('actionMethodName', 'fooAction'); 00440 $mockController->_call('initializeActionMethodValidators'); 00441 00442 $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator()); 00443 } 00444 00445 /** 00446 * @test 00447 * @author Sebastian Kurfürst <sbastian@typo3.org> 00448 */ 00449 public function initializeActionMethodValidatorsRegistersModelBasedValidators() { 00450 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction'), array(), '', FALSE); 00451 00452 $argument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getDataType'), array(), '', FALSE); 00453 $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1')); 00454 $argument->expects($this->any())->method('getDataType')->will($this->returnValue('F3_Foo_Quux')); 00455 00456 $arguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('dummy'), array(), '', FALSE); 00457 $arguments->addArgument($argument); 00458 00459 $methodTagsValues = array( 00460 00461 ); 00462 00463 $quuxBaseValidatorConjunction = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE); 00464 00465 $methodArgumentsValidatorConjunctions = array(); 00466 $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE); 00467 $methodArgumentsValidatorConjunctions['arg1']->expects($this->once())->method('addValidator')->with($quuxBaseValidatorConjunction); 00468 00469 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE); 00470 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues)); 00471 00472 $mockValidatorResolver = $this->getMock('Tx_Extbase_Validation_ValidatorResolver', array(), array(), '', FALSE); 00473 $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions)); 00474 $mockValidatorResolver->expects($this->once())->method('getBaseValidatorConjunction')->with('F3_Foo_Quux')->will($this->returnValue($quuxBaseValidatorConjunction)); 00475 00476 $mockController->injectReflectionService($mockReflectionService); 00477 $mockController->injectValidatorResolver($mockValidatorResolver); 00478 $mockController->_set('arguments', $arguments); 00479 $mockController->_set('actionMethodName', 'fooAction'); 00480 $mockController->_call('initializeActionMethodValidators'); 00481 00482 $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator()); 00483 } 00484 00485 /** 00486 * @test 00487 * @author Sebastian Kurfürst <sbastian@typo3.org> 00488 */ 00489 public function initializeActionMethodValidatorsDoesNotRegisterModelBasedValidatorsIfDontValidateAnnotationIsSet() { 00490 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction'), array(), '', FALSE); 00491 00492 $argument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getDataType'), array(), '', FALSE); 00493 $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1')); 00494 $argument->expects($this->any())->method('getDataType')->will($this->returnValue('F3_Foo_Quux')); 00495 00496 $arguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('dummy'), array(), '', FALSE); 00497 $arguments->addArgument($argument); 00498 00499 $methodTagsValues = array( 00500 'dontvalidate' => array( 00501 '$arg1' 00502 ) 00503 ); 00504 00505 $methodArgumentsValidatorConjunctions = array(); 00506 $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE); 00507 00508 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE); 00509 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues)); 00510 00511 $mockValidatorResolver = $this->getMock('Tx_Extbase_Validation_ValidatorResolver', array(), array(), '', FALSE); 00512 $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions)); 00513 $mockValidatorResolver->expects($this->any())->method('getBaseValidatorConjunction')->will($this->throwException(new Exception("This should not be called because the dontvalidate annotation is set."))); 00514 00515 $mockController->injectReflectionService($mockReflectionService); 00516 $mockController->injectValidatorResolver($mockValidatorResolver); 00517 $mockController->_set('arguments', $arguments); 00518 $mockController->_set('actionMethodName', 'fooAction'); 00519 $mockController->_call('initializeActionMethodValidators'); 00520 00521 $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator()); 00522 } 00523 00524 /** 00525 * @test 00526 * @author Christopher Hlubek <hlubek@networkteam.com> 00527 */ 00528 public function defaultErrorActionSetsArgumentMappingResultsErrorsInRequest() { 00529 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE); 00530 $mockFlashMessages = $this->getMock('Tx_Extbase_MVC_Controller_FlashMessages', array(), array(), '', FALSE); 00531 00532 $mockError = $this->getMock('Tx_Extbase_Error_Error', array('getMessage'), array(), '', FALSE); 00533 $mockArgumentsMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array('getErrors', 'getWarnings'), array(), '', FALSE); 00534 $mockArgumentsMappingResults->expects($this->atLeastOnce())->method('getErrors')->will($this->returnValue(array($mockError))); 00535 $mockArgumentsMappingResults->expects($this->any())->method('getWarnings')->will($this->returnValue(array())); 00536 00537 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('pushFlashMessage', 'clearCacheOnError'), array(), '', FALSE); 00538 $mockController->_set('request', $mockRequest); 00539 $mockController->_set('flashMessages', $mockFlashMessages); 00540 $mockController->_set('argumentsMappingResults', $mockArgumentsMappingResults); 00541 00542 $mockRequest->expects($this->once())->method('setErrors')->with(array($mockError)); 00543 00544 $mockController->_call('errorAction'); 00545 } 00546 00547 /** 00548 * @test 00549 * @author Christopher Hlubek <hlubek@networkteam.com> 00550 */ 00551 public function defaultErrorActionCallsGetErrorFlashMessageAndPutsFlashMessage() { 00552 $this->markTestIncomplete('To be implemented'); 00553 } 00554 00555 /** 00556 * Data Provider for checkRequestHashDoesNotThrowExceptionInNormalOperations 00557 */ 00558 public function checkRequestHashInNormalOperation() { 00559 return array( 00560 // HMAC is verified 00561 array(TRUE), 00562 // HMAC not verified, but objects are directly fetched from persistence layer 00563 array(FALSE, FALSE, Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE, Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE), 00564 // HMAC not verified, objects new and modified, but dontverifyrequesthash-annotation set 00565 array(FALSE, TRUE, Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE, Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE_AND_MODIFIED, array('dontverifyrequesthash' => '')) 00566 ); 00567 } 00568 00569 /** 00570 * @test 00571 * @author Sebastian Kurfürst <sebastian@typo3.org> 00572 * @dataProvider checkRequestHashInNormalOperation 00573 */ 00574 public function checkRequestHashDoesNotThrowExceptionInNormalOperations($hmacVerified, $reflectionServiceNeedsInitialization = FALSE, $argument1Origin = 3, $argument2Origin = 3, $methodTagsValues = array()) { 00575 $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request', array('isHmacVerified'), array(), '', FALSE); 00576 $mockRequest->expects($this->once())->method('isHmacVerified')->will($this->returnValue($hmacVerified)); 00577 00578 $argument1 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getOrigin'), array(), '', FALSE); 00579 $argument1->expects($this->any())->method('getOrigin')->will($this->returnValue($argument1Origin)); 00580 $argument2 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getOrigin'), array(), '', FALSE); 00581 $argument2->expects($this->any())->method('getOrigin')->will($this->returnValue($argument2Origin)); 00582 00583 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('dummy'), array(), '', FALSE); 00584 00585 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array('getMethodTagsValues'), array(), '', FALSE); 00586 if ($reflectionServiceNeedsInitialization) { 00587 // Somehow this is needed, else I get "Mocked method does not exist." 00588 $mockReflectionService->expects($this->any())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues)); 00589 } 00590 $mockController->_set('arguments', array($argument1, $argument2)); 00591 $mockController->_set('request', $mockRequest); 00592 $mockController->_set('actionMethodName', 'fooAction'); 00593 $mockController->injectReflectionService($mockReflectionService); 00594 00595 $mockController->_call('checkRequestHash'); 00596 } 00597 00598 /** 00599 * @test 00600 * @expectedException Tx_Extbase_MVC_Exception_InvalidOrNoRequestHash 00601 * @author Sebastian Kurfürst <sebastian@typo3.org> 00602 */ 00603 public function checkRequestHashThrowsExceptionIfNeeded() { 00604 // $this->markTestIncomplete('To be implemented'); 00605 $hmacVerified = FALSE; 00606 $argument1Origin = Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE_AND_MODIFIED; 00607 $argument2Origin = Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE; 00608 $methodTagsValues = array(); 00609 00610 $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request', array('isHmacVerified'), array(), '', FALSE); 00611 $mockRequest->expects($this->once())->method('isHmacVerified')->will($this->returnValue($hmacVerified)); 00612 00613 $argument1 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getOrigin'), array(), '', FALSE); 00614 $argument1->expects($this->any())->method('getOrigin')->will($this->returnValue($argument1Origin)); 00615 $argument2 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getOrigin'), array(), '', FALSE); 00616 $argument2->expects($this->any())->method('getOrigin')->will($this->returnValue($argument2Origin)); 00617 00618 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('dummy'), array(), '', FALSE); 00619 00620 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array('getMethodTagsValues'), array(), '', FALSE); 00621 $mockReflectionService->expects($this->any())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues)); 00622 00623 $mockController->_set('arguments', array($argument1, $argument2)); 00624 $mockController->_set('request', $mockRequest); 00625 $mockController->_set('actionMethodName', 'fooAction'); 00626 $mockController->injectReflectionService($mockReflectionService); 00627 00628 $mockController->_call('checkRequestHash'); 00629 } 00630 00631 } 00632 ?>
1.8.0