[~CONFIGURATION] Extbase: Set lockType to empty string instead of 'system'.
[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'),
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('resolveView')->will($this->returnValue($mockView));
53 $mockController->expects($this->at(7))->method('initializeView');
54 $mockController->expects($this->at(8))->method('callActionMethod');
55
56 $mockController->processRequest($mockRequest, $mockResponse);
57 $this->assertSame($mockRequest, $mockController->_get('request'));
58 $this->assertSame($mockResponse, $mockController->_get('response'));
59 }
60
61 /**
62 * @test
63 * @author Robert Lemke <robert@typo3.org>
64 */
65 public function callActionMethodAppendsStringsReturnedByActionMethodToTheResponseObject() {
66 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
67
68 $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface', array(), array(), '', FALSE);
69 $mockResponse->expects($this->once())->method('appendContent')->with('the returned string');
70
71 $mockArguments = new ArrayObject;
72
73 $mockArgumentMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE);
74 $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE));
75
76 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'initializeAction'), array(), '', FALSE);
77 $mockController->expects($this->once())->method('fooAction')->will($this->returnValue('the returned string'));
78 $mockController->_set('request', $mockRequest);
79 $mockController->_set('response', $mockResponse);
80 $mockController->_set('arguments', $mockArguments);
81 $mockController->_set('actionMethodName', 'fooAction');
82 $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
83 $mockController->_call('callActionMethod');
84 }
85
86 /**
87 * @test
88 * @author Robert Lemke <robert@typo3.org>
89 */
90 public function callActionMethodRendersTheViewAutomaticallyIfTheActionReturnedNullAndAViewExists() {
91 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
92
93 $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface', array(), array(), '', FALSE);
94 $mockResponse->expects($this->once())->method('appendContent')->with('the view output');
95
96 $mockView = $this->getMock('Tx_Extbase_MVC_View_ViewInterface');
97 $mockView->expects($this->once())->method('render')->will($this->returnValue('the view output'));
98
99 $mockArguments = new ArrayObject;
100
101 $mockArgumentMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE);
102 $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE));
103
104 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'initializeAction'), array(), '', FALSE);
105 $mockController->expects($this->once())->method('fooAction');
106 $mockController->_set('request', $mockRequest);
107 $mockController->_set('response', $mockResponse);
108 $mockController->_set('arguments', $mockArguments);
109 $mockController->_set('actionMethodName', 'fooAction');
110 $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
111 $mockController->_set('view', $mockView);
112 $mockController->_call('callActionMethod');
113 }
114
115 /**
116 * @test
117 * @author Robert Lemke <robert@typo3.org>
118 */
119 public function callActionMethodCallsTheErrorActionIfTheMappingResultsHaveErrors() {
120 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
121
122 $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface', array(), array(), '', FALSE);
123 $mockResponse->expects($this->once())->method('appendContent')->with('the returned string');
124
125 $mockArguments = new ArrayObject;
126
127 $mockArgumentMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE);
128 $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(TRUE));
129
130 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('barAction', 'initializeAction'), array(), '', FALSE);
131 $mockController->expects($this->once())->method('barAction')->will($this->returnValue('the returned string'));
132 $mockController->_set('request', $mockRequest);
133 $mockController->_set('response', $mockResponse);
134 $mockController->_set('arguments', $mockArguments);
135 $mockController->_set('actionMethodName', 'fooAction');
136 $mockController->_set('errorMethodName', 'barAction');
137 $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
138 $mockController->_call('callActionMethod');
139 }
140
141 /**
142 * @test
143 * @author Sebastian Kurfürst <sebastian@typo3.org>
144 */
145 public function callActionMethodPassesDefaultValuesAsArguments() {
146 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
147
148 $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface', array(), array(), '', FALSE);
149
150 $arguments = new ArrayObject();
151 $optionalArgument = new Tx_Extbase_MVC_Controller_Argument('name1', 'Text');
152 $optionalArgument->setDefaultValue('Default value');
153 $arguments[] = $optionalArgument;
154
155 $mockArgumentMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE);
156 $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE));
157
158 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'initializeAction'), array(), '', FALSE);
159 $mockController->expects($this->once())->method('fooAction')->with('Default value');
160 $mockController->_set('request', $mockRequest);
161 $mockController->_set('response', $mockResponse);
162 $mockController->_set('arguments', $arguments);
163 $mockController->_set('actionMethodName', 'fooAction');
164 $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
165 $mockController->_call('callActionMethod');
166 }
167
168 /**
169 * @test
170 * @author Karsten Dambekalns <karsten@typo3.org>
171 */
172 public function resolveViewUsesFluidTemplateViewIfTemplateIsAvailable() {
173 $mockSession = $this->getMock('Tx_Extbase_Session_SessionInterface');
174 $mockControllerContext = $this->getMock('Tx_Extbase_MVC_Controller_ControllerContext', array(), array(), '', FALSE);
175
176 $mockFluidTemplateView = $this->getMock('Tx_Extbase_MVC_View_ViewInterface', array('setControllerContext', 'getViewHelper', 'assign', 'assignMultiple', 'render', 'hasTemplate', 'initializeView'));
177 $mockFluidTemplateView->expects($this->once())->method('setControllerContext')->with($mockControllerContext);
178 $mockFluidTemplateView->expects($this->once())->method('hasTemplate')->will($this->returnValue(TRUE));
179
180 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ManagerInterface', array(), array(), '', FALSE);
181 $mockObjectManager->expects($this->at(0))->method('getObject')->with('Tx_Fluid_View_TemplateView')->will($this->returnValue($mockFluidTemplateView));
182
183 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('buildControllerContext'), array(), '', FALSE);
184 $mockController->expects($this->once())->method('buildControllerContext')->will($this->returnValue($mockControllerContext));
185 $mockController->_set('session', $mockSession);
186 $mockController->_set('objectManager', $mockObjectManager);
187
188 $this->assertSame($mockFluidTemplateView, $mockController->_call('resolveView'));
189 }
190
191 /**
192 * @test
193 * @author Bastian Waidelich <bastian@typo3.org>
194 */
195 public function resolveViewObjectNameUsesViewObjectNamePatternToResolveViewObjectName() {
196 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
197 $mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('MyPackage'));
198 $mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('MyController'));
199 $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('MyAction'));
200 $mockRequest->expects($this->once())->method('getFormat')->will($this->returnValue('MyFormat'));
201
202 $mockObjectManager = $this->getMock('Tx_Extbase_Object_ManagerInterface', array(), array(), '', FALSE);
203
204 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('dummy'), array(), '', FALSE);
205 $mockController->_set('request', $mockRequest);
206 $mockController->_set('objectManager', $mockObjectManager);
207 $mockController->_set('viewObjectNamePattern', 'RandomViewObjectPattern_@package_@controller_@action_@format');
208
209 $mockController->_call('resolveViewObjectName');
210 }
211
212 /**
213 * @test
214 * @author Robert Lemke <robert@typo3.org>
215 */
216 public function initializeActionMethodArgumentsRegistersArgumentsFoundInTheSignatureOfTheCurrentActionMethod() {
217 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
218
219 $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('addNewArgument', 'removeAll'), array(), '', FALSE);
220 $mockArguments->expects($this->at(0))->method('addNewArgument')->with('stringArgument', 'string', TRUE);
221 $mockArguments->expects($this->at(1))->method('addNewArgument')->with('integerArgument', 'integer', TRUE);
222 $mockArguments->expects($this->at(2))->method('addNewArgument')->with('objectArgument', 'F3_Foo_Bar', TRUE);
223
224 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'evaluateDontValidateAnnotations'), array(), '', FALSE);
225
226 $methodParameters = array(
227 'stringArgument' => array(
228 'position' => 0,
229 'byReference' => FALSE,
230 'array' => FALSE,
231 'optional' => FALSE,
232 'allowsNull' => FALSE,
233 'type' => 'string'
234 ),
235 'integerArgument' => array(
236 'position' => 1,
237 'byReference' => FALSE,
238 'array' => FALSE,
239 'optional' => FALSE,
240 'allowsNull' => FALSE,
241 'type' => 'integer'
242 ),
243 'objectArgument' => array(
244 'position' => 2,
245 'byReference' => FALSE,
246 'array' => FALSE,
247 'optional' => FALSE,
248 'allowsNull' => FALSE,
249 'type' => 'F3_Foo_Bar'
250 )
251 );
252
253 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
254 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
255
256 $mockController->injectReflectionService($mockReflectionService);
257 $mockController->_set('request', $mockRequest);
258 $mockController->_set('arguments', $mockArguments);
259 $mockController->_set('actionMethodName', 'fooAction');
260 $mockController->_call('initializeActionMethodArguments');
261 }
262
263 /**
264 * @test
265 * @author Robert Lemke <robert@typo3.org>
266 */
267 public function initializeActionMethodArgumentsRegistersOptionalArgumentsAsSuch() {
268 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
269
270 $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array(), array(), '', FALSE);
271 $mockArguments->expects($this->at(0))->method('addNewArgument')->with('arg1', 'string', TRUE);
272 $mockArguments->expects($this->at(1))->method('addNewArgument')->with('arg2', 'array', FALSE, array(21));
273 $mockArguments->expects($this->at(2))->method('addNewArgument')->with('arg3', 'string', FALSE, 42);
274
275 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction', 'evaluateDontValidateAnnotations'), array(), '', FALSE);
276
277 $methodParameters = array(
278 'arg1' => array(
279 'position' => 0,
280 'byReference' => FALSE,
281 'array' => FALSE,
282 'optional' => FALSE,
283 'allowsNull' => FALSE,
284 'type' => 'string'
285 ),
286 'arg2' => array(
287 'position' => 1,
288 'byReference' => FALSE,
289 'array' => TRUE,
290 'optional' => TRUE,
291 'defaultValue' => array(21),
292 'allowsNull' => FALSE
293 ),
294 'arg3' => array(
295 'position' => 2,
296 'byReference' => FALSE,
297 'array' => FALSE,
298 'optional' => TRUE,
299 'defaultValue' => 42,
300 'allowsNull' => FALSE,
301 'type' => 'string'
302 )
303 );
304
305 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
306 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
307
308 $mockController->injectReflectionService($mockReflectionService);
309 $mockController->_set('request', $mockRequest);
310 $mockController->_set('arguments', $mockArguments);
311 $mockController->_set('actionMethodName', 'fooAction');
312 $mockController->_call('initializeActionMethodArguments');
313 }
314
315 /**
316 * @test
317 * @author Sebastian Kurfürst <sbastian@typo3.org>
318 * @expectedException Tx_Extbase_MVC_Exception_InvalidArgumentType
319 */
320 public function initializeActionMethodArgumentsThrowsExceptionIfDataTypeWasNotSpecified() {
321 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
322
323 $mockArguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array(), array(), '', FALSE);
324
325 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction'), array(), '', FALSE);
326
327 $methodParameters = array(
328 'arg1' => array(
329 'position' => 0,
330 'byReference' => FALSE,
331 'array' => FALSE,
332 'optional' => FALSE,
333 'allowsNull' => FALSE,
334 )
335 );
336
337 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
338 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
339
340 $mockController->injectReflectionService($mockReflectionService);
341 $mockController->_set('request', $mockRequest);
342 $mockController->_set('arguments', $mockArguments);
343 $mockController->_set('actionMethodName', 'fooAction');
344 $mockController->_call('initializeActionMethodArguments');
345 }
346
347 /**
348 * @test
349 * @author Sebastian Kurfürst <sbastian@typo3.org>
350 */
351 public function initializeActionMethodValidatorsCorrectlyRegistersValidatorsBasedOnDataType() {
352 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction'), array(), '', FALSE);
353
354 $argument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName'), array(), '', FALSE);
355 $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1'));
356
357 $arguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('dummy'), array(), '', FALSE);
358 $arguments->addArgument($argument);
359
360 $methodTagsValues = array(
361
362 );
363
364 $methodArgumentsValidatorConjunctions = array();
365 $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE);
366
367 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
368 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
369
370 $mockValidatorResolver = $this->getMock('Tx_Extbase_Validation_ValidatorResolver', array(), array(), '', FALSE);
371 $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions));
372
373 $mockController->injectReflectionService($mockReflectionService);
374 $mockController->injectValidatorResolver($mockValidatorResolver);
375 $mockController->_set('arguments', $arguments);
376 $mockController->_set('actionMethodName', 'fooAction');
377 $mockController->_call('initializeActionMethodValidators');
378
379 $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator());
380 }
381
382 /**
383 * @test
384 * @author Sebastian Kurfürst <sbastian@typo3.org>
385 */
386 public function initializeActionMethodValidatorsRegistersModelBasedValidators() {
387 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction'), array(), '', FALSE);
388
389 $argument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getDataType'), array(), '', FALSE);
390 $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1'));
391 $argument->expects($this->any())->method('getDataType')->will($this->returnValue('F3_Foo_Quux'));
392
393 $arguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('dummy'), array(), '', FALSE);
394 $arguments->addArgument($argument);
395
396 $methodTagsValues = array(
397
398 );
399
400 $quuxBaseValidatorConjunction = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE);
401
402 $methodArgumentsValidatorConjunctions = array();
403 $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE);
404 $methodArgumentsValidatorConjunctions['arg1']->expects($this->once())->method('addValidator')->with($quuxBaseValidatorConjunction);
405
406 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
407 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
408
409 $mockValidatorResolver = $this->getMock('Tx_Extbase_Validation_ValidatorResolver', array(), array(), '', FALSE);
410 $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions));
411 $mockValidatorResolver->expects($this->once())->method('getBaseValidatorConjunction')->with('F3_Foo_Quux')->will($this->returnValue($quuxBaseValidatorConjunction));
412
413 $mockController->injectReflectionService($mockReflectionService);
414 $mockController->injectValidatorResolver($mockValidatorResolver);
415 $mockController->_set('arguments', $arguments);
416 $mockController->_set('actionMethodName', 'fooAction');
417 $mockController->_call('initializeActionMethodValidators');
418
419 $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator());
420 }
421
422 /**
423 * @test
424 * @author Sebastian Kurfürst <sbastian@typo3.org>
425 */
426 public function initializeActionMethodValidatorsDoesNotRegisterModelBasedValidatorsIfDontValidateAnnotationIsSet() {
427 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('fooAction'), array(), '', FALSE);
428
429 $argument = $this->getMock('Tx_Extbase_MVC_Controller_Argument', array('getName', 'getDataType'), array(), '', FALSE);
430 $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1'));
431 $argument->expects($this->any())->method('getDataType')->will($this->returnValue('F3_Foo_Quux'));
432
433 $arguments = $this->getMock('Tx_Extbase_MVC_Controller_Arguments', array('dummy'), array(), '', FALSE);
434 $arguments->addArgument($argument);
435
436 $methodTagsValues = array(
437 'dontvalidate' => array(
438 '$arg1'
439 )
440 );
441
442 $methodArgumentsValidatorConjunctions = array();
443 $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('Tx_Extbase_Validation_Validator_ConjunctionValidator', array(), array(), '', FALSE);
444
445 $mockReflectionService = $this->getMock('Tx_Extbase_Reflection_Service', array(), array(), '', FALSE);
446 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
447
448 $mockValidatorResolver = $this->getMock('Tx_Extbase_Validation_ValidatorResolver', array(), array(), '', FALSE);
449 $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions));
450 $mockValidatorResolver->expects($this->any())->method('getBaseValidatorConjunction')->will($this->throwException(new Exception("This should not be called because the dontvalidate annotation is set.")));
451
452 $mockController->injectReflectionService($mockReflectionService);
453 $mockController->injectValidatorResolver($mockValidatorResolver);
454 $mockController->_set('arguments', $arguments);
455 $mockController->_set('actionMethodName', 'fooAction');
456 $mockController->_call('initializeActionMethodValidators');
457
458 $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator());
459 }
460
461 /**
462 * @test
463 * @author Christopher Hlubek <hlubek@networkteam.com>
464 */
465 public function defaultErrorActionSetsArgumentMappingResultsErrorsInRequest() {
466 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface', array(), array(), '', FALSE);
467 $mockFlashMessages = $this->getMock('Tx_Extbase_MVC_Controller_FlashMessages', array(), array(), '', FALSE);
468
469 $mockError = $this->getMock('Tx_Extbase_Error_Error', array('getMessage'), array(), '', FALSE);
470 $mockArgumentsMappingResults = $this->getMock('Tx_Extbase_Property_MappingResults', array('getErrors', 'getWarnings'), array(), '', FALSE);
471 $mockArgumentsMappingResults->expects($this->atLeastOnce())->method('getErrors')->will($this->returnValue(array($mockError)));
472 $mockArgumentsMappingResults->expects($this->any())->method('getWarnings')->will($this->returnValue(array()));
473
474 $mockController = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Controller_ActionController'), array('pushFlashMessage'), array(), '', FALSE);
475 $mockController->_set('request', $mockRequest);
476 $mockController->_set('flashMessages', $mockFlashMessages);
477 $mockController->_set('argumentsMappingResults', $mockArgumentsMappingResults);
478
479 $mockRequest->expects($this->once())->method('setErrors')->with(array($mockError));
480
481 $mockController->_call('errorAction');
482 }
483
484 /**
485 * @test
486 * @author Christopher Hlubek <hlubek@networkteam.com>
487 */
488 public function defaultErrorActionCallsGetErrorFlashMessageAndPutsFlashMessage() {
489 $this->markTestIncomplete('To be implemented');
490 }
491
492 }
493 ?>