Exemplo n.º 1
0
 public function testGetPathTracking()
 {
     $processor = new CM_Http_Response_Page_ProcessingResult();
     $this->assertInstanceOf('CM_Exception', $this->catchException(function () use($processor) {
         $processor->getPathTracking();
     }));
     $processor->addPath('/foo1');
     $this->assertSame('/foo1', $processor->getPathTracking());
     /** @var CM_Page_Abstract|\Mocka\AbstractClassTrait $page */
     $page = $this->mockObject('CM_Page_Abstract');
     $page->mockMethod('getPathVirtualPageView')->set('/foo2');
     $processor->addPage($page);
     $this->assertSame('/foo2', $processor->getPathTracking());
 }
Exemplo n.º 2
0
 /**
  * @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;
     });
 }