public function testFindByLocationUseCityWithCountry() { $countryId = CM_Db_Db::insert('cm_model_location_country', array('abbreviation' => 'DE', 'name' => 'Germany')); $country = new CM_Model_Location(CM_Model_Location::LEVEL_COUNTRY, $countryId); $cityId = CM_Db_Db::insert('cm_model_location_city', array('stateId' => null, 'countryId' => $countryId, 'name' => 'Berlin', 'lat' => 12.345678, 'lon' => 12.345678)); $city = new CM_Model_Location(CM_Model_Location::LEVEL_CITY, $cityId); $this->assertNull(CM_Model_Currency::findByLocation($city)); $currency = CM_Model_Currency::create('978', 'EUR'); $cache = CM_Cache_Local::getInstance(); $cacheKey = CM_CacheConst::Currency_CountryId . '_countryId:' . $country->getId(); $currency->setCountryMapping($country); $cache->delete($cacheKey); $this->assertEquals($currency, CM_Model_Currency::findByLocation($city)); }
public function testGet() { foreach (self::$_fields as $level => $fields) { $location = new CM_Model_Location($level, $fields['id']); foreach (array(CM_Model_Location::LEVEL_COUNTRY, CM_Model_Location::LEVEL_STATE, CM_Model_Location::LEVEL_CITY, CM_Model_Location::LEVEL_ZIP) as $level2) { $location2 = $location->get($level2); if ($level2 > $level) { $this->assertNull($location2); } else { $this->assertInstanceOf('CM_Model_Location', $location2); $this->assertSame($location->getId($level2), $location2->getId()); $this->assertSame($level2, $location2->getLevel()); } } } }
/** * @param CM_Model_Location $location */ public function filterLocation(CM_Model_Location $location) { $this->filterTerm('ids.' . $location->getLevel(), $location->getId()); }