TYPO3 CMS  TYPO3_6-2
ActionControllerTest.php
Go to the documentation of this file.
1 <?php
3 
21 
25  protected $actionController;
26 
30  protected $mockObjectManager;
31 
35  protected $mockUriBuilder;
36 
41 
42  public function setUp() {
43  $this->actionController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController');
44  }
45 
49  public function processRequestSticksToSpecifiedSequence() {
50  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request', array(), array(), '', FALSE);
51  $mockRequest->expects($this->once())->method('setDispatched')->with(TRUE);
52  $mockUriBuilder = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder');
53  $mockUriBuilder->expects($this->once())->method('setRequest')->with($mockRequest);
54  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
55  $mockObjectManager->expects($this->once())->method('get')->with('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder')->will($this->returnValue($mockUriBuilder));
56  $mockResponse = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Response', array(), array(), '', FALSE);
57  $configurationService = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\MvcPropertyMappingConfigurationService');
59  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array(
60  'initializeFooAction',
61  'initializeAction',
62  'resolveActionMethodName',
63  'initializeActionMethodArguments',
64  'initializeActionMethodValidators',
65  'mapRequestArgumentsToControllerArguments',
66  'buildControllerContext',
67  'resolveView',
68  'initializeView',
69  'callActionMethod',
70  'checkRequestHash'
71  ), array(), '', FALSE);
72  $mockController->_set('objectManager', $mockObjectManager);
73 
74  $mockController->expects($this->at(0))->method('resolveActionMethodName')->will($this->returnValue('fooAction'));
75  $mockController->expects($this->at(1))->method('initializeActionMethodArguments');
76  $mockController->expects($this->at(2))->method('initializeActionMethodValidators');
77  $mockController->expects($this->at(3))->method('initializeAction');
78  $mockController->expects($this->at(4))->method('initializeFooAction');
79  $mockController->expects($this->at(5))->method('mapRequestArgumentsToControllerArguments');
80  $mockController->expects($this->at(6))->method('checkRequestHash');
81  $mockController->expects($this->at(7))->method('buildControllerContext');
82  $mockController->expects($this->at(8))->method('resolveView');
83 
84  $mockController->_set('mvcPropertyMappingConfigurationService', $configurationService);
85  $mockController->_set('arguments', new \TYPO3\CMS\Extbase\Mvc\Controller\Arguments());
86 
87  $mockController->processRequest($mockRequest, $mockResponse);
88  $this->assertSame($mockRequest, $mockController->_get('request'));
89  $this->assertSame($mockResponse, $mockController->_get('response'));
90  }
91 
97  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
98  $mockResponse = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\ResponseInterface', array(), array(), '', FALSE);
99  $mockResponse->expects($this->once())->method('appendContent')->with('the returned string');
100  $mockArguments = new \ArrayObject();
101  $mockArgumentMappingResults = $this->getMock('TYPO3\\CMS\\Extbase\\Property\\MappingResults', array(), array(), '', FALSE);
102  $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE));
103  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction', 'initializeAction'), array(), '', FALSE);
104  $mockSignalSlotDispatcher = $this->getMock('TYPO3\\CMS\Extbase\\SignalSlot\\Dispatcher', array(), array(), '', FALSE);
105  $mockController->_set('signalSlotDispatcher', $mockSignalSlotDispatcher);
106  $this->enableDeprecatedPropertyMapperInController($mockController);
107  $mockController->expects($this->once())->method('fooAction')->will($this->returnValue('the returned string'));
108  $mockController->_set('request', $mockRequest);
109  $mockController->_set('response', $mockResponse);
110  $mockController->_set('arguments', $mockArguments);
111  $mockController->_set('actionMethodName', 'fooAction');
112  $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
113  $mockController->_call('callActionMethod');
114  }
115 
121  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
122  $mockResponse = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\ResponseInterface', array(), array(), '', FALSE);
123  $mockResponse->expects($this->once())->method('appendContent')->with('the view output');
124  $mockView = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\View\\ViewInterface');
125  $mockView->expects($this->once())->method('render')->will($this->returnValue('the view output'));
126  $mockArguments = new \ArrayObject();
127  $mockArgumentMappingResults = $this->getMock('TYPO3\\CMS\\Extbase\\Property\\MappingResults', array(), array(), '', FALSE);
128  $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE));
129  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction', 'initializeAction'), array(), '', FALSE);
130  $mockSignalSlotDispatcher = $this->getMock('TYPO3\\CMS\Extbase\\SignalSlot\\Dispatcher', array(), array(), '', FALSE);
131  $mockController->_set('signalSlotDispatcher', $mockSignalSlotDispatcher);
132  $this->enableDeprecatedPropertyMapperInController($mockController);
133  $mockController->expects($this->once())->method('fooAction');
134  $mockController->_set('request', $mockRequest);
135  $mockController->_set('response', $mockResponse);
136  $mockController->_set('arguments', $mockArguments);
137  $mockController->_set('actionMethodName', 'fooAction');
138  $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
139  $mockController->_set('view', $mockView);
140  $mockController->_call('callActionMethod');
141  }
142 
148  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
149  $mockResponse = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\ResponseInterface', array(), array(), '', FALSE);
150  $mockResponse->expects($this->once())->method('appendContent')->with('the returned string');
151  $mockArguments = new \ArrayObject();
152  $mockArgumentMappingResults = $this->getMock('TYPO3\\CMS\\Extbase\\Property\\MappingResults', array(), array(), '', FALSE);
153  $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(TRUE));
154  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('barAction', 'initializeAction'), array(), '', FALSE);
155  $this->enableDeprecatedPropertyMapperInController($mockController);
156  $mockController->expects($this->once())->method('barAction')->will($this->returnValue('the returned string'));
157  $mockController->_set('request', $mockRequest);
158  $mockController->_set('response', $mockResponse);
159  $mockController->_set('arguments', $mockArguments);
160  $mockController->_set('actionMethodName', 'fooAction');
161  $mockController->_set('errorMethodName', 'barAction');
162  $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
163  $mockController->_call('callActionMethod');
164  }
165 
171  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
172  $mockResponse = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\ResponseInterface', array(), array(), '', FALSE);
173  $arguments = new \ArrayObject();
174  $optionalArgument = new \TYPO3\CMS\Extbase\Mvc\Controller\Argument('name1', 'Text');
175  $optionalArgument->setDefaultValue('Default value');
176  $arguments[] = $optionalArgument;
177  $mockArgumentMappingResults = $this->getMock('TYPO3\\CMS\\Extbase\\Property\\MappingResults', array(), array(), '', FALSE);
178  $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE));
179  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction', 'initializeAction'), array(), '', FALSE);
180  $mockSignalSlotDispatcher = $this->getMock('TYPO3\\CMS\Extbase\\SignalSlot\\Dispatcher', array(), array(), '', FALSE);
181  $mockController->_set('signalSlotDispatcher', $mockSignalSlotDispatcher);
182  $this->enableDeprecatedPropertyMapperInController($mockController);
183  $mockController->expects($this->once())->method('fooAction')->with('Default value');
184  $mockController->_set('request', $mockRequest);
185  $mockController->_set('response', $mockResponse);
186  $mockController->_set('arguments', $arguments);
187  $mockController->_set('actionMethodName', 'fooAction');
188  $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
189  $mockController->_call('callActionMethod');
190  }
191 
197  $mockSession = $this->getMock('Tx_Extbase_Session_SessionInterface');
198  $mockControllerContext = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext', array(), array(), '', FALSE);
199  $mockFluidTemplateView = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\View\\ViewInterface');
200  $mockFluidTemplateView->expects($this->once())->method('setControllerContext')->with($mockControllerContext);
201  $mockFluidTemplateView->expects($this->once())->method('canRender')->with($mockControllerContext)->will($this->returnValue(TRUE));
202  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface', array(), array(), '', FALSE);
203  $mockObjectManager->expects($this->at(0))->method('get')->with('TYPO3\\CMS\\Fluid\\View\\TemplateView')->will($this->returnValue($mockFluidTemplateView));
204  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('buildControllerContext', 'resolveViewObjectName', 'setViewConfiguration'), array(), '', FALSE);
205  $mockController->expects($this->once())->method('resolveViewObjectName')->will($this->returnValue(FALSE));
206  $mockController->_set('session', $mockSession);
207  $mockController->_set('objectManager', $mockObjectManager);
208  $mockController->_set('controllerContext', $mockControllerContext);
209  $this->assertSame($mockFluidTemplateView, $mockController->_call('resolveView'));
210  }
211 
217  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
218  $mockRequest->expects($this->once())->method('getControllerVendorName')->will($this->returnValue('MyVendor'));
219  $mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('MyPackage'));
220  $mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('MyController'));
221  $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('MyAction'));
222  $mockRequest->expects($this->atLeastOnce())->method('getFormat')->will($this->returnValue('MyFormat'));
223  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface', array(), array(), '', FALSE);
224  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
225  $mockController->_set('request', $mockRequest);
226  $mockController->_set('objectManager', $mockObjectManager);
227  $mockController->_set('namespacesViewObjectNamePattern', 'RandomViewObject@vendor\@extension\View\@controller\@action@format');
228  $mockController->_call('resolveViewObjectName');
229  }
230 
235  eval('class Tx_MyPackage_View_MyController_MyActionMyFormat {}');
236 
237  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
238  $mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('MyPackage'));
239  $mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('MyController'));
240  $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('MyAction'));
241  $mockRequest->expects($this->once())->method('getControllerVendorName')->will($this->returnValue(NULL));
242  $mockRequest->expects($this->atLeastOnce())->method('getFormat')->will($this->returnValue('MyFormat'));
243  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface', array(), array(), '', FALSE);
244  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
245  $mockController->_set('request', $mockRequest);
246  $mockController->_set('objectManager', $mockObjectManager);
247 
248  $this->assertEquals(
249  'Tx_MyPackage_View_MyController_MyActionMyFormat',
250  $mockController->_call('resolveViewObjectName')
251  );
252  }
253 
258  eval('namespace MyVendor\MyPackage\View\MyController; class MyActionMyFormat {}');
259 
260  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
261  $mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('MyPackage'));
262  $mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('MyController'));
263  $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('MyAction'));
264  $mockRequest->expects($this->once())->method('getControllerVendorName')->will($this->returnValue('MyVendor'));
265  $mockRequest->expects($this->atLeastOnce())->method('getFormat')->will($this->returnValue('MyFormat'));
266  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface', array(), array(), '', FALSE);
267  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
268  $mockController->_set('request', $mockRequest);
269  $mockController->_set('objectManager', $mockObjectManager);
270 
271  $this->assertEquals(
272  'MyVendor\MyPackage\View\MyController\MyActionMyFormat',
273  $mockController->_call('resolveViewObjectName')
274  );
275  }
276 
281  public function resolveActionMethodNameReturnsTheCurrentActionMethodNameFromTheRequest() {
282  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
283  $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('fooBar'));
285  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooBarAction'), array(), '', FALSE);
286  $mockController->_set('request', $mockRequest);
287  $this->assertEquals('fooBarAction', $mockController->_call('resolveActionMethodName'));
288  }
289 
295  public function resolveActionMethodNameThrowsAnExceptionIfTheActionDefinedInTheRequestDoesNotExist() {
296  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
297  $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('fooBar'));
299  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('otherBarAction'), array(), '', FALSE);
300  $mockController->_set('request', $mockRequest);
301  $mockController->_call('resolveActionMethodName');
302  }
303 
309  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
310  $mockArguments = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Arguments', array('addNewArgument', 'removeAll'));
311  $mockArguments->expects($this->at(0))->method('addNewArgument')->with('stringArgument', 'string', TRUE);
312  $mockArguments->expects($this->at(1))->method('addNewArgument')->with('integerArgument', 'integer', TRUE);
313  $mockArguments->expects($this->at(2))->method('addNewArgument')->with('objectArgument', 'F3_Foo_Bar', TRUE);
314  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction', 'evaluateDontValidateAnnotations'), array(), '', FALSE);
315  $methodParameters = array(
316  'stringArgument' => array(
317  'position' => 0,
318  'byReference' => FALSE,
319  'array' => FALSE,
320  'optional' => FALSE,
321  'allowsNull' => FALSE,
322  'type' => 'string'
323  ),
324  'integerArgument' => array(
325  'position' => 1,
326  'byReference' => FALSE,
327  'array' => FALSE,
328  'optional' => FALSE,
329  'allowsNull' => FALSE,
330  'type' => 'integer'
331  ),
332  'objectArgument' => array(
333  'position' => 2,
334  'byReference' => FALSE,
335  'array' => FALSE,
336  'optional' => FALSE,
337  'allowsNull' => FALSE,
338  'type' => 'F3_Foo_Bar'
339  )
340  );
341  $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
342  $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
343  $mockController->_set('reflectionService', $mockReflectionService);
344  $mockController->_set('request', $mockRequest);
345  $mockController->_set('arguments', $mockArguments);
346  $mockController->_set('actionMethodName', 'fooAction');
347  $mockController->_call('initializeActionMethodArguments');
348  }
349 
355  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
356  $mockArguments = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Arguments', array(), array(), '', FALSE);
357  $mockArguments->expects($this->at(0))->method('addNewArgument')->with('arg1', 'string', TRUE);
358  $mockArguments->expects($this->at(1))->method('addNewArgument')->with('arg2', 'array', FALSE, array(21));
359  $mockArguments->expects($this->at(2))->method('addNewArgument')->with('arg3', 'string', FALSE, 42);
360  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction', 'evaluateDontValidateAnnotations'), array(), '', FALSE);
361  $methodParameters = array(
362  'arg1' => array(
363  'position' => 0,
364  'byReference' => FALSE,
365  'array' => FALSE,
366  'optional' => FALSE,
367  'allowsNull' => FALSE,
368  'type' => 'string'
369  ),
370  'arg2' => array(
371  'position' => 1,
372  'byReference' => FALSE,
373  'array' => TRUE,
374  'optional' => TRUE,
375  'defaultValue' => array(21),
376  'allowsNull' => FALSE
377  ),
378  'arg3' => array(
379  'position' => 2,
380  'byReference' => FALSE,
381  'array' => FALSE,
382  'optional' => TRUE,
383  'defaultValue' => 42,
384  'allowsNull' => FALSE,
385  'type' => 'string'
386  )
387  );
388  $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
389  $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
390  $mockController->_set('reflectionService', $mockReflectionService);
391  $mockController->_set('request', $mockRequest);
392  $mockController->_set('arguments', $mockArguments);
393  $mockController->_set('actionMethodName', 'fooAction');
394  $mockController->_call('initializeActionMethodArguments');
395  }
396 
403  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
404  $mockArguments = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Arguments', array(), array(), '', FALSE);
405  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction'), array(), '', FALSE);
406  $methodParameters = array(
407  'arg1' => array(
408  'position' => 0,
409  'byReference' => FALSE,
410  'array' => FALSE,
411  'optional' => FALSE,
412  'allowsNull' => FALSE
413  )
414  );
415  $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
416  $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
417  $mockController->_set('reflectionService', $mockReflectionService);
418  $mockController->_set('request', $mockRequest);
419  $mockController->_set('arguments', $mockArguments);
420  $mockController->_set('actionMethodName', 'fooAction');
421  $mockController->_call('initializeActionMethodArguments');
422  }
423 
429  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction'), array(), '', FALSE);
430  $this->enableDeprecatedPropertyMapperInController($mockController);
431  $argument = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('getName'), array(), '', FALSE);
432  $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1'));
433  $arguments = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Arguments', array('dummy'));
434  $arguments->addArgument($argument);
435  $methodTagsValues = array();
436  $methodArgumentsValidatorConjunctions = array();
437  $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
438  $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
439  $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
440  $mockValidatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array(), array(), '', FALSE);
441  $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions));
442  $mockController->_set('reflectionService', $mockReflectionService);
443  $mockController->_set('validatorResolver', $mockValidatorResolver);
444  $mockController->_set('arguments', $arguments);
445  $mockController->_set('actionMethodName', 'fooAction');
446  $mockController->_call('initializeActionMethodValidators');
447  $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator());
448  }
449 
455  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction'), array(), '', FALSE);
456  $this->enableDeprecatedPropertyMapperInController($mockController);
457  $argument = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('getName', 'getDataType'), array(), '', FALSE);
458  $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1'));
459  $argument->expects($this->any())->method('getDataType')->will($this->returnValue('F3_Foo_Quux'));
460  $arguments = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Arguments', array('dummy'));
461  $arguments->addArgument($argument);
462  $methodTagsValues = array();
463  $quuxBaseValidatorConjunction = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
464  $methodArgumentsValidatorConjunctions = array();
465  $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
466  $methodArgumentsValidatorConjunctions['arg1']->expects($this->once())->method('addValidator')->with($quuxBaseValidatorConjunction);
467  $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
468  $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
469  $mockValidatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array(), array(), '', FALSE);
470  $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions));
471  $mockValidatorResolver->expects($this->once())->method('getBaseValidatorConjunction')->with('F3_Foo_Quux')->will($this->returnValue($quuxBaseValidatorConjunction));
472  $mockController->_set('reflectionService', $mockReflectionService);
473  $mockController->_set('validatorResolver', $mockValidatorResolver);
474  $mockController->_set('arguments', $arguments);
475  $mockController->_set('actionMethodName', 'fooAction');
476  $mockController->_call('initializeActionMethodValidators');
477  $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator());
478  }
479 
485  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction'), array(), '', FALSE);
486  $this->enableDeprecatedPropertyMapperInController($mockController);
487  $argument = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('getName', 'getDataType'), array(), '', FALSE);
488  $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1'));
489  $argument->expects($this->any())->method('getDataType')->will($this->returnValue('F3_Foo_Quux'));
490  $arguments = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Arguments', array('dummy'));
491  $arguments->addArgument($argument);
492  $methodTagsValues = array(
493  'dontvalidate' => array(
494  '$arg1'
495  )
496  );
497  $methodArgumentsValidatorConjunctions = array();
498  $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
499  $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
500  $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
501  $mockValidatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array(), array(), '', FALSE);
502  $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions));
503  $mockValidatorResolver->expects($this->any())->method('getBaseValidatorConjunction')->will($this->throwException(new \Exception('This should not be called because the dontvalidate annotation is set.')));
504  $mockController->_set('reflectionService', $mockReflectionService);
505  $mockController->_set('validatorResolver', $mockValidatorResolver);
506  $mockController->_set('arguments', $arguments);
507  $mockController->_set('actionMethodName', 'fooAction');
508  $mockController->_call('initializeActionMethodValidators');
509  $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator());
510  }
511 
516  public function defaultErrorActionSetsArgumentMappingResultsErrorsInRequest() {
517  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
518  $mockError = $this->getMock('TYPO3\\CMS\\Extbase\\Error\\Error', array('getMessage'), array(), '', FALSE);
519  $mockArgumentsMappingResults = $this->getMock('TYPO3\\CMS\\Extbase\\Property\\MappingResults', array('getErrors', 'getWarnings'), array(), '', FALSE);
520  $mockArgumentsMappingResults->expects($this->atLeastOnce())->method('getErrors')->will($this->returnValue(array($mockError)));
521  $mockArgumentsMappingResults->expects($this->any())->method('getWarnings')->will($this->returnValue(array()));
523  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('clearCacheOnError'), array(), '', FALSE);
524  $controllerContext = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext', array('getFlashMessageQueue'));
525  $controllerContext->expects($this->any())->method('getFlashMessageQueue')->will($this->returnValue(new \TYPO3\CMS\Core\Messaging\FlashMessageQueue('foo')));
526  $this->enableDeprecatedPropertyMapperInController($mockController);
527  $mockController->_set('controllerContext', $controllerContext);
528  $mockController->_set('request', $mockRequest);
529  $mockController->_set('argumentsMappingResults', $mockArgumentsMappingResults);
530  $mockRequest->expects($this->once())->method('setErrors')->with(array($mockError));
531  $mockController->_call('errorAction');
532  }
533 
540  return array(
541  // HMAC is verified
542  array(TRUE),
543  // HMAC not verified, but objects are directly fetched from persistence layer
544  array(FALSE, FALSE, \TYPO3\CMS\Extbase\Mvc\Controller\Argument::ORIGIN_PERSISTENCE, \TYPO3\CMS\Extbase\Mvc\Controller\Argument::ORIGIN_PERSISTENCE),
545  // HMAC not verified, objects new and modified, but dontverifyrequesthash-annotation set
546  array(FALSE, TRUE, \TYPO3\CMS\Extbase\Mvc\Controller\Argument::ORIGIN_PERSISTENCE, \TYPO3\CMS\Extbase\Mvc\Controller\Argument::ORIGIN_PERSISTENCE_AND_MODIFIED, array('dontverifyrequesthash' => ''))
547  );
548  }
549 
560  public function checkRequestHashDoesNotThrowExceptionInNormalOperations($hmacVerified, $reflectionServiceNeedsInitialization = FALSE, $argument1Origin = 3, $argument2Origin = 3, array $methodTagsValues = array()) {
561  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request', array('isHmacVerified'), array(), '', FALSE);
562  $mockRequest->expects($this->once())->method('isHmacVerified')->will($this->returnValue($hmacVerified));
563  $argument1 = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('getOrigin'), array(), '', FALSE);
564  $argument1->expects($this->any())->method('getOrigin')->will($this->returnValue($argument1Origin));
565  $argument2 = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('getOrigin'), array(), '', FALSE);
566  $argument2->expects($this->any())->method('getOrigin')->will($this->returnValue($argument2Origin));
567  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
568  $this->enableDeprecatedPropertyMapperInController($mockController);
569  $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array('getMethodTagsValues'), array(), '', FALSE);
570  if ($reflectionServiceNeedsInitialization) {
571  // Somehow this is needed, else I get "Mocked method does not exist."
572  $mockReflectionService->expects($this->any())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
573  }
574  $mockController->_set('arguments', array($argument1, $argument2));
575  $mockController->_set('request', $mockRequest);
576  $mockController->_set('actionMethodName', 'fooAction');
577  $mockController->_set('reflectionService', $mockReflectionService);
578  $mockController->_call('checkRequestHash');
579  }
580 
587  $hmacVerified = FALSE;
590  $methodTagsValues = array();
591  $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request', array('isHmacVerified'), array(), '', FALSE);
592  $mockRequest->expects($this->once())->method('isHmacVerified')->will($this->returnValue($hmacVerified));
593  $argument1 = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('getOrigin'), array(), '', FALSE);
594  $argument1->expects($this->any())->method('getOrigin')->will($this->returnValue($argument1Origin));
595  $argument2 = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('getOrigin'), array(), '', FALSE);
596  $argument2->expects($this->any())->method('getOrigin')->will($this->returnValue($argument2Origin));
597  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
598  $this->enableDeprecatedPropertyMapperInController($mockController);
599  $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array('getMethodTagsValues'), array(), '', FALSE);
600  $mockReflectionService->expects($this->any())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
601  $mockController->_set('arguments', array($argument1, $argument2));
602  $mockController->_set('request', $mockRequest);
603  $mockController->_set('actionMethodName', 'fooAction');
604  $mockController->_set('reflectionService', $mockReflectionService);
605  $mockController->_call('checkRequestHash');
606  }
607 
613  protected function enableDeprecatedPropertyMapperInController(\TYPO3\CMS\Extbase\Mvc\Controller\ActionController $actionController) {
614  $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
615  $mockConfigurationManager->expects($this->any())->method('isFeatureEnabled')->with('rewrittenPropertyMapper')->will($this->returnValue(FALSE));
616  $actionController->injectConfigurationManager($mockConfigurationManager);
617  }
618 
625  public function setViewConfigurationResolvesTemplateRootPathsForTemplateRootPath($configuration, $expected) {
626  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
627  $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
628  $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration));
629  $mockController->injectConfigurationManager($mockConfigurationManager);
630  $mockController->_set('request', $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request'), array('getControllerExtensionKey'));
631  $view = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\View\\ViewInterface', array('setControllerContext', 'assign', 'assignMultiple', 'canRender', 'render', 'initializeView', 'setTemplateRootPaths'));
632  $view->expects($this->once())->method('setTemplateRootPaths')->with($expected);
633  $mockController->_call('setViewConfiguration', $view);
634  }
635 
639  public function templateRootPathDataProvider() {
640  return array(
641  'old behaviour only' => array(
642  array(
643  'view' => array(
644  'templateRootPath' => 'some path'
645  )
646  ),
647  array('some path')
648  ),
649  'new behaviour only with text keys' => array(
650  array(
651  'view' => array(
652  'templateRootPaths' => array(
653  'default' => 'some path',
654  'extended' => 'some other path'
655  )
656  )
657  ),
658  array(
659  'extended' => 'some other path',
660  'default' => 'some path'
661  )
662  ),
663  'new behaviour only with numerical keys' => array(
664  array(
665  'view' => array(
666  'templateRootPaths' => array(
667  '10' => 'some path',
668  '20' => 'some other path',
669  '15' => 'intermediate specific path'
670  )
671  )
672  ),
673  array(
674  '20' => 'some other path',
675  '15' => 'intermediate specific path',
676  '10' => 'some path'
677  )
678  ),
679  'new behaviour only with mixed keys' => array(
680  array(
681  'view' => array(
682  'templateRootPaths' => array(
683  '10' => 'some path',
684  'very_specific' => 'some other path',
685  '15' => 'intermediate specific path'
686  )
687  )
688  ),
689  array(
690  '15' => 'intermediate specific path',
691  'very_specific' => 'some other path',
692  '10' => 'some path'
693  )
694  ),
695  'old and new behaviour mixed with text keys' => array(
696  array(
697  'view' => array(
698  'templateRootPaths' => array(
699  'default' => 'some path',
700  'specific' => 'intermediate specific path',
701  'very_specific' => 'some other path'
702  ),
703  'templateRootPath' => 'old path'
704  )
705  ),
706  array(
707  'very_specific' => 'some other path',
708  'specific' => 'intermediate specific path',
709  'default' => 'some path',
710  '0' => 'old path'
711  )
712  ),
713  'old and new behaviour mixed with numerical keys' => array(
714  array(
715  'view' => array(
716  'templateRootPaths' => array(
717  '10' => 'some path',
718  '20' => 'intermediate specific path',
719  '30' => 'some other path'
720  ),
721  'templateRootPath' => 'old path'
722  )
723  ),
724  array(
725  '30' => 'some other path',
726  '20' => 'intermediate specific path',
727  '10' => 'some path',
728  '31' => 'old path'
729  )
730  ),
731  'old and new behaviour mixed with mixed keys' => array(
732  array(
733  'view' => array(
734  'templateRootPaths' => array(
735  '10' => 'some path',
736  'very_specific' => 'some other path',
737  '15' => 'intermediate specific path'
738  ),
739  'templateRootPath' => 'old path'
740  )
741  ),
742  array(
743  '15' => 'intermediate specific path',
744  'very_specific' => 'some other path',
745  '10' => 'some path',
746  '16' => 'old path'
747  )
748  )
749  );
750  }
751 
759  public function setViewConfigurationResolvesLayoutRootPathsForLayoutRootPath($configuration, $expected) {
760  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
761  $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
762  $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration));
763  $mockController->injectConfigurationManager($mockConfigurationManager);
764  $mockController->_set('request', $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request'), array('getControllerExtensionKey'));
765  $view = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\View\\ViewInterface', array('setControllerContext', 'assign', 'assignMultiple', 'canRender', 'render', 'initializeView', 'setlayoutRootPaths'));
766  $view->expects($this->once())->method('setlayoutRootPaths')->with($expected);
767  $mockController->_call('setViewConfiguration', $view);
768  }
769 
773  public function layoutRootPathDataProvider() {
774  return array(
775  'old behaviour only' => array(
776  array(
777  'view' => array(
778  'layoutRootPath' => 'some path'
779  )
780  ),
781  array('some path')
782  ),
783  'new behaviour only with text keys' => array(
784  array(
785  'view' => array(
786  'layoutRootPaths' => array(
787  'default' => 'some path',
788  'extended' => 'some other path'
789  )
790  )
791  ),
792  array(
793  'extended' => 'some other path',
794  'default' => 'some path'
795  )
796  ),
797  'new behaviour only with numerical keys' => array(
798  array(
799  'view' => array(
800  'layoutRootPaths' => array(
801  '10' => 'some path',
802  '20' => 'some other path',
803  '15' => 'intermediate specific path'
804  )
805  )
806  ),
807  array(
808  '20' => 'some other path',
809  '15' => 'intermediate specific path',
810  '10' => 'some path'
811  )
812  ),
813  'new behaviour only with mixed keys' => array(
814  array(
815  'view' => array(
816  'layoutRootPaths' => array(
817  '10' => 'some path',
818  'very_specific' => 'some other path',
819  '15' => 'intermediate specific path'
820  )
821  )
822  ),
823  array(
824  '15' => 'intermediate specific path',
825  'very_specific' => 'some other path',
826  '10' => 'some path'
827  )
828  ),
829  'old and new behaviour mixed with text keys' => array(
830  array(
831  'view' => array(
832  'layoutRootPaths' => array(
833  'default' => 'some path',
834  'specific' => 'intermediate specific path',
835  'very_specific' => 'some other path'
836  ),
837  'layoutRootPath' => 'old path'
838  )
839  ),
840  array(
841  'very_specific' => 'some other path',
842  'specific' => 'intermediate specific path',
843  'default' => 'some path',
844  '0' => 'old path'
845  )
846  ),
847  'old and new behaviour mixed with numerical keys' => array(
848  array(
849  'view' => array(
850  'layoutRootPaths' => array(
851  '10' => 'some path',
852  '20' => 'intermediate specific path',
853  '30' => 'some other path'
854  ),
855  'layoutRootPath' => 'old path'
856  )
857  ),
858  array(
859  '30' => 'some other path',
860  '20' => 'intermediate specific path',
861  '10' => 'some path',
862  '31' => 'old path'
863  )
864  ),
865  'old and new behaviour mixed with mixed keys' => array(
866  array(
867  'view' => array(
868  'layoutRootPaths' => array(
869  '10' => 'some path',
870  'very_specific' => 'some other path',
871  '15' => 'intermediate specific path'
872  ),
873  'layoutRootPath' => 'old path'
874  )
875  ),
876  array(
877  '15' => 'intermediate specific path',
878  'very_specific' => 'some other path',
879  '10' => 'some path',
880  '16' => 'old path'
881  )
882  )
883  );
884  }
885 
893  public function setViewConfigurationResolvesPartialRootPathsForPartialRootPath($configuration, $expected) {
894  $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
895  $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
896  $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration));
897  $mockController->injectConfigurationManager($mockConfigurationManager);
898  $mockController->_set('request', $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request'), array('getControllerExtensionKey'));
899  $view = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\View\\ViewInterface', array('setControllerContext', 'assign', 'assignMultiple', 'canRender', 'render', 'initializeView', 'setpartialRootPaths'));
900  $view->expects($this->once())->method('setpartialRootPaths')->with($expected);
901  $mockController->_call('setViewConfiguration', $view);
902  }
903 
907  public function partialRootPathDataProvider() {
908  return array(
909  'old behaviour only' => array(
910  array(
911  'view' => array(
912  'partialRootPath' => 'some path'
913  )
914  ),
915  array('some path')
916  ),
917  'new behaviour only with text keys' => array(
918  array(
919  'view' => array(
920  'partialRootPaths' => array(
921  'default' => 'some path',
922  'extended' => 'some other path'
923  )
924  )
925  ),
926  array(
927  'extended' => 'some other path',
928  'default' => 'some path'
929  )
930  ),
931  'new behaviour only with numerical keys' => array(
932  array(
933  'view' => array(
934  'partialRootPaths' => array(
935  '10' => 'some path',
936  '20' => 'some other path',
937  '15' => 'intermediate specific path'
938  )
939  )
940  ),
941  array(
942  '20' => 'some other path',
943  '15' => 'intermediate specific path',
944  '10' => 'some path'
945  )
946  ),
947  'new behaviour only with mixed keys' => array(
948  array(
949  'view' => array(
950  'partialRootPaths' => array(
951  '10' => 'some path',
952  'very_specific' => 'some other path',
953  '15' => 'intermediate specific path'
954  )
955  )
956  ),
957  array(
958  '15' => 'intermediate specific path',
959  'very_specific' => 'some other path',
960  '10' => 'some path'
961  )
962  ),
963  'old and new behaviour mixed with text keys' => array(
964  array(
965  'view' => array(
966  'partialRootPath' => 'old path',
967  'partialRootPaths' => array(
968  'default' => 'some path',
969  'specific' => 'intermediate specific path',
970  'very_specific' => 'some other path'
971  )
972  )
973  ),
974  array(
975  'very_specific' => 'some other path',
976  'specific' => 'intermediate specific path',
977  'default' => 'some path',
978  '0' => 'old path'
979  )
980  ),
981  'old and new behaviour mixed with numerical keys' => array(
982  array(
983  'view' => array(
984  'partialRootPaths' => array(
985  '10' => 'some path',
986  '20' => 'intermediate specific path',
987  '30' => 'some other path'
988  ),
989  'partialRootPath' => 'old path'
990  )
991  ),
992  array(
993  '30' => 'some other path',
994  '20' => 'intermediate specific path',
995  '10' => 'some path',
996  '31' => 'old path'
997  )
998  ),
999  'old and new behaviour mixed with mixed keys' => array(
1000  array(
1001  'view' => array(
1002  'partialRootPaths' => array(
1003  '10' => 'some path',
1004  'very_specific' => 'some other path',
1005  '15' => 'intermediate specific path'
1006  ),
1007  'partialRootPath' => 'old path'
1008  )
1009  ),
1010  array(
1011  '15' => 'intermediate specific path',
1012  'very_specific' => 'some other path',
1013  '10' => 'some path',
1014  '16' => 'old path'
1015  )
1016  )
1017  );
1018  }
1019 }
checkRequestHashDoesNotThrowExceptionInNormalOperations($hmacVerified, $reflectionServiceNeedsInitialization=FALSE, $argument1Origin=3, $argument2Origin=3, array $methodTagsValues=array())
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
enableDeprecatedPropertyMapperInController(\TYPO3\CMS\Extbase\Mvc\Controller\ActionController $actionController)