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

MappableDataTest::testStaticMapVaryTerrain()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 21

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 24
rs 8.9714
cc 1
eloc 21
nc 1
nop 0
1
<?php
2
3
class MappableDataTest extends SapphireTest {
4
5
	public function setUpOnce() {
6
		$this->requiredExtensions = array(
7
			'Member' => array('MapExtension')
8
		);
9
10
		parent::setupOnce();
11
	}
12
13
	public function setUp() {
14
		MapUtil::reset();
15
		parent::setUp();
16
	}
17
18
	public function testGetRenderableMapSetNoMarkerValues() {
19
		$instance = $this->getInstance();
20
		$instance->MapPinEdited = true;
21
		$html = $instance->getRenderableMap(300, 800, 2)->setDivId('testmap')->forTemplate()->getValue();
22
23
24
		$expected = <<<HTML
25
26
27
<div id="testmap" style="width:300; height: 800;"
28
 class=" mappable"
29
data-map
30
data-centre='{"lat":13.8188931,"lng":100.5005558}'
31
data-zoom=2
32
data-maptype='road'
33
data-allowfullscreen='1'
34
data-clusterergridsize=50,
35
data-clusterermaxzoom=17,
36
data-enableautocentrezoom=false
37
data-mapmarkers='[{"latitude":13.8188931,"longitude":100.5005558,"html":"MEMBER: Test User","category":"default","icon":false}]'
38
data-lines='[]'
39
data-kmlfiles='[]'
40
data-mapstyles='[]'
41
data-useclusterer=false
42
>
43
</div>
44
45
HTML;
46
		$this->assertEquals($expected, $html);
47
	}
48
49
	/**
50
	 * The existenve of 'TestKeyVal' in the markers is the test here
51
	 *
52
	 * FIXME: Leading blank space
53
	 */
54
	public function testSetMarkerTemplateValues() {
55
		$instance = $this->getInstance();
56
		$instance->MapPinEdited = true;
57
		$vals = array('TestKey' => ' TestKeyVal');
58
		$instance->setMarkerTemplateValues($vals);
59
		$html = $instance->getRenderableMap(300, 800, 2)->setDivId('testmap')->forTemplate()->getValue();
60
		$expected = <<<HTML
61
62
63
<div id="testmap" style="width:300; height: 800;"
64
 class=" mappable"
65
data-map
66
data-centre='{"lat":13.8188931,"lng":100.5005558}'
67
data-zoom=2
68
data-maptype='road'
69
data-allowfullscreen='1'
70
data-clusterergridsize=50,
71
data-clusterermaxzoom=17,
72
data-enableautocentrezoom=false
73
data-mapmarkers='[{"latitude":13.8188931,"longitude":100.5005558,"html":"MEMBER: Test User TestKeyVal","category":"default","icon":false}]'
74
data-lines='[]'
75
data-kmlfiles='[]'
76
data-mapstyles='[]'
77
data-useclusterer=false
78
>
79
</div>
80
81
HTML;
82
83
		$this->assertEquals($expected, $html);
84
	}
85
86
87
88
	public function testStaticMapChangeLocation() {
89
		$instance = $this->getInstance();
90
		$instance->Lat = 13.84;
91
		$instance->Lon = 100.52;
92
		$html = $instance->StaticMap(300, 800);
93
		$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
94
				  . '13.84%2C100.52&amp;markers=13.84%2C100.52'
95
				  . '&amp;zoom=13&amp;size=300x800&amp;sensor=false&amp;mapt'
96
				  . 'ype=roadmap" width="300" height="800" alt="User" />';
97
		$this->assertEquals($expected, $html);
98
	}
99
100
	public function testStaticMapVarySize() {
101
		$instance = $this->getInstance();
102
		$instance->Lat = 13.8188931;
103
		$instance->Lon = 100.5005558;
104
		$html = $instance->StaticMap(300, 800);
105
		$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
106
				  . '13.8188931%2C100.5005558&amp;markers=13.8188931%2C100.5005'
107
				  . '558&amp;zoom=13&amp;size=300x800&amp;sensor=false&amp;mapt'
108
				  . 'ype=roadmap" width="300" height="800" alt="User" />';
109
		$this->assertEquals($expected, $html);
110
111
		$html = $instance->StaticMap(310, 810);
112
		$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
113
				  . '13.8188931%2C100.5005558&amp;markers=13.8188931%2C100.5005'
114
				  . '558&amp;zoom=13&amp;size=310x810&amp;sensor=false&amp;mapt'
115
				  . 'ype=roadmap" width="310" height="810" alt="User" />';
116
		$this->assertEquals($expected, $html);
117
	}
118
119
120
	public function testStaticMapVaryTerrain() {
121
		$instance = $this->getInstance();
122
		$instance->Lat = 13.8188931;
123
		$instance->Lon = 100.5005558;
124
		$html = $instance->StaticMap(300, 800, null, 'satellite');
125
		$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
126
				  . '13.8188931%2C100.5005558&amp;markers=13.8188931%2C100.5005'
127
				  . '558&amp;zoom=13&amp;size=300x800&amp;sensor=false&amp;mapt'
128
				  . 'ype=satellite" width="300" height="800" alt="User" />';
129
		$this->assertEquals($expected, $html);
130
131
		$html = $instance->StaticMap(300, 800, null, 'terrain');
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...
132
		$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
0 ignored issues
show
Unused Code introduced by
$expected 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...
133
				  . '13.8188931%2C100.5005558&amp;markers=13.8188931%2C100.5005'
134
				  . '558&amp;zoom=13&amp;size=300x800&amp;sensor=false&amp;mapt'
135
				  . 'ype=terrain" width="300" height="800" alt="User" />';
136
137
		$html = $instance->StaticMap(300, 800, null, 'hybrid');
138
		$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
139
				  . '13.8188931%2C100.5005558&amp;markers=13.8188931%2C100.5005'
140
				  . '558&amp;zoom=13&amp;size=300x800&amp;sensor=false&amp;mapt'
141
				  . 'ype=hybrid" width="300" height="800" alt="User" />';
142
		$this->assertEquals($expected, $html);
143
	}
144
145
	public function testStaticMapVaryZoom() {
146
		$instance = $this->getInstance();
147
148
		$html = $instance->StaticMap(300, 800, 2);
149
		$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
150
				  . '13.8188931%2C100.5005558&amp;markers=13.8188931%2C100.5005'
151
				  . '558&amp;zoom=2&amp;size=300x800&amp;sensor=false&amp;mapt'
152
				  . 'ype=roadmap" width="300" height="800" alt="User" />';
153
		$this->assertEquals($expected, $html);
154
155
		$html = $instance->StaticMap(300, 800, 12);
156
		$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
157
				  . '13.8188931%2C100.5005558&amp;markers=13.8188931%2C100.5005'
158
				  . '558&amp;zoom=12&amp;size=300x800&amp;sensor=false&amp;mapt'
159
				  . 'ype=roadmap" width="300" height="800" alt="User" />';
160
		$this->assertEquals($expected, $html);
161
	}
162
163
	public function testStaticMapWithMapPin() {
164
		$instance = $this->getInstance();
165
		$this->addMapPinToInstance($instance);
166
167
		$html = $instance->StaticMap(300, 800, 2);
168
		$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center='
169
				  . '13.8188931%2C100.5005558&amp;markers=icon%3Ahttp%3A%2F%2Fd'
170
				  . 'ev.jakayanrides.com%2Fmappable%2Ftests%2Fimages%2Fmapicont'
171
				  . 'est.png%7C13.8188931%2C100.5005558&amp;zoom=2&amp;size=300'
172
				  . 'x800&amp;sensor=false&amp;maptype=roadmap" width="300" hei'
173
				  . 'ght="800" alt="User, Test" />';
174
		$this->assertEquals($expected, $html);
175
176
	}
177
178
	private function getInstance() {
179
		$instance = new Member();
180
		$instance->Lat = 13.8188931;
181
		$instance->Lon = 100.5005558;
182
		$instance->FirstName = 'Test';
183
		$instance->Surname = 'User';
184
		return $instance;
185
	}
186
187
188
	private function addMapPinToInstance(&$instance) {
189
		// Create a pin
190
		$imageFile = new Image(array('Name' => 'mapicontest.png', 'Filename' => 'mappable/tests/images/mapicontest.png'));
191
		$imageFile->write();
192
		$instance->MapPinIconID = $imageFile->ID;
193
		$instance->write();
194
	}
195
196
}
197