Example #1
0
 /**
  * @return ControllerContext
  */
 protected function createControllerContextFromEnvironment()
 {
     $httpRequest = Request::createFromEnvironment();
     /** @var ActionRequest $request */
     $request = new ActionRequest($httpRequest);
     $uriBuilder = new UriBuilder();
     $uriBuilder->setRequest($request);
     return new ControllerContext($request, new Response(), new Arguments(array()), $uriBuilder);
 }
 /**
  * @return void
  */
 public function setUp()
 {
     $this->viewHelperVariableContainer = $this->createMock(\TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer::class);
     $this->viewHelperVariableContainer->expects($this->any())->method('exists')->will($this->returnCallback(array($this, 'viewHelperVariableContainerExistsCallback')));
     $this->viewHelperVariableContainer->expects($this->any())->method('get')->will($this->returnCallback(array($this, 'viewHelperVariableContainerGetCallback')));
     $this->templateVariableContainer = $this->createMock(TemplateVariableContainer::class);
     $this->uriBuilder = $this->createMock(\Neos\Flow\Mvc\Routing\UriBuilder::class);
     $this->uriBuilder->expects($this->any())->method('reset')->will($this->returnValue($this->uriBuilder));
     $this->uriBuilder->expects($this->any())->method('setArguments')->will($this->returnValue($this->uriBuilder));
     $this->uriBuilder->expects($this->any())->method('setSection')->will($this->returnValue($this->uriBuilder));
     $this->uriBuilder->expects($this->any())->method('setFormat')->will($this->returnValue($this->uriBuilder));
     $this->uriBuilder->expects($this->any())->method('setCreateAbsoluteUri')->will($this->returnValue($this->uriBuilder));
     $this->uriBuilder->expects($this->any())->method('setAddQueryString')->will($this->returnValue($this->uriBuilder));
     $this->uriBuilder->expects($this->any())->method('setArgumentsToBeExcludedFromQueryString')->will($this->returnValue($this->uriBuilder));
     // BACKPORTER TOKEN #1
     $httpRequest = \Neos\Flow\Http\Request::create(new \Neos\Flow\Http\Uri('http://localhost/foo'));
     $this->request = $this->getMockBuilder(\Neos\Flow\Mvc\ActionRequest::class)->setConstructorArgs(array($httpRequest))->getMock();
     $this->request->expects($this->any())->method('isMainRequest')->will($this->returnValue(true));
     $this->controllerContext = $this->getMockBuilder(\Neos\Flow\Mvc\Controller\ControllerContext::class)->disableOriginalConstructor()->getMock();
     $this->controllerContext->expects($this->any())->method('getUriBuilder')->will($this->returnValue($this->uriBuilder));
     $this->controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
     $this->tagBuilder = $this->createMock(TagBuilder::class);
     $this->arguments = array();
     $this->renderingContext = new \Neos\FluidAdaptor\Core\Rendering\RenderingContext(new StandaloneView(), []);
     $this->renderingContext->setVariableProvider($this->templateVariableContainer);
     $this->renderingContext->setViewHelperVariableContainer($this->viewHelperVariableContainer);
     $this->renderingContext->setControllerContext($this->controllerContext);
 }
 /**
  * Helper to build a Fusion view object
  *
  * @return FusionView
  */
 protected function buildView()
 {
     $view = new FusionView();
     $httpRequest = Request::createFromEnvironment();
     $request = $httpRequest->createActionRequest();
     $uriBuilder = new UriBuilder();
     $uriBuilder->setRequest($request);
     $this->controllerContext = new ControllerContext($request, new Response(), new Arguments(array()), $uriBuilder);
     $view->setControllerContext($this->controllerContext);
     $view->disableFallbackView();
     $view->setPackageKey('Neos.Fusion');
     $view->setTypoScriptPathPattern(__DIR__ . '/Fixtures/TypoScript');
     $view->assign('fixtureDirectory', __DIR__ . '/Fixtures/');
     return $view;
 }
