3 * SPDX-License-Identifier: GPL-2.0-only
5 * This file is part of Nominatim. (https://nominatim.org)
7 * Copyright (C) 2022 by the Nominatim developer community.
8 * For a full list of authors see the git log.
13 require_once(CONST_LibDir.'/ClassTypes.php');
15 class ClassTypesTest extends \PHPUnit\Framework\TestCase
17 public function testGetLabelTag()
19 $aPlace = array('class' => 'boundary', 'type' => 'administrative',
20 'rank_address' => '4', 'place_type' => 'city');
21 $this->assertEquals('city', ClassTypes\getLabelTag($aPlace));
23 $aPlace = array('class' => 'boundary', 'type' => 'administrative',
24 'rank_address' => '10');
25 $this->assertEquals('state_district', ClassTypes\getLabelTag($aPlace));
27 $aPlace = array('class' => 'boundary', 'type' => 'administrative');
28 $this->assertEquals('administrative', ClassTypes\getLabelTag($aPlace));
30 $aPlace = array('class' => 'place', 'type' => 'hamlet', 'rank_address' => '20');
31 $this->assertEquals('hamlet', ClassTypes\getLabelTag($aPlace));
33 $aPlace = array('class' => 'highway', 'type' => 'residential',
34 'rank_address' => '26');
35 $this->assertEquals('road', ClassTypes\getLabelTag($aPlace));
37 $aPlace = array('class' => 'place', 'type' => 'house_number',
38 'rank_address' => '30');
39 $this->assertEquals('house_number', ClassTypes\getLabelTag($aPlace));
41 $aPlace = array('class' => 'amenity', 'type' => 'prison',
42 'rank_address' => '30');
43 $this->assertEquals('amenity', ClassTypes\getLabelTag($aPlace));
46 public function testGetLabel()
48 $aPlace = array('class' => 'boundary', 'type' => 'administrative',
49 'rank_address' => '4', 'place_type' => 'city');
50 $this->assertEquals('City', ClassTypes\getLabel($aPlace));
52 $aPlace = array('class' => 'boundary', 'type' => 'administrative',
53 'rank_address' => '10');
54 $this->assertEquals('State District', ClassTypes\getLabel($aPlace));
56 $aPlace = array('class' => 'boundary', 'type' => 'administrative');
57 $this->assertEquals('Administrative', ClassTypes\getLabel($aPlace));
59 $aPlace = array('class' => 'amenity', 'type' => 'prison');
60 $this->assertEquals('Prison', ClassTypes\getLabel($aPlace));
62 $aPlace = array('class' => 'amenity', 'type' => 'foobar');
63 $this->assertNull(ClassTypes\getLabel($aPlace));
66 public function testGetBoundaryLabel()
68 $this->assertEquals('City', ClassTypes\getBoundaryLabel(8, null));
69 $this->assertEquals('Administrative', ClassTypes\getBoundaryLabel(18, null));
70 $this->assertEquals('None', ClassTypes\getBoundaryLabel(18, null, 'None'));
71 $this->assertEquals('State', ClassTypes\getBoundaryLabel(4, 'de', 'None'));
72 $this->assertEquals('County', ClassTypes\getBoundaryLabel(4, 'se', 'None'));
73 $this->assertEquals('Municipality', ClassTypes\getBoundaryLabel(7, 'se', 'None'));
76 public function testGetDefRadius()
78 $aResult = array('class' => '', 'type' => '');
79 $this->assertEquals(0.00005, ClassTypes\getDefRadius($aResult));
81 $aResult = array('class' => 'place', 'type' => 'country');
82 $this->assertEquals(7, ClassTypes\getDefRadius($aResult));
85 public function testGetIcon()
87 $aResult = array('class' => '', 'type' => '');
88 $this->assertNull(ClassTypes\getIcon($aResult));
90 $aResult = array('class' => 'place', 'type' => 'airport');
91 $this->assertEquals('transport_airport2', ClassTypes\getIcon($aResult));
94 public function testGetImportance()
96 $aResult = array('class' => '', 'type' => '');
97 $this->assertNull(ClassTypes\getImportance($aResult));
99 $aResult = array('class' => 'place', 'type' => 'airport');
100 $this->assertGreaterThan(0, ClassTypes\getImportance($aResult));