/** * Initializes the controller * * This method should be called by the concrete processRequest() method. * * @param \TYPO3\FLOW3\Mvc\RequestInterface $request * @param \TYPO3\FLOW3\Mvc\ResponseInterface $response * @throws \TYPO3\FLOW3\Mvc\Exception\UnsupportedRequestTypeException */ protected function initializeController(\TYPO3\FLOW3\Mvc\RequestInterface $request, \TYPO3\FLOW3\Mvc\ResponseInterface $response) { if (!$request instanceof ActionRequest) { throw new \TYPO3\FLOW3\Mvc\Exception\UnsupportedRequestTypeException(get_class($this) . ' only supports action requests – requests of type "' . get_class($request) . '" given. ', 1187701131); } $this->request = $request; $this->request->setDispatched(TRUE); $this->response = $response; $this->uriBuilder = new UriBuilder(); $this->uriBuilder->setRequest($this->request); $this->arguments = new Arguments(array()); $this->controllerContext = new ControllerContext($this->request, $this->response, $this->arguments, $this->uriBuilder, $this->flashMessageContainer); $mediaType = $request->getHttpRequest()->getNegotiatedMediaType($this->supportedMediaTypes); if ($mediaType === NULL) { $this->throwStatus(406); } if ($request->getFormat() === NULL) { $this->request->setFormat(MediaTypes::getFilenameExtensionFromMediaType($mediaType)); } }
/** * @test */ public function redirectUsesRequestFormatAsDefaultAndUnsetsSubPackageKeyIfNeccessary() { $arguments = array('foo' => 'bar'); $request = new ActionRequest(HttpRequest::create(new Uri('http://localhost/foo.json'))); $request->setFormat('json'); $response = new HttpResponse(); $mockUriBuilder = $this->getMock('TYPO3\\FLOW3\\Mvc\\Routing\\UriBuilder'); $mockUriBuilder->expects($this->once())->method('reset')->will($this->returnValue($mockUriBuilder)); $mockUriBuilder->expects($this->once())->method('setFormat')->with('json')->will($this->returnValue($mockUriBuilder)); $mockUriBuilder->expects($this->once())->method('setCreateAbsoluteUri')->will($this->returnValue($mockUriBuilder)); $mockUriBuilder->expects($this->once())->method('uriFor')->with('show', $arguments, 'Stuff', 'Super', NULL)->will($this->returnValue('the uri')); $controller = $this->getAccessibleMock('TYPO3\\FLOW3\\Mvc\\Controller\\AbstractController', array('processRequest', 'redirectToUri')); $this->inject($controller, 'flashMessageContainer', new FlashMessageContainer()); $controller->_call('initializeController', $request, $response); $this->inject($controller, 'uriBuilder', $mockUriBuilder); $controller->expects($this->once())->method('redirectToUri')->with('the uri'); $controller->_call('redirect', 'show', 'Stuff', 'Super', $arguments); }
/** * @test */ public function theRepresentationFormatCanBeSetAndRetrieved() { $httpRequest = HttpRequest::create(new Uri('http://foo.com')); $actionRequest = new ActionRequest($httpRequest); $actionRequest->setFormat('html'); $this->assertEquals('html', $actionRequest->getFormat()); $actionRequest->setFormat('doc'); $this->assertEquals('doc', $actionRequest->getFormat()); $actionRequest->setFormat('hTmL'); $this->assertEquals('html', $actionRequest->getFormat()); }