Completed
Push — AUTOMATED_TESTING ( 263a75...9a3504 )
by Gordon
13:31 queued 01:26
created

MapAPITest::getMapMultipleItems()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 21
rs 9.3143
cc 1
eloc 17
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
	public function testSetKey() {
13
14
	}
15
16
17
	public function testSetIncludeDownloadJavascript() {
18
19
	}
20
21
22
	public function testSetShowInlineMapDivStyle() {
23
24
	}
25
26
27
	public function testSetAdditionalCSSClasses() {
28
		$map = $this->getMap();
29
		$map->setAdditionalCSSClasses('bigMap shadowMap');
30
		$html = $map->forTemplate();
31
		$expected = 'class="bigMap shadowMap mappable"';
32
		$this->assertContains($expected, $html);
33
	}
34
35
36
	public function testSetMapStyle() {
37
38
	}
39
40
41
	public function testSetDelayLoadMapFunction() {
42
43
	}
44
45
46
	public function testSetDivId() {
47
		$map = $this->getMap();
48
		$map->setDivId('mymapid');
49
		$html = $map->forTemplate();
50
		$expected = '<div id="mymapid" style=';
51
		$this->assertContains($expected, $html);
52
	}
53
54
55
	public function testSetDirectionDivId() {
56
57
	}
58
59
60
	public function testSetSize() {
61
		$map = $this->getMap();
62
		$map->setSize('432px','1234px');
63
		$html = $map->forTemplate();
64
		$this->assertContains('style="width:432px; height: 1234px;"', $html);
65
	}
66
67
68
	public function testSetIconSize() {
69
70
	}
71
72
73
	public function testSetLang() {
74
		$map = $this->getMap();
75
		$map->setLang('fr');
76
		$html = $map->forTemplate();
77
		$this->assertContains('style="width:432px; height: 1234px;"', $html);
78
	}
79
80
81
	public function testSetZoom() {
82
		$map = $this->getMap();
83
		$map->setZoom(4);
84
		$html = $map->forTemplate();
85
		$this->assertContains('data-zoom=4', $html);
86
		$map->setZoom(12);
87
		$html = $map->forTemplate();
88
		$this->assertContains('data-zoom=12', $html);
89
	}
90
91
92
	public function testSetInfoWindowZoom() {
93
94
	}
95
96
97
	public function testSetEnableWindowZoom() {
98
99
	}
100
101
102
	public function testSetEnableAutomaticCenterZoom() {
103
		$map = $this->getMap();
104
		$map->setLang('fr');
105
		$html = $map->forTemplate();
106
		$this->assertContains('style="width:432px; height: 1234px;"', $html);
107
	}
108
109
110
	public function testSetCenter() {
111
		$map = $this->getMap();
112
		$map->setIncludeDownloadJavascript(true);
113
		$map->setCenter(-23.714,47.149);
114
		$html = $map->forTemplate();
115
		echo $html;
116
		$expected = "data-centre='{\"lat\":023.714,\"lng\":47.149}'";
117
		$this->assertContains($expected, $html);
118
	}
119
120
121
	public function testSetLatLongCenter() {
122
		$map = $this->getMap();
123
		$map->setIncludeDownloadJavascript(true);
124
		$map->setLatLongCenter(-23.714,47.149);
125
		$html = $map->forTemplate();
126
		echo $html;
127
		$expected = "data-centre='{\"lat\":023.714,\"lng\":47.149}'";
128
		$this->assertContains($expected, $html);
129
	}
130
131
132
	public function testSetMapType() {
133
		$map = $this->getMap();
134
135
		$mapTypes = array(
136
			'road' => 'road',
137
			'satellite' => 'satellite',
138
			'hybrid' => 'hybrid',
139
			'terrain' => 'terrain',
140
			'google.maps.MapTypeId.ROADMAP' => 'road',
141
			'google.maps.MapTypeId.SATELLITE' => 'satellite',
142
			'google.maps.MapTypeId.G_HYBRID_MAP' => 'hybrid',
143
			'google.maps.MapTypeId.G_PHYSICAL_MAP' => 'terrain',
144
			'unrecognised_name' => 'road'
145
146
		);
147
148
		foreach ($mapTypes as $mapType) {
149
			$map->setMapType($mapType);
150
			$expected = "data-maptype='".$mapTypes[$mapType]."'";
151
			$html = $map->forTemplate();
152
			$this->assertContains($expected, $html);
153
154
		}
155
		echo $html;
0 ignored issues
show
Bug introduced by
The variable $html does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
156
	}
