/** * @test */ public function handleStoresRouterMatchResultsInTheComponentContext() { $mockMatchResults = ['someRouterMatchResults']; $this->mockRouter->expects($this->atLeastOnce())->method('route')->with($this->mockHttpRequest)->will($this->returnValue($mockMatchResults)); $this->mockComponentContext->expects($this->atLeastOnce())->method('setParameter')->with(RoutingComponent::class, 'matchResults', $mockMatchResults); $this->routingComponent->handle($this->mockComponentContext); }
/** * Set the routes configuration for the Neos setup and configures the routing component * to skip initialisation, which would overwrite the specific settings again. * * @param ComponentContext $componentContext * @return void */ public function handle(ComponentContext $componentContext) { $configurationSource = $this->objectManager->get(\Neos\Flow\Configuration\Source\YamlSource::class); $routesConfiguration = $configurationSource->load($this->packageManager->getPackage('Neos.Setup')->getConfigurationPath() . ConfigurationManager::CONFIGURATION_TYPE_ROUTES); $this->router->setRoutesConfiguration($routesConfiguration); $componentContext->setParameter(\Neos\Flow\Mvc\Routing\RoutingComponent::class, 'skipRouterInitialization', true); }
/** * Route the given route path * * This command takes a given path and displays the detected route and * the selected package, controller and action. * * @param string $path The route path to resolve * @param string $method The request method (GET, POST, PUT, DELETE, ...) to simulate * @return void */ public function routePathCommand($path, $method = 'GET') { $server = ['REQUEST_URI' => $path, 'REQUEST_METHOD' => $method]; $httpRequest = new Request([], [], [], $server); /** @var Route $route */ foreach ($this->router->getRoutes() as $route) { if ($route->matches($httpRequest) === true) { $routeValues = $route->getMatchResults(); $this->outputLine('<b>Path:</b>'); $this->outputLine(' ' . $path); $this->outputLine('<b>Route:</b>'); $this->outputLine(' Name: ' . $route->getName()); $this->outputLine(' Pattern: ' . $route->getUriPattern()); $this->outputLine('<b>Result:</b>'); $this->outputLine(' Package: ' . (isset($routeValues['@package']) ? $routeValues['@package'] : '-')); $this->outputLine(' Subpackage: ' . (isset($routeValues['@subpackage']) ? $routeValues['@subpackage'] : '-')); $this->outputLine(' Controller: ' . (isset($routeValues['@controller']) ? $routeValues['@controller'] : '-')); $this->outputLine(' Action: ' . (isset($routeValues['@action']) ? $routeValues['@action'] : '-')); $this->outputLine(' Format: ' . (isset($routeValues['@format']) ? $routeValues['@format'] : '-')); $controllerObjectName = $this->getControllerObjectName($routeValues['@package'], isset($routeValues['@subpackage']) ? $routeValues['@subpackage'] : null, $routeValues['@controller']); if ($controllerObjectName === null) { $this->outputLine('<b>Controller Error:</b>'); $this->outputLine(' !!! No Controller Object found !!!'); $this->quit(1); } $this->outputLine('<b>Controller:</b>'); $this->outputLine(' ' . $controllerObjectName); $this->quit(0); } } $this->outputLine('No matching Route was found'); $this->quit(1); }
/** * Sets up a virtual browser and web environment for seamless HTTP and MVC * related tests. * * @return void */ protected function setupHttp() { $this->browser = new \Neos\Flow\Http\Client\Browser(); $this->browser->setRequestEngine(new \Neos\Flow\Http\Client\InternalRequestEngine()); $this->router = $this->browser->getRequestEngine()->getRouter(); $this->router->setRoutesConfiguration(null); $requestHandler = self::$bootstrap->getActiveRequestHandler(); $request = Request::create(new \Neos\Flow\Http\Uri('http://localhost/typo3/flow/test')); $componentContext = new ComponentContext($request, new \Neos\Flow\Http\Response()); $requestHandler->setComponentContext($componentContext); }
/** * Resolve a route for the request * * Stores the resolved route values in the ComponentContext to pass them * to other components. They can be accessed via ComponentContext::getParameter(outingComponent::class, 'matchResults'); * * @param ComponentContext $componentContext * @return void */ public function handle(ComponentContext $componentContext) { $matchResults = $this->router->route($componentContext->getHttpRequest()); $componentContext->setParameter(RoutingComponent::class, 'matchResults', $matchResults); }
/** * @test */ public function getLastMatchedRouteReturnsNullByDefault() { $this->assertNull($this->router->getLastMatchedRoute()); }