]> git.openstreetmap.org Git - nominatim.git/blob - test/php/Nominatim/ClassTypesTest.php
Merge branch 'separate-compilation' of https://github.com/eyusupov/Nominatim into...
[nominatim.git] / test / php / Nominatim / ClassTypesTest.php
1 <?php
2
3 namespace Nominatim;
4
5 require_once(CONST_BasePath.'/lib/ClassTypes.php');
6
7 class ClassTypesTest extends \PHPUnit\Framework\TestCase
8 {
9     public function testGetInfo()
10     {
11         // 1) Admin level set
12         // city Dublin
13         // https://nominatim.openstreetmap.org/details.php?osmtype=R&osmid=1109531
14         $aPlace = array(
15                    'admin_level' => 7,
16                    'class' => 'boundary',
17                    'type' => 'administrative',
18                    'rank_address' => 14
19         );
20
21         $this->assertEquals('Municipality', ClassTypes\getInfo($aPlace)['label']);
22         $this->assertEquals('Municipality', ClassTypes\getFallbackInfo($aPlace)['label']);
23         $this->assertEquals('Municipality', ClassTypes\getProperty($aPlace, 'label'));
24
25         // 2) No admin level
26         // Eiffel Tower
27         // https://nominatim.openstreetmap.org/details.php?osmtype=W&osmid=5013364
28         $aPlace = array(
29                    'class' => 'tourism',
30                    'type' => 'attraction',
31                    'rank_address' => 29
32         );
33         $this->assertEquals('Attraction', ClassTypes\getInfo($aPlace)['label']);
34         $this->assertEquals(array('simplelabel' => 'address29'), ClassTypes\getFallbackInfo($aPlace));
35         $this->assertEquals('Attraction', ClassTypes\getProperty($aPlace, 'label'));
36
37         // 3) Unknown type
38         // La Maison du Toutou, Paris
39         // https://nominatim.openstreetmap.org/details.php?osmtype=W&osmid=164011651
40         $aPlace = array(
41                    'class' => 'shop',
42                    'type' => 'pet_grooming',
43                    'rank_address' => 29
44         );
45         $this->assertEquals(false, ClassTypes\getInfo($aPlace));
46         $this->assertEquals(array('simplelabel' => 'address29'), ClassTypes\getFallbackInfo($aPlace));
47         $this->assertEquals(false, ClassTypes\getProperty($aPlace, 'label'));
48         $this->assertEquals('mydefault', ClassTypes\getProperty($aPlace, 'label', 'mydefault'));
49     }
50
51     public function testGetClassTypesWithImportance()
52     {
53         $aClasses = ClassTypes\getListWithImportance();
54
55         $this->assertGreaterThan(
56             200,
57             count($aClasses)
58         );
59
60         $this->assertEquals(
61             array(
62              'label' => 'Country',
63              'frequency' => 0,
64              'icon' => 'poi_boundary_administrative',
65              'defzoom' => 6,
66              'defdiameter' => 15,
67              'importance' => 3
68             ),
69             $aClasses['place:country']
70         );
71     }
72
73
74     public function testGetResultDiameter()
75     {
76         $aResult = array('class' => '', 'type' => '');
77         $this->assertEquals(
78             0.0001,
79             ClassTypes\getProperty($aResult, 'defdiameter', 0.0001)
80         );
81
82         $aResult = array('class' => 'place', 'type' => 'country');
83         $this->assertEquals(
84             15,
85             ClassTypes\getProperty($aResult, 'defdiameter', 0.0001)
86         );
87
88         $aResult = array('class' => 'boundary', 'type' => 'administrative', 'admin_level' => 6);
89         $this->assertEquals(
90             0.32,
91             ClassTypes\getProperty($aResult, 'defdiameter', 0.0001)
92         );
93     }
94 }