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