1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backend\Modules\Location\Tests\Engine; |
4
|
|
|
|
5
|
|
|
use Backend\Modules\Location\Engine\Model; |
6
|
|
|
use Common\WebTestCase; |
7
|
|
|
|
8
|
|
|
class ModelTest extends WebTestCase |
9
|
|
|
{ |
10
|
9 |
|
public function setUp() |
11
|
|
|
{ |
12
|
9 |
|
parent::setUp(); |
13
|
|
|
|
14
|
9 |
|
if (!defined('APPLICATION')) { |
15
|
|
|
define('APPLICATION', 'Backend'); |
16
|
|
|
} |
17
|
9 |
|
} |
18
|
|
|
|
19
|
1 |
|
public function testInsertingLocation(): void |
20
|
|
|
{ |
21
|
1 |
|
$client = self::createClient(); |
22
|
1 |
|
$this->loadFixtures($client); |
23
|
|
|
|
24
|
1 |
|
$locationArray = $this->getLocationArray(); |
25
|
|
|
|
26
|
1 |
|
Model::insert($locationArray); |
27
|
|
|
|
28
|
1 |
|
$addedLocation = Model::get(1); |
29
|
|
|
|
30
|
1 |
|
self::assertEquals($locationArray['language'], $addedLocation['language']); |
31
|
1 |
|
self::assertEquals($locationArray['title'], $addedLocation['title']); |
32
|
1 |
|
self::assertEquals($locationArray['street'], $addedLocation['street']); |
33
|
1 |
|
self::assertEquals($locationArray['number'], $addedLocation['number']); |
34
|
1 |
|
self::assertEquals($locationArray['zip'], $addedLocation['zip']); |
35
|
1 |
|
self::assertEquals($locationArray['city'], $addedLocation['city']); |
36
|
1 |
|
self::assertEquals($locationArray['country'], $addedLocation['country']); |
37
|
1 |
|
self::assertEquals($locationArray['lat'], $addedLocation['lat']); |
38
|
1 |
|
self::assertEquals($locationArray['lng'], $addedLocation['lng']); |
39
|
1 |
|
self::assertEquals($locationArray['show_overview'], $addedLocation['show_overview']); |
40
|
1 |
|
} |
41
|
|
|
|
42
|
1 |
|
public function testInsertingLocationSetting(): void |
43
|
|
|
{ |
44
|
1 |
|
Model::setMapSetting( |
45
|
1 |
|
1, |
46
|
1 |
|
'foo', |
47
|
1 |
|
'bar' |
48
|
|
|
); |
49
|
|
|
|
50
|
1 |
|
Model::setMapSetting( |
51
|
1 |
|
1, |
52
|
1 |
|
'ping', |
53
|
1 |
|
'pong' |
54
|
|
|
); |
55
|
|
|
|
56
|
1 |
|
self::assertEquals('bar', Model::getMapSetting(1, 'foo')); |
57
|
1 |
|
self::assertEquals('pong', Model::getMapSetting(1, 'ping')); |
58
|
1 |
|
} |
59
|
|
|
|
60
|
1 |
|
public function testEditingLocationSetting(): void |
61
|
|
|
{ |
62
|
1 |
|
Model::setMapSetting( |
63
|
1 |
|
1, |
64
|
1 |
|
'foo', |
65
|
1 |
|
'pong' |
66
|
|
|
); |
67
|
|
|
|
68
|
1 |
|
Model::setMapSetting( |
69
|
1 |
|
1, |
70
|
1 |
|
'ping', |
71
|
1 |
|
'bar' |
72
|
|
|
); |
73
|
|
|
|
74
|
1 |
|
self::assertEquals('pong', Model::getMapSetting(1, 'foo')); |
75
|
1 |
|
self::assertEquals('bar', Model::getMapSetting(1, 'ping')); |
76
|
1 |
|
} |
77
|
|
|
|
78
|
1 |
|
public function testGettingAllLocationSettings(): void |
79
|
|
|
{ |
80
|
1 |
|
$settings = Model::getMapSettings(1); |
81
|
|
|
|
82
|
1 |
|
self::assertCount(2, $settings); |
83
|
1 |
|
self::assertEquals('pong', $settings['foo']); |
84
|
1 |
|
self::assertEquals('bar', $settings['ping']); |
85
|
1 |
|
} |
86
|
|
|
|
87
|
1 |
|
public function testGettingNonexistantSettingReturnsFalse(): void |
88
|
|
|
{ |
89
|
1 |
|
self::assertFalse(Model::getMapSetting(1, 'i-dont-exist')); |
90
|
1 |
|
self::assertFalse(Model::getMapSetting(3, 'the-location-also-doesnt-exist')); |
91
|
1 |
|
} |
92
|
|
|
|
93
|
1 |
|
public function testLocationExists(): void |
94
|
|
|
{ |
95
|
1 |
|
self::assertEquals(true, Model::exists(1)); |
96
|
1 |
|
self::assertEquals(false, Model::exists(2)); |
97
|
1 |
|
} |
98
|
|
|
|
99
|
1 |
|
public function testGettingAllLocations(): void |
100
|
|
|
{ |
101
|
1 |
|
$locations = Model::getAll(); |
102
|
|
|
|
103
|
1 |
|
self::assertCount(1, $locations); |
104
|
|
|
|
105
|
1 |
|
$firstLocation = $locations[0]; |
106
|
|
|
|
107
|
1 |
|
$locationArray = $this->getLocationArray(); |
108
|
|
|
|
109
|
1 |
|
self::assertEquals($locationArray['language'], $firstLocation['language']); |
110
|
1 |
|
self::assertEquals($locationArray['title'], $firstLocation['title']); |
111
|
1 |
|
self::assertEquals($locationArray['street'], $firstLocation['street']); |
112
|
1 |
|
self::assertEquals($locationArray['number'], $firstLocation['number']); |
113
|
1 |
|
self::assertEquals($locationArray['zip'], $firstLocation['zip']); |
114
|
1 |
|
self::assertEquals($locationArray['city'], $firstLocation['city']); |
115
|
1 |
|
self::assertEquals($locationArray['country'], $firstLocation['country']); |
116
|
1 |
|
self::assertEquals($locationArray['lat'], $firstLocation['lat']); |
117
|
1 |
|
self::assertEquals($locationArray['lng'], $firstLocation['lng']); |
118
|
1 |
|
self::assertEquals($locationArray['show_overview'], $firstLocation['show_overview']); |
119
|
1 |
|
} |
120
|
|
|
|
121
|
1 |
|
public function testEditingLocation(): void |
122
|
|
|
{ |
123
|
1 |
|
$locationArray = $this->getUpdatedLocationArray(); |
124
|
|
|
|
125
|
1 |
|
Model::update($locationArray); |
126
|
|
|
|
127
|
1 |
|
$editedLocation = Model::get(1); |
128
|
|
|
|
129
|
1 |
|
self::assertEquals($locationArray['language'], $editedLocation['language']); |
130
|
1 |
|
self::assertEquals($locationArray['title'], $editedLocation['title']); |
131
|
1 |
|
self::assertEquals($locationArray['street'], $editedLocation['street']); |
132
|
1 |
|
self::assertEquals($locationArray['number'], $editedLocation['number']); |
133
|
1 |
|
self::assertEquals($locationArray['zip'], $editedLocation['zip']); |
134
|
1 |
|
self::assertEquals($locationArray['city'], $editedLocation['city']); |
135
|
1 |
|
self::assertEquals($locationArray['country'], $editedLocation['country']); |
136
|
1 |
|
self::assertEquals($locationArray['lat'], $editedLocation['lat']); |
137
|
1 |
|
self::assertEquals($locationArray['lng'], $editedLocation['lng']); |
138
|
1 |
|
self::assertEquals($locationArray['show_overview'], $editedLocation['show_overview']); |
139
|
1 |
|
} |
140
|
|
|
|
141
|
1 |
|
public function testDeletingLocation(): void |
142
|
|
|
{ |
143
|
1 |
|
self::assertEquals(true, Model::exists(1)); |
144
|
|
|
|
145
|
1 |
|
Model::delete(1); |
146
|
|
|
|
147
|
1 |
|
self::assertEquals(false, Model::exists(1)); |
148
|
1 |
|
self::assertEmpty(Model::getMapSettings(1)); |
149
|
1 |
|
} |
150
|
|
|
|
151
|
2 |
|
private function getLocationArray(): array |
152
|
|
|
{ |
153
|
|
|
return [ |
154
|
2 |
|
'language' => 'en', |
155
|
|
|
'title' => 'Test location', |
156
|
|
|
'street' => 'Afrikalaan', |
157
|
|
|
'number' => '289', |
158
|
|
|
'zip' => '9000', |
159
|
|
|
'city' => 'Ghent', |
160
|
|
|
'country' => 'BE', |
161
|
|
|
'lat' => '51.0728', |
162
|
|
|
'lng' => '3.73599', |
163
|
|
|
'show_overview' => '1' |
164
|
|
|
]; |
165
|
|
|
} |
166
|
|
|
|
167
|
1 |
|
private function getUpdatedLocationArray(): array |
168
|
|
|
{ |
169
|
|
|
return [ |
170
|
1 |
|
'id' => '1', |
171
|
|
|
'extra_id' => '999', |
172
|
|
|
'language' => 'en', |
173
|
|
|
'title' => 'Test location edit', |
174
|
|
|
'street' => 'Visserij', |
175
|
|
|
'number' => '1', |
176
|
|
|
'zip' => '9000', |
177
|
|
|
'city' => 'Ghent', |
178
|
|
|
'country' => 'BE', |
179
|
|
|
'lat' => '51.0713', |
180
|
|
|
'lng' => '3.73523', |
181
|
|
|
'show_overview' => '0' |
182
|
|
|
]; |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|