Ejemplo n.º 1
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());
 }
Ejemplo n.º 2
0
 public function setUp()
 {
     $smarty = new Smarty();
     $this->_render = new CM_Frontend_Render();
     $this->_template = $smarty->createTemplate('string:');
     $this->_template->assignGlobal('render', $this->_render);
     $this->_location = CMTest_TH::createLocation();
 }
Ejemplo n.º 3
0
 public function testProcessHostRedirect_parameter()
 {
     $site = CM_Site_Abstract::factory();
     $location = CMTest_TH::createLocation();
     $locationEncoded = CM_Params::encode($location, true);
     $query = http_build_query(['location' => $locationEncoded]);
     $response = CMTest_TH::createResponsePage('/mock5?' . $query, array('host' => 'incorrect-host.org'));
     $response->process();
     $siteUrl = 'http://' . $site->getHost();
     $this->assertContains('Location: ' . $siteUrl . '/mock5?' . $query, $response->getHeaders());
 }
Ejemplo n.º 4
0
 public function testProcessLanguageRedirect_parameter()
 {
     CMTest_TH::createLanguage('en');
     $viewer = CMTest_TH::createUser();
     $location = CMTest_TH::createLocation();
     $locationEncoded = CM_Params::encode($location, true);
     $query = http_build_query(['location' => $locationEncoded]);
     $site = CM_Site_Abstract::factory();
     $request = new CM_Http_Request_Get('/en/mock5?' . $query, ['host' => $site->getHost()], null, $viewer);
     $response = CM_Http_Response_Page::createFromRequest($request, $site, $this->getServiceManager());
     $response->process();
     $siteUrl = $response->getSite()->getUrl();
     $this->assertContains('Location: ' . $siteUrl . '/mock5?' . $query, $response->getHeaders());
 }
Ejemplo n.º 5
0
 public function testGetLocation()
 {
     $location = CMTest_TH::createLocation();
     $params = new CM_Params(['location' => $location, 'locationParameters' => ['id' => $location->getId(), 'level' => $location->getLevel()], 'insufficientParameters' => 1]);
     $this->assertEquals($location, $params->getLocation('location'));
     $this->assertEquals($location, $params->getLocation('locationParameters'));
     try {
         $params->getLocation('insufficientParameters');
         $this->fail('Instantiating location with insufficient parameters');
     } catch (CM_Exception_InvalidParam $ex) {
         $this->assertSame('Not enough parameters', $ex->getMessage());
         $this->assertSame(['parameters' => 1, 'className' => 'CM_Model_Location'], $ex->getMetaInfo());
     }
 }
Ejemplo n.º 6
0
 public function testArrayConvertible()
 {
     $location = CMTest_TH::createLocation();
     $this->assertEquals($location, CM_Model_Location::fromArray($location->toArray()));
 }