Completed
Push — AUTOMATED_TESTING ( 4cfed4...8e1a94 )
by Gordon
18:08
created

MapAPITest::testaddDirection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
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();
0 ignored issues
show
Unused Code introduced by
$html 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 $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.

Loading history...
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();
0 ignored issues
show
Unused Code introduced by
$html 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 $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.

Loading history...
32
		$map->setIncludeDownloadJavascript(false);
33
34
		$this->fail('where to check effect?');
35
	}
36
37
38
	public function testSetShowInlineMapDivStyle() {
39
40
41
42
	}
43
44
45
	public function testSetAdditionalCSSClasses() {
46
		$map = $this->getMap();
47
		$map->setAdditionalCSSClasses('bigMap shadowMap');
48
		$html = $map->forTemplate();
49
		$expected = 'class="bigMap shadowMap mappable"';
50
		$this->assertContains($expected, $html);
51
		$map->setAdditionalCSSClasses('bigMap shadowMap');
52
	}
53
54
55
	public function testSetMapStyle() {
56
		$style = <<<STYLE
57
[{
58
	"featureType": "landscape",
59
	"stylers": [{
60
		"hue": "#FFBB00"
61
	}, {
62
		"saturation": 43.400000000000006
63
	}, {
64
		"lightness": 37.599999999999994
65
	}, {
66
		"gamma": 1
67
	}]
68
}]
69
STYLE;
70
		$map = $this->getMap();
71
		$map->setMapStyle($style);
72
		$html = $map->forTemplate()->getValue();
73
		$expected = <<<HTML
74
75
76
<div id="google_map_1" style="width:100%; height: 400px;"
77
 class=" mappable"
78
data-map
79
data-centre='{"lat":48.856614,"lng":2.3522219}'
80
data-zoom=9
81
data-maptype='road'
82
data-allowfullscreen='1'
83
data-clusterergridsize=50,
84
data-clusterermaxzoom=17,
85
data-enableautocentrezoom=false
86
data-mapmarkers='[]'
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);
0 ignored issues
show
Bug introduced by
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.

Loading history...
107
		$map->setMapStyle(null);
108
	}
109
110
111
	public function testSetDelayLoadMapFunction() {
112
		$this->fail('Not clear if this is still used');
113
	}
114
115
116
	public function testSetDivId() {
117
		$map = $this->getMap();
118
		$map->setDivId('mymapid');
119
		$html = $map->forTemplate();
120
		$expected = '<div id="mymapid" style=';
121
		$this->assertContains($expected, $html);
122
	}
123
124
	public function testSetSize() {
125
		$map = $this->getMap();
126
		$map->setSize('432px', '1234px');
127
		$html = $map->forTemplate();
128
		$this->assertContains('style="width:432px; height: 1234px;"', $html);
129
	}
130
131
	public function testSetLang() {
132
		$map = $this->getMap();
133
		$map->setLang('fr');
134
		$html = $map->forTemplate();
0 ignored issues
show
Unused Code introduced by
$html 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 $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.

Loading history...
135
		$this->fail('Response needs checked');
136
	}
137
138
139
	public function testSetZoom() {
140
		$map = $this->getMap();
141
		$map->setZoom(4);
142
		$html = $map->forTemplate();
143
		$this->assertContains('data-zoom=4', $html);
144
		$map->setZoom(12);
145
		$html = $map->forTemplate();
146
		$this->assertContains('data-zoom=12', $html);
147
	}
148
149
150
	public function testSetInfoWindowZoom() {
151
152
	}
153
154
155
	public function testSetEnableWindowZoom() {
156
157
	}
158
159
	public function testSetIconSize() {
160
161
	}
162
163
164
165
	public function testSetEnableAutomaticCenterZoom() {
166
		$map = $this->getMap();
167
		$map->setEnableAutomaticCenterZoom(true);
168
		$html = $map->forTemplate();
169
		$this->assertContains('data-enableautocentrezoom=1', $html);
170
	}
171
172
173
	/**
174
	 * setCentre is mis-named, as the method expects text for a geocoder
175
	 */
176
	public function testSetCenter() {
177
		$map = $this->getMap();
178
		$map->setIncludeDownloadJavascript(true);
179
		$map->setCenter('Klong Tan, Bangkok, Thailand');
180
		$html = $map->forTemplate();
181
182
		//coordinates of Klong Tan in Bangkok
183
		$expected = 'data-centre=\'{"lat":13.7243075,"lng":100.5718086}';
184
		$this->assertContains($expected, $html);
185
		$map->setCenter('Paris, France');
186
	}
