[BUGFIX] Get unit tests working again
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Mvc / Controller / ActionControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * This class is a backport of the corresponding class of TYPO3 Flow.
8 * All credits go to the TYPO3 Flow team.
9 * All rights reserved
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 * A copy is found in the text file GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30
31 /**
32 * Test case
33 */
34 class ActionControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
35
36 /**
37 * @var \TYPO3\CMS\Extbase\Mvc\Controller\ActionController|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
38 */
39 protected $actionController;
40
41 /**
42 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
43 */
44 protected $mockObjectManager;
45
46 /**
47 * @var \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
48 */
49 protected $mockUriBuilder;
50
51 /**
52 * @var \TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService
53 */
54 protected $mockMvcPropertyMappingConfigurationService;
55
56 public function setUp() {
57 $this->actionController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController');
58 }
59
60 /**
61 * @test
62 */
63 public function processRequestSticksToSpecifiedSequence() {
64 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request', array(), array(), '', FALSE);
65 $mockRequest->expects($this->once())->method('setDispatched')->with(TRUE);
66 $mockUriBuilder = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder');
67 $mockUriBuilder->expects($this->once())->method('setRequest')->with($mockRequest);
68 $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
69 $mockObjectManager->expects($this->once())->method('get')->with('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder')->will($this->returnValue($mockUriBuilder));
70 $mockResponse = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Response', array(), array(), '', FALSE);
71 $configurationService = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\MvcPropertyMappingConfigurationService');
72 /** @var \TYPO3\CMS\Extbase\Mvc\Controller\ActionController|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
73 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array(
74 'initializeFooAction',
75 'initializeAction',
76 'resolveActionMethodName',
77 'initializeActionMethodArguments',
78 'initializeActionMethodValidators',
79 'mapRequestArgumentsToControllerArguments',
80 'buildControllerContext',
81 'resolveView',
82 'initializeView',
83 'callActionMethod',
84 'checkRequestHash'
85 ), array(), '', FALSE);
86 $mockController->_set('objectManager', $mockObjectManager);
87
88 $mockController->expects($this->at(0))->method('resolveActionMethodName')->will($this->returnValue('fooAction'));
89 $mockController->expects($this->at(1))->method('initializeActionMethodArguments');
90 $mockController->expects($this->at(2))->method('initializeActionMethodValidators');
91 $mockController->expects($this->at(3))->method('initializeAction');
92 $mockController->expects($this->at(4))->method('initializeFooAction');
93 $mockController->expects($this->at(5))->method('mapRequestArgumentsToControllerArguments');
94 $mockController->expects($this->at(6))->method('checkRequestHash');
95 $mockController->expects($this->at(7))->method('buildControllerContext');
96 $mockController->expects($this->at(8))->method('resolveView');
97
98 $mockController->_set('mvcPropertyMappingConfigurationService', $configurationService);
99 $mockController->_set('arguments', new \TYPO3\CMS\Extbase\Mvc\Controller\Arguments());
100
101 $mockController->processRequest($mockRequest, $mockResponse);
102 $this->assertSame($mockRequest, $mockController->_get('request'));
103 $this->assertSame($mockResponse, $mockController->_get('response'));
104 }
105
106 /**
107 * @test
108 * @author Robert Lemke <robert@typo3.org>
109 */
110 public function callActionMethodAppendsStringsReturnedByActionMethodToTheResponseObject() {
111 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
112 $mockResponse = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\ResponseInterface', array(), array(), '', FALSE);
113 $mockResponse->expects($this->once())->method('appendContent')->with('the returned string');
114 $mockArguments = new \ArrayObject();
115 $mockArgumentMappingResults = $this->getMock('TYPO3\\CMS\\Extbase\\Property\\MappingResults', array(), array(), '', FALSE);
116 $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE));
117 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction', 'initializeAction'), array(), '', FALSE);
118 $mockSignalSlotDispatcher = $this->getMock('TYPO3\\CMS\Extbase\\SignalSlot\\Dispatcher', array(), array(), '', FALSE);
119 $mockController->_set('signalSlotDispatcher', $mockSignalSlotDispatcher);
120 $this->enableDeprecatedPropertyMapperInController($mockController);
121 $mockController->expects($this->once())->method('fooAction')->will($this->returnValue('the returned string'));
122 $mockController->_set('request', $mockRequest);
123 $mockController->_set('response', $mockResponse);
124 $mockController->_set('arguments', $mockArguments);
125 $mockController->_set('actionMethodName', 'fooAction');
126 $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
127 $mockController->_call('callActionMethod');
128 }
129
130 /**
131 * @test
132 * @author Robert Lemke <robert@typo3.org>
133 */
134 public function callActionMethodRendersTheViewAutomaticallyIfTheActionReturnedNullAndAViewExists() {
135 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
136 $mockResponse = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\ResponseInterface', array(), array(), '', FALSE);
137 $mockResponse->expects($this->once())->method('appendContent')->with('the view output');
138 $mockView = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\View\\ViewInterface');
139 $mockView->expects($this->once())->method('render')->will($this->returnValue('the view output'));
140 $mockArguments = new \ArrayObject();
141 $mockArgumentMappingResults = $this->getMock('TYPO3\\CMS\\Extbase\\Property\\MappingResults', array(), array(), '', FALSE);
142 $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE));
143 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction', 'initializeAction'), array(), '', FALSE);
144 $mockSignalSlotDispatcher = $this->getMock('TYPO3\\CMS\Extbase\\SignalSlot\\Dispatcher', array(), array(), '', FALSE);
145 $mockController->_set('signalSlotDispatcher', $mockSignalSlotDispatcher);
146 $this->enableDeprecatedPropertyMapperInController($mockController);
147 $mockController->expects($this->once())->method('fooAction');
148 $mockController->_set('request', $mockRequest);
149 $mockController->_set('response', $mockResponse);
150 $mockController->_set('arguments', $mockArguments);
151 $mockController->_set('actionMethodName', 'fooAction');
152 $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
153 $mockController->_set('view', $mockView);
154 $mockController->_call('callActionMethod');
155 }
156
157 /**
158 * @test
159 * @author Robert Lemke <robert@typo3.org>
160 */
161 public function callActionMethodCallsTheErrorActionIfTheMappingResultsHaveErrors() {
162 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
163 $mockResponse = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\ResponseInterface', array(), array(), '', FALSE);
164 $mockResponse->expects($this->once())->method('appendContent')->with('the returned string');
165 $mockArguments = new \ArrayObject();
166 $mockArgumentMappingResults = $this->getMock('TYPO3\\CMS\\Extbase\\Property\\MappingResults', array(), array(), '', FALSE);
167 $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(TRUE));
168 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('barAction', 'initializeAction'), array(), '', FALSE);
169 $this->enableDeprecatedPropertyMapperInController($mockController);
170 $mockController->expects($this->once())->method('barAction')->will($this->returnValue('the returned string'));
171 $mockController->_set('request', $mockRequest);
172 $mockController->_set('response', $mockResponse);
173 $mockController->_set('arguments', $mockArguments);
174 $mockController->_set('actionMethodName', 'fooAction');
175 $mockController->_set('errorMethodName', 'barAction');
176 $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
177 $mockController->_call('callActionMethod');
178 }
179
180 /**
181 * @test
182 * @author Sebastian Kurfürst <sebastian@typo3.org>
183 */
184 public function callActionMethodPassesDefaultValuesAsArguments() {
185 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
186 $mockResponse = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\ResponseInterface', array(), array(), '', FALSE);
187 $arguments = new \ArrayObject();
188 $optionalArgument = new \TYPO3\CMS\Extbase\Mvc\Controller\Argument('name1', 'Text');
189 $optionalArgument->setDefaultValue('Default value');
190 $arguments[] = $optionalArgument;
191 $mockArgumentMappingResults = $this->getMock('TYPO3\\CMS\\Extbase\\Property\\MappingResults', array(), array(), '', FALSE);
192 $mockArgumentMappingResults->expects($this->once())->method('hasErrors')->will($this->returnValue(FALSE));
193 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction', 'initializeAction'), array(), '', FALSE);
194 $mockSignalSlotDispatcher = $this->getMock('TYPO3\\CMS\Extbase\\SignalSlot\\Dispatcher', array(), array(), '', FALSE);
195 $mockController->_set('signalSlotDispatcher', $mockSignalSlotDispatcher);
196 $this->enableDeprecatedPropertyMapperInController($mockController);
197 $mockController->expects($this->once())->method('fooAction')->with('Default value');
198 $mockController->_set('request', $mockRequest);
199 $mockController->_set('response', $mockResponse);
200 $mockController->_set('arguments', $arguments);
201 $mockController->_set('actionMethodName', 'fooAction');
202 $mockController->_set('argumentsMappingResults', $mockArgumentMappingResults);
203 $mockController->_call('callActionMethod');
204 }
205
206 /**
207 * @test
208 * @author Karsten Dambekalns <karsten@typo3.org>
209 */
210 public function resolveViewUsesFluidTemplateViewIfTemplateIsAvailable() {
211 $mockSession = $this->getMock('Tx_Extbase_Session_SessionInterface');
212 $mockControllerContext = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext', array(), array(), '', FALSE);
213 $mockFluidTemplateView = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\View\\ViewInterface');
214 $mockFluidTemplateView->expects($this->once())->method('setControllerContext')->with($mockControllerContext);
215 $mockFluidTemplateView->expects($this->once())->method('canRender')->with($mockControllerContext)->will($this->returnValue(TRUE));
216 $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface', array(), array(), '', FALSE);
217 $mockObjectManager->expects($this->at(0))->method('get')->with('TYPO3\\CMS\\Fluid\\View\\TemplateView')->will($this->returnValue($mockFluidTemplateView));
218 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('buildControllerContext', 'resolveViewObjectName', 'setViewConfiguration'), array(), '', FALSE);
219 $mockController->expects($this->once())->method('resolveViewObjectName')->will($this->returnValue(FALSE));
220 $mockController->_set('session', $mockSession);
221 $mockController->_set('objectManager', $mockObjectManager);
222 $mockController->_set('controllerContext', $mockControllerContext);
223 $this->assertSame($mockFluidTemplateView, $mockController->_call('resolveView'));
224 }
225
226 /**
227 * @test
228 * @author Bastian Waidelich <bastian@typo3.org>
229 */
230 public function resolveViewObjectNameUsesViewObjectNamePatternToResolveViewObjectName() {
231 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
232 $mockRequest->expects($this->once())->method('getControllerVendorName')->will($this->returnValue('MyVendor'));
233 $mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('MyPackage'));
234 $mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('MyController'));
235 $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('MyAction'));
236 $mockRequest->expects($this->atLeastOnce())->method('getFormat')->will($this->returnValue('MyFormat'));
237 $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface', array(), array(), '', FALSE);
238 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
239 $mockController->_set('request', $mockRequest);
240 $mockController->_set('objectManager', $mockObjectManager);
241 $mockController->_set('namespacesViewObjectNamePattern', 'RandomViewObject@vendor\@extension\View\@controller\@action@format');
242 $mockController->_call('resolveViewObjectName');
243 }
244
245 /**
246 * @test
247 */
248 public function resolveViewObjectNameUsesDeprecatedViewObjectNamePatternForExtensionsWithoutVendor() {
249 eval('class Tx_MyPackage_View_MyController_MyActionMyFormat {}');
250
251 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
252 $mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('MyPackage'));
253 $mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('MyController'));
254 $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('MyAction'));
255 $mockRequest->expects($this->once())->method('getControllerVendorName')->will($this->returnValue(NULL));
256 $mockRequest->expects($this->atLeastOnce())->method('getFormat')->will($this->returnValue('MyFormat'));
257 $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface', array(), array(), '', FALSE);
258 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
259 $mockController->_set('request', $mockRequest);
260 $mockController->_set('objectManager', $mockObjectManager);
261
262 $this->assertEquals(
263 'Tx_MyPackage_View_MyController_MyActionMyFormat',
264 $mockController->_call('resolveViewObjectName')
265 );
266 }
267
268 /**
269 * @test
270 */
271 public function resolveViewObjectNameUsesNamespacedViewObjectNamePatternForExtensionsWithVendor() {
272 eval('namespace MyVendor\MyPackage\View\MyController; class MyActionMyFormat {}');
273
274 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
275 $mockRequest->expects($this->once())->method('getControllerExtensionName')->will($this->returnValue('MyPackage'));
276 $mockRequest->expects($this->once())->method('getControllerName')->will($this->returnValue('MyController'));
277 $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('MyAction'));
278 $mockRequest->expects($this->once())->method('getControllerVendorName')->will($this->returnValue('MyVendor'));
279 $mockRequest->expects($this->atLeastOnce())->method('getFormat')->will($this->returnValue('MyFormat'));
280 $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface', array(), array(), '', FALSE);
281 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
282 $mockController->_set('request', $mockRequest);
283 $mockController->_set('objectManager', $mockObjectManager);
284
285 $this->assertEquals(
286 'MyVendor\MyPackage\View\MyController\MyActionMyFormat',
287 $mockController->_call('resolveViewObjectName')
288 );
289 }
290
291 /**
292 * @test
293 * @author Robert Lemke <robert@typo3.org>
294 */
295 public function resolveActionMethodNameReturnsTheCurrentActionMethodNameFromTheRequest() {
296 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
297 $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('fooBar'));
298 /** @var \TYPO3\CMS\Extbase\Mvc\Controller\ActionController|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
299 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooBarAction'), array(), '', FALSE);
300 $mockController->_set('request', $mockRequest);
301 $this->assertEquals('fooBarAction', $mockController->_call('resolveActionMethodName'));
302 }
303
304 /**
305 * @test
306 * @expectedException \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchActionException
307 * @author Robert Lemke <robert@typo3.org>
308 */
309 public function resolveActionMethodNameThrowsAnExceptionIfTheActionDefinedInTheRequestDoesNotExist() {
310 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
311 $mockRequest->expects($this->once())->method('getControllerActionName')->will($this->returnValue('fooBar'));
312 /** @var \TYPO3\CMS\Extbase\Mvc\Controller\ActionController|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
313 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('otherBarAction'), array(), '', FALSE);
314 $mockController->_set('request', $mockRequest);
315 $mockController->_call('resolveActionMethodName');
316 }
317
318 /**
319 * @test
320 * @author Robert Lemke <robert@typo3.org>
321 */
322 public function initializeActionMethodArgumentsRegistersArgumentsFoundInTheSignatureOfTheCurrentActionMethod() {
323 $this->markTestSkipped('Triggers "UnexpectedValueException: Serialized string cannot be empty", with phpunit since PHP in 5.4.29 and 5.5.13, needs investigation, see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/178');
324 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
325 $mockArguments = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Arguments', array('addNewArgument', 'removeAll'), array(), '', FALSE);
326 $mockArguments->expects($this->at(0))->method('addNewArgument')->with('stringArgument', 'string', TRUE);
327 $mockArguments->expects($this->at(1))->method('addNewArgument')->with('integerArgument', 'integer', TRUE);
328 $mockArguments->expects($this->at(2))->method('addNewArgument')->with('objectArgument', 'F3_Foo_Bar', TRUE);
329 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction', 'evaluateDontValidateAnnotations'), array(), '', FALSE);
330 $methodParameters = array(
331 'stringArgument' => array(
332 'position' => 0,
333 'byReference' => FALSE,
334 'array' => FALSE,
335 'optional' => FALSE,
336 'allowsNull' => FALSE,
337 'type' => 'string'
338 ),
339 'integerArgument' => array(
340 'position' => 1,
341 'byReference' => FALSE,
342 'array' => FALSE,
343 'optional' => FALSE,
344 'allowsNull' => FALSE,
345 'type' => 'integer'
346 ),
347 'objectArgument' => array(
348 'position' => 2,
349 'byReference' => FALSE,
350 'array' => FALSE,
351 'optional' => FALSE,
352 'allowsNull' => FALSE,
353 'type' => 'F3_Foo_Bar'
354 )
355 );
356 $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
357 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
358 $mockController->_set('reflectionService', $mockReflectionService);
359 $mockController->_set('request', $mockRequest);
360 $mockController->_set('arguments', $mockArguments);
361 $mockController->_set('actionMethodName', 'fooAction');
362 $mockController->_call('initializeActionMethodArguments');
363 }
364
365 /**
366 * @test
367 * @author Robert Lemke <robert@typo3.org>
368 */
369 public function initializeActionMethodArgumentsRegistersOptionalArgumentsAsSuch() {
370 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
371 $mockArguments = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Arguments', array(), array(), '', FALSE);
372 $mockArguments->expects($this->at(0))->method('addNewArgument')->with('arg1', 'string', TRUE);
373 $mockArguments->expects($this->at(1))->method('addNewArgument')->with('arg2', 'array', FALSE, array(21));
374 $mockArguments->expects($this->at(2))->method('addNewArgument')->with('arg3', 'string', FALSE, 42);
375 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction', 'evaluateDontValidateAnnotations'), array(), '', FALSE);
376 $methodParameters = array(
377 'arg1' => array(
378 'position' => 0,
379 'byReference' => FALSE,
380 'array' => FALSE,
381 'optional' => FALSE,
382 'allowsNull' => FALSE,
383 'type' => 'string'
384 ),
385 'arg2' => array(
386 'position' => 1,
387 'byReference' => FALSE,
388 'array' => TRUE,
389 'optional' => TRUE,
390 'defaultValue' => array(21),
391 'allowsNull' => FALSE
392 ),
393 'arg3' => array(
394 'position' => 2,
395 'byReference' => FALSE,
396 'array' => FALSE,
397 'optional' => TRUE,
398 'defaultValue' => 42,
399 'allowsNull' => FALSE,
400 'type' => 'string'
401 )
402 );
403 $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
404 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
405 $mockController->_set('reflectionService', $mockReflectionService);
406 $mockController->_set('request', $mockRequest);
407 $mockController->_set('arguments', $mockArguments);
408 $mockController->_set('actionMethodName', 'fooAction');
409 $mockController->_call('initializeActionMethodArguments');
410 }
411
412 /**
413 * @test
414 * @author Sebastian Kurfürst <sbastian@typo3.org>
415 * @expectedException \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException
416 */
417 public function initializeActionMethodArgumentsThrowsExceptionIfDataTypeWasNotSpecified() {
418 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
419 $mockArguments = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Arguments', array(), array(), '', FALSE);
420 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction'), array(), '', FALSE);
421 $methodParameters = array(
422 'arg1' => array(
423 'position' => 0,
424 'byReference' => FALSE,
425 'array' => FALSE,
426 'optional' => FALSE,
427 'allowsNull' => FALSE
428 )
429 );
430 $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
431 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
432 $mockController->_set('reflectionService', $mockReflectionService);
433 $mockController->_set('request', $mockRequest);
434 $mockController->_set('arguments', $mockArguments);
435 $mockController->_set('actionMethodName', 'fooAction');
436 $mockController->_call('initializeActionMethodArguments');
437 }
438
439 /**
440 * @test
441 * @author Sebastian Kurfürst <sbastian@typo3.org>
442 */
443 public function initializeActionMethodValidatorsCorrectlyRegistersValidatorsBasedOnDataType() {
444 $this->markTestSkipped('Triggers "UnexpectedValueException: Serialized string cannot be empty", with phpunit since PHP in 5.4.29 and 5.5.13, needs investigation, see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/178');
445 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction'), array(), '', FALSE);
446 $this->enableDeprecatedPropertyMapperInController($mockController);
447 $argument = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('getName'), array(), '', FALSE);
448 $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1'));
449 $arguments = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Arguments', array('dummy'), array(), '', FALSE);
450 $arguments->addArgument($argument);
451 $methodTagsValues = array();
452 $methodArgumentsValidatorConjunctions = array();
453 $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
454 $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
455 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
456 $mockValidatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array(), array(), '', FALSE);
457 $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions));
458 $mockController->_set('reflectionService', $mockReflectionService);
459 $mockController->_set('validatorResolver', $mockValidatorResolver);
460 $mockController->_set('arguments', $arguments);
461 $mockController->_set('actionMethodName', 'fooAction');
462 $mockController->_call('initializeActionMethodValidators');
463 $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator());
464 }
465
466 /**
467 * @test
468 * @author Sebastian Kurfürst <sbastian@typo3.org>
469 */
470 public function initializeActionMethodValidatorsRegistersModelBasedValidators() {
471 $this->markTestSkipped('Triggers "UnexpectedValueException: Serialized string cannot be empty", with phpunit since PHP in 5.4.29 and 5.5.13, needs investigation, see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/178');
472 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction'), array(), '', FALSE);
473 $this->enableDeprecatedPropertyMapperInController($mockController);
474 $argument = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('getName', 'getDataType'), array(), '', FALSE);
475 $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1'));
476 $argument->expects($this->any())->method('getDataType')->will($this->returnValue('F3_Foo_Quux'));
477 $arguments = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Arguments', array('dummy'), array(), '', FALSE);
478 $arguments->addArgument($argument);
479 $methodTagsValues = array();
480 $quuxBaseValidatorConjunction = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
481 $methodArgumentsValidatorConjunctions = array();
482 $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
483 $methodArgumentsValidatorConjunctions['arg1']->expects($this->once())->method('addValidator')->with($quuxBaseValidatorConjunction);
484 $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
485 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
486 $mockValidatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array(), array(), '', FALSE);
487 $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions));
488 $mockValidatorResolver->expects($this->once())->method('getBaseValidatorConjunction')->with('F3_Foo_Quux')->will($this->returnValue($quuxBaseValidatorConjunction));
489 $mockController->_set('reflectionService', $mockReflectionService);
490 $mockController->_set('validatorResolver', $mockValidatorResolver);
491 $mockController->_set('arguments', $arguments);
492 $mockController->_set('actionMethodName', 'fooAction');
493 $mockController->_call('initializeActionMethodValidators');
494 $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator());
495 }
496
497 /**
498 * @test
499 * @author Sebastian Kurfürst <sbastian@typo3.org>
500 */
501 public function initializeActionMethodValidatorsDoesNotRegisterModelBasedValidatorsIfDontValidateAnnotationIsSet() {
502 $this->markTestSkipped('Triggers "UnexpectedValueException: Serialized string cannot be empty", with phpunit since PHP in 5.4.29 and 5.5.13, needs investigation, see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/178');
503 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction'), array(), '', FALSE);
504 $this->enableDeprecatedPropertyMapperInController($mockController);
505 $argument = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('getName', 'getDataType'), array(), '', FALSE);
506 $argument->expects($this->any())->method('getName')->will($this->returnValue('arg1'));
507 $argument->expects($this->any())->method('getDataType')->will($this->returnValue('F3_Foo_Quux'));
508 $arguments = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Arguments', array('dummy'), array(), '', FALSE);
509 $arguments->addArgument($argument);
510 $methodTagsValues = array(
511 'dontvalidate' => array(
512 '$arg1'
513 )
514 );
515 $methodArgumentsValidatorConjunctions = array();
516 $methodArgumentsValidatorConjunctions['arg1'] = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
517 $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
518 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
519 $mockValidatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array(), array(), '', FALSE);
520 $mockValidatorResolver->expects($this->once())->method('buildMethodArgumentsValidatorConjunctions')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodArgumentsValidatorConjunctions));
521 $mockValidatorResolver->expects($this->any())->method('getBaseValidatorConjunction')->will($this->throwException(new \Exception('This should not be called because the dontvalidate annotation is set.')));
522 $mockController->_set('reflectionService', $mockReflectionService);
523 $mockController->_set('validatorResolver', $mockValidatorResolver);
524 $mockController->_set('arguments', $arguments);
525 $mockController->_set('actionMethodName', 'fooAction');
526 $mockController->_call('initializeActionMethodValidators');
527 $this->assertEquals($methodArgumentsValidatorConjunctions['arg1'], $arguments['arg1']->getValidator());
528 }
529
530 /**
531 * @test
532 * @author Christopher Hlubek <hlubek@networkteam.com>
533 */
534 public function defaultErrorActionSetsArgumentMappingResultsErrorsInRequest() {
535 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
536 $mockError = $this->getMock('TYPO3\\CMS\\Extbase\\Error\\Error', array('getMessage'), array(), '', FALSE);
537 $mockArgumentsMappingResults = $this->getMock('TYPO3\\CMS\\Extbase\\Property\\MappingResults', array('getErrors', 'getWarnings'), array(), '', FALSE);
538 $mockArgumentsMappingResults->expects($this->atLeastOnce())->method('getErrors')->will($this->returnValue(array($mockError)));
539 $mockArgumentsMappingResults->expects($this->any())->method('getWarnings')->will($this->returnValue(array()));
540 /** @var $mockController \TYPO3\CMS\Extbase\Mvc\Controller\ActionController|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
541 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('clearCacheOnError'), array(), '', FALSE);
542 $controllerContext = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext', array('getFlashMessageQueue'));
543 $controllerContext->expects($this->any())->method('getFlashMessageQueue')->will($this->returnValue(new \TYPO3\CMS\Core\Messaging\FlashMessageQueue('foo')));
544 $this->enableDeprecatedPropertyMapperInController($mockController);
545 $mockController->_set('controllerContext', $controllerContext);
546 $mockController->_set('request', $mockRequest);
547 $mockController->_set('argumentsMappingResults', $mockArgumentsMappingResults);
548 $mockRequest->expects($this->once())->method('setErrors')->with(array($mockError));
549 $mockController->_call('errorAction');
550 }
551
552 /**
553 * Data Provider for checkRequestHashDoesNotThrowExceptionInNormalOperations
554 *
555 * @return array
556 */
557 public function checkRequestHashInNormalOperation() {
558 return array(
559 // HMAC is verified
560 array(TRUE),
561 // HMAC not verified, but objects are directly fetched from persistence layer
562 array(FALSE, FALSE, \TYPO3\CMS\Extbase\Mvc\Controller\Argument::ORIGIN_PERSISTENCE, \TYPO3\CMS\Extbase\Mvc\Controller\Argument::ORIGIN_PERSISTENCE),
563 // HMAC not verified, objects new and modified, but dontverifyrequesthash-annotation set
564 array(FALSE, TRUE, \TYPO3\CMS\Extbase\Mvc\Controller\Argument::ORIGIN_PERSISTENCE, \TYPO3\CMS\Extbase\Mvc\Controller\Argument::ORIGIN_PERSISTENCE_AND_MODIFIED, array('dontverifyrequesthash' => ''))
565 );
566 }
567
568 /**
569 * @test
570 * @author Sebastian Kurfürst <sebastian@typo3.org>
571 * @dataProvider checkRequestHashInNormalOperation
572 * @param boolean $hmacVerified
573 * @param boolean $reflectionServiceNeedsInitialization
574 * @param integer $argument1Origin
575 * @param integer $argument2Origin
576 * @param array $methodTagsValues
577 */
578 public function checkRequestHashDoesNotThrowExceptionInNormalOperations($hmacVerified, $reflectionServiceNeedsInitialization = FALSE, $argument1Origin = 3, $argument2Origin = 3, array $methodTagsValues = array()) {
579 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request', array('isHmacVerified'), array(), '', FALSE);
580 $mockRequest->expects($this->once())->method('isHmacVerified')->will($this->returnValue($hmacVerified));
581 $argument1 = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('getOrigin'), array(), '', FALSE);
582 $argument1->expects($this->any())->method('getOrigin')->will($this->returnValue($argument1Origin));
583 $argument2 = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('getOrigin'), array(), '', FALSE);
584 $argument2->expects($this->any())->method('getOrigin')->will($this->returnValue($argument2Origin));
585 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
586 $this->enableDeprecatedPropertyMapperInController($mockController);
587 $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array('getMethodTagsValues'), array(), '', FALSE);
588 if ($reflectionServiceNeedsInitialization) {
589 // Somehow this is needed, else I get "Mocked method does not exist."
590 $mockReflectionService->expects($this->any())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
591 }
592 $mockController->_set('arguments', array($argument1, $argument2));
593 $mockController->_set('request', $mockRequest);
594 $mockController->_set('actionMethodName', 'fooAction');
595 $mockController->_set('reflectionService', $mockReflectionService);
596 $mockController->_call('checkRequestHash');
597 }
598
599 /**
600 * @test
601 * @expectedException \TYPO3\CMS\Extbase\Mvc\Exception\InvalidOrNoRequestHashException
602 * @author Sebastian Kurfürst <sebastian@typo3.org>
603 */
604 public function checkRequestHashThrowsExceptionIfNeeded() {
605 $hmacVerified = FALSE;
606 $argument1Origin = \TYPO3\CMS\Extbase\Mvc\Controller\Argument::ORIGIN_PERSISTENCE_AND_MODIFIED;
607 $argument2Origin = \TYPO3\CMS\Extbase\Mvc\Controller\Argument::ORIGIN_PERSISTENCE;
608 $methodTagsValues = array();
609 $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request', array('isHmacVerified'), array(), '', FALSE);
610 $mockRequest->expects($this->once())->method('isHmacVerified')->will($this->returnValue($hmacVerified));
611 $argument1 = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('getOrigin'), array(), '', FALSE);
612 $argument1->expects($this->any())->method('getOrigin')->will($this->returnValue($argument1Origin));
613 $argument2 = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument', array('getOrigin'), array(), '', FALSE);
614 $argument2->expects($this->any())->method('getOrigin')->will($this->returnValue($argument2Origin));
615 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
616 $this->enableDeprecatedPropertyMapperInController($mockController);
617 $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array('getMethodTagsValues'), array(), '', FALSE);
618 $mockReflectionService->expects($this->any())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
619 $mockController->_set('arguments', array($argument1, $argument2));
620 $mockController->_set('request', $mockRequest);
621 $mockController->_set('actionMethodName', 'fooAction');
622 $mockController->_set('reflectionService', $mockReflectionService);
623 $mockController->_call('checkRequestHash');
624 }
625
626 /**
627 * Helper which enables the deprecated property mapper in the ActionController class.
628 *
629 * @param \TYPO3\CMS\Extbase\Mvc\Controller\ActionController $actionController
630 */
631 protected function enableDeprecatedPropertyMapperInController(\TYPO3\CMS\Extbase\Mvc\Controller\ActionController $actionController) {
632 $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
633 $mockConfigurationManager->expects($this->any())->method('isFeatureEnabled')->with('rewrittenPropertyMapper')->will($this->returnValue(FALSE));
634 $actionController->injectConfigurationManager($mockConfigurationManager);
635 }
636
637 /**
638 * @test
639 * @dataProvider templateRootPathDataProvider
640 * @param array $configuration
641 * @param array $expected
642 */
643 public function setViewConfigurationResolvesTemplateRootPathsForTemplateRootPath($configuration, $expected) {
644 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
645 $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
646 $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration));
647 $mockController->injectConfigurationManager($mockConfigurationManager);
648 $mockController->_set('request', $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request'), array('getControllerExtensionKey'));
649 $view = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\View\\ViewInterface', array('setControllerContext', 'assign', 'assignMultiple', 'canRender', 'render', 'initializeView', 'setTemplateRootPaths'));
650 $view->expects($this->once())->method('setTemplateRootPaths')->with($expected);
651 $mockController->_call('setViewConfiguration', $view);
652 }
653
654 /**
655 * @return array
656 */
657 public function templateRootPathDataProvider() {
658 return array(
659 'old behaviour only' => array(
660 array(
661 'view' => array(
662 'templateRootPath' => 'some path'
663 )
664 ),
665 array('some path')
666 ),
667 'new behaviour only with text keys' => array(
668 array(
669 'view' => array(
670 'templateRootPaths' => array(
671 'default' => 'some path',
672 'extended' => 'some other path'
673 )
674 )
675 ),
676 array(
677 'extended' => 'some other path',
678 'default' => 'some path'
679 )
680 ),
681 'new behaviour only with numerical keys' => array(
682 array(
683 'view' => array(
684 'templateRootPaths' => array(
685 '10' => 'some path',
686 '20' => 'some other path',
687 '15' => 'intermediate specific path'
688 )
689 )
690 ),
691 array(
692 '20' => 'some other path',
693 '15' => 'intermediate specific path',
694 '10' => 'some path'
695 )
696 ),
697 'new behaviour only with mixed keys' => array(
698 array(
699 'view' => array(
700 'templateRootPaths' => array(
701 '10' => 'some path',
702 'very_specific' => 'some other path',
703 '15' => 'intermediate specific path'
704 )
705 )
706 ),
707 array(
708 '15' => 'intermediate specific path',
709 'very_specific' => 'some other path',
710 '10' => 'some path'
711 )
712 ),
713 'old and new behaviour mixed with text keys' => array(
714 array(
715 'view' => array(
716 'templateRootPaths' => array(
717 'default' => 'some path',
718 'specific' => 'intermediate specific path',
719 'very_specific' => 'some other path'
720 ),
721 'templateRootPath' => 'old path'
722 )
723 ),
724 array(
725 'very_specific' => 'some other path',
726 'specific' => 'intermediate specific path',
727 'default' => 'some path',
728 '0' => 'old path'
729 )
730 ),
731 'old and new behaviour mixed with numerical keys' => array(
732 array(
733 'view' => array(
734 'templateRootPaths' => array(
735 '10' => 'some path',
736 '20' => 'intermediate specific path',
737 '30' => 'some other path'
738 ),
739 'templateRootPath' => 'old path'
740 )
741 ),
742 array(
743 '30' => 'some other path',
744 '20' => 'intermediate specific path',
745 '10' => 'some path',
746 '31' => 'old path'
747 )
748 ),
749 'old and new behaviour mixed with mixed keys' => array(
750 array(
751 'view' => array(
752 'templateRootPaths' => array(
753 '10' => 'some path',
754 'very_specific' => 'some other path',
755 '15' => 'intermediate specific path'
756 ),
757 'templateRootPath' => 'old path'
758 )
759 ),
760 array(
761 '15' => 'intermediate specific path',
762 'very_specific' => 'some other path',
763 '10' => 'some path',
764 '16' => 'old path'
765 )
766 )
767 );
768 }
769
770 /**
771 * @test
772 * @dataProvider layoutRootPathDataProvider
773 *
774 * @param array $configuration
775 * @param array $expected
776 */
777 public function setViewConfigurationResolvesLayoutRootPathsForLayoutRootPath($configuration, $expected) {
778 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
779 $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
780 $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration));
781 $mockController->injectConfigurationManager($mockConfigurationManager);
782 $mockController->_set('request', $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request'), array('getControllerExtensionKey'));
783 $view = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\View\\ViewInterface', array('setControllerContext', 'assign', 'assignMultiple', 'canRender', 'render', 'initializeView', 'setlayoutRootPaths'));
784 $view->expects($this->once())->method('setlayoutRootPaths')->with($expected);
785 $mockController->_call('setViewConfiguration', $view);
786 }
787
788 /**
789 * @return array
790 */
791 public function layoutRootPathDataProvider() {
792 return array(
793 'old behaviour only' => array(
794 array(
795 'view' => array(
796 'layoutRootPath' => 'some path'
797 )
798 ),
799 array('some path')
800 ),
801 'new behaviour only with text keys' => array(
802 array(
803 'view' => array(
804 'layoutRootPaths' => array(
805 'default' => 'some path',
806 'extended' => 'some other path'
807 )
808 )
809 ),
810 array(
811 'extended' => 'some other path',
812 'default' => 'some path'
813 )
814 ),
815 'new behaviour only with numerical keys' => array(
816 array(
817 'view' => array(
818 'layoutRootPaths' => array(
819 '10' => 'some path',
820 '20' => 'some other path',
821 '15' => 'intermediate specific path'
822 )
823 )
824 ),
825 array(
826 '20' => 'some other path',
827 '15' => 'intermediate specific path',
828 '10' => 'some path'
829 )
830 ),
831 'new behaviour only with mixed keys' => array(
832 array(
833 'view' => array(
834 'layoutRootPaths' => array(
835 '10' => 'some path',
836 'very_specific' => 'some other path',
837 '15' => 'intermediate specific path'
838 )
839 )
840 ),
841 array(
842 '15' => 'intermediate specific path',
843 'very_specific' => 'some other path',
844 '10' => 'some path'
845 )
846 ),
847 'old and new behaviour mixed with text keys' => array(
848 array(
849 'view' => array(
850 'layoutRootPaths' => array(
851 'default' => 'some path',
852 'specific' => 'intermediate specific path',
853 'very_specific' => 'some other path'
854 ),
855 'layoutRootPath' => 'old path'
856 )
857 ),
858 array(
859 'very_specific' => 'some other path',
860 'specific' => 'intermediate specific path',
861 'default' => 'some path',
862 '0' => 'old path'
863 )
864 ),
865 'old and new behaviour mixed with numerical keys' => array(
866 array(
867 'view' => array(
868 'layoutRootPaths' => array(
869 '10' => 'some path',
870 '20' => 'intermediate specific path',
871 '30' => 'some other path'
872 ),
873 'layoutRootPath' => 'old path'
874 )
875 ),
876 array(
877 '30' => 'some other path',
878 '20' => 'intermediate specific path',
879 '10' => 'some path',
880 '31' => 'old path'
881 )
882 ),
883 'old and new behaviour mixed with mixed keys' => array(
884 array(
885 'view' => array(
886 'layoutRootPaths' => array(
887 '10' => 'some path',
888 'very_specific' => 'some other path',
889 '15' => 'intermediate specific path'
890 ),
891 'layoutRootPath' => 'old path'
892 )
893 ),
894 array(
895 '15' => 'intermediate specific path',
896 'very_specific' => 'some other path',
897 '10' => 'some path',
898 '16' => 'old path'
899 )
900 )
901 );
902 }
903
904 /**
905 * @test
906 * @dataProvider partialRootPathDataProvider
907 *
908 * @param array $configuration
909 * @param array $expected
910 */
911 public function setViewConfigurationResolvesPartialRootPathsForPartialRootPath($configuration, $expected) {
912 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('dummy'), array(), '', FALSE);
913 $mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
914 $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration));
915 $mockController->injectConfigurationManager($mockConfigurationManager);
916 $mockController->_set('request', $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request'), array('getControllerExtensionKey'));
917 $view = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\View\\ViewInterface', array('setControllerContext', 'assign', 'assignMultiple', 'canRender', 'render', 'initializeView', 'setpartialRootPaths'));
918 $view->expects($this->once())->method('setpartialRootPaths')->with($expected);
919 $mockController->_call('setViewConfiguration', $view);
920 }
921
922 /**
923 * @return array
924 */
925 public function partialRootPathDataProvider() {
926 return array(
927 'old behaviour only' => array(
928 array(
929 'view' => array(
930 'partialRootPath' => 'some path'
931 )
932 ),
933 array('some path')
934 ),
935 'new behaviour only with text keys' => array(
936 array(
937 'view' => array(
938 'partialRootPaths' => array(
939 'default' => 'some path',
940 'extended' => 'some other path'
941 )
942 )
943 ),
944 array(
945 'extended' => 'some other path',
946 'default' => 'some path'
947 )
948 ),
949 'new behaviour only with numerical keys' => array(
950 array(
951 'view' => array(
952 'partialRootPaths' => array(
953 '10' => 'some path',
954 '20' => 'some other path',
955 '15' => 'intermediate specific path'
956 )
957 )
958 ),
959 array(
960 '20' => 'some other path',
961 '15' => 'intermediate specific path',
962 '10' => 'some path'
963 )
964 ),
965 'new behaviour only with mixed keys' => array(
966 array(
967 'view' => array(
968 'partialRootPaths' => array(
969 '10' => 'some path',
970 'very_specific' => 'some other path',
971 '15' => 'intermediate specific path'
972 )
973 )
974 ),
975 array(
976 '15' => 'intermediate specific path',
977 'very_specific' => 'some other path',
978 '10' => 'some path'
979 )
980 ),
981 'old and new behaviour mixed with text keys' => array(
982 array(
983 'view' => array(
984 'partialRootPath' => 'old path',
985 'partialRootPaths' => array(
986 'default' => 'some path',
987 'specific' => 'intermediate specific path',
988 'very_specific' => 'some other path'
989 )
990 )
991 ),
992 array(
993 'very_specific' => 'some other path',
994 'specific' => 'intermediate specific path',
995 'default' => 'some path',
996 '0' => 'old path'
997 )
998 ),
999 'old and new behaviour mixed with numerical keys' => array(
1000 array(
1001 'view' => array(
1002 'partialRootPaths' => array(
1003 '10' => 'some path',
1004 '20' => 'intermediate specific path',
1005 '30' => 'some other path'
1006 ),
1007 'partialRootPath' => 'old path'
1008 )
1009 ),
1010 array(
1011 '30' => 'some other path',
1012 '20' => 'intermediate specific path',
1013 '10' => 'some path',
1014 '31' => 'old path'
1015 )
1016 ),
1017 'old and new behaviour mixed with mixed keys' => array(
1018 array(
1019 'view' => array(
1020 'partialRootPaths' => array(
1021 '10' => 'some path',
1022 'very_specific' => 'some other path',
1023 '15' => 'intermediate specific path'
1024 ),
1025 'partialRootPath' => 'old path'
1026 )
1027 ),
1028 array(
1029 '15' => 'intermediate specific path',
1030 'very_specific' => 'some other path',
1031 '10' => 'some path',
1032 '16' => 'old path'
1033 )
1034 )
1035 );
1036 }
1037 }