TYPO3 API  SVNRelease
DispatcherTest.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2010 Jochen Rau <jochen.rau@typoplanet.de>
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00024 
00025 /**
00026  * Testcase for the MVC Dispatcher
00027  *
00028  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
00029  */
00030 class Tx_Extbase_Tests_Unit_MVC_DispatcherTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
00031 
00032     /**
00033      * @test
00034      */
00035     public function dispatchCallsTheControllersProcessRequestMethodUntilTheIsDispatchedFlagInTheRequestObjectIsSet() {
00036         $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface');
00037         $mockRequest->expects($this->at(0))->method('isDispatched')->will($this->returnValue(FALSE));
00038         $mockRequest->expects($this->at(1))->method('isDispatched')->will($this->returnValue(FALSE));
00039         $mockRequest->expects($this->at(2))->method('isDispatched')->will($this->returnValue(TRUE));
00040 
00041         $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface');
00042 
00043         $mockController = $this->getMock('Tx_Extbase_MVC_Controller_ControllerInterface', array('processRequest', 'canProcessRequest'));
00044         $mockController->expects($this->exactly(2))->method('processRequest')->with($mockRequest, $mockResponse);
00045 
00046         $dispatcher = $this->getMock('Tx_Extbase_MVC_Dispatcher', array('resolveController'), array(), '', FALSE);
00047         $dispatcher->expects($this->any())->method('resolveController')->will($this->returnValue($mockController));
00048         $dispatcher->dispatch($mockRequest, $mockResponse);
00049     }
00050 
00051     /**
00052      * @test
00053      * @expectedException Tx_Extbase_MVC_Exception_InfiniteLoop
00054      */
00055     public function dispatchThrowsAnInfiniteLoopExceptionIfTheRequestCouldNotBeDispachedAfter99Iterations() {
00056         $requestCallCounter = 0;
00057         /*
00058         $requestCallBack = function() use (&$requestCallCounter) {
00059             return ($requestCallCounter++ < 101) ? FALSE : TRUE;
00060         };
00061          */
00062         $mockRequest = $this->getMock('Tx_Extbase_MVC_RequestInterface');
00063         $mockRequest->expects($this->any())->method('isDispatched')->will($this->returnCallBack($requestCallBack, '__invoke'));
00064 
00065         $mockResponse = $this->getMock('Tx_Extbase_MVC_ResponseInterface');
00066         $mockController = $this->getMock('Tx_Extbase_MVC_Controller_ControllerInterface', array('processRequest', 'canProcessRequest'));
00067 
00068         $dispatcher = $this->getMock('Tx_Extbase_MVC_Dispatcher', array('resolveController'), array(), '', FALSE);
00069         $dispatcher->expects($this->any())->method('resolveController')->will($this->returnValue($mockController));
00070         $dispatcher->dispatch($mockRequest, $mockResponse);
00071     }
00072 
00073 }
00074 ?>