[BUGFIX] CLI argument handling chokes on = use
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / MVC / DispatcherTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Testcase for the MVC Dispatcher
27 *
28 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
29 */
30 class Tx_Extbase_Tests_Unit_MVC_DispatcherTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
31
32 /**
33 * @test
34 */
35 public function dispatchCallsTheControllersProcessRequestMethodUntilTheIsDispatchedFlagInTheRequestObjectIsSet() {
36 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface');
37 $mockRequest->expects($this->at(0))->method('isDispatched')->will($this->returnValue(FALSE));
38 $mockRequest->expects($this->at(1))->method('isDispatched')->will($this->returnValue(FALSE));
39 $mockRequest->expects($this->at(2))->method('isDispatched')->will($this->returnValue(TRUE));
40
41 $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface');
42
43 $mockController = $this->getMock('Tx_Extbase_MVC_Controller_ControllerInterface', array('processRequest', 'canProcessRequest'));
44 $mockController->expects($this->exactly(2))->method('processRequest')->with($mockRequest, $mockResponse);
45 $mockSignalSlotDispatcher = $this->getMock('Tx_Extbase_SignalSlot_Dispatcher', array('dispatch'));
46
47 $dispatcher = $this->getMock('Tx_Extbase_MVC_Dispatcher', array('resolveController'), array(), '', FALSE);
48 $dispatcher->injectSignalSlotDispatcher($mockSignalSlotDispatcher);
49 $dispatcher->expects($this->any())->method('resolveController')->will($this->returnValue($mockController));
50 $dispatcher->dispatch($mockRequest, $mockResponse);
51 }
52
53 /**
54 * @test
55 * @expectedException Tx_Extbase_MVC_Exception_InfiniteLoop
56 */
57 public function dispatchThrowsAnInfiniteLoopExceptionIfTheRequestCouldNotBeDispachedAfter99Iterations() {
58 $requestCallCounter = 0;
59 $requestCallBack = function() use (&$requestCallCounter) {
60 return ($requestCallCounter++ < 101) ? FALSE : TRUE;
61 };
62 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface');
63 $mockRequest->expects($this->any())->method('isDispatched')->will($this->returnCallBack($requestCallBack, '__invoke'));
64
65 $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface');
66 $mockController = $this->getMock('Tx_Extbase_MVC_Controller_ControllerInterface', array('processRequest', 'canProcessRequest'));
67 $mockSignalSlotDispatcher = $this->getMock('Tx_Extbase_SignalSlot_Dispatcher', array('dispatch'));
68
69 $dispatcher = $this->getMock('Tx_Extbase_MVC_Dispatcher', array('resolveController'), array(), '', FALSE);
70 $dispatcher->injectSignalSlotDispatcher($mockSignalSlotDispatcher);
71 $dispatcher->expects($this->any())->method('resolveController')->will($this->returnValue($mockController));
72 $dispatcher->dispatch($mockRequest, $mockResponse);
73 }
74
75 /**
76 * @test
77 */
78 public function dispatchDispatchesSignalAfterDispatchOfRequest() {
79
80 $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface');
81 $mockRequest->expects($this->at(0))->method('isDispatched')->will($this->returnValue(TRUE));
82
83 $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface');
84
85 $mockSignalSlotDispatcher = $this->getMock('Tx_Extbase_SignalSlot_Dispatcher', array('dispatch'));
86 $mockSignalSlotDispatcher->expects($this->exactly(1))->method('dispatch')->with('Tx_Extbase_MVC_Dispatcher', 'afterRequestDispatch', array('request' => $mockRequest, 'response' => $mockResponse));
87
88 $dispatcher = $this->getMock('Tx_Extbase_MVC_Dispatcher', array('resolveController'), array(), '', FALSE);
89 $dispatcher->injectSignalSlotDispatcher($mockSignalSlotDispatcher);
90 $dispatcher->dispatch($mockRequest, $mockResponse);
91 }
92 }
93 ?>