Exemplo n.º 1
0
 /**
  * @param CM_Frontend_Environment $environment
  * @return DateTimeZone
  */
 protected function _getTimeZone(CM_Frontend_Environment $environment)
 {
     if (null === $this->_timeZone) {
         return $environment->getTimeZone();
     }
     return $this->_timeZone;
 }
Exemplo n.º 2
0
 public function testHasViewer()
 {
     $environment = new CM_Frontend_Environment();
     $this->assertFalse($environment->hasViewer());
     $environment = new CM_Frontend_Environment(null, CM_Model_User::createStatic());
     $this->assertTrue($environment->hasViewer());
 }
Exemplo n.º 3
0
 public function testSetValueByEnvironment()
 {
     $location = CMTest_TH::createLocation();
     $locationCity = $location->get(CM_Model_Location::LEVEL_CITY);
     $environment = new CM_Frontend_Environment();
     $environment->setLocation(null);
     $field = new CM_FormField_Location();
     $field->setValueByEnvironment($environment);
     $this->assertNull($field->getValue());
     $environment->setLocation($location->get(CM_Model_Location::LEVEL_COUNTRY));
     $field = new CM_FormField_Location(['levelMin' => CM_Model_Location::LEVEL_CITY]);
     $field->setValueByEnvironment($environment);
     $this->assertNull($field->getValue());
     $environment->setLocation($location);
     $field = new CM_FormField_Location(['levelMin' => CM_Model_Location::LEVEL_CITY, 'levelMax' => CM_Model_Location::LEVEL_CITY]);
     $field->setValueByEnvironment($environment);
     $value = $field->getValue();
     /** @var CM_Model_Location $locationValue */
     $locationValue = $value[0];
     $this->assertSame($locationCity->getId(), $locationValue->getId());
     $this->assertSame($locationCity->getLevel(), $locationValue->getLevel());
     $environment->setLocation($locationCity);
     $field = new CM_FormField_Location(['levelMin' => CM_Model_Location::LEVEL_CITY, 'levelMax' => CM_Model_Location::LEVEL_CITY]);
     $field->setValueByEnvironment($environment);
     $value = $field->getValue();
     /** @var CM_Model_Location $locationValue */
     $locationValue = $value[0];
     $this->assertSame($locationCity->getId(), $locationValue->getId());
     $this->assertSame($locationCity->getLevel(), $locationValue->getLevel());
 }
Exemplo n.º 4
0
 /**
  * @param CM_Frontend_Environment $environment
  */
 public function setValueByEnvironment(CM_Frontend_Environment $environment)
 {
     $location = $environment->getLocation();
     $location = $this->_squashLocationInConstraints($location);
     if (null !== $location) {
         $this->setValue($location);
     }
 }
Exemplo n.º 5
0
 public function testRenderDateTime()
 {
     $value = new DateTime('2016-05-31T12:30:00Z+00:00');
     $formField = new CM_FormField_Time();
     $formField->setValue($value);
     $environment = new CM_Frontend_Environment();
     $environment->setTimeZone(new DateTimeZone('Etc/GMT+2'));
     $render = new CM_Frontend_Render($environment);
     $renderAdapter = new CM_RenderAdapter_FormField($render, $formField);
     $actual = $renderAdapter->fetch(new CM_Params());
     $this->assertContains('value="10:30"', $actual);
 }
Exemplo n.º 6
0
 /**
  * @param CM_Frontend_Environment $environment
  * @param string|null             $layoutName
  * @throws CM_Exception_Invalid
  * @return CM_Layout_Abstract
  */
 public function getLayout(CM_Frontend_Environment $environment, $layoutName = null)
 {
     if (null === $layoutName) {
         $layoutName = 'Default';
     }
     $layoutName = (string) $layoutName;
     foreach ($environment->getSite()->getModules() as $moduleNamespace) {
         $classname = $moduleNamespace . '_Layout_' . $layoutName;
         if (class_exists($classname)) {
             return new $classname();
         }
     }
     throw new CM_Exception_Invalid('layout `' . $layoutName . '` is not defined in any namespace');
 }
Exemplo n.º 7
0
 public function prepare(CM_Params $renderParams, CM_Frontend_Environment $environment, CM_Frontend_ViewResponse $viewResponse)
 {
     $viewResponse->set('class', $renderParams->has('class') ? $renderParams->getString('class') : null);
     $years = range($this->_yearFirst, $this->_yearLast);
     $months = range(1, 12);
     $days = range(1, 31);
     $viewResponse->set('years', array_combine($years, $years));
     $viewResponse->set('months', array_combine($months, $months));
     $viewResponse->set('days', array_combine($days, $days));
     /** @var DateTime|null $value */
     $value = $this->getValue();
     $year = $month = $day = null;
     if (null !== $value) {
         $value->setTimezone($environment->getTimeZone());
         $year = $value->format('Y');
         $month = $value->format('n');
         $day = $value->format('j');
     }
     $viewResponse->set('yy', $year);
     $viewResponse->set('mm', $month);
     $viewResponse->set('dd', $day);
 }
