/** * @param IURLGenerator $urlGenerator * @param string $appName * @param \Exception $exception * * @return RedirectResponse */ public function htmlError($urlGenerator, $appName, Exception $exception) { $message = $exception->getMessage(); $code = $this->getHttpStatusCode($exception); $url = $urlGenerator->linkToRoute($appName . '.page.error_page', ['code' => $code]); $response = new RedirectResponse($url); $response->addCookie('galleryErrorMessage', $message); return $response; }
public function testGetRedirectUrl() { $this->assertEquals('/url', $this->response->getRedirectUrl()); }
public function testPublicIndexWithFileToken() { $token = 'aaaabbbbccccdddd'; $filename = 'happy.jpg'; $fileId = 12345; $this->mockGetSharedNode('file', $fileId); $redirectUrl = 'http://owncloud/download/' . $filename; $this->mockUrlToDownloadPage($token, $fileId, $filename, $redirectUrl); $template = new RedirectResponse($redirectUrl); $response = $this->controller->publicIndex($token, $filename); $this->assertTrue($response instanceof RedirectResponse); $this->assertEquals($template->getRedirectURL(), $response->getRedirectURL()); }
/** * Redirects the client to an error page * * @param string $message * @param int $code * * @return RedirectResponse */ private function redirectToErrorPage($message, $code) { $url = $this->urlGenerator->linkToRoute($this->appName . '.page.error_page', ['code' => $code]); $response = new RedirectResponse($url); $response->addCookie('galleryErrorMessage', $message); return $response; }
/** * @NoAdminRequired * * Sends the file matching the fileId * * @param int $fileId the ID of the file we want to download * @param string|null $filename * * @return ImageResponse */ public function download($fileId, $filename = null) { try { $download = $this->getDownload($fileId, $filename); } catch (ServiceException $exception) { $code = $this->getHttpStatusCode($exception); $url = $this->urlGenerator->linkToRoute($this->appName . '.page.error_page', ['code' => $code]); $response = new RedirectResponse($url); $response->addCookie('galleryErrorMessage', $exception->getMessage()); return $response; } // That's the only exception out of all the image media types we serve if ($download['mimetype'] === 'image/svg+xml') { $download['mimetype'] = 'text/plain'; } return new ImageResponse($download); }
public function testDownloadWithWrongId() { $fileId = 99999; $filename = null; $this->mockGetResourceFromId($fileId, false); $redirect = new RedirectResponse($this->urlGenerator->linkToRoute($this->appName . '.page.error_page')); $response = $this->controller->download($fileId, $filename); $this->assertEquals($redirect->getRedirectURL(), $response->getRedirectURL()); }