Example #4
0
 /**
  * @param ActionRequest $request
  * @return string
  */
 protected function buildActionUri(ActionRequest $request)
 {
     $packageKey = $this->parseOption('package');
     $controllerName = $this->parseOption('controller');
     $actionName = $this->parseOption('action');
     $arguments = $this->parseOption('arguments');
     $subpackageKey = null;
     if ($packageKey !== null && strpos($packageKey, '\\') !== false) {
         list($packageKey, $subpackageKey) = explode('\\', $packageKey, 2);
     }
     $uriBuilder = new UriBuilder();
     $uriBuilder->setRequest($request);
     $uriBuilder->reset();
     $uri = $uriBuilder->uriFor($actionName, $arguments, $controllerName, $packageKey, $subpackageKey);
     return $uri;
 }
 /**
  * @test
  */
 public function setArgumentsSetsNonPrefixedArgumentsByDefault()
 {
     $arguments = ['argument1' => 'argument1Value', 'argument2' => ['argument2a' => 'argument2aValue']];
     $this->uriBuilder->setArguments($arguments);
     $expectedResult = $arguments;
     $this->assertEquals($expectedResult, $this->uriBuilder->getArguments());
 }
 /**
  * Creates an UriBuilder instance for the current request
  *
  * @return UriBuilder
  */
 protected function getUriBuilder()
 {
     if ($this->uriBuilder === null) {
         $httpRequest = Request::createFromEnvironment();
         $actionRequest = new ActionRequest($httpRequest);
         $this->uriBuilder = new UriBuilder();
         $this->uriBuilder->setRequest($actionRequest);
         $this->uriBuilder->setFormat('html')->setCreateAbsoluteUri(false);
     }
     return $this->uriBuilder;
 }
 /**
  * @test
  */
 public function callingRenderAssignsVariablesCorrectlyToUriBuilder()
 {
     $this->uriBuilder->expects($this->once())->method('setSection')->with('section')->will($this->returnSelf());
     $this->uriBuilder->expects($this->once())->method('setArguments')->with(array('additionalParams'))->will($this->returnSelf());
     $this->uriBuilder->expects($this->once())->method('setArgumentsToBeExcludedFromQueryString')->with(array('argumentsToBeExcludedFromQueryString'))->will($this->returnSelf());
     $this->uriBuilder->expects($this->once())->method('setFormat')->with('format')->will($this->returnSelf());
     $expectedModifiedArguments = array('module' => 'the/path', 'moduleArguments' => array('arguments', '@action' => 'action'));
     $this->uriBuilder->expects($this->once())->method('uriFor')->with('index', $expectedModifiedArguments);
     // fallback for the method chaining of the URI builder
     $this->uriBuilder->expects($this->any())->method($this->anything())->will($this->returnValue($this->uriBuilder));
     $this->viewHelper->render('the/path', 'action', array('arguments'), 'section', 'format', array('additionalParams'), true, array('argumentsToBeExcludedFromQueryString'));
 }
 /**
  * Starts the authentication: Redirect to login page
  *
  * @param Request $request The current request
  * @param Response $response The current response
  * @return void
  * @throws MissingConfigurationException
  */
 public function startAuthentication(Request $request, Response $response)
 {
     if (isset($this->options['routeValues'])) {
         $routeValues = $this->options['routeValues'];
         if (!is_array($routeValues)) {
             throw new MissingConfigurationException(sprintf('The configuration for the WebRedirect authentication entry point is incorrect. "routeValues" must be an array, got "%s".', gettype($routeValues)), 1345040415);
         }
         $actionRequest = new ActionRequest($request);
         $this->uriBuilder->setRequest($actionRequest);
         $actionName = $this->extractRouteValue($routeValues, '@action');
         $controllerName = $this->extractRouteValue($routeValues, '@controller');
         $packageKey = $this->extractRouteValue($routeValues, '@package');
         $subPackageKey = $this->extractRouteValue($routeValues, '@subpackage');
         $uri = $this->uriBuilder->setCreateAbsoluteUri(true)->uriFor($actionName, $routeValues, $controllerName, $packageKey, $subPackageKey);
     } elseif (isset($this->options['uri'])) {
         $uri = strpos($this->options['uri'], '://') !== false ? $this->options['uri'] : $request->getBaseUri() . $this->options['uri'];
     } else {
         throw new MissingConfigurationException('The configuration for the WebRedirect authentication entry point is incorrect or missing. You need to specify either the target "uri" or "routeValues".', 1237282583);
     }
     $response->setContent(sprintf('<html><head><meta http-equiv="refresh" content="0;url=%s"/></head></html>', htmlentities($uri, ENT_QUOTES, 'utf-8')));
     $response->setStatus(303);
     $response->setHeader('Location', $uri);
 }
 /**
  * Redirects the request to another action and / or controller.
  *
  * Redirect will be sent to the client which then performs another request to the new URI.
  *
  * NOTE: This method only supports web requests and will throw an exception
  * if used with other request types.
  *
  * @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. If not specified, the current package is assumed.
  * @param array $arguments Array of arguments for the target action
  * @param integer $delay (optional) The delay in seconds. Default is no delay.
  * @param integer $statusCode (optional) The HTTP status code for the redirect. Default is "303 See Other"
  * @param string $format The format to use for the redirect URI
  * @return void
  * @throws StopActionException
  * @see forward()
  * @api
  */
 protected function redirect($actionName, $controllerName = null, $packageKey = null, array $arguments = null, $delay = 0, $statusCode = 303, $format = null)
 {
     if ($packageKey !== null && strpos($packageKey, '\\') !== false) {
         list($packageKey, $subpackageKey) = explode('\\', $packageKey, 2);
     } else {
         $subpackageKey = null;
     }
     $this->uriBuilder->reset();
     if ($format === null) {
         $this->uriBuilder->setFormat($this->request->getFormat());
     } else {
         $this->uriBuilder->setFormat($format);
     }
     $uri = $this->uriBuilder->setCreateAbsoluteUri(true)->uriFor($actionName, $arguments, $controllerName, $packageKey, $subpackageKey);
     $this->redirectToUri($uri, $delay, $statusCode);
 }
