/** * @test */ public function dispatchContinuesWithNextRequestFoundInAForwardException() { /** @var ActionRequest|\PHPUnit_Framework_MockObject_MockObject $nextRequest */ $nextRequest = $this->getMockBuilder(\TYPO3\Flow\Mvc\ActionRequest::class)->disableOriginalConstructor()->getMock(); $nextRequest->expects($this->atLeastOnce())->method('isDispatched')->will($this->returnValue(TRUE)); $this->mockParentRequest->expects($this->atLeastOnce())->method('isDispatched')->will($this->returnValue(FALSE)); $this->mockController->expects($this->at(0))->method('processRequest')->with($this->mockActionRequest)->will($this->throwException(new StopActionException())); $forwardException = new ForwardException(); $forwardException->setNextRequest($nextRequest); $this->mockController->expects($this->at(1))->method('processRequest')->with($this->mockParentRequest)->will($this->throwException($forwardException)); $this->dispatcher->dispatch($this->mockActionRequest, $this->mockHttpResponse); }
/** * @test */ public function dispatchContinuesWithNextRequestFoundInAForwardException() { $subRequest = $this->getMockBuilder('TYPO3\\Flow\\Mvc\\ActionRequest')->disableOriginalConstructor()->getMock(); $subRequest->expects($this->atLeastOnce())->method('isMainRequest')->will($this->returnValue(FALSE)); $subRequest->expects($this->atLeastOnce())->method('getParentRequest')->will($this->returnValue($this->mockRequest)); $subRequest->expects($this->atLeastOnce())->method('isDispatched')->will($this->returnValue(FALSE)); $nextRequest = $this->getMockBuilder('TYPO3\\Flow\\Mvc\\ActionRequest')->disableOriginalConstructor()->getMock(); $nextRequest->expects($this->atLeastOnce())->method('isDispatched')->will($this->returnValue(TRUE)); $this->mockRequest->expects($this->atLeastOnce())->method('isDispatched')->will($this->returnValue(FALSE)); $this->mockController->expects($this->at(0))->method('processRequest')->with($subRequest)->will($this->throwException(new \TYPO3\Flow\Mvc\Exception\StopActionException())); $forwardException = new ForwardException(); $forwardException->setNextRequest($nextRequest); $this->mockController->expects($this->at(1))->method('processRequest')->with($this->mockRequest)->will($this->throwException($forwardException)); $this->dispatcher->dispatch($subRequest, $this->mockResponse); }
/** * @test */ public function dispatchContinuesWithNextRequestFoundInAForwardException() { $httpRequest = Request::create(new Uri('http://localhost')); $httpResponse = new Response(); $mainRequest = $httpRequest->createActionRequest(); $subRequest = new ActionRequest($mainRequest); $nextRequest = $httpRequest->createActionRequest(); $mainRequest->setDispatched(TRUE); $mainRequest->setControllerSubPackageKey('main'); $subRequest->setControllerSubPackageKey('sub'); $nextRequest->setControllerSubPackageKey('next'); $mockController = $this->getMock('TYPO3\\Flow\\Mvc\\Controller\\ControllerInterface', array('processRequest')); $mockController->expects($this->at(0))->method('processRequest')->will($this->returnCallback(function (ActionRequest $request) use($nextRequest) { $request->setDispatched(TRUE); $forwardException = new ForwardException(); $forwardException->setNextRequest($nextRequest); throw $forwardException; })); $mockController->expects($this->at(1))->method('processRequest')->will($this->returnCallback(function (ActionRequest $request) use($nextRequest) { // NOTE: PhpUnit creates a clone of $nextRequest, thus $request is not the same instance as expected. if ($request == $nextRequest) { $nextRequest->setDispatched(TRUE); } })); $dispatcher = $this->getMock('TYPO3\\Flow\\Mvc\\Dispatcher', array('resolveController', 'emitAfterControllerInvocation'), array(), '', FALSE); $dispatcher->expects($this->any())->method('resolveController')->will($this->returnValue($mockController)); $dispatcher->dispatch($subRequest, $httpResponse); }
/** * Forwards the request to another action and / or controller. * * Request is directly transferred to the other action / controller * * @param string $actionName Name of the action to forward to * @param string $controllerName Unqualified object name of the controller to forward to. If not specified, the current controller is used. * @param string $packageKey Key of the package containing the controller to forward to. May also contain the sub package, concatenated with backslash (Vendor.Foo\Bar\Baz). If not specified, the current package is assumed. * @param array $arguments Arguments to pass to the target action * @return void * @throws ForwardException * @see redirect() * @api */ protected function forward($actionName, $controllerName = null, $packageKey = null, array $arguments = []) { $nextRequest = clone $this->request; $nextRequest->setControllerActionName($actionName); if ($controllerName !== null) { $nextRequest->setControllerName($controllerName); } if ($packageKey !== null && strpos($packageKey, '\\') !== false) { list($packageKey, $subpackageKey) = explode('\\', $packageKey, 2); } else { $subpackageKey = null; } if ($packageKey !== null) { $nextRequest->setControllerPackageKey($packageKey); $nextRequest->setControllerSubpackageKey($subpackageKey); } $regularArguments = []; foreach ($arguments as $argumentName => $argumentValue) { if (substr($argumentName, 0, 2) === '__') { $nextRequest->setArgument($argumentName, $argumentValue); } else { $regularArguments[$argumentName] = $argumentValue; } } $nextRequest->setArguments($this->persistenceManager->convertObjectsToIdentityArrays($regularArguments)); $this->arguments->removeAll(); $forwardException = new ForwardException(); $forwardException->setNextRequest($nextRequest); throw $forwardException; }