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