forked from Zverik/Level0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOsmApiTest.php
93 lines (73 loc) · 2.3 KB
/
OsmApiTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace Level0;
define('GENERATOR', 'Level0 v1.2');
require_once 'www/config.php';
require_once 'www/osmapi.php';
use PHPUnit\Framework\TestCase;
class OsmApiTest extends TestCase
{
public function test_url_to_api() {
$this->assertFalse(url_to_api(''));
$this->assertFalse(url_to_api('abc'));
$this->assertEquals(url_to_api('/api/0.6/node/123'), 'https://api.openstreetmap.org/api/0.6/node/123');
$this->assertEquals(url_to_api('overpass-api.de/api/interpreter?data=a-long-query'), 'http://overpass-api.de/api/interpreter?data=a-long-query');
$this->assertEquals(
url_to_api('n12,w34,r56'),
[
'https://api.openstreetmap.org/api/0.6/node/12',
'https://api.openstreetmap.org/api/0.6/way/34',
'https://api.openstreetmap.org/api/0.6/relation/56'
]
);
$this->assertEquals(url_to_api('15/12.34/56.78'), 'https://api.openstreetmap.org/api/0.6/map?bbox=56.77970,12.33970,56.78030,12.34030');
}
public function test_create_osc() {
$data = [
[
'action' => 'change',
'timestamp' => 'TODAY',
'version' => '2',
'type' => 'node',
'id' => '123',
'lat' => '51.12',
'lon' => '21.34',
'tags' => [
'building' => 'yes',
'key' => 'value'
]
]
];
// var_dump(create_osc($data));
$expected = <<<END
<?xml version="1.0" encoding="UTF-8"?>
<osmChange version="0.6" generator="Level0 v1.2">
<change>
<node id='123' version='2' lat='51.12' lon='21.34' timestamp='TODAY'>
<tag k='building' v='yes' />
<tag k='key' v='value' />
</node>
</change>
</osmChange>
END;
$this->assertEquals(create_osc($data), $expected);
$expected = <<<END
<?xml version='1.0' encoding='UTF-8'?>
<osm version='0.6' upload='true' generator='Level0 v1.2'>
<node id='123' version='2' lat='51.12' lon='21.34' action='change' timestamp='TODAY'>
<tag k='building' v='yes' />
<tag k='key' v='value' />
</node>
</osm>
END;
$this->assertEquals(create_osm($data), $expected);
}
public function test_hard_trim() {
$this->assertEquals(hard_trim(' abc def '), 'abc def');
$this->assertEquals(hard_trim(" \t abc def \0 \r\n"), 'abc def');
$this->assertEquals(hard_trim(" \n "), '');
}
public function testis_pint() {
$this->assertTrue(is_pint('12'));
$this->assertTrue(is_pint('-12', false));
}
}