Completed
Branch AUTOMATED_TESTING (69f515)
by Gordon
33:05 queued 18:10
created

MapAPITest::setUpOnce()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4286
cc 1
eloc 4
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
174
175
176
	public function testSetDisplayDirectionFields() {
177
178
	}
179
180
181
	public function testSetDefaultHideMarker() {
182
183
	}
184
185
186
	public function testgetGoogleMap() {
187
188
	}
189
190
191
	public function testgetContent() {
192
193
	}
194
195
196
	public function testgeocoding() {
197
198
	}
199
200
	public function testaddMarkerByCoords() {
201
202
	}
203
204
205
	public function testaddMarkerByAddress() {
206
207
	}
208
209
210
	public function testaddArrayMarkerByCoords() {
211
212
	}
213
214
215
	public function testaddMarkerAsObject() {
216
217
	}
218
219
220
	public function testconnectPoints() {
221
222
	}
223
224
225
	public function testforTemplate() {
226
227
	}
228
229
230
	public function testaddArrayMarkerByAddress() {
231
232
	}
233
234
235
	public function testaddDirection() {
236
237
	}
238
239
240
	public function testaddKML() {
241
242
	}
243
244
245
	public function testaddLine() {
246
247
	}
248
249
250
	public function testjsonRemoveUnicodeSequences() {
251
252
	}
253
254
255
	public function testgenerate() {
256
257
	}
258
259
260
	public function testprocessTemplateJS() {
261
262
	}
263
264
265
	public function testprocessTemplateHTML() {
266
267
	}
268
269
	private function getMap() {
270
		$instance = new Member();
271
		return $instance->getRenderableMap();
272
	}
273
274
}
275