187
188
189
	public function testSetLatLongCenter() {
190
		$map = $this->getMap();
191
		$map->setIncludeDownloadJavascript(true);
192
		$llc = array('lat' => -23.714, 'lng' => 47.419);
193
		$map->setLatLongCenter($llc);
194
		$html = $map->forTemplate();
195
		$expected = "data-centre='{\"lat\":-23.714,\"lng\":47.419}'";
196
		$this->assertContains($expected, $html);
197
	}
198
199
200
	public function testSetMapType() {
201
		$map = $this->getMap();
202
203
		$mapTypes = array(
204
			'road' => 'road',
205
			'satellite' => 'satellite',
206
			'hybrid' => 'hybrid',
207
			'terrain' => 'terrain',
208
			'google.maps.MapTypeId.ROADMAP' => 'road',
209
			'google.maps.MapTypeId.SATELLITE' => 'satellite',
210
			'google.maps.MapTypeId.G_HYBRID_MAP' => 'hybrid',
211
			'google.maps.MapTypeId.G_PHYSICAL_MAP' => 'terrain',
212
			'unrecognised_name' => 'road'
213
214
		);
215
216
		foreach ($mapTypes as $mapType) {
217
			$map->setMapType($mapType);
218
			$expected = "data-maptype='".$mapTypes[$mapType]."'";
219
			$html = $map->forTemplate();
220
			$this->assertContains($expected, $html);
221
		}
222
	}
223
224
225
	public function testSetAllowFullScreen() {
226
		$map = $this->getMap();
227
		$map->setAllowFullScreen(false);
228
		$html = $map->forTemplate();
229
230
		//FIXME this is possibly problematic
231
		$this->assertContains("data-allowfullscreen='false'", $html);
232
233
		$map->setAllowFullScreen(true);
234
		$html = $map->forTemplate();
235
		$this->assertContains("data-allowfullscreen='1'", $html);
236
	}
237
238
	public function testMapWithMarkers() {
239
		$config = Config::inst();
0 ignored issues
show
Unused Code introduced by
$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 $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.

Loading history...
240
241
		$map = $this->getMapMultipleItems();
242
		$html = $map->forTemplate();
243
		$expected = 'data-mapmarkers=\'[{"latitude":23,"longitude":78,"html":"'
244
				  . 'MEMBER: Fred Bloggs","category":"default","icon":false},{"latitude'
245
				  . '":-12,"longitude":42.1,"html":"MEMBER: Kane Williamson","category"'
246
				  . ':"default","icon":false}]\'';
247
		$this->assertContains($expected, $html);
248
	}
249
250
251
	public function testMapWithMarkersDifferentCategory() {
252
		$this->markTestSkipped('TODO');
253
	}
254
255
256
	public function testSetDefaultHideMarker() {
257
258
	}
259
260
261
	public function testgetGoogleMap() {
262
263
	}
264
265
266
	public function testgetContent() {
267
268
	}
269
270
271
	public function testgeocoding() {
272
273
	}
274
275
	public function testaddMarkerByCoords() {
276
277
	}
278
279
280
	public function testaddMarkerByAddress() {
281
282
	}
283
284
285
	public function testaddArrayMarkerByCoords() {
286
287
	}
288
289
290
	public function testaddMarkerAsObject() {
291
292
	}
293
294
295
	public function testconnectPoints() {
296
297
	}
298
299
300
	public function testaddArrayMarkerByAddress() {
301
302
	}
303
304
	public function testaddKML() {
305
306
	}
307
308
309
	public function testaddLine() {
310
311
	}
312
313
314
	public function testjsonRemoveUnicodeSequences() {
315
316
	}
317
318
319
	public function testprocessTemplateJS() {
320
321
	}
322
323
324
	public function testprocessTemplateHTML() {
325
326
	}
327
328
329
330
331
	private function getMap() {
332
		$instance = new Member();
333
		return $instance->getRenderableMap();
334
	}
335
336
	private function getMapMultipleItems() {
337
		$members = new ArrayList();
338
339
		$member1 = new Member();
340
		$member1->Lat = 23;
341
		$member1->Lon = 78;
342
		$member1->MapPinEdited = true;
343
		$member1->FirstName = 'Fred';
344
		$member1->Surname = 'Bloggs';
345
		$members->push($member1);
346
347
		$member2 = new Member();
348
		$member2->Lat = -12;
349
		$member2->Lon = 42.1;
350
		$member2->MapPinEdited = true;
351
		$member2->FirstName = 'Kane';
352
		$member2->Surname = 'Williamson';
353
		$members->push($member2);
354
355
		return $members->getRenderableMap();
356
	}
357
358
}
359