1 | <?php |
||
3 | class MapAPITest extends SapphireTest { |
||
4 | |||
5 | public function setUpOnce() { |
||
11 | |||
12 | |||
13 | public function setUp() { |
||
17 | |||
18 | public function testSetKey() { |
||
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() { |
||
114 | |||
115 | |||
116 | public function testSetDivId() { |
||
123 | |||
124 | public function testSetSize() { |
||
130 | |||
131 | public function testSetLang() { |
||
137 | |||
138 | |||
139 | public function testSetZoom() { |
||
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() { |
||
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() { |
||
321 | |||
322 | public function testAddMarkerByCoords() { |
||
337 | |||
338 | |||
339 | public function testAddMarkerAsObject() { |
||
357 | |||
358 | |||
359 | public function testConnectPoints() { |
||
369 | |||
370 | |||
371 | public function testAddKML() { |
||
379 | |||
380 | |||
381 | public function testAddLine() { |
||
398 | |||
399 | |||
400 | public function testJsonRemoveUnicodeSequences() { |
||
403 | |||
404 | |||
405 | private function getMap() { |
||
409 | |||
410 | private function getMapMultipleItems() { |
||
414 | |||
415 | private function getGeolocatedMembers() { |
||
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.