Raised DBAL version from 1.1.5 to 1.1.6
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / MVC / Controller / ActionController_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 class Tx_Extbase_MVC_Controller_ActionController_testcase extends Tx_Extbase_BaseTestCase {
29
30 /**
31 * @test
32 * @author Robert Lemke <robert@typo3.org>
33 */
34 public function processRequestSticksToSpecifiedSequence() {
35 $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request', array(), array(), '', FALSE);
36 $mockRequest->expects($this->once())->method('setDispatched')->with(TRUE);
37
38 $mockResponse = $this->getMock('Tx_Extbase_MVC_Web_Response', array(), array(), '', FALSE);
39
40 $mockView = $this->getMock('Tx_Extbase_MVC_View_ViewInterface');
41
42 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array(
43 'initializeFooAction', 'initializeAction', 'resolveActionMethodName', 'initializeActionMethodArguments', 'initializeActionMethodValidators', 'mapRequestArgumentsToControllerArguments', 'resolveView', 'initializeView', 'callActionMethod', 'checkRequestHash'),
44 array(), '', FALSE);
45 $mockController->_set('objectFactory', $mockObjectFactory);
46 $mockController->expects($this->at(0))->method('resolveActionMethodName')->will($this->returnValue('fooAction'));
47 $mockController->expects($this->at(1))->method('initializeActionMethodArguments');
48 $mockController->expects($this->at(2))->method('initializeActionMethodValidators');
49 $mockController->expects($this->at(3))->method('initializeAction');
50 $mockController->expects($this->at(4))->method('initializeFooAction');
51 $mockController->expects($this->at(5))->method('mapRequestArgumentsToControllerArguments');
52 $mockController->expects($this->at(6))->method('checkRequestHash');
53 $mockController->expects($this->at(7))->method('resolveView')->will($this->returnValue($mockView));
54 $mockController->expects($this->at(8))->method('initializeView');
55 $mockController->expects($this->at(9))->method('callActionMethod');
56
57 $mockController->processRequest($mockRequest, $mockResponse);
58 $this->assertSame($mockRequest, $mockController->_get('request'));
59 $this->assertSame($mockResponse, $mockController->_get('response'));
60 }
61
62 /**
63 * @test
64 * @author Robert Lemke <robert@typo3.org>
65 */
66 public function callActionMethodAppendsStringsReturnedByActionMethodToTheResponseObject() {
67 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
68
69 $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface', array(), array(), '', FALSE);
70 $mockResponse->expects($this->once())->method('appendContent')->with('the returned string');
71
72 $mockArguments = new ArrayObject;
73
74 $mockArgumentMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE);
75 $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE));
76
77 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'initializeAction'), array(), '', FALSE);
78 $mockController->expects($this->once())->method('fooAction')->will($this->returnValue('the returned string'));
79 $mockController->_set('request', $mockRequest);
80 $mockController->_set('response', $mockResponse);
81 $mockController->_set('arguments', $mockArguments);
82 $mockController->_set('actionMethodName', 'fooAction');
83 $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
84 $mockController->_call('callActionMethod');
85 }
86
87 /**
88 * @test
89 * @author Robert Lemke <robert@typo3.org>
90 */
91 public function callActionMethodRendersTheViewAutomaticallyIfTheActionReturnedNullAndAViewExists() {
92 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
93
94 $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface', array(), array(), '', FALSE);
95 $mockResponse->expects($this->once())->method('appendContent')->with('the view output');
96
97 $mockView = $this->getMock('Tx_Extbase_MVC_View_ViewInterface');
98 $mockView->expects($this->once())->method('render')->will($this->returnValue('the view output'));
99
100 $mockArguments = new ArrayObject;
101
102 $mockArgumentMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE);
103 $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE));
104
105 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'initializeAction'), array(), '', FALSE);
106 $mockController->expects($this->once())->method('fooAction');
107 $mockController->_set('request', $mockRequest);
108 $mockController->_set('response', $mockResponse);
109 $mockController->_set('arguments', $mockArguments);
110 $mockController->_set('actionMethodName', 'fooAction');
111 $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
112 $mockController->_set('view', $mockView);
113 $mockController->_call('callActionMethod');
114 }
115
116 /**
117 * @test
118 * @author Robert Lemke <robert@typo3.org>
119 */
120 public function callActionMethodCallsTheErrorActionIfTheMappingResultsHaveErrors() {
121 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
122
123 $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface', array(), array(), '', FALSE);
124 $mockResponse->expects($this->once())->method('appendContent')->with('the returned string');
125
126 $mockArguments = new ArrayObject;
127
128 $mockArgumentMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE);
129 $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(TRUE));
130
131 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('barAction', 'initializeAction'), array(), '', FALSE);
132 $mockController->expects($this->once())->method('barAction')->will($this->returnValue('the returned string'));
133 $mockController->_set('request', $mockRequest);
134 $mockController->_set('response', $mockResponse);
135 $mockController->_set('arguments', $mockArguments);
136 $mockController->_set('actionMethodName', 'fooAction');
137 $mockController->_set('errorMethodName', 'barAction');
138 $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
139 $mockController->_call('callActionMethod');
140 }
141
142 /**
143 * @test
144 * @author Sebastian Kurfürst <sebastian@typo3.org>
145 */
146 public function callActionMethodPassesDefaultValuesAsArguments() {
147 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
148
149 $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface', array(), array(), '', FALSE);
150
151 $arguments = new ArrayObject();
152 $optionalArgument = new Tx_Extbase_MVC_Controller_Argument('name1', 'Text');
153 $optionalArgument->setDefaultValue('Default value');
154 $arguments[] = $optionalArgument;
155
156 $mockArgumentMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE);
157 $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE));
158
159 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'initializeAction'), array(), '', FALSE);
160 $mockController->expects($this->once())->method('fooAction')->with('Default value');
161 $mockController->_set('request', $mockRequest);
162 $mockController->_set('response', $mockResponse);
163 $mockController->_set('arguments', $arguments);
164 $mockController->_set('actionMethodName', 'fooAction');
165 $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
166 $mockController->_call('callActionMethod');
167 }
168
169 /**
170 * @test
171 * @author Karsten Dambekalns <karsten@typo3.org>
172 */
173 public function resolveViewUsesFluidTemplateViewIfTemplateIsAvailable() {
174 $mockSession = $this->getMock('Tx_Extbase_Session_SessionInterface');
175 $mockControllerContext = $this->getMock('Tx_Extbase_MVC_Controller_ControllerContext', array(), array(), '', FALSE);
176
177 $mockFluidTemplateView = $this->getMock('Tx_Extbase_MVC_View_ViewInterface', array('setControllerContext', 'getViewHelper', 'assign', 'assignMultiple', 'render', 'hasTemplate', 'initializeView'));
178 $mockFluidTemplateView->expects($this->once())->method('setControllerContext')->with($mockControllerContext);
179 $mockFluidTemplateView->expects($this->once())->method('hasTemplate')->will($this->returnValue(TRUE));
180
181 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ManagerInterface', array(), array(), '', FALSE);
182 $mockObjectManager->expects($this->at(0))->method('getObject')->with('Tx_Fluid_View_TemplateView')->will($this->returnValue($mockFluidTemplateView));
183
184 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('buildControllerContext'), array(), '', FALSE);
185 $mockController->expects($this->once())->method('buildControllerContext')->will($this->returnValue($mockControllerContext));
186 $mockController->_set('session', $mockSession);
187 $mockController->_set('objectManager', $mockObjectManager);
188
189 $this->assertSame($mockFluidTemplateView, $mockController->_call('resolveView'));
190 }
191
192 /**
193 * @test
194 * @author Bastian Waidelich <bastian@typo3.org>
195 */
196 public function resolveViewObjectNameUsesViewObjectNamePatternToResolveViewObjectName() {
197 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
198 $mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('MyPackage'));
199 $mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('MyController'));
200 $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('MyAction'));
201 $mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('MyFormat'));
202
203 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ManagerInterface', array(), array(), '', FALSE);
204
205 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('dummy'), array(), '', FALSE);
206 $mockController->_set('request', $mockRequest);
207 $mockController->_set('objectManager', $mockObjectManager);
208 $mockController->_set('viewObjectNamePattern', 'RandomViewObjectPattern_@package_@controller_@action_@format');
209
210 $mockController->_call('resolveViewObjectName');
211 }
212
213 /**
214 * @test
215 * @author Robert Lemke <robert@typo3.org>
216 */
217 public function initializeActionMethodArgumentsRegistersArgumentsFoundInTheSignatureOfTheCurrentActionMethod() {
218 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
219
220 $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('addNewArgument', 'removeAll'), array(), '', FALSE);
221 $mockArguments->expects($this->at(0))->method('addNewArgument')->with('stringArgument', 'string', TRUE);
222 $mockArguments->expects($this->at(1))->method('addNewArgument')->with('integerArgument', 'integer', TRUE);
223 $mockArguments->expects($this->at(2))->method('addNewArgument')->with('objectArgument', 'F3_Foo_Bar', TRUE);
224
225 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'evaluateDontValidateAnnotations'), array(), '', FALSE);
226
227 $methodParameters = array(
228 'stringArgument' => array(
229 'position' => 0,
230 'byReference' => FALSE,
231 'array' => FALSE,
232 'optional' => FALSE,
233 'allowsNull' => FALSE,
234 'type' => 'string'
235 ),
236 'integerArgument' => array(
237 'position' => 1,
238 'byReference' => FALSE,
239 'array' => FALSE,
240 'optional' => FALSE,
241 'allowsNull' => FALSE,
242 'type' => 'integer'
243 ),
244 'objectArgument' => array(
245 'position' => 2,
246 'byReference' => FALSE,
247 'array' => FALSE,
248 'optional' => FALSE,
249 'allowsNull' => FALSE,
250 'type' => 'F3_Foo_Bar'
251 )
252 );
253
254 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
255 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
256
257 $mockController->injectReflectionService($mockReflectionService);
258 $mockController->_set('request', $mockRequest);
259 $mockController->_set('arguments', $mockArguments);
260 $mockController->_set('actionMethodName', 'fooAction');
261 $mockController->_call('initializeActionMethodArguments');
262 }
263
264 /**
265 * @test
266 * @author Robert Lemke <robert@typo3.org>
267 */
268 public function initializeActionMethodArgumentsRegistersOptionalArgumentsAsSuch() {
269 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
270
271 $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array(), array(), '', FALSE);
272 $mockArguments->expects($this->at(0))->method('addNewArgument')->with('arg1', 'string', TRUE);
273 $mockArguments->expects($this->at(1))->method('addNewArgument')->with('arg2', 'array', FALSE, array(21));
274 $mockArguments->expects($this->at(2))->method('addNewArgument')->with('arg3', 'string', FALSE, 42);
275
276 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'evaluateDontValidateAnnotations'), array(), '', FALSE);
277
278 $methodParameters = array(
279 'arg1' => array(
280 'position' => 0,
281 'byReference' => FALSE,
282 'array' => FALSE,
283 'optional' => FALSE,
284 'allowsNull' => FALSE,
285 'type' => 'string'
286 ),
287 'arg2' => array(
288 'position' => 1,
289 'byReference' => FALSE,
290 'array' => TRUE,
291 'optional' => TRUE,
292 'defaultValue' => array(21),
293 'allowsNull' => FALSE
294 ),
295 'arg3' => array(
296 'position' => 2,
297 'byReference' => FALSE,
298 'array' => FALSE,
299 'optional' => TRUE,
300 'defaultValue' => 42,
301 'allowsNull' => FALSE,
302 'type' => 'string'
303 )
304 );
305
306 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
307 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
308
309 $mockController->injectReflectionService($mockReflectionService);
310 $mockController->_set('request', $mockRequest);
311 $mockController->_set('arguments', $mockArguments);
312 $mockController->_set('actionMethodName', 'fooAction');
313 $mockController->_call('initializeActionMethodArguments');
314 }
315
316 /**
317 * @test
318 * @author Sebastian Kurfürst <sbastian@typo3.org>
319 * @expectedException Tx_Extbase_MVC_Exception_InvalidArgumentType
320 */
321 public function initializeActionMethodArgumentsThrowsExceptionIfDataTypeWasNotSpecified() {
322 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
323
324 $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array(), array(), '', FALSE);
325
326 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction'), array(), '', FALSE);
327
328 $methodParameters = array(
329 'arg1' => array(
330 'position' => 0,
331 'byReference' => FALSE,
332 'array' => FALSE,
333 'optional' => FALSE,
334 'allowsNull' => FALSE,
335 )
336 );
337
338 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
339 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
340
341 $mockController->injectReflectionService($mockReflectionService);
342 $mockController->_set('request', $mockRequest);
343 $mockController->_set('arguments', $mockArguments);
344 $mockController->_set('actionMethodName', 'fooAction');
345 $mockController->_call('initializeActionMethodArguments');
346 }
347
348 /**
349 * @test
350 * @author Sebastian Kurfürst <sbastian@typo3.org>
351 */
352 public function initializeActionMethodValidatorsCorrectlyRegistersValidatorsBasedOnDataType() {
353 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction'), array(), '', FALSE);
354
355 $argument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
356 $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1'));
357
358 $arguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('dummy'), array(), '', FALSE);
359 $arguments->addArgument($argument);
360
361 $methodTagsValues = array(
362
363 );
364
365 $methodArgumentsValidatorConjunctions = array();
366 $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE);
367
368 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
369 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
370
371 $mockValidatorResolver = $this->getMock('Tx_Extbase_Validation_ValidatorResolver', array(), array(), '', FALSE);
372 $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions));
373
374 $mockController->injectReflectionService($mockReflectionService);
375 $mockController->injectValidatorResolver($mockValidatorResolver);
376 $mockController->_set('arguments', $arguments);
377 $mockController->_set('actionMethodName', 'fooAction');
378 $mockController->_call('initializeActionMethodValidators');
379
380 $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator());
381 }
382
383 /**
384 * @test
385 * @author Sebastian Kurfürst <sbastian@typo3.org>
386 */
387 public function initializeActionMethodValidatorsRegistersModelBasedValidators() {
388 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction'), array(), '', FALSE);
389
390 $argument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getDataType'), array(), '', FALSE);
391 $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1'));
392 $argument->expects($this->any())->method('getDataType')->will($this->returnValue('F3_Foo_Quux'));
393
394 $arguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('dummy'), array(), '', FALSE);
395 $arguments->addArgument($argument);
396
397 $methodTagsValues = array(
398
399 );
400
401 $quuxBaseValidatorConjunction = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE);
402
403 $methodArgumentsValidatorConjunctions = array();
404 $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE);
405 $methodArgumentsValidatorConjunctions['arg1']->expects($this->once())->method('addValidator')->with($quuxBaseValidatorConjunction);
406
407 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
408 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
409
410 $mockValidatorResolver = $this->getMock('Tx_Extbase_Validation_ValidatorResolver', array(), array(), '', FALSE);
411 $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions));
412 $mockValidatorResolver->expects($this->once())->method('getBaseValidatorConjunction')->with('F3_Foo_Quux')->will($this->returnValue($quuxBaseValidatorConjunction));
413
414 $mockController->injectReflectionService($mockReflectionService);
415 $mockController->injectValidatorResolver($mockValidatorResolver);
416 $mockController->_set('arguments', $arguments);
417 $mockController->_set('actionMethodName', 'fooAction');
418 $mockController->_call('initializeActionMethodValidators');
419
420 $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator());
421 }
422
423 /**
424 * @test
425 * @author Sebastian Kurfürst <sbastian@typo3.org>
426 */
427 public function initializeActionMethodValidatorsDoesNotRegisterModelBasedValidatorsIfDontValidateAnnotationIsSet() {
428 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction'), array(), '', FALSE);
429
430 $argument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getDataType'), array(), '', FALSE);
431 $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1'));
432 $argument->expects($this->any())->method('getDataType')->will($this->returnValue('F3_Foo_Quux'));
433
434 $arguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('dummy'), array(), '', FALSE);
435 $arguments->addArgument($argument);
436
437 $methodTagsValues = array(
438 'dontvalidate' => array(
439 '$arg1'
440 )
441 );
442
443 $methodArgumentsValidatorConjunctions = array();
444 $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE);
445
446 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
447 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
448
449 $mockValidatorResolver = $this->getMock('Tx_Extbase_Validation_ValidatorResolver', array(), array(), '', FALSE);
450 $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions));
451 $mockValidatorResolver->expects($this->any())->method('getBaseValidatorConjunction')->will($this->throwException(new Exception("This should not be called because the dontvalidate annotation is set.")));
452
453 $mockController->injectReflectionService($mockReflectionService);
454 $mockController->injectValidatorResolver($mockValidatorResolver);
455 $mockController->_set('arguments', $arguments);
456 $mockController->_set('actionMethodName', 'fooAction');
457 $mockController->_call('initializeActionMethodValidators');
458
459 $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator());
460 }
461
462 /**
463 * @test
464 * @author Christopher Hlubek <hlubek@networkteam.com>
465 */
466 public function defaultErrorActionSetsArgumentMappingResultsErrorsInRequest() {
467 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
468 $mockFlashMessages = $this->getMock('Tx_Extbase_MVC_Controller_FlashMessages', array(), array(), '', FALSE);
469
470 $mockError = $this->getMock('Tx_Extbase_Error_Error', array('getMessage'), array(), '', FALSE);
471 $mockArgumentsMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array('getErrors', 'getWarnings'), array(), '', FALSE);
472 $mockArgumentsMappingResults->expects($this->atLeastOnce())->method('getErrors')->will($this->returnValue(array($mockError)));
473 $mockArgumentsMappingResults->expects($this->any())->method('getWarnings')->will($this->returnValue(array()));
474
475 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('pushFlashMessage'), array(), '', FALSE);
476 $mockController->_set('request', $mockRequest);
477 $mockController->_set('flashMessages', $mockFlashMessages);
478 $mockController->_set('argumentsMappingResults', $mockArgumentsMappingResults);
479
480 $mockRequest->expects($this->once())->method('setErrors')->with(array($mockError));
481
482 $mockController->_call('errorAction');
483 }
484
485 /**
486 * @test
487 * @author Christopher Hlubek <hlubek@networkteam.com>
488 */
489 public function defaultErrorActionCallsGetErrorFlashMessageAndPutsFlashMessage() {
490 $this->markTestIncomplete('To be implemented');
491 }
492
493 /**
494 * Data Provider for checkRequestHashDoesNotThrowExceptionInNormalOperations
495 */
496 public function checkRequestHashInNormalOperation() {
497 return array(
498 // HMAC is verified
499 array(TRUE),
500 // HMAC not verified, but objects are directly fetched from persistence layer
501 array(FALSE, FALSE, Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE, Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE),
502 // HMAC not verified, objects new and modified, but dontverifyrequesthash-annotation set
503 array(FALSE, TRUE, Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE, Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE_AND_MODIFIED, array('dontverifyrequesthash' => ''))
504 );
505 }
506
507 /**
508 * @test
509 * @author Sebastian Kurfürst <sebastian@typo3.org>
510 * @dataProvider checkRequestHashInNormalOperation
511 */
512 public function checkRequestHashDoesNotThrowExceptionInNormalOperations($hmacVerified, $reflectionServiceNeedsInitialization = FALSE, $argument1Origin = 3, $argument2Origin = 3, $methodTagsValues = array()) {
513 $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request', array('isHmacVerified'), array(), '', FALSE);
514 $mockRequest->expects($this->once())->method('isHmacVerified')->will($this->returnValue($hmacVerified));
515
516 $argument1 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getOrigin'), array(), '', FALSE);
517 $argument1->expects($this->any())->method('getOrigin')->will($this->returnValue($argument1Origin));
518 $argument2 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getOrigin'), array(), '', FALSE);
519 $argument2->expects($this->any())->method('getOrigin')->will($this->returnValue($argument2Origin));
520
521 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('dummy'), array(), '', FALSE);
522
523 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array('getMethodTagsValues'), array(), '', FALSE);
524 if ($reflectionServiceNeedsInitialization) {
525 // Somehow this is needed, else I get "Mocked method does not exist."
526 $mockReflectionService->expects($this->any())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
527 }
528 $mockController->_set('arguments', array($argument1, $argument2));
529 $mockController->_set('request', $mockRequest);
530 $mockController->_set('actionMethodName', 'fooAction');
531 $mockController->injectReflectionService($mockReflectionService);
532
533 $mockController->_call('checkRequestHash');
534 }
535
536 /**
537 * @test
538 * @expectedException Tx_Extbase_MVC_Exception_InvalidOrNoRequestHash
539 * @author Sebastian Kurfürst <sebastian@typo3.org>
540 */
541 public function checkRequestHashThrowsExceptionIfNeeded() {
542 // $this->markTestIncomplete('To be implemented');
543 $hmacVerified = FALSE;
544 $argument1Origin = Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE_AND_MODIFIED;
545 $argument2Origin = Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE;
546 $methodTagsValues = array();
547
548 $mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request', array('isHmacVerified'), array(), '', FALSE);
549 $mockRequest->expects($this->once())->method('isHmacVerified')->will($this->returnValue($hmacVerified));
550
551 $argument1 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getOrigin'), array(), '', FALSE);
552 $argument1->expects($this->any())->method('getOrigin')->will($this->returnValue($argument1Origin));
553 $argument2 = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getOrigin'), array(), '', FALSE);
554 $argument2->expects($this->any())->method('getOrigin')->will($this->returnValue($argument2Origin));
555
556 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('dummy'), array(), '', FALSE);
557
558 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array('getMethodTagsValues'), array(), '', FALSE);
559 $mockReflectionService->expects($this->any())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
560
561 $mockController->_set('arguments', array($argument1, $argument2));
562 $mockController->_set('request', $mockRequest);
563 $mockController->_set('actionMethodName', 'fooAction');
564 $mockController->injectReflectionService($mockReflectionService);
565
566 $mockController->_call('checkRequestHash');
567 }
568
569 }
570 ?>