1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class MapAPITest extends SapphireTest { |
4
|
|
|
|
5
|
|
|
public function setUpOnce() { |
6
|
|
|
$this->requiredExtensions = array( |
7
|
|
|
'Member' => array('MapExtension') |
8
|
|
|
); |
9
|
|
|
parent::setupOnce(); |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
public function setUp() { |
14
|
|
|
MapUtil::reset(); |
15
|
|
|
parent::setUp(); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function testSetKey() { |
19
|
|
|
$map = $this->getMap(); |
20
|
|
|
$map->setKey('PRETEND_KEY'); |
21
|
|
|
$html = $map->forTemplate(); |
|
|
|
|
22
|
|
|
$map->setKey(null); |
23
|
|
|
|
24
|
|
|
$this->fail('where to check effect?'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testSetClusterer() { |
28
|
|
|
$map = $this->getMap(); |
29
|
|
|
$map->setClusterer(true); |
30
|
|
|
$html = $map->forTemplate(); |
31
|
|
|
$this->assertContains('data-clusterergridsize=50', $html); |
32
|
|
|
$this->assertContains('data-clusterermaxzoom=17', $html); |
33
|
|
|
$this->assertContains('data-useclusterer=1', $html); |
34
|
|
|
|
35
|
|
|
$map = $this->getMap(); |
36
|
|
|
$map->setClusterer(true, 60,14); |
37
|
|
|
$html = $map->forTemplate(); |
38
|
|
|
$this->assertContains('data-clusterergridsize=60', $html); |
39
|
|
|
$this->assertContains('data-clusterermaxzoom=14', $html); |
40
|
|
|
$this->assertContains('data-useclusterer=1', $html); |
41
|
|
|
|
42
|
|
|
$map = $this->getMap(); |
43
|
|
|
$map->setClusterer(false); |
44
|
|
|
$html = $map->forTemplate(); |
45
|
|
|
$this->assertContains('data-useclusterer=false', $html); |
46
|
|
|
$this->assertContains('data-clusterergridsize=50', $html); |
47
|
|
|
$this->assertContains('data-clusterermaxzoom=17', $html); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/* |
51
|
|
|
Toggle as to whether or not to include a style= attribute with width/height |
52
|
|
|
*/ |
53
|
|
|
public function testSetShowInlineMapDivStyle() { |
54
|
|
|
$map = $this->getMap(); |
55
|
|
|
$map->setShowInlineMapDivStyle(true); |
56
|
|
|
$html = $map->forTemplate(); |
57
|
|
|
$expected = 'style="width:100%; height: 400px;"'; |
58
|
|
|
$this->assertContains($expected, $html); |
59
|
|
|
|
60
|
|
|
$map->setShowInlineMapDivStyle(false); |
61
|
|
|
$html = $map->forTemplate(); |
62
|
|
|
$this->assertNotContains($expected, $html); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testSetAdditionalCSSClasses() { |
66
|
|
|
$map = $this->getMap(); |
67
|
|
|
$map->setAdditionalCSSClasses('bigMap shadowMap'); |
68
|
|
|
$html = $map->forTemplate(); |
69
|
|
|
$expected = 'class="bigMap shadowMap mappable"'; |
70
|
|
|
$this->assertContains($expected, $html); |
71
|
|
|
$map->setAdditionalCSSClasses('bigMap shadowMap'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
public function testSetMapStyle() { |
76
|
|
|
$style = <<<STYLE |
77
|
|
|
[{ |
78
|
|
|
"featureType": "landscape", |
79
|
|
|
"stylers": [{ |
80
|
|
|
"hue": "#FFBB00" |
81
|
|
|
}, { |
82
|
|
|
"saturation": 43.400000000000006 |
83
|
|
|
}, { |
84
|
|
|
"lightness": 37.599999999999994 |
85
|
|
|
}, { |
86
|
|
|
"gamma": 1 |
87
|
|
|
}] |
88
|
|
|
}] |
89
|
|
|
STYLE; |
90
|
|
|
$map = $this->getMap(); |
91
|
|
|
$map->setMapStyle($style); |
92
|
|
|
$html = $map->forTemplate()->getValue(); |
93
|
|
|
$expected = <<<HTML |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
<div id="google_map_1" style="width:100%; height: 400px;" |
97
|
|
|
class=" mappable" |
98
|
|
|
data-map |
99
|
|
|
data-centre='{"lat":48.856614,"lng":2.3522219}' |
100
|
|
|
data-zoom=9 |
101
|
|
|
data-maptype='road' |
102
|
|
|
data-allowfullscreen='1' |
103
|
|
|
data-clusterergridsize=50, |
104
|
|
|
data-clusterermaxzoom=17, |
105
|
|
|
data-enableautocentrezoom=false |
106
|
|
|
data-enablewindowzoom=false |
107
|
|
|
data-infowindowzoom=13 |
108
|
|
|
data-mapmarkers='[]' |
109
|
|
|
data-defaulthidemarker=false |
110
|
|
|
data-lines='[]' |
111
|
|
|
data-kmlfiles='[]' |
112
|
|
|
data-mapstyles='[{ |
113
|
|
|
"featureType": "landscape", |
114
|
|
|
"stylers": [{ |
115
|
|
|
"hue": "#FFBB00" |
116
|
|
|
}, { |
117
|
|
|
"saturation": 43.400000000000006 |
118
|
|
|
}, { |
119
|
|
|
"lightness": 37.599999999999994 |
120
|
|
|
}, { |
121
|
|
|
"gamma": 1 |
122
|
|
|
}] |
123
|
|
|
}]' |
124
|
|
|
data-useclusterer=false |
125
|
|
|
> |
126
|
|
|
</div> |
127
|
|
|
|
128
|
|
|
HTML; |
129
|
|
|
$this->assertEquals($expected, $html); |
|
|
|
|
130
|
|
|
$map->setMapStyle(null); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
public function testSetDelayLoadMapFunction() { |
135
|
|
|
$this->fail('Not clear if this is still used'); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
public function testSetDivId() { |
140
|
|
|
$map = $this->getMap(); |
141
|
|
|
$map->setDivId('mymapid'); |
142
|
|
|
$html = $map->forTemplate(); |
143
|
|
|
$expected = '<div id="mymapid" style='; |
144
|
|
|
$this->assertContains($expected, $html); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function testSetSize() { |
148
|
|
|
$map = $this->getMap(); |
149
|
|
|
$map->setSize('432px', '1234px'); |
150
|
|
|
$html = $map->forTemplate(); |
151
|
|
|
$this->assertContains('style="width:432px; height: 1234px;"', $html); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function testSetLang() { |
155
|
|
|
$map = $this->getMap(); |
156
|
|
|
$map->setLang('fr'); |
157
|
|
|
$html = $map->forTemplate(); |
|
|
|
|
158
|
|
|
$this->fail('Response needs checked'); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
public function testSetZoom() { |
163
|
|
|
$map = $this->getMap(); |
164
|
|
|
$map->setZoom(4); |
165
|
|
|
$html = $map->forTemplate(); |
166
|
|
|
$this->assertContains('data-zoom=4', $html); |
167
|
|
|
$map->setZoom(12); |
168
|
|
|
$html = $map->forTemplate(); |
169
|
|
|
$this->assertContains('data-zoom=12', $html); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function testSetInfoWindowZoom() { |
173
|
|
|
$map = $this->getMap(); |
174
|
|
|
$map->setInfoWindowZoom(4); |
175
|
|
|
$html = $map->forTemplate(); |
176
|
|
|
$this->assertContains('data-infowindowzoom=4', $html); |
177
|
|
|
$map->setInfoWindowZoom(12); |
178
|
|
|
$html = $map->forTemplate(); |
179
|
|
|
$this->assertContains('data-infowindowzoom=12', $html); |
180
|
|
|
|
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function testSetEnableWindowZoom() { |
184
|
|
|
$map = $this->getMap(); |
185
|
|
|
$map->setEnableWindowZoom(false); |
186
|
|
|
$html = $map->forTemplate(); |
187
|
|
|
$this->assertContains('data-enablewindowzoom=false', $html); |
188
|
|
|
$map->setEnableWindowZoom(true); |
189
|
|
|
$html = $map->forTemplate(); |
190
|
|
|
$this->assertContains('data-enablewindowzoom=1', $html); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function testSetEnableAutomaticCenterZoom() { |
194
|
|
|
$map = $this->getMap(); |
195
|
|
|
$map->setEnableAutomaticCenterZoom(true); |
196
|
|
|
$html = $map->forTemplate(); |
197
|
|
|
$this->assertContains('data-enableautocentrezoom=1', $html); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* setCentre is mis-named, as the method expects text for a geocoder |
202
|
|
|
*/ |
203
|
|
|
public function testSetCenter() { |
204
|
|
|
$map = $this->getMap(); |
205
|
|
|
$map->setCenter('Klong Tan, Bangkok, Thailand'); |
206
|
|
|
$html = $map->forTemplate(); |
207
|
|
|
|
208
|
|
|
//coordinates of Klong Tan in Bangkok |
209
|
|
|
$expected = 'data-centre=\'{"lat":13.7243075,"lng":100.5718086}'; |
210
|
|
|
$this->assertContains($expected, $html); |
211
|
|
|
$map->setCenter('Paris, France'); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
|
215
|
|
|
public function testSetLatLongCenter() { |
216
|
|
|
$map = $this->getMap(); |
217
|
|
|
$llc = array('lat' => -23.714, 'lng' => 47.419); |
218
|
|
|
$map->setLatLongCenter($llc); |
219
|
|
|
$html = $map->forTemplate(); |
220
|
|
|
$expected = "data-centre='{\"lat\":-23.714,\"lng\":47.419}'"; |
221
|
|
|
$this->assertContains($expected, $html); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
|
225
|
|
|
public function testSetMapType() { |
226
|
|
|
$map = $this->getMap(); |
227
|
|
|
|
228
|
|
|
$mapTypes = array( |
229
|
|
|
'road' => 'road', |
230
|
|
|
'satellite' => 'satellite', |
231
|
|
|
'hybrid' => 'hybrid', |
232
|
|
|
'terrain' => 'terrain', |
233
|
|
|
'google.maps.MapTypeId.ROADMAP' => 'road', |
234
|
|
|
'google.maps.MapTypeId.SATELLITE' => 'satellite', |
235
|
|
|
'google.maps.MapTypeId.G_HYBRID_MAP' => 'hybrid', |
236
|
|
|
'google.maps.MapTypeId.G_PHYSICAL_MAP' => 'terrain', |
237
|
|
|
'custom_layer' => 'custom_layer' |
238
|
|
|
|
239
|
|
|
); |
240
|
|
|
|
241
|
|
|
foreach (array_keys($mapTypes) as $mapType) { |
242
|
|
|
$map->setMapType($mapType); |
243
|
|
|
$expected = "data-maptype='".$mapTypes[$mapType]."'"; |
244
|
|
|
$html = $map->forTemplate(); |
245
|
|
|
$this->assertContains($expected, $html); |
246
|
|
|
} |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
|
250
|
|
|
public function testSetAllowFullScreen() { |
251
|
|
|
$map = $this->getMap(); |
252
|
|
|
$map->setAllowFullScreen(false); |
253
|
|
|
$html = $map->forTemplate(); |
254
|
|
|
|
255
|
|
|
//FIXME this is possibly problematic |
256
|
|
|
$this->assertContains("data-allowfullscreen='false'", $html); |
257
|
|
|
|
258
|
|
|
$map->setAllowFullScreen(true); |
259
|
|
|
$html = $map->forTemplate(); |
260
|
|
|
$this->assertContains("data-allowfullscreen='1'", $html); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
public function testMapWithMarkers() { |
264
|
|
|
$config = Config::inst(); |
|
|
|
|
265
|
|
|
|
266
|
|
|
$map = $this->getMapMultipleItems(); |
267
|
|
|
$html = $map->forTemplate(); |
268
|
|
|
$expected = 'data-mapmarkers=\'[{"latitude":23,"longitude":78,"html":"' |
269
|
|
|
. 'MEMBER: Fred Bloggs","category":"default","icon":false},{"latitude' |
270
|
|
|
. '":-12,"longitude":42.1,"html":"MEMBER: Kane Williamson","category"' |
271
|
|
|
. ':"default","icon":false}]\''; |
272
|
|
|
$this->assertContains($expected, $html); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
|
276
|
|
|
public function testMapWithMarkersDifferentCategory() { |
277
|
|
|
$this->markTestSkipped('TODO'); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
|
281
|
|
|
public function testSetDefaultHideMarker() { |
282
|
|
|
$map = $this->getMapMultipleItems(); |
283
|
|
|
$map->setDefaultHideMarker(false); |
284
|
|
|
$html = $map->forTemplate(); |
285
|
|
|
$this->assertContains( |
286
|
|
|
'data-defaulthidemarker=false', |
287
|
|
|
$html |
288
|
|
|
); |
289
|
|
|
|
290
|
|
|
$map = $this->getMapMultipleItems(); |
291
|
|
|
$map->setDefaultHideMarker(true); |
292
|
|
|
$html = $map->forTemplate(); |
293
|
|
|
$this->assertContains( |
294
|
|
|
'data-defaulthidemarker=1', |
295
|
|
|
$html |
296
|
|
|
); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
public function testGetContent() { |
300
|
|
|
$this->markTestSkipped('Skipping this test so as testable offline'); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
public function testGeocoding() { |
304
|
|
|
$map = $this->getMap(); |
305
|
|
|
$location = $map->geocoding("Nonthaburi, Thailand"); |
306
|
|
|
$expected = array( |
307
|
|
|
'lat' => 13.8621125, |
308
|
|
|
'lon' => 100.5143528, |
309
|
|
|
'geocoded' => true |
310
|
|
|
); |
311
|
|
|
$this->assertEquals($expected, $location); |
|
|
|
|
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
public function testAddMarkerByAddress() { |
315
|
|
|
//$address, $content = '', $category = '', $icon = '' |
|
|
|
|
316
|
|
|
$map = $this->getMap(); |
317
|
|
|
$map->addMarkerByAddress( |
318
|
|
|
'Koh Kred, Nonthaburi, Thailand', |
319
|
|
|
'Small island in the Chao Phraya river', |
320
|
|
|
'testing', |
321
|
|
|
'http://www.test.com/icon.png' |
322
|
|
|
); |
323
|
|
|
$html = $map->forTemplate(); |
324
|
|
|
$expected = 'data-mapmarkers=\'[{"latitude":13.9114455,"longitude":100.4761897,"html":"Small island in the Chao Phraya river","category":"testing","icon":"http://www.test.com/icon.png"}]\''; |
325
|
|
|
$this->assertContains($expected, $html); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
|
329
|
|
|
public function testAddArrayMarkerByCoords() { |
330
|
|
|
$map = $this->getMap(); |
331
|
|
|
|
332
|
|
|
$markerArray = array(); |
333
|
|
|
$marker1 = array(48.2, 27, 'Description marker 1', 'Marker Test', ''); |
334
|
|
|
$marker2 = array(-12.2, 47, 'Description marker 2', 'Marker Test', ''); |
335
|
|
|
|
336
|
|
|
array_push($markerArray, $marker1); |
337
|
|
|
array_push($markerArray, $marker2); |
338
|
|
|
|
339
|
|
|
$map->addArrayMarkerByCoords($markerArray); |
340
|
|
|
$html = $map->forTemplate(); |
341
|
|
|
$expected = 'data-mapmarkers=\'[{"latitude":48.2,"longitude":27,"html":"Description marker 1","category":"","icon":""},{"latitude":-12.2,"longitude":47,"html":"Description marker 2","category":"","icon":""}]\''; |
342
|
|
|
$this->assertContains($expected, $html); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
public function testAddMarkerByCoords() { |
346
|
|
|
$map = $this->getMap(); |
347
|
|
|
$map->addMarkerByCoords( |
348
|
|
|
13.91, |
349
|
|
|
100.47, |
350
|
|
|
'Description of marker', |
351
|
|
|
'testing', |
352
|
|
|
'http://www.test.com/icon.png' |
353
|
|
|
); |
354
|
|
|
$html = $map->forTemplate(); |
355
|
|
|
$expected = |
356
|
|
|
'data-mapmarkers=\'[{"latitude":13.91,"longitude":100.47,"html":"Description of marker","category":"testing","icon":"http://www.test.com/icon.png"}]'; |
357
|
|
|
|
358
|
|
|
$this->assertContains($expected, $html); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
|
362
|
|
|
public function testAddMarkerAsObject() { |
363
|
|
|
$map = $this->getMap(); |
364
|
|
|
$member = new Member(); |
365
|
|
|
$member->FirstName = 'Test'; |
366
|
|
|
$member->Surname = 'User'; |
367
|
|
|
$member->Lat = 24.2; |
368
|
|
|
$member->Lon = -40; |
369
|
|
|
$member->write(); |
370
|
|
|
$params = array(); |
371
|
|
|
$map->addMarkerAsObject( |
372
|
|
|
$member, |
373
|
|
|
$params |
374
|
|
|
); |
375
|
|
|
|
376
|
|
|
$html = $map->forTemplate(); |
377
|
|
|
$expected = 'data-mapmarkers=\'[{"latitude":24.2,"longitude":-40,"html":"MEMBER: Test User","category":"default","icon":false}]\''; |
378
|
|
|
$this->assertContains($expected, $html); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
|
382
|
|
|
public function testConnectPoints() { |
383
|
|
|
$members = $this->getGeolocatedMembers(); |
384
|
|
|
$member1 = $members->pop(); |
385
|
|
|
$member2 = $members->pop(); |
386
|
|
|
$map = $this->getMap(); |
387
|
|
|
$map->connectPoints($member1, $member2); |
388
|
|
|
$html = $map->forTemplate(); |
389
|
|
|
$expected = 'data-lines=\'[{"lat1":-12,"lon1":42.1,"lat2":23,"lon2":78,"color":"#FF3300"}]\''; |
390
|
|
|
$this->assertContains($expected, $html); |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
|
394
|
|
|
public function testAddKML() { |
395
|
|
|
$map = $this->getMap(); |
396
|
|
|
$map->addKml('http://www.test.com/route1.kml'); |
397
|
|
|
$map->addKml('http://www.test.com/route2.kml'); |
398
|
|
|
$html = $map->forTemplate(); |
399
|
|
|
$expected = 'data-kmlfiles=\'["http://www.test.com/route1.kml","http://www.test.com/route2.kml"]\''; |
400
|
|
|
$this->assertContains($expected, $html); |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
|
404
|
|
|
public function testAddLine() { |
405
|
|
|
$map = $this->getMap(); |
406
|
|
|
$map->addLine( |
407
|
|
|
array(13,101), |
408
|
|
|
array(13.2, 101.4), |
409
|
|
|
'#F32' |
410
|
|
|
); |
411
|
|
|
|
412
|
|
|
$map->addLine( |
413
|
|
|
array(13.2, 101.4), |
414
|
|
|
array(14.2,99.8) |
415
|
|
|
); |
416
|
|
|
|
417
|
|
|
$html = $map->forTemplate(); |
418
|
|
|
$expected = 'data-lines=\'[{"lat1":13,"lon1":101,"lat2":13.2,"lon2":101.4,"color":"#F32"},{"lat1":13.2,"lon1":101.4,"lat2":14.2,"lon2":99.8,"color":"#FF3300"}]\''; |
419
|
|
|
$this->assertContains($expected, $html); |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
|
423
|
|
|
public function testJsonRemoveUnicodeSequences() { |
424
|
|
|
$this->markTestSkipped('TODO - private function for PHP 5.3'); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
|
428
|
|
|
private function getMap() { |
429
|
|
|
$instance = new Member(); |
430
|
|
|
return $instance->getRenderableMap(); |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
private function getMapMultipleItems() { |
434
|
|
|
$members = $this->getGeolocatedMembers(); |
435
|
|
|
return $members->getRenderableMap(); |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
private function getGeolocatedMembers() { |
439
|
|
|
$members = new ArrayList(); |
440
|
|
|
|
441
|
|
|
$member1 = new Member(); |
442
|
|
|
$member1->Lat = 23; |
443
|
|
|
$member1->Lon = 78; |
444
|
|
|
$member1->MapPinEdited = true; |
445
|
|
|
$member1->FirstName = 'Fred'; |
446
|
|
|
$member1->Surname = 'Bloggs'; |
447
|
|
|
$member1->write(); |
448
|
|
|
$members->push($member1); |
449
|
|
|
|
450
|
|
|
$member2 = new Member(); |
451
|
|
|
$member2->Lat = -12; |
452
|
|
|
$member2->Lon = 42.1; |
453
|
|
|
$member2->MapPinEdited = true; |
454
|
|
|
$member2->FirstName = 'Kane'; |
455
|
|
|
$member2->Surname = 'Williamson'; |
456
|
|
|
$member2->write(); |
457
|
|
|
$members->push($member2); |
458
|
|
|
|
459
|
|
|
return $members; |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
} |
463
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.