forked from Zverik/Level0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoreTest.php
87 lines (68 loc) · 1.67 KB
/
CoreTest.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
<?php
namespace Level0;
require_once 'www/core.php';
use PHPUnit\Framework\TestCase;
class CoreTest extends TestCase
{
public function test_store_and_read_base() {
global $l0id;
$l0id = mt_rand(1000, 9999999);
$testdata = [
'key' => 'value',
'tags' => [
1,
2
]
];
global $basedata;
$basedata = $testdata;
store_base();
$basedata = [];
read_base();
$this->assertEquals($basedata, $testdata);
clear_data();
$this->assertEquals($basedata, []);
read_base();
$this->assertEquals($basedata, []);
}
public function test_strip_version() {
$this->assertEquals(
strip_version([]),
[]
);
$this->assertEquals(
strip_version(['a' => 'b', 'type' => 'node', 'version' => "1"]),
['a' => 'b', 'type' => 'node']
);
$this->assertEquals(
strip_version([['b' => 'c', 'type' => 'node', 'version' => "1"]]),
[['b' => 'c', 'type' => 'node']]
);
}
public function test_usort() {
$result = [
['action' => 'delete', 'type' => 'way', 'expected_order' => 3],
['action' => 'delete', 'type' => 'node', 'expected_order' => 4],
['action' => 'modify', 'type' => 'way', 'expected_order' => 2],
['action' => 'modify', 'type' => 'node', 'expected_order' => 1]
];
usort($result, 'export_cmp');
$this->assertEquals(
array_map(fn($o) => $o['expected_order'], $result),
[1, 2, 3, 4]
);
}
public function test_calculate_center() {
global $userdata;
$userdata = [];
$this->assertFalse(calculate_center());
$userdata = [
['type' => 'node', 'lat' => '12.0', 'lon' => '34.0'],
['type' => 'node', 'lat' => '12.2', 'lon' => '34.2']
];
$this->assertEquals(
calculate_center(),
[12.1, 34.1]
);
}
}