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
|
|
|
$this->fail('where to check effect?'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
public function testSetIncludeDownloadJavascript() { |
28
|
|
|
$map = $this->getMap(); |
29
|
|
|
$map->setIncludeDownloadJavascript(true); |
30
|
|
|
$html = $map->forTemplate(); |
|
|
|
|
31
|
|
|
$map->setIncludeDownloadJavascript(false); |
32
|
|
|
|
33
|
|
|
$this->fail('where to check effect?'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
public function testSetShowInlineMapDivStyle() { |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function testSetAdditionalCSSClasses() { |
45
|
|
|
$map = $this->getMap(); |
46
|
|
|
$map->setAdditionalCSSClasses('bigMap shadowMap'); |
47
|
|
|
$html = $map->forTemplate(); |
48
|
|
|
$expected = 'class="bigMap shadowMap mappable"'; |
49
|
|
|
$this->assertContains($expected, $html); |
50
|
|
|
$map->setAdditionalCSSClasses('bigMap shadowMap'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testSetMapStyle() { |
55
|
|
|
$style = <<<STYLE |
56
|
|
|
[{ |
57
|
|
|
"featureType": "landscape", |
58
|
|
|
"stylers": [{ |
59
|
|
|
"hue": "#FFBB00" |
60
|
|
|
}, { |
61
|
|
|
"saturation": 43.400000000000006 |
62
|
|
|
}, { |
63
|
|
|
"lightness": 37.599999999999994 |
64
|
|
|
}, { |
65
|
|
|
"gamma": 1 |
66
|
|
|
}] |
67
|
|
|
}] |
68
|
|
|
STYLE; |
69
|
|
|
$map = $this->getMap(); |
70
|
|
|
$map->setMapStyle($style); |
71
|
|
|
$html = $map->forTemplate()->getValue(); |
72
|
|
|
$expected = <<<HTML |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
<div id="google_map_1" style="width:100%; height: 400px;" |
76
|
|
|
class=" mappable" |
77
|
|
|
data-map |
78
|
|
|
data-centre='{"lat":48.856614,"lng":2.3522219}' |
79
|
|
|
data-zoom=9 |
80
|
|
|
data-maptype='road' |
81
|
|
|
data-allowfullscreen='1' |
82
|
|
|
data-clusterergridsize=50, |
83
|
|
|
data-clusterermaxzoom=17, |
84
|
|
|
data-enableautocentrezoom=false |
85
|
|
|
data-mapmarkers='[]' |
86
|
|
|
data-lines='[]' |
87
|
|
|
data-kmlfiles='[]' |
88
|
|
|
data-mapstyles='[{ |
89
|
|
|
"featureType": "landscape", |
90
|
|
|
"stylers": [{ |
91
|
|
|
"hue": "#FFBB00" |
92
|
|
|
}, { |
93
|
|
|
"saturation": 43.400000000000006 |
94
|
|
|
}, { |
95
|
|
|
"lightness": 37.599999999999994 |
96
|
|
|
}, { |
97
|
|
|
"gamma": 1 |
98
|
|
|
}] |
99
|
|
|
}]' |
100
|
|
|
data-useclusterer=false |
101
|
|
|
> |
102
|
|
|
</div> |
103
|
|
|
|
104
|
|
|
HTML; |
105
|
|
|
$this->assertEquals($expected, $html); |
|
|
|
|
106
|
|
|
$map->setMapStyle(null); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
public function testSetDelayLoadMapFunction() { |
111
|
|
|
$this->fail('Not clear if this is still used'); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
public function testSetDivId() { |
116
|
|
|
$map = $this->getMap(); |
117
|
|
|
$map->setDivId('mymapid'); |
118
|
|
|
$html = $map->forTemplate(); |
119
|
|
|
$expected = '<div id="mymapid" style='; |
120
|
|
|
$this->assertContains($expected, $html); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
public function testSetDirectionDivId() { |
125
|
|
|
$map = $this->getMap(); |
126
|
|
|
$map->setDirectionDivId('mymapdirectionid'); |
127
|
|
|
$html = $map->forTemplate(); |
|
|
|
|
128
|
|
|
//$expected = '<div id="mymapid" style='; |
|
|
|
|
129
|
|
|
//$this->assertContains($expected, $html); |
|
|
|
|
130
|
|
|
$this->fail('Check if still used'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
public function testSetSize() { |
135
|
|
|
$map = $this->getMap(); |
136
|
|
|
$map->setSize('432px','1234px'); |
137
|
|
|
$html = $map->forTemplate(); |
138
|
|
|
$this->assertContains('style="width:432px; height: 1234px;"', $html); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
|
143
|
|
|
|
144
|
|
|
public function testSetLang() { |
145
|
|
|
$map = $this->getMap(); |
146
|
|
|
$map->setLang('fr'); |
147
|
|
|
$html = $map->forTemplate(); |
|
|
|
|
148
|
|
|
$this->fail('Response needs checked'); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
public function testSetZoom() { |
153
|
|
|
$map = $this->getMap(); |
154
|
|
|
$map->setZoom(4); |
155
|
|
|
$html = $map->forTemplate(); |
156
|
|
|
$this->assertContains('data-zoom=4', $html); |
157
|
|
|
$map->setZoom(12); |
158
|
|
|
$html = $map->forTemplate(); |
159
|
|
|
$this->assertContains('data-zoom=12', $html); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
public function testSetInfoWindowZoom() { |
164
|
|
|
|
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
|
168
|
|
|
public function testSetEnableWindowZoom() { |
169
|
|
|
|
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function testSetIconSize() { |
173
|
|
|
|
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
|
177
|
|
|
|
178
|
|
|
public function testSetEnableAutomaticCenterZoom() { |
179
|
|
|
$map = $this->getMap(); |
180
|
|
|
$map->setEnableAutomaticCenterZoom(true); |
181
|
|
|
$html = $map->forTemplate(); |
182
|
|
|
$this->assertContains('data-enableautocentrezoom=1', $html); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* setCentre is mis-named, as the method expects text for a geocoder |
188
|
|
|
*/ |
189
|
|
|
public function testSetCenter() { |
190
|
|
|
$map = $this->getMap(); |
191
|
|
|
$map->setIncludeDownloadJavascript(true); |
192
|
|
|
$map->setCenter('Klong Tan, Bangkok, Thailand'); |
193
|
|
|
$html = $map->forTemplate(); |
194
|
|
|
|
195
|
|
|
//coordinates of Klong Tan in Bangkok |
196
|
|
|
$expected = 'data-centre=\'{"lat":13.7243075,"lng":100.5718086}'; |
197
|
|
|
$this->assertContains($expected, $html); |
198
|
|
|
$map->setCenter('Paris, France'); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
|
202
|
|
|
public function testSetLatLongCenter() { |
203
|
|
|
$map = $this->getMap(); |
204
|
|
|
$map->setIncludeDownloadJavascript(true); |
205
|
|
|
$llc = array('lat' => -23.714, 'lng' => 47.419); |
206
|
|
|
$map->setLatLongCenter($llc); |
207
|
|
|
$html = $map->forTemplate(); |
208
|
|
|
$expected = "data-centre='{\"lat\":-23.714,\"lng\":47.419}'"; |
209
|
|
|
$this->assertContains($expected, $html); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
|
213
|
|
|
public function testSetMapType() { |
214
|
|
|
$map = $this->getMap(); |
215
|
|
|
|
216
|
|
|
$mapTypes = array( |
217
|
|
|
'road' => 'road', |
218
|
|
|
'satellite' => 'satellite', |
219
|
|
|
'hybrid' => 'hybrid', |
220
|
|
|
'terrain' => 'terrain', |
221
|
|
|
'google.maps.MapTypeId.ROADMAP' => 'road', |
222
|
|
|
'google.maps.MapTypeId.SATELLITE' => 'satellite', |
223
|
|
|
'google.maps.MapTypeId.G_HYBRID_MAP' => 'hybrid', |
224
|
|
|
'google.maps.MapTypeId.G_PHYSICAL_MAP' => 'terrain', |
225
|
|
|
'unrecognised_name' => 'road' |
226
|
|
|
|
227
|
|
|
); |
228
|
|
|
|
229
|
|
|
foreach ($mapTypes as $mapType) { |
230
|
|
|
$map->setMapType($mapType); |
231
|
|
|
$expected = "data-maptype='".$mapTypes[$mapType]."'"; |
232
|
|
|
$html = $map->forTemplate(); |
233
|
|
|
$this->assertContains($expected, $html); |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
|
238
|
|
|
public function testSetAllowFullScreen() { |
239
|
|
|
$map = $this->getMap(); |
240
|
|
|
$map->setAllowFullScreen(false); |
241
|
|
|
$html = $map->forTemplate(); |
242
|
|
|
|
243
|
|
|
//FIXME this is possibly problematic |
244
|
|
|
$this->assertContains("data-allowfullscreen='false'", $html); |
245
|
|
|
|
246
|
|
|
$map->setAllowFullScreen(true); |
247
|
|
|
$html = $map->forTemplate(); |
248
|
|
|
$this->assertContains("data-allowfullscreen='1'", $html); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
|
252
|
|
|
public function testSetDisplayDirectionFields() { |
253
|
|
|
$map = $this->getMap(); |
254
|
|
|
$map->setDisplayDirectionFields(false); |
255
|
|
|
$html = $map->forTemplate(); |
|
|
|
|
256
|
|
|
|
257
|
|
|
$map->setDisplayDirectionFields(true); |
258
|
|
|
$html = $map->forTemplate(); |
|
|
|
|
259
|
|
|
$this->fail('Does not appear to be used'); |
260
|
|
|
} |
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
|
|
|
|
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
|
286
|
|
|
public function testgetGoogleMap() { |
287
|
|
|
|
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
|
291
|
|
|
public function testgetContent() { |
292
|
|
|
|
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
|
296
|
|
|
public function testgeocoding() { |
297
|
|
|
|
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
public function testaddMarkerByCoords() { |
301
|
|
|
|
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
|
305
|
|
|
public function testaddMarkerByAddress() { |
306
|
|
|
|
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
|
310
|
|
|
public function testaddArrayMarkerByCoords() { |
311
|
|
|
|
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
|
315
|
|
|
public function testaddMarkerAsObject() { |
316
|
|
|
|
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
|
320
|
|
|
public function testconnectPoints() { |
321
|
|
|
|
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
|
325
|
|
|
public function testaddArrayMarkerByAddress() { |
326
|
|
|
|
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
|
330
|
|
|
public function testaddDirection() { |
331
|
|
|
|
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
|
335
|
|
|
public function testaddKML() { |
336
|
|
|
|
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
|
340
|
|
|
public function testaddLine() { |
341
|
|
|
|
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
|
345
|
|
|
public function testjsonRemoveUnicodeSequences() { |
346
|
|
|
|
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
|
350
|
|
|
public function testprocessTemplateJS() { |
351
|
|
|
|
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
|
355
|
|
|
public function testprocessTemplateHTML() { |
356
|
|
|
|
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
|
360
|
|
|
|
361
|
|
|
|
362
|
|
|
private function getMap() { |
363
|
|
|
$instance = new Member(); |
364
|
|
|
return $instance->getRenderableMap(); |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
private function getMapMultipleItems() { |
368
|
|
|
$members = new ArrayList(); |
369
|
|
|
|
370
|
|
|
$member1 = new Member(); |
371
|
|
|
$member1->Lat = 23; |
372
|
|
|
$member1->Lon = 78; |
373
|
|
|
$member1->MapPinEdited = true; |
374
|
|
|
$member1->FirstName = 'Fred'; |
375
|
|
|
$member1->Surname = 'Bloggs'; |
376
|
|
|
$members->push($member1); |
377
|
|
|
|
378
|
|
|
$member2 = new Member(); |
379
|
|
|
$member2->Lat = -12; |
380
|
|
|
$member2->Lon = 42.1; |
381
|
|
|
$member2->MapPinEdited = true; |
382
|
|
|
$member2->FirstName = 'Kane'; |
383
|
|
|
$member2->Surname = 'Williamson'; |
384
|
|
|
$members->push($member2); |
385
|
|
|
|
386
|
|
|
return $members->getRenderableMap(); |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
} |
390
|
|
|
|
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.