Example #10
0
 /**
  * For the given $token an activation link is returned.
  *
  * @param Token $token
  * @return string
  * @throws InvalidTokenException
  */
 public function getActivationLink(Token $token)
 {
     $activationConfiguration = $token->getPreset()['activation'];
     $tokenHash = $token->getHash();
     if ($activationConfiguration['uri'] === NULL) {
         throw new \RuntimeException('Building activation link failed, no uri configuration is set', 1434728943);
     } elseif (is_array($activationConfiguration['uri'])) {
         $routerConfiguration = $activationConfiguration['uri'];
         $this->uriBuilder->setRequest($this->request);
         $uri = $this->uriBuilder->setCreateAbsoluteUri(TRUE)->setFormat($routerConfiguration['@format'])->uriFor($routerConfiguration['@action'], $routerConfiguration['arguments'], $routerConfiguration['@controller'], $routerConfiguration['@package'], $routerConfiguration['@subpackage']);
     } elseif (is_string($activationConfiguration['uri'])) {
         $uri = $activationConfiguration['uri'];
     } else {
         throw new \RuntimeException('Building activation link failed, uri configuration is invalid (neither array nor string)', 1434732898);
     }
     $this->logger->log(sprintf('Activation link built for token with hash %s', $tokenHash, $token->getIdentifier()), LOG_INFO);
     return str_replace('-tokenhash-', $tokenHash, $uri);
 }
 /**
  * Calculates the dimensions of the thumbnail to be generated and returns the thumbnail URI.
  * In case of Images this is a thumbnail of the image, in case of other assets an icon representation.
  *
  * @param AssetInterface $asset
  * @param ThumbnailConfiguration $configuration
  * @param ActionRequest $request Request argument must be provided for asynchronous thumbnails
  * @return array|null Array with keys "width", "height" and "src" if the thumbnail generation work or null
  * @throws AssetServiceException
  */
 public function getThumbnailUriAndSizeForAsset(AssetInterface $asset, ThumbnailConfiguration $configuration, ActionRequest $request = null)
 {
     $thumbnailImage = $this->thumbnailService->getThumbnail($asset, $configuration);
     if (!$thumbnailImage instanceof ImageInterface) {
         return null;
     }
     $resource = $thumbnailImage->getResource();
     if ($thumbnailImage instanceof Thumbnail) {
         $staticResource = $thumbnailImage->getStaticResource();
         if ($configuration->isAsync() === true && $resource === null && $staticResource === null) {
             if ($request === null) {
                 throw new AssetServiceException('Request argument must be provided for async thumbnails.', 1447660835);
             }
             $this->uriBuilder->setRequest($request->getMainRequest());
             $uri = $this->uriBuilder->reset()->setCreateAbsoluteUri(true)->uriFor('thumbnail', array('thumbnail' => $thumbnailImage), 'Thumbnail', 'Neos.Media');
         } else {
             $uri = $this->thumbnailService->getUriForThumbnail($thumbnailImage);
         }
     } else {
         $uri = $this->resourceManager->getPublicPersistentResourceUri($resource);
     }
     return array('width' => $thumbnailImage->getWidth(), 'height' => $thumbnailImage->getHeight(), 'src' => $uri);
 }
 /**
  * Returns a specific URI string to redirect to after the logout; or NULL if there is none.
  * In case of NULL, it's the responsibility of the AuthenticationController where to redirect,
  * most likely to the LoginController's index action.
  *
  * @param ActionRequest $actionRequest
  * @return string A possible redirection URI, if any
  */
 public function getAfterLogoutRedirectionUri(ActionRequest $actionRequest)
 {
     $lastVisitedNode = $this->getLastVisitedNode('live');
     if ($lastVisitedNode === null) {
         return null;
     }
     $uriBuilder = new UriBuilder();
     $uriBuilder->setRequest($actionRequest);
     $uriBuilder->setFormat('html');
     $uriBuilder->setCreateAbsoluteUri(true);
     return $uriBuilder->uriFor('show', array('node' => $lastVisitedNode), 'Frontend\\Node', 'Neos.Neos');
 }
 /**
  * Extracted out to this method in order to be better unit-testable.
  *
  * @return void
  */
 protected function setMainRequestToUriBuilder()
 {
     $mainRequest = $this->controllerContext->getRequest()->getMainRequest();
     $this->uriBuilder->setRequest($mainRequest);
 }
 /**
  * Prepares a Fluid view for rendering the custom error page.
  *
  * @param object $exception \Exception or \Throwable
  * @param array $renderingOptions Rendering options as defined in the settings
  * @return ViewInterface
  */
 protected function buildView($exception, array $renderingOptions)
 {
     $statusCode = 500;
     $referenceCode = null;
     if ($exception instanceof FlowException) {
         $statusCode = $exception->getStatusCode();
         $referenceCode = $exception->getReferenceCode();
     }
     $statusMessage = Response::getStatusMessageByCode($statusCode);
     $viewClassName = $renderingOptions['viewClassName'];
     /** @var ViewInterface $view */
     $view = $viewClassName::createWithOptions($renderingOptions['viewOptions']);
     $view = $this->applyLegacyViewOptions($view, $renderingOptions);
     $httpRequest = Request::createFromEnvironment();
     $request = new ActionRequest($httpRequest);
     $request->setControllerPackageKey('Neos.Flow');
     $uriBuilder = new UriBuilder();
     $uriBuilder->setRequest($request);
     $view->setControllerContext(new ControllerContext($request, new Response(), new Arguments([]), $uriBuilder));
     if (isset($renderingOptions['variables'])) {
         $view->assignMultiple($renderingOptions['variables']);
     }
     $view->assignMultiple(['exception' => $exception, 'renderingOptions' => $renderingOptions, 'statusCode' => $statusCode, 'statusMessage' => $statusMessage, 'referenceCode' => $referenceCode]);
     return $view;
 }
 /**
  * Initiates the StandaloneView by creating the required ControllerContext
  *
  * @return void
  */
 public function initializeObject()
 {
     if ($this->request === null) {
         $httpRequest = Request::createFromEnvironment();
         $this->request = new ActionRequest($httpRequest);
     }
     $uriBuilder = new UriBuilder();
     $uriBuilder->setRequest($this->request);
     $this->setControllerContext(new ControllerContext($this->request, new Response(), new Arguments(array()), $uriBuilder));
 }