Exemplo n.º 8
0
 /**
  * @param CM_View_Abstract             $view
  * @param string                       $methodName
  * @param array|null                   $params
  * @param CM_Frontend_Environment|null $environment
  * @return CM_Http_Response_View_Ajax
  */
 public function getResponseAjax(CM_View_Abstract $view, $methodName, array $params = null, CM_Frontend_Environment $environment = null)
 {
     $request = $this->createRequestAjax($view, $methodName, $params);
     if ($environment) {
         $request->mockMethod('getViewer')->set(function () use($environment) {
             return $environment->getViewer();
         });
     }
     return $this->processRequest($request);
 }
Exemplo n.º 9
0
 public function trackPageView(CM_Frontend_Environment $environment, $path = null)
 {
     $this->setPageView($path);
     if ($viewer = $environment->getViewer()) {
         $this->setUserId($viewer->getId());
         $this->_flushTrackingQueue($viewer);
     }
 }
Exemplo n.º 10
0
 /**
  * @param CM_Frontend_Environment $environment
  * @throws CM_Exception_AuthRequired
  */
 protected function _checkViewer(CM_Frontend_Environment $environment)
 {
     $environment->getViewer(true);
 }
Exemplo n.º 11
0
 public function trackPageView(CM_Frontend_Environment $environment, $path)
 {
     if ($viewer = $environment->getViewer()) {
         $this->setUserId($viewer->getId());
     }
     if (CM_Http_Request_Abstract::hasInstance()) {
         $this->setRequestClientId(CM_Http_Request_Abstract::getInstance()->getClientId());
     }
 }
Exemplo n.º 12
0
 public function trackPageView(CM_Frontend_Environment $environment, $path)
 {
     if ($viewer = $environment->getViewer()) {
         $this->_flushTrackingQueue($viewer);
     }
 }
Exemplo n.º 13
0
 /**
  * @param CM_Frontend_Environment $environment
  * @param string                  $layoutName
  * @return string
  * @throws CM_Exception_Invalid
  */
 protected function _getLayoutClassByName(CM_Frontend_Environment $environment, $layoutName)
 {
     $layoutName = (string) $layoutName;
     foreach ($environment->getSite()->getModules() as $moduleNamespace) {
         $classname = $moduleNamespace . '_Layout_' . $layoutName;
         if (class_exists($classname)) {
             return $classname;
         }
     }
     throw new CM_Exception_Invalid('Layout is not defined in any namespace', null, ['layoutName' => $layoutName]);
 }
Exemplo n.º 14
0
 public function trackPageView(CM_Frontend_Environment $environment, $path = null)
 {
     if ($viewer = $environment->getViewer()) {
         $this->setUserId($viewer->getId());
     }
     $this->setPageView($path);
 }
Exemplo n.º 15
0
 public function trackPageView(CM_Frontend_Environment $environment, $path)
 {
     if ($viewer = $environment->getViewer()) {
         $this->_setUser($viewer);
     }
 }
Exemplo n.º 16
0
 public function checkAccessible(CM_Frontend_Environment $environment)
 {
     if (!$environment->isDebug()) {
         throw new CM_Exception_NotAllowed();
     }
 }
Exemplo n.º 17
0
 /**
  * @param CM_View_Abstract             $view
  * @param string                       $methodName
  * @param array|null                   $params
  * @param CM_Frontend_Environment|null $environment
  * @return CM_Http_Response_View_Ajax
  */
 public function getResponseAjax(CM_View_Abstract $view, $methodName, array $params = null, CM_Frontend_Environment $environment = null)
 {
     $site = CM_Site_Abstract::factory();
     $request = $this->createRequestAjax($view, $methodName, $params, null, null, $site);
     if ($environment) {
         $request->mockMethod('getViewer')->set(function () use($environment) {
             return $environment->getViewer();
         });
     }
     $response = CM_Http_Response_View_Ajax::createFromRequest($request, $site, $this->getServiceManager());
     $response->process();
     return $response;
 }
Exemplo n.º 18
0
 /**
  * @param CM_Frontend_Environment $environment
  */
 public function trackSignUp(CM_Frontend_Environment $environment)
 {
     if ($viewer = $environment->getViewer()) {
         $this->_pushEvent($viewer, 'signup', ['site' => $environment->getSite()->getHost()]);
     }
 }