This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | class MapAPITest extends SapphireTest |
||
4 | { |
||
5 | public function setUpOnce() |
||
6 | { |
||
7 | $this->requiredExtensions = array( |
||
8 | 'Member' => array('MapExtension'), |
||
9 | ); |
||
10 | parent::setupOnce(); |
||
11 | } |
||
12 | |||
13 | 30 | public function setUp() |
|
14 | { |
||
15 | 30 | MapUtil::reset(); |
|
16 | 30 | parent::setUp(); |
|
17 | 30 | } |
|
18 | |||
19 | 1 | public function testSetClusterer() |
|
20 | { |
||
21 | 1 | $map = $this->getMap(); |
|
22 | 1 | $map->setClusterer(true); |
|
23 | 1 | $html = $map->forTemplate(); |
|
24 | 1 | $this->assertContains('data-clusterergridsize=50', $html); |
|
25 | 1 | $this->assertContains('data-clusterermaxzoom=17', $html); |
|
26 | 1 | $this->assertContains('data-useclusterer=1', $html); |
|
27 | |||
28 | 1 | $map = $this->getMap(); |
|
29 | 1 | $map->setClusterer(true, 60, 14); |
|
30 | 1 | $html = $map->forTemplate(); |
|
31 | 1 | $this->assertContains('data-clusterergridsize=60', $html); |
|
32 | 1 | $this->assertContains('data-clusterermaxzoom=14', $html); |
|
33 | 1 | $this->assertContains('data-useclusterer=1', $html); |
|
34 | |||
35 | 1 | $map = $this->getMap(); |
|
36 | 1 | $map->setClusterer(false); |
|
37 | 1 | $html = $map->forTemplate(); |
|
38 | 1 | $this->assertContains('data-useclusterer=false', $html); |
|
39 | 1 | $this->assertContains('data-clusterergridsize=50', $html); |
|
40 | 1 | $this->assertContains('data-clusterermaxzoom=17', $html); |
|
41 | 1 | } |
|
42 | |||
43 | /* |
||
44 | Toggle as to whether or not to include a style= attribute with width/height |
||
45 | */ |
||
46 | 1 | View Code Duplication | public function testSetShowInlineMapDivStyle() |
0 ignored issues
–
show
|
|||
47 | { |
||
48 | 1 | $map = $this->getMap(); |
|
49 | 1 | $map->setShowInlineMapDivStyle(true); |
|
50 | 1 | $html = $map->forTemplate(); |
|
51 | 1 | $expected = 'style="width:100%; height: 400px;"'; |
|
52 | 1 | $this->assertContains($expected, $html); |
|
53 | |||
54 | 1 | $map->setShowInlineMapDivStyle(false); |
|
55 | 1 | $html = $map->forTemplate(); |
|
56 | 1 | $this->assertNotContains($expected, $html); |
|
57 | 1 | } |
|
58 | |||
59 | 1 | public function testSetAdditionalCSSClasses() |
|
60 | { |
||
61 | 1 | $map = $this->getMap(); |
|
62 | 1 | $map->setAdditionalCSSClasses('bigMap shadowMap'); |
|
63 | 1 | $html = $map->forTemplate(); |
|
64 | 1 | $expected = 'class="bigMap shadowMap mappable"'; |
|
65 | 1 | $this->assertContains($expected, $html); |
|
66 | 1 | $map->setAdditionalCSSClasses('bigMap shadowMap'); |
|
67 | 1 | } |
|
68 | |||
69 | 1 | public function testSetMapStyle() |
|
70 | { |
||
71 | $style = <<<STYLE |
||
72 | [{ |
||
73 | "featureType": "landscape", |
||
74 | "stylers": [{ |
||
75 | "hue": "#FFBB00" |
||
76 | }, { |
||
77 | "saturation": 43.400000000000006 |
||
78 | }, { |
||
79 | "lightness": 37.599999999999994 |
||
80 | }, { |
||
81 | "gamma": 1 |
||
82 | }] |
||
83 | }] |
||
84 | 1 | STYLE; |
|
85 | 1 | $map = $this->getMap(); |
|
86 | 1 | $map->setMapStyle($style); |
|
87 | 1 | $html = $map->forTemplate()->getValue(); |
|
88 | $expected = <<<HTML |
||
89 | |||
90 | |||
91 | <div id="google_map_1" data-google-map-lang="en" style="width:100%; height: 400px;" |
||
92 | class=" mappable" |
||
93 | data-map |
||
94 | data-centre='{"lat":48.856614,"lng":2.3522219}' |
||
95 | data-zoom=9 |
||
96 | data-maptype='road' |
||
97 | data-allowfullscreen='1' |
||
98 | data-clusterergridsize=50, |
||
99 | data-clusterermaxzoom=17, |
||
100 | data-enableautocentrezoom=false |
||
101 | data-enablewindowzoom=false |
||
102 | data-infowindowzoom=13 |
||
103 | data-mapmarkers='[]' |
||
104 | data-defaulthidemarker=false |
||
105 | data-lines='[]' |
||
106 | data-kmlfiles='[]' |
||
107 | data-mapstyles='[{ |
||
108 | "featureType": "landscape", |
||
109 | "stylers": [{ |
||
110 | "hue": "#FFBB00" |
||
111 | }, { |
||
112 | "saturation": 43.400000000000006 |
||
113 | }, { |
||
114 | "lightness": 37.599999999999994 |
||
115 | }, { |
||
116 | "gamma": 1 |
||
117 | }] |
||
118 | }]' |
||
119 | data-useclusterer=false |
||
120 | > |
||
121 | </div> |
||
122 | |||
123 | 1 | HTML; |
|
124 | 1 | $this->assertEquals($expected, $html); |
|
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<MapAPITest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
125 | 1 | $map->setMapStyle(null); |
|
126 | 1 | } |
|
127 | |||
128 | 1 | public function testSetDivId() |
|
129 | { |
||
130 | 1 | $map = $this->getMap(); |
|
131 | 1 | $map->setDivId('mymapid'); |
|
132 | 1 | $html = $map->forTemplate(); |
|
133 | 1 | $expected = '<div id="mymapid" data-google-map-lang="en" style='; |
|
134 | 1 | $this->assertContains($expected, $html); |
|
135 | 1 | } |
|
136 | |||
137 | 1 | public function testSetSize() |
|
138 | { |
||
139 | 1 | $map = $this->getMap(); |
|
140 | 1 | $map->setSize('432px', '1234px'); |
|
141 | 1 | $html = $map->forTemplate(); |
|
142 | 1 | $this->assertContains('style="width:432px; height: 1234px;"', $html); |
|
143 | 1 | } |
|
144 | |||
145 | 1 | public function testSetLang() |
|
146 | { |
||
147 | 1 | Config::inst()->update('Mappable', 'language', 'fr'); |
|
148 | 1 | $map = $this->getMap(); |
|
149 | 1 | $html = $map->forTemplate(); |
|
150 | 1 | $this->assertContains( |
|
151 | 1 | '<div id="google_map_1" data-google-map-lang="fr" ', |
|
152 | $html |
||
153 | 1 | ); |
|
154 | 1 | } |
|
155 | |||
156 | 1 | public function testSetZoom() |
|
157 | { |
||
158 | 1 | $map = $this->getMap(); |
|
159 | 1 | $map->setZoom(4); |
|
160 | 1 | $html = $map->forTemplate(); |
|
161 | 1 | $this->assertContains('data-zoom=4', $html); |
|
162 | 1 | $map->setZoom(12); |
|
163 | 1 | $html = $map->forTemplate(); |
|
164 | 1 | $this->assertContains('data-zoom=12', $html); |
|
165 | 1 | } |
|
166 | |||
167 | 1 | public function testSetInfoWindowZoom() |
|
168 | { |
||
169 | 1 | $map = $this->getMap(); |
|
170 | 1 | $map->setInfoWindowZoom(4); |
|
171 | 1 | $html = $map->forTemplate(); |
|
172 | 1 | $this->assertContains('data-infowindowzoom=4', $html); |
|
173 | 1 | $map->setInfoWindowZoom(12); |
|
174 | 1 | $html = $map->forTemplate(); |
|
175 | 1 | $this->assertContains('data-infowindowzoom=12', $html); |
|
176 | 1 | } |
|
177 | |||
178 | 1 | public function testSetEnableWindowZoom() |
|
179 | { |
||
180 | 1 | $map = $this->getMap(); |
|
181 | 1 | $map->setEnableWindowZoom(false); |
|
182 | 1 | $html = $map->forTemplate(); |
|
183 | 1 | $this->assertContains('data-enablewindowzoom=false', $html); |
|
184 | 1 | $map->setEnableWindowZoom(true); |
|
185 | 1 | $html = $map->forTemplate(); |
|
186 | 1 | $this->assertContains('data-enablewindowzoom=1', $html); |
|
187 | 1 | } |
|
188 | |||
189 | 30 | public function testSetEnableAutomaticCenterZoom() |
|
190 | { |
||
191 | 30 | $map = $this->getMap(); |
|
192 | 30 | $map->setEnableAutomaticCenterZoom(true); |
|
193 | 1 | $html = $map->forTemplate(); |
|
194 | 1 | $this->assertContains('data-enableautocentrezoom=1', $html); |
|
195 | 1 | } |
|
196 | |||
197 | 1 | public function testSetNoLocation() |
|
198 | { |
||
199 | 1 | $map = $this->getMap(); |
|
200 | 1 | $html = $map->forTemplate(); |
|
201 | 1 | $this->assertContains( |
|
202 | 1 | 'data-centre=\'{"lat":48.856614,"lng":2.3522219}\'', |
|
203 | $html |
||
204 | 1 | ); |
|
205 | 1 | } |
|
206 | |||
207 | /** |
||
208 | * setCentre is mis-named, as the method expects text for a geocoder. |
||
209 | */ |
||
210 | 1 | public function testSetCenter() |
|
211 | { |
||
212 | 1 | $map = $this->getMap(); |
|
213 | 1 | $map->setCenter('Klong Tan, Bangkok, Thailand'); |
|
214 | 1 | $html = $map->forTemplate(); |
|
215 | |||
216 | //coordinates of Klong Tan in Bangkok |
||
217 | 1 | $expected = 'data-centre=\'{"lat":13.7243075,"lng":100.5718086}'; |
|
218 | 1 | $this->assertContains($expected, $html); |
|
219 | 1 | $map->setCenter('Paris, France'); |
|
220 | 1 | } |
|
221 | |||
222 | 1 | public function testSetLatLongCenter() |
|
223 | { |
||
224 | 1 | $map = $this->getMap(); |
|
225 | 1 | $llc = array('lat' => -23.714, 'lng' => 47.419); |
|
226 | 1 | $map->setLatLongCenter($llc); |
|
227 | 1 | $html = $map->forTemplate(); |
|
228 | 1 | $expected = "data-centre='{\"lat\":-23.714,\"lng\":47.419}'"; |
|
229 | 1 | $this->assertContains($expected, $html); |
|
230 | |||
231 | // now test error conditions |
||
232 | try { |
||
233 | 1 | $map->setLatLongCenter('This is not a coordinate'); |
|
234 | $this->fail('Should not be able to set coordinate as text'); |
||
235 | 1 | } catch (InvalidArgumentException $e) { |
|
236 | 1 | $message = $e->getMessage(); |
|
237 | 1 | $this->assertEquals( |
|
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<MapAPITest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
238 | 1 | 'Center must be an associative array containing lat,lng', |
|
239 | $message |
||
240 | 1 | ); |
|
241 | } |
||
242 | |||
243 | try { |
||
244 | 1 | $badKeys = array('lat' => 47.2, 'wibble' => 76.10); |
|
245 | 1 | $map->setLatLongCenter($badKeys); |
|
246 | $this->fail('Should not be able to set coordinate as text'); |
||
247 | 1 | } catch (InvalidArgumentException $e) { |
|
248 | 1 | $message = $e->getMessage(); |
|
249 | |||
250 | 1 | $this->assertEquals( |
|
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<MapAPITest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
251 | 1 | 'Keys provided must be lat, lng', |
|
252 | $message |
||
253 | 1 | ); |
|
254 | } |
||
255 | 1 | } |
|
256 | |||
257 | 1 | public function testSetMapType() |
|
258 | { |
||
259 | 1 | $map = $this->getMap(); |
|
260 | |||
261 | $mapTypes = array( |
||
262 | 1 | 'road' => 'road', |
|
263 | 1 | 'satellite' => 'satellite', |
|
264 | 1 | 'hybrid' => 'hybrid', |
|
265 | 1 | 'terrain' => 'terrain', |
|
266 | 1 | 'google.maps.MapTypeId.ROADMAP' => 'road', |
|
267 | 1 | 'google.maps.MapTypeId.SATELLITE' => 'satellite', |
|
268 | 1 | 'google.maps.MapTypeId.G_HYBRID_MAP' => 'hybrid', |
|
269 | 1 | 'google.maps.MapTypeId.G_PHYSICAL_MAP' => 'terrain', |
|
270 | 1 | 'custom_layer' => 'custom_layer', |
|
271 | 1 | ); |
|
272 | |||
273 | 1 | foreach (array_keys($mapTypes) as $mapType) { |
|
274 | 1 | $map->setMapType($mapType); |
|
275 | 1 | $expected = "data-maptype='".$mapTypes[$mapType]."'"; |
|
276 | 1 | $html = $map->forTemplate(); |
|
277 | 1 | $this->assertContains($expected, $html); |
|
278 | 1 | } |
|
279 | 1 | } |
|
280 | |||
281 | 1 | public function testSetAllowFullScreen() |
|
282 | { |
||
283 | 1 | $map = $this->getMap(); |
|
284 | 1 | $map->setAllowFullScreen(false); |
|
285 | 1 | $html = $map->forTemplate(); |
|
286 | |||
287 | 1 | $this->assertContains("data-allowfullscreen='false'", $html); |
|
288 | |||
289 | 1 | $map->setAllowFullScreen(true); |
|
290 | 1 | $html = $map->forTemplate(); |
|
291 | 1 | $this->assertContains("data-allowfullscreen='1'", $html); |
|
292 | |||
293 | // deal with the null calse |
||
294 | 1 | $map->setAllowFullScreen(null); |
|
295 | 1 | $html = $map->forTemplate(); |
|
296 | 1 | $expected = Config::inst()->get('Mappable', 'allow_full_screen'); |
|
297 | 1 | $this->assertContains("data-allowfullscreen='{$expected}'", $html); |
|
298 | 1 | } |
|
299 | |||
300 | 1 | public function testMapWithMarkers() |
|
301 | { |
||
302 | 1 | $config = Config::inst(); |
|
0 ignored issues
–
show
$config is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
303 | |||
304 | 1 | $map = $this->getMapMultipleItems(); |
|
305 | 1 | $html = $map->forTemplate(); |
|
306 | $expected = 'data-mapmarkers=\'[{"latitude":23,"longitude":78,"html":"' |
||
307 | .'MEMBER: Fred Bloggs","category":"default","icon":false},{"latitude' |
||
308 | 1 | .'":-12,"longitude":42.1,"html":"MEMBER: Kane Williamson","category"' |
|
309 | 1 | .':"default","icon":false}]\''; |
|
310 | 1 | $this->assertContains($expected, $html); |
|
311 | 1 | } |
|
312 | |||
313 | public function testMapWithMarkersDifferentCategory() |
||
314 | { |
||
315 | $this->markTestSkipped('TODO'); |
||
316 | } |
||
317 | |||
318 | 1 | View Code Duplication | public function testSetDefaultHideMarker() |
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
319 | { |
||
320 | 1 | $map = $this->getMapMultipleItems(); |
|
321 | 1 | $map->setDefaultHideMarker(false); |
|
322 | 1 | $html = $map->forTemplate(); |
|
323 | 1 | $this->assertContains( |
|
324 | 1 | 'data-defaulthidemarker=false', |
|
325 | $html |
||
326 | 1 | ); |
|
327 | |||
328 | 1 | $map = $this->getMapMultipleItems(); |
|
329 | 1 | $map->setDefaultHideMarker(true); |
|
330 | 1 | $html = $map->forTemplate(); |
|
331 | 1 | $this->assertContains( |
|
332 | 1 | 'data-defaulthidemarker=1', |
|
333 | $html |
||
334 | 1 | ); |
|
335 | 1 | } |
|
336 | |||
337 | 1 | public function testGetContent() |
|
338 | { |
||
339 | 1 | $map = $this->getMap(); |
|
340 | 1 | $filepath = 'file://'.Director::baseFolder() |
|
341 | 1 | .'/mappable/tests/kml/example.kml'; |
|
342 | 1 | $content = $map->getContent($filepath); |
|
343 | 1 | $textHash = hash('ripemd160', $content); |
|
344 | 1 | $fileHash = hash_file('ripemd160', $filepath); |
|
345 | 1 | $this->assertEquals($fileHash, $textHash); |
|
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<MapAPITest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
346 | 1 | } |
|
347 | |||
348 | 1 | public function testGeocoding() |
|
349 | { |
||
350 | 1 | $map = $this->getMap(); |
|
351 | 1 | $location = $map->geocoding('Nonthaburi, Thailand'); |
|
352 | $expected = array( |
||
353 | 1 | 'lat' => 13.8621125, |
|
354 | 1 | 'lon' => 100.5143528, |
|
355 | 1 | 'geocoded' => true, |
|
356 | 1 | ); |
|
357 | 1 | $this->assertEquals($expected, $location); |
|
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<MapAPITest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
358 | 1 | } |
|
359 | |||
360 | 1 | public function testGeocodingNoResultsFound() |
|
361 | { |
||
362 | 1 | $map = $this->getMap(); |
|
363 | 1 | $location = $map->geocoding('aasdfsafsfdsfasdf'); |
|
364 | 1 | $expected = array(); |
|
365 | 1 | $this->assertEquals($expected, $location); |
|
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<MapAPITest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
366 | 1 | } |
|
367 | |||
368 | 1 | View Code Duplication | public function testAddMarkerByAddress() |
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
369 | { |
||
370 | //$address, $content = '', $category = '', $icon = '' |
||
371 | 1 | $map = $this->getMap(); |
|
372 | 1 | $map->addMarkerByAddress( |
|
373 | 1 | 'Koh Kred, Nonthaburi, Thailand', |
|
374 | 1 | 'Small island in the Chao Phraya river', |
|
375 | 1 | 'testing', |
|
376 | 'http://www.test.com/icon.png' |
||
377 | 1 | ); |
|
378 | 1 | $html = $map->forTemplate(); |
|
379 | 1 | $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"}]\''; |
|
380 | 1 | $this->assertContains($expected, $html); |
|
381 | 1 | } |
|
382 | |||
383 | 1 | public function testAddArrayMarkerByCoords() |
|
384 | { |
||
385 | 1 | $map = $this->getMap(); |
|
386 | |||
387 | 1 | $markerArray = array(); |
|
388 | 1 | $marker1 = array(48.2, 27, 'Description marker 1', 'Marker Test', ''); |
|
389 | 1 | $marker2 = array(-12.2, 47, 'Description marker 2', 'Marker Test', ''); |
|
390 | |||
391 | 1 | array_push($markerArray, $marker1); |
|
392 | 1 | array_push($markerArray, $marker2); |
|
393 | |||
394 | 1 | $map->addArrayMarkerByCoords($markerArray); |
|
395 | 1 | $html = $map->forTemplate(); |
|
396 | 1 | $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":""}]\''; |
|
397 | 1 | $this->assertContains($expected, $html); |
|
398 | 1 | } |
|
399 | |||
400 | 1 | View Code Duplication | public function testAddMarkerByCoords() |
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
401 | { |
||
402 | 1 | $map = $this->getMap(); |
|
403 | 1 | $map->addMarkerByCoords( |
|
404 | 1 | 13.91, |
|
405 | 1 | 100.47, |
|
406 | 1 | 'Description of marker', |
|
407 | 1 | 'testing', |
|
408 | 'http://www.test.com/icon.png' |
||
409 | 1 | ); |
|
410 | 1 | $html = $map->forTemplate(); |
|
411 | $expected = |
||
412 | 1 | 'data-mapmarkers=\'[{"latitude":13.91,"longitude":100.47,"html":"Description of marker","category":"testing","icon":"http://www.test.com/icon.png"}]'; |
|
413 | |||
414 | 1 | $this->assertContains($expected, $html); |
|
415 | 1 | } |
|
416 | |||
417 | 1 | public function testAddMarkerAsObject() |
|
418 | { |
||
419 | 1 | $map = $this->getMap(); |
|
420 | 1 | $member = new Member(); |
|
421 | 1 | $member->FirstName = 'Test'; |
|
422 | 1 | $member->Surname = 'User'; |
|
423 | 1 | $member->Lat = 24.2; |
|
424 | 1 | $member->Lon = -40; |
|
425 | 1 | $member->write(); |
|
426 | 1 | $params = array(); |
|
427 | 1 | $map->addMarkerAsObject( |
|
428 | 1 | $member, |
|
429 | $params |
||
430 | 1 | ); |
|
431 | |||
432 | 1 | $html = $map->forTemplate(); |
|
433 | 1 | $expected = 'data-mapmarkers=\'[{"latitude":24.2,"longitude":-40,"html":"MEMBER: Test User","category":"default","icon":false}]\''; |
|
434 | 1 | $this->assertContains($expected, $html); |
|
435 | 1 | } |
|
436 | |||
437 | 1 | public function testAddMarkerThatIsMappableAsObject() |
|
438 | { |
||
439 | 1 | $map = $this->getMap(); |
|
440 | 1 | $member = new MappableExampleClass(); |
|
441 | //$member->write(); |
||
442 | 1 | $params = array(); |
|
443 | 1 | $map->addMarkerAsObject( |
|
444 | 1 | $member, |
|
445 | $params |
||
446 | 1 | ); |
|
447 | |||
448 | 1 | $html = $map->forTemplate(); |
|
449 | 1 | $expected = 'data-mapmarkers=\'[{"latitude":13.4,"longitude":100.7,"html":"example content","category":"default","icon":null}]\''; |
|
450 | 1 | $this->assertContains($expected, $html); |
|
451 | 1 | } |
|
452 | |||
453 | 1 | public function testConnectPoints() |
|
454 | { |
||
455 | 1 | $members = $this->getGeolocatedMembers(); |
|
456 | 1 | $member1 = $members->pop(); |
|
457 | 1 | $member2 = $members->pop(); |
|
458 | 1 | $map = $this->getMap(); |
|
459 | 1 | $map->connectPoints($member1, $member2); |
|
460 | 1 | $html = $map->forTemplate(); |
|
461 | 1 | $expected = 'data-lines=\'[{"lat1":-12,"lon1":42.1,"lat2":23,"lon2":78,"color":"#FF3300"}]\''; |
|
462 | 1 | $this->assertContains($expected, $html); |
|
463 | 1 | } |
|
464 | |||
465 | 1 | public function testAddKML() |
|
466 | { |
||
467 | 1 | $map = $this->getMap(); |
|
468 | 1 | $map->addKml('http://www.test.com/route1.kml'); |
|
469 | 1 | $map->addKml('http://www.test.com/route2.kml'); |
|
470 | 1 | $html = $map->forTemplate(); |
|
471 | 1 | $expected = 'data-kmlfiles=\'["http://www.test.com/route1.kml","http://www.test.com/route2.kml"]\''; |
|
472 | 1 | $this->assertContains($expected, $html); |
|
473 | 1 | } |
|
474 | |||
475 | 1 | public function testAddLine() |
|
476 | { |
||
477 | 1 | $map = $this->getMap(); |
|
478 | 1 | $map->addLine( |
|
479 | 1 | array(13, 101), |
|
480 | 1 | array(13.2, 101.4), |
|
481 | '#F32' |
||
482 | 1 | ); |
|
483 | |||
484 | 1 | $map->addLine( |
|
485 | 1 | array(13.2, 101.4), |
|
486 | 1 | array(14.2, 99.8) |
|
487 | 1 | ); |
|
488 | |||
489 | 1 | $html = $map->forTemplate(); |
|
490 | 1 | $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"}]\''; |
|
491 | 1 | $this->assertContains($expected, $html); |
|
492 | 1 | } |
|
493 | |||
494 | /** |
||
495 | * This tests out a specific case of passing null for template values. |
||
496 | */ |
||
497 | 1 | public function testProcessTemplate() |
|
498 | { |
||
499 | 1 | $map = $this->getMap(); |
|
500 | 1 | $html = $map->processTemplateHTML('Map', null); |
|
501 | $expected = <<<HTML |
||
502 | |||
503 | |||
504 | <div id="" |
||
505 | data-map |
||
506 | data-centre='' |
||
507 | data-zoom= |
||
508 | data-maptype='' |
||
509 | data-allowfullscreen='' |
||
510 | data-clusterergridsize=, |
||
511 | data-clusterermaxzoom=, |
||
512 | data-enableautocentrezoom= |
||
513 | data-enablewindowzoom= |
||
514 | data-infowindowzoom= |
||
515 | data-mapmarkers='' |
||
516 | data-defaulthidemarker= |
||
517 | data-lines='' |
||
518 | data-kmlfiles='' |
||
519 | data-mapstyles='' |
||
520 | data-useclusterer= |
||
521 | > |
||
522 | </div> |
||
523 | |||
524 | 1 | HTML; |
|
525 | 1 | $this->assertEquals($expected, $html->getValue()); |
|
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<MapAPITest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
526 | 1 | } |
|
527 | |||
528 | 28 | private function getMap() |
|
529 | { |
||
530 | 28 | $instance = new Member(); |
|
531 | |||
532 | 28 | return $instance->getRenderableMap(); |
|
533 | } |
||
534 | |||
535 | 25 | private function getMapMultipleItems() |
|
536 | { |
||
537 | 2 | $members = $this->getGeolocatedMembers(); |
|
538 | |||
539 | 2 | return $members->getRenderableMap(); |
|
540 | } |
||
541 | |||
542 | 4 | private function getGeolocatedMembers() |
|
543 | { |
||
544 | 3 | $members = new ArrayList(); |
|
545 | |||
546 | 3 | $member1 = new Member(); |
|
547 | 4 | $member1->Lat = 23; |
|
548 | 3 | $member1->Lon = 78; |
|
549 | 3 | $member1->MapPinEdited = true; |
|
550 | 3 | $member1->FirstName = 'Fred'; |
|
551 | 3 | $member1->Surname = 'Bloggs'; |
|
552 | 3 | $member1->write(); |
|
553 | 3 | $members->push($member1); |
|
554 | |||
555 | 3 | $member2 = new Member(); |
|
556 | 3 | $member2->Lat = -12; |
|
557 | 3 | $member2->Lon = 42.1; |
|
558 | 3 | $member2->MapPinEdited = true; |
|
559 | 3 | $member2->FirstName = 'Kane'; |
|
560 | 3 | $member2->Surname = 'Williamson'; |
|
561 | 3 | $member2->write(); |
|
562 | 3 | $members->push($member2); |
|
563 | |||
564 | 3 | return $members; |
|
565 | } |
||
566 | } |
||
567 | |||
568 | // basic implementation of Mappable interface for some of the tests |
||
569 | class MappableExampleClass extends ViewableData implements TestOnly, Mappable |
||
0 ignored issues
–
show
|
|||
570 | { |
||
571 | 1 | public function getMappableLatitude() |
|
572 | { |
||
573 | 1 | return 13.4; |
|
574 | } |
||
575 | |||
576 | 1 | public function getMappableLongitude() |
|
577 | { |
||
578 | 1 | return 100.7; |
|
579 | } |
||
580 | |||
581 | 1 | public function getMappableMapPin() |
|
582 | { |
||
583 | 1 | return; |
|
584 | } |
||
585 | |||
586 | 1 | public function getMappableMapContent() |
|
587 | { |
||
588 | 1 | return 'example content'; |
|
589 | } |
||
590 | } |
||
591 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.