157
158
159
	public function testSetAllowFullScreen() {
160
		$map = $this->getMap();
161
		$map->setAllowFullScreen(false);
162
		$html = $map->forTemplate();
163
164
		//FIXME this is possibly problematic
165
		$this->assertContains("data-allowfullscreen='false'", $html);
166
167
		$map->setAllowFullScreen(true);
168
		$html = $map->forTemplate();
169
		$this->assertContains("data-allowfullscreen='1'", $html);
170
	}
171
172
173
	public function testSetDisplayDirectionFields() {
174
		$map = $this->getMap();
175
		$map->setDisplayDirectionFields(false);
176
		$html = $map->forTemplate();
177
		echo $html;
178
179
		$map->setDisplayDirectionFields(true);
180
		$html = $map->forTemplate();
181
		echo $html;
182
		$this->fail('Does not appear to be used');
1 ignored issue
show
Bug introduced by
The method fail() 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...
183
	}
184
185
186
	public function testMapWithMarkers() {
187
		$map = $this->getMapMultipleItems();
188
		$html = $map->forTemplate();
189
		$expected = 'data-mapmarkers=\'[{"latitude":23,"longitude":78,"html":"'
190
				  . 'Fred Bloggs","category":"default","icon":false},{"latitude'
191
				  . '":-12,"longitude":42.1,"html":"Kane Williamson","category"'
192
				  . ':"default","icon":false}]\'';
193
		$this->assertContains($expected, $html);
194
	}
195
196
197
	public function testMapWithMarkersDifferentCategory() {
198
		$this->markTestSkipped('TODO');
1 ignored issue
show
Bug introduced by
The method markTestSkipped() 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...
199
	}
200
201
202
	public function testSetDefaultHideMarker() {
203
204
	}
205
206
207
	public function testgetGoogleMap() {
208
209
	}
210
211
212
	public function testgetContent() {
213
214
	}
215
216
217
	public function testgeocoding() {
218
219
	}
220
221
	public function testaddMarkerByCoords() {
222
223
	}
224
225
226
	public function testaddMarkerByAddress() {
227
228
	}
229
230
231
	public function testaddArrayMarkerByCoords() {
232
233
	}
234
235
236
	public function testaddMarkerAsObject() {
237
238
	}
239
240
241
	public function testconnectPoints() {
242
243
	}
244
245
246
	public function testaddArrayMarkerByAddress() {
247
248
	}
249
250
251
	public function testaddDirection() {
252
253
	}
254
255
256
	public function testaddKML() {
257
258
	}
259
260
261
	public function testaddLine() {
262
263
	}
264
265
266
	public function testjsonRemoveUnicodeSequences() {
267
268
	}
269
270
271
	public function testprocessTemplateJS() {
272
273
	}
274
275
276
	public function testprocessTemplateHTML() {
277
278
	}
279
280
281
282
283
	private function getMap() {
284
		$instance = new Member();
285
		return $instance->getRenderableMap();
286
	}
287
288
	private function getMapMultipleItems() {
289
		$members = new ArrayList();
290
291
		$member1 = new Member();
292
		$member1->Lat = 23;
293
		$member1->Lon = 78;
294
		$member1->MapPinEdited = true;
295
		$member1->FirstName = 'Fred';
296
		$member1->Surname = 'Bloggs';
297
		$members->push($member1);
298
299
		$member2 = new Member();
300
		$member2->Lat = -12;
301
		$member2->Lon = 42.1;
302
		$member2->MapPinEdited = true;
303
		$member2->FirstName = 'Kane';
304
		$member2->Surname = 'Williamson';
305
		$members->push($member2);
306
307
		return $members->getRenderableMap();
308
	}
309
310
}
311