public function testGetModulesByFrontName() { $frontName = 'route'; $scope = null; $this->_object->expects($this->once())->method('getModulesByFrontName')->with($frontName, $scope); $this->_proxy->getModulesByFrontName($frontName, $scope); }
/** * Check and process no route request * * @param \Magento\Framework\App\RequestInterface $request * @return bool */ public function process(\Magento\Framework\App\RequestInterface $request) { $requestPathParams = explode('/', trim($request->getPathInfo(), '/')); $areaFrontName = array_shift($requestPathParams); if ($areaFrontName == $this->helper->getAreaFrontName()) { $moduleName = $this->routeConfig->getRouteFrontName('adminhtml'); $actionNamespace = 'noroute'; $actionName = 'index'; $request->setModuleName($moduleName)->setControllerName($actionNamespace)->setActionName($actionName); return true; } return false; }
/** * Create matched controller instance * * @param \Magento\Framework\App\RequestInterface $request * @param array $params * @return \Magento\Framework\App\Action\Action|null */ protected function matchAction(\Magento\Framework\App\RequestInterface $request, array $params) { $moduleFrontName = $this->matchModuleFrontName($request, $params['moduleFrontName']); if (empty($moduleFrontName)) { return null; } /** * Searching router args by module name from route using it as key */ $modules = $this->_routeConfig->getModulesByFrontName($moduleFrontName); if (empty($modules) === true) { return null; } /** * Going through modules to find appropriate controller */ $currentModuleName = null; $actionPath = null; $action = null; $actionInstance = null; $request->setRouteName($this->_routeConfig->getRouteByFrontName($moduleFrontName)); $actionPath = $this->matchActionPath($request, $params['actionPath']); $action = $request->getActionName() ?: ($params['actionName'] ?: $this->_defaultPath->getPart('action')); $this->_checkShouldBeSecure($request, '/' . $moduleFrontName . '/' . $actionPath . '/' . $action); foreach ($modules as $moduleName) { $currentModuleName = $moduleName; $actionClassName = $this->actionList->get($moduleName, $this->pathPrefix, $actionPath, $action); if (!$actionClassName || !is_subclass_of($actionClassName, $this->actionInterface)) { continue; } $actionInstance = $this->actionFactory->create($actionClassName, array('request' => $request)); break; } if (null == $actionInstance) { $actionInstance = $this->getNotFoundAction($currentModuleName, $request); if (is_null($actionInstance)) { return null; } $action = 'noroute'; } // set values only after all the checks are done $request->setModuleName($moduleFrontName); $request->setControllerName($actionPath); $request->setActionName($action); $request->setControllerModule($currentModuleName); if (isset($params['variables'])) { $request->setParams($params['variables']); } return $actionInstance; }
/** * Get route name used in request (ignore rewrite) * * @return string */ public function getRequestedRouteName() { if (isset($this->_routingInfo['requested_route'])) { return $this->_routingInfo['requested_route']; } if ($this->_requestedRouteName === null) { if ($this->_rewritedPathInfo !== null && isset($this->_rewritedPathInfo[0])) { $frontName = $this->_rewritedPathInfo[0]; $this->_requestedRouteName = $this->_routeConfig->getRouteByFrontName($frontName); } else { // no rewritten path found, use default route name return $this->getRouteName(); } } return $this->_requestedRouteName; }
public function testMatchEmptyActionInstance() { // Test Data $nullActionInstance = null; $moduleFrontName = 'module front name'; $actionPath = 'action path'; $actionName = 'action name'; $actionClassName = 'Magento\\Cms\\Controller\\Index\\Index'; $moduleName = 'module name'; $moduleList = [$moduleName]; // Stubs $this->requestMock->expects($this->any())->method('getModuleName')->willReturn($moduleFrontName); $this->routeConfigMock->expects($this->any())->method('getModulesByFrontName')->willReturn($moduleList); $this->requestMock->expects($this->any())->method('getControllerName')->willReturn($actionPath); $this->requestMock->expects($this->any())->method('getActionName')->willReturn($actionName); $this->appStateMock->expects($this->any())->method('isInstalled')->willReturn(false); $this->actionListMock->expects($this->any())->method('get')->willReturn($actionClassName); $this->actionFactoryMock->expects($this->any())->method('create')->willReturn($nullActionInstance); // Expectations and Test $this->assertNull($this->model->match($this->requestMock)); }
/** * Retrieve route front name * * @return string */ protected function _getRouteFrontName() { if (!$this->hasData('route_front_name')) { $frontName = $this->_routeConfig->getRouteFrontName( $this->_getRouteName(), $this->_scopeResolver->getAreaCode() ); $this->setData('route_front_name', $frontName); } return $this->_getData('route_front_name'); }