mirror of
https://github.com/osm-search/Nominatim.git
synced 2024-11-23 13:44:36 +03:00
adapt php tests
Also fixes some errors found by the tests.
This commit is contained in:
parent
1faa0f4d41
commit
528fe6553f
@ -17,7 +17,7 @@ function getLabelTag($aPlace, $sCountry = null)
|
|||||||
if (isset($aPlace['place_type'])) {
|
if (isset($aPlace['place_type'])) {
|
||||||
$sLabel = $aPlace['place_type'];
|
$sLabel = $aPlace['place_type'];
|
||||||
} elseif ($aPlace['class'] == 'boundary' && $aPlace['type'] == 'administrative') {
|
} elseif ($aPlace['class'] == 'boundary' && $aPlace['type'] == 'administrative') {
|
||||||
$sLabel = getBoundaryLabel($iRank, $sCountry);
|
$sLabel = getBoundaryLabel($iRank/2, $sCountry);
|
||||||
} elseif ($iRank < 26) {
|
} elseif ($iRank < 26) {
|
||||||
$sLabel = $aPlace['type'];
|
$sLabel = $aPlace['type'];
|
||||||
} elseif ($iRank < 28) {
|
} elseif ($iRank < 28) {
|
||||||
@ -32,7 +32,7 @@ function getLabelTag($aPlace, $sCountry = null)
|
|||||||
$sLabel = $aPlace['class'];
|
$sLabel = $aPlace['class'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return strtolower(str_replace('_', ' ', $sLabel));
|
return strtolower(str_replace(' ', '_', $sLabel));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,11 +47,11 @@ function getLabel($aPlace, $sCountry = null)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($aPlace['class'] == 'boundary' && $aPlace['type'] == 'administrative') {
|
if ($aPlace['class'] == 'boundary' && $aPlace['type'] == 'administrative') {
|
||||||
return getBoundaryLabel((int)($aPlace['admin_level'] ?? 15, $sCountry ?? null);
|
return getBoundaryLabel(($aPlace['rank_address'] ?? 30)/2, $sCountry ?? null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a label only for 'important' class/type combinations
|
// Return a label only for 'important' class/type combinations
|
||||||
if (isset(getImportance($aPlace)) {
|
if (getImportance($aPlace) !== null) {
|
||||||
return ucwords(str_replace('_', ' ', $aPlace['type']));
|
return ucwords(str_replace('_', ' ', $aPlace['type']));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ function getBoundaryLabel($iAdminLevel, $sCountry, $sFallback = 'Administrative'
|
|||||||
6 => 'County',
|
6 => 'County',
|
||||||
7 => 'Municipality',
|
7 => 'Municipality',
|
||||||
8 => 'City',
|
8 => 'City',
|
||||||
9 => 'City District'
|
9 => 'City District',
|
||||||
10 => 'Suburb',
|
10 => 'Suburb',
|
||||||
11 => 'Neighbourhood'
|
11 => 'Neighbourhood'
|
||||||
)
|
)
|
||||||
@ -108,7 +108,7 @@ function getBoundaryLabel($iAdminLevel, $sCountry, $sFallback = 'Administrative'
|
|||||||
function getDefRadius($aPlace)
|
function getDefRadius($aPlace)
|
||||||
{
|
{
|
||||||
$aSpecialRadius = array(
|
$aSpecialRadius = array(
|
||||||
'place:continent' => 25
|
'place:continent' => 25,
|
||||||
'place:country' => 7,
|
'place:country' => 7,
|
||||||
'place:state' => 2.6,
|
'place:state' => 2.6,
|
||||||
'place:province' => 2.6,
|
'place:province' => 2.6,
|
||||||
@ -246,7 +246,10 @@ function getIcon($aPlace)
|
|||||||
*/
|
*/
|
||||||
function getImportance($aPlace)
|
function getImportance($aPlace)
|
||||||
{
|
{
|
||||||
static $aWithImportance = array_flip(array(
|
static $aWithImportance = null;
|
||||||
|
|
||||||
|
if ($aWithImportance === null) {
|
||||||
|
$aWithImportance = array_flip(array(
|
||||||
'place:country',
|
'place:country',
|
||||||
'place:state',
|
'place:state',
|
||||||
'place:province',
|
'place:province',
|
||||||
@ -526,7 +529,8 @@ function getImportance($aPlace)
|
|||||||
'railway:disused_station',
|
'railway:disused_station',
|
||||||
'railway:abandoned',
|
'railway:abandoned',
|
||||||
'railway:disused'
|
'railway:disused'
|
||||||
);
|
));
|
||||||
|
}
|
||||||
|
|
||||||
$sClassPlace = $aPlace['class'].':'.$aPlace['type'];
|
$sClassPlace = $aPlace['class'].':'.$aPlace['type'];
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ class AddressDetailsTest extends \PHPUnit\Framework\TestCase
|
|||||||
{
|
{
|
||||||
$oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en');
|
$oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en');
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'attraction' => '10 Downing Street',
|
'tourism' => '10 Downing Street',
|
||||||
'house_number' => '10',
|
'house_number' => '10',
|
||||||
'road' => 'Downing Street',
|
'road' => 'Downing Street',
|
||||||
'neighbourhood' => 'St. James\'s',
|
'neighbourhood' => 'St. James\'s',
|
||||||
|
@ -6,89 +6,88 @@ require_once(CONST_BasePath.'/lib/ClassTypes.php');
|
|||||||
|
|
||||||
class ClassTypesTest extends \PHPUnit\Framework\TestCase
|
class ClassTypesTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
public function testGetInfo()
|
public function testGetLabelTag()
|
||||||
{
|
{
|
||||||
// 1) Admin level set
|
$aPlace = array('class' => 'boundary', 'type' => 'administrative',
|
||||||
// city Dublin
|
'rank_address' => '4', 'place_type' => 'city');
|
||||||
// https://nominatim.openstreetmap.org/details.php?osmtype=R&osmid=1109531
|
$this->assertEquals('city', ClassTypes\getLabelTag($aPlace));
|
||||||
$aPlace = array(
|
|
||||||
'admin_level' => 7,
|
|
||||||
'class' => 'boundary',
|
|
||||||
'type' => 'administrative',
|
|
||||||
'rank_address' => 14
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertEquals('Municipality', ClassTypes\getInfo($aPlace)['label']);
|
$aPlace = array('class' => 'boundary', 'type' => 'administrative',
|
||||||
$this->assertEquals('Municipality', ClassTypes\getFallbackInfo($aPlace)['label']);
|
'rank_address' => '10');
|
||||||
$this->assertEquals('Municipality', ClassTypes\getProperty($aPlace, 'label'));
|
$this->assertEquals('state_district', ClassTypes\getLabelTag($aPlace));
|
||||||
|
|
||||||
// 2) No admin level
|
$aPlace = array('class' => 'boundary', 'type' => 'administrative');
|
||||||
// Eiffel Tower
|
$this->assertEquals('administrative', ClassTypes\getLabelTag($aPlace));
|
||||||
// https://nominatim.openstreetmap.org/details.php?osmtype=W&osmid=5013364
|
|
||||||
$aPlace = array(
|
|
||||||
'class' => 'tourism',
|
|
||||||
'type' => 'attraction',
|
|
||||||
'rank_address' => 29
|
|
||||||
);
|
|
||||||
$this->assertEquals('Attraction', ClassTypes\getInfo($aPlace)['label']);
|
|
||||||
$this->assertEquals(array('simplelabel' => 'address29'), ClassTypes\getFallbackInfo($aPlace));
|
|
||||||
$this->assertEquals('Attraction', ClassTypes\getProperty($aPlace, 'label'));
|
|
||||||
|
|
||||||
// 3) Unknown type
|
$aPlace = array('class' => 'place', 'type' => 'hamlet',
|
||||||
// La Maison du Toutou, Paris
|
'rank_address' => '20');
|
||||||
// https://nominatim.openstreetmap.org/details.php?osmtype=W&osmid=164011651
|
$this->assertEquals('hamlet', ClassTypes\getLabelTag($aPlace));
|
||||||
$aPlace = array(
|
|
||||||
'class' => 'shop',
|
$aPlace = array('class' => 'highway', 'type' => 'residential',
|
||||||
'type' => 'pet_grooming',
|
'rank_address' => '26');
|
||||||
'rank_address' => 29
|
$this->assertEquals('road', ClassTypes\getLabelTag($aPlace));
|
||||||
);
|
|
||||||
$this->assertEquals(false, ClassTypes\getInfo($aPlace));
|
$aPlace = array('class' => 'place', 'type' => 'house_number',
|
||||||
$this->assertEquals(array('simplelabel' => 'address29'), ClassTypes\getFallbackInfo($aPlace));
|
'rank_address' => '30');
|
||||||
$this->assertEquals(false, ClassTypes\getProperty($aPlace, 'label'));
|
$this->assertEquals('house_number', ClassTypes\getLabelTag($aPlace));
|
||||||
$this->assertEquals('mydefault', ClassTypes\getProperty($aPlace, 'label', 'mydefault'));
|
|
||||||
|
$aPlace = array('class' => 'amenity', 'type' => 'prison',
|
||||||
|
'rank_address' => '30');
|
||||||
|
$this->assertEquals('amenity', ClassTypes\getLabelTag($aPlace));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetClassTypesWithImportance()
|
public function testGetLabel()
|
||||||
{
|
{
|
||||||
$aClasses = ClassTypes\getListWithImportance();
|
$aPlace = array('class' => 'boundary', 'type' => 'administrative',
|
||||||
|
'rank_address' => '4', 'place_type' => 'city');
|
||||||
|
$this->assertEquals('City', ClassTypes\getLabel($aPlace));
|
||||||
|
|
||||||
$this->assertGreaterThan(
|
$aPlace = array('class' => 'boundary', 'type' => 'administrative',
|
||||||
200,
|
'rank_address' => '10');
|
||||||
count($aClasses)
|
$this->assertEquals('State District', ClassTypes\getLabel($aPlace));
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertEquals(
|
$aPlace = array('class' => 'boundary', 'type' => 'administrative');
|
||||||
array(
|
$this->assertEquals('Administrative', ClassTypes\getLabel($aPlace));
|
||||||
'label' => 'Country',
|
|
||||||
'frequency' => 0,
|
$aPlace = array('class' => 'amenity', 'type' => 'prison');
|
||||||
'icon' => 'poi_boundary_administrative',
|
$this->assertEquals('Prison', ClassTypes\getLabel($aPlace));
|
||||||
'defzoom' => 6,
|
|
||||||
'defdiameter' => 15,
|
$aPlace = array('class' => 'amenity', 'type' => 'foobar');
|
||||||
'importance' => 3
|
$this->assertNull(ClassTypes\getLabel($aPlace));
|
||||||
),
|
|
||||||
$aClasses['place:country']
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetBoundaryLabel()
|
||||||
|
{
|
||||||
|
$this->assertEquals('City', ClassTypes\getBoundaryLabel(8, null));
|
||||||
|
$this->assertEquals('Administrative', ClassTypes\getBoundaryLabel(18, null));
|
||||||
|
$this->assertEquals('None', ClassTypes\getBoundaryLabel(18, null, 'None'));
|
||||||
|
$this->assertEquals('State', ClassTypes\getBoundaryLabel(4, 'de', 'None'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetResultDiameter()
|
public function testGetDefRadius()
|
||||||
{
|
{
|
||||||
$aResult = array('class' => '', 'type' => '');
|
$aResult = array('class' => '', 'type' => '');
|
||||||
$this->assertEquals(
|
$this->assertEquals(0.00005, ClassTypes\getDefRadius($aResult));
|
||||||
0.0001,
|
|
||||||
ClassTypes\getProperty($aResult, 'defdiameter', 0.0001)
|
|
||||||
);
|
|
||||||
|
|
||||||
$aResult = array('class' => 'place', 'type' => 'country');
|
$aResult = array('class' => 'place', 'type' => 'country');
|
||||||
$this->assertEquals(
|
$this->assertEquals(7, ClassTypes\getDefRadius($aResult));
|
||||||
15,
|
}
|
||||||
ClassTypes\getProperty($aResult, 'defdiameter', 0.0001)
|
|
||||||
);
|
|
||||||
|
|
||||||
$aResult = array('class' => 'boundary', 'type' => 'administrative', 'admin_level' => 6);
|
public function testGetIcon()
|
||||||
$this->assertEquals(
|
{
|
||||||
0.32,
|
$aResult = array('class' => '', 'type' => '');
|
||||||
ClassTypes\getProperty($aResult, 'defdiameter', 0.0001)
|
$this->assertNull(ClassTypes\getIcon($aResult));
|
||||||
);
|
|
||||||
|
$aResult = array('class' => 'place', 'type' => 'airport');
|
||||||
|
$this->assertEquals('transport_airport2', ClassTypes\getIcon($aResult));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetImportance()
|
||||||
|
{
|
||||||
|
$aResult = array('class' => '', 'type' => '');
|
||||||
|
$this->assertNull(ClassTypes\getImportance($aResult));
|
||||||
|
|
||||||
|
$aResult = array('class' => 'place', 'type' => 'airport');
|
||||||
|
$this->assertGreaterThan(0, ClassTypes\getImportance($aResult));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user