/** * @expectedException CM_Exception_Invalid * @expectedExceptionMessage The class was not found in any namespace. */ public function testGetClassnameByPathNotExists() { $site = $this->getMockBuilder('CM_Site_Abstract')->setMethods(array('getModules'))->getMock(); $site->expects($this->any())->method('getModules')->will($this->returnValue(array('FooBar'))); /** @var CM_Site_Abstract $site */ $render = new CM_Frontend_Render(new CM_Frontend_Environment($site)); CM_Page_Abstract::getClassnameByPath($render, '/test'); }
/** * @param CM_Page_Abstract $page */ public static function assertPageNotViewable(CM_Page_Abstract $page) { self::assertFalse($page->isViewable()); }
/** * @param CM_Http_Request_Abstract $request * @param CM_Http_Response_Page_ProcessingResult $result * @throws CM_Exception * @throws Exception * @return boolean */ private function _processPage(CM_Http_Request_Abstract $request, CM_Http_Response_Page_ProcessingResult $result) { return $this->_runWithCatching(function () use($request, $result) { $path = CM_Util::link($request->getPath(), $request->getQuery()); $result->addPath($path); $this->getSite()->rewrite($request); $pageParams = CM_Params::factory($request->getQuery(), true); try { $className = CM_Page_Abstract::getClassnameByPath($this->getRender(), $request->getPath()); $page = CM_Page_Abstract::factory($className, $pageParams); } catch (CM_Exception $ex) { throw new CM_Exception_Nonexistent('Cannot load page `' . $request->getPath() . '`: ' . $ex->getMessage()); } $result->addPage($page); $environment = $this->getRender()->getEnvironment(); $page->prepareResponse($environment, $this); if ($this->getRedirectUrl()) { $request->setUri($this->getRedirectUrl()); return true; } if ($page->getCanTrackPageView()) { $this->getRender()->getServiceManager()->getTrackings()->trackPageView($environment, $result->getPathTracking()); } $result->setHtml($this->_renderPage($page)); return true; }, function (CM_Exception $ex, array $errorOptions) use($request) { $this->getRender()->getGlobalResponse()->clear(); /** @var CM_Page_Abstract $errorPage */ $errorPage = $errorOptions['errorPage']; $request->setPath($errorPage::getPath()); $request->setQuery(array()); return false; }); }
/** * @param CM_Http_Request_Abstract $request * @throws CM_Exception_Nonexistent * @throws CM_Exception * @throws CM_Exception_Nonexistent * @return string|null|boolean */ private function _processPage(CM_Http_Request_Abstract $request) { return $this->_runWithCatching(function () use($request) { $this->getSite()->rewrite($request); $pageParams = CM_Params::factory($request->getQuery(), true); try { $className = CM_Page_Abstract::getClassnameByPath($this->getRender(), $request->getPath()); $page = CM_Page_Abstract::factory($className, $pageParams); } catch (CM_Exception $ex) { throw new CM_Exception_Nonexistent('Cannot load page `' . $request->getPath() . '`: ' . $ex->getMessage()); } $this->_setStringRepresentation(get_class($page)); $page->prepareResponse($this->getRender()->getEnvironment(), $this); if ($this->getRedirectUrl()) { $request->setUri($this->getRedirectUrl()); return null; } $html = $this->_renderPage($page); $this->_page = $page; $this->_pageParams = $pageParams; return $html; }, function (CM_Exception $ex, array $errorOptions) use($request) { $this->getRender()->getGlobalResponse()->clear(); /** @var CM_Page_Abstract $errorPage */ $errorPage = $errorOptions['errorPage']; $request->setPath($errorPage::getPath()); $request->setQuery(array()); return false; }); }