1 | <?php |
||
3 | class MapAPITest extends SapphireTest { |
||
4 | |||
5 | public function setUpOnce() { |
||
11 | |||
12 | |||
13 | public function setUp() { |
||
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() { |
||
274 | |||
275 | |||
276 | public function testMapWithMarkersDifferentCategory() { |
||
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 | ); |
||
298 | |||
299 | public function testGetContent() { |
||
302 | |||
303 | public function testGeocoding() { |
||
313 | |||
314 | public function testAddMarkerByAddress() { |
||
327 | |||
328 | |||
329 | public function testAddArrayMarkerByCoords() { |
||
344 | |||
345 | public function testAddMarkerByCoords() { |
||
360 | |||
361 | |||
362 | public function testAddMarkerAsObject() { |
||
380 | |||
381 | |||
382 | public function testConnectPoints() { |
||
392 | |||
393 | |||
394 | public function testAddKML() { |
||
402 | |||
403 | |||
404 | public function testAddLine() { |
||
421 | |||
422 | |||
423 | public function testJsonRemoveUnicodeSequences() { |
||
426 | |||
427 | |||
428 | private function getMap() { |
||
432 | |||
433 | private function getMapMultipleItems() { |
||
437 | |||
438 | private function getGeolocatedMembers() { |
||
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.