<commit_before><?php

class CM_FormField_UrlTest extends CMTest_TestCase {

	public static function setUpBeforeClass() {
		$switzerland = CM_Db_Db::insert(TBL_CM_LOCATIONCOUNTRY, array('abbreviation' => 'CH', 'name' => 'Switzerland'));
		$baselStadt = CM_Db_Db::insert(TBL_CM_LOCATIONSTATE, array('countryId' => $switzerland, 'name' => 'Basel-Stadt'));
		$basel = CM_Db_Db::insert(TBL_CM_LOCATIONCITY, array('stateId' => $baselStadt, 'countryId' => $switzerland, 'name' => 'Basel',
															 'lat'     => 47.569535, 'lon' => 7.574063));
		CM_Db_Db::insert(TBL_CM_LOCATIONZIP, array('cityId' => $basel, 'name' => '4057', 'lat' => 47.574155, 'lon' => 7.592993));
	}

	public function testSetValueByRequest() {
		CM_Config::get()->testIp = '0.0.0.1';
		$cityId = (int) CM_Db_Db::getRandId(TBL_CM_LOCATIONCITY, 'id');
		CM_Db_Db::insert(TBL_CM_LOCATIONCITYIP, array('ipStart' => 1, 'ipEnd' => 1, 'cityId' => $cityId));
		$countryId = (int) CM_Db_Db::getRandId(TBL_CM_LOCATIONCOUNTRY, 'id');
		CM_Db_Db::insert(TBL_CM_LOCATIONCOUNTRYIP, array('ipStart' => 1, 'ipEnd' => 1, 'countryId' => $countryId));

		$field = new CM_FormField_Location('foo', CM_Model_Location::LEVEL_CITY, CM_Model_Location::LEVEL_CITY);
		$request = new CM_Request_Get('/fuu/');
		$field->setValueByRequest($request);
		$value = $field->getValue();
		/** @var CM_Model_Location $location */
		$location = $value[0];
		$this->assertSame($location->getId(), $cityId);

		$field = new CM_FormField_Location('foo', CM_Model_Location::LEVEL_COUNTRY, CM_Model_Location::LEVEL_COUNTRY);
		$request = new CM_Request_Get('/fuu/');
		$field->setValueByRequest($request);
		$value = $field->getValue();
		/** @var CM_Model_Location $location */
		$location = $value[0];
		$this->assertSame($location->getId(), $countryId);
	}
}<commit_msg>Fixed tests<commit_after><?php

class CM_FormField_LocationTest extends CMTest_TestCase {

	public static function setUpBeforeClass() {
		$switzerland = CM_Db_Db::insert(TBL_CM_LOCATIONCOUNTRY, array('abbreviation' => 'CH', 'name' => 'Switzerland'));
		$baselStadt = CM_Db_Db::insert(TBL_CM_LOCATIONSTATE, array('countryId' => $switzerland, 'name' => 'Basel-Stadt'));
		$basel = CM_Db_Db::insert(TBL_CM_LOCATIONCITY, array('stateId' => $baselStadt, 'countryId' => $switzerland, 'name' => 'Basel',
															 'lat'     => 47.569535, 'lon' => 7.574063));
		CM_Db_Db::insert(TBL_CM_LOCATIONZIP, array('cityId' => $basel, 'name' => '4057', 'lat' => 47.574155, 'lon' => 7.592993));
	}

	public function testSetValueByRequest() {
		CM_Config::get()->testIp = '0.0.0.1';
		$request = new CM_Request_Get('/fuu/');
		$cityId = (int) CM_Db_Db::getRandId(TBL_CM_LOCATIONCITY, 'id');
		CM_Db_Db::insert(TBL_CM_LOCATIONCITYIP, array('ipStart' => 1, 'ipEnd' => 1, 'cityId' => $cityId));
		$countryId = (int) CM_Db_Db::getRandId(TBL_CM_LOCATIONCOUNTRY, 'id');
		CM_Db_Db::insert(TBL_CM_LOCATIONCOUNTRYIP, array('ipStart' => 1, 'ipEnd' => 1, 'countryId' => $countryId));

		$field = new CM_FormField_Location('foo', CM_Model_Location::LEVEL_CITY, CM_Model_Location::LEVEL_CITY);
		$field->setValueByRequest($request);
		$value = $field->getValue();
		/** @var CM_Model_Location $location */
		$location = $value[0];
		$this->assertSame($location->getId(), $cityId);

		$field = new CM_FormField_Location('foo', CM_Model_Location::LEVEL_COUNTRY, CM_Model_Location::LEVEL_COUNTRY);
		$field->setValueByRequest($request);
		$value = $field->getValue();
		/** @var CM_Model_Location $location */
		$location = $value[0];
		$this->assertSame($location->getId(), $countryId);
	}
}
{'fraction_non_alphanumeric': 0.18934081346423562, 'fraction_numerical': 0.024684431977559606, 'mean_word_length': 6.307377049180328, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6878161', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1364, 'n_words': 208}