1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class MappableDataTest extends SapphireTest { |
4
|
|
|
|
5
|
|
|
public function setUpOnce() { |
6
|
|
|
$this->requiredExtensions = array( |
7
|
|
|
'Member' => array('MapExtension') |
8
|
|
|
); |
9
|
|
|
parent::setupOnce(); |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
public function testGetRenderableMapSetNoMarkerValues() { |
13
|
|
|
$instance = $this->getInstance(); |
14
|
|
|
$instance->MapPinEdited = true; |
15
|
|
|
$html = $instance->getRenderableMap(300,800,2)->forTemplate()->getValue(); |
16
|
|
|
echo $html; |
17
|
|
|
$expected = <<<HTML |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
<div id="google_map_1" style="width:300; height: 800;" |
21
|
|
|
class=" mappable" |
22
|
|
|
data-map |
23
|
|
|
data-centre='{"lat":13.8188931,"lng":100.5005558}' |
24
|
|
|
data-zoom=2 |
25
|
|
|
data-maptype='road' |
26
|
|
|
data-allowfullscreen='1' |
27
|
|
|
data-clusterergridsize=50, |
28
|
|
|
data-clusterermaxzoom=17, |
29
|
|
|
data-enableautocentrezoom=false |
30
|
|
|
data-mapmarkers='[{"latitude":13.8188931,"longitude":100.5005558,"html":"MEMBER: Test User","category":"default","icon":false}]' |
31
|
|
|
data-lines='[]' |
32
|
|
|
data-kmlfiles='[]' |
33
|
|
|
data-mapstyles='[]' |
34
|
|
|
data-useclusterer=false |
35
|
|
|
> |
36
|
|
|
</div> |
37
|
|
|
|
38
|
|
|
HTML; |
39
|
|
|
$this->assertEquals($expected, $html); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The existenve of 'TestKeyVal' in the markers is the test here |
44
|
|
|
* |
45
|
|
|
* FIXME: Leading blank space |
46
|
|
|
*/ |
47
|
|
|
public function testSetMarkerTemplateValues() { |
48
|
|
|
$instance = $this->getInstance(); |
49
|
|
|
$instance->MapPinEdited = true; |
50
|
|
|
$vals = array('TestKey' => ' TestKeyVal'); |
51
|
|
|
$instance->setMarkerTemplateValues($vals); |
52
|
|
|
$html = $instance->getRenderableMap(300,800,2)->forTemplate()->getValue(); |
53
|
|
|
echo $html; |
54
|
|
|
$expected = <<<HTML |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
<div id="google_map_1" style="width:300; height: 800;" |
58
|
|
|
class=" mappable" |
59
|
|
|
data-map |
60
|
|
|
data-centre='{"lat":13.8188931,"lng":100.5005558}' |
61
|
|
|
data-zoom=2 |
62
|
|
|
data-maptype='road' |
63
|
|
|
data-allowfullscreen='1' |
64
|
|
|
data-clusterergridsize=50, |
65
|
|
|
data-clusterermaxzoom=17, |
66
|
|
|
data-enableautocentrezoom=false |
67
|
|
|
data-mapmarkers='[{"latitude":13.8188931,"longitude":100.5005558,"html":"MEMBER: Test User TestKeyVal","category":"default","icon":false}]' |
68
|
|
|
data-lines='[]' |
69
|
|
|
data-kmlfiles='[]' |
70
|
|
|
data-mapstyles='[]' |
71
|
|
|
data-useclusterer=false |
72
|
|
|
> |
73
|
|
|
</div> |
74
|
|
|
|
75
|
|
|
HTML; |
76
|
|
|
|
77
|
|
|
$this->assertEquals($expected, $html); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
|
82
|
|
|
public function testStaticMapChangeLocation() { |
83
|
|
|
$instance = $this->getInstance(); |
84
|
|
|
$instance->Lat = 13.84; |
85
|
|
|
$instance->Lon = 100.52; |
86
|
|
|
$html = $instance->StaticMap(300, 800); |
87
|
|
|
$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
88
|
|
|
. '13.84%2C100.52&markers=13.84%2C100.52' |
89
|
|
|
. '&zoom=13&size=300x800&sensor=false&mapt' |
90
|
|
|
. 'ype=roadmap" width="300" height="800" alt="User" />'; |
91
|
|
|
$this->assertEquals($expected, $html); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testStaticMapVarySize() { |
95
|
|
|
$instance = $this->getInstance(); |
96
|
|
|
$instance->Lat = 13.8188931; |
97
|
|
|
$instance->Lon = 100.5005558; |
98
|
|
|
$html = $instance->StaticMap(300, 800); |
99
|
|
|
$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
100
|
|
|
. '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
101
|
|
|
. '558&zoom=13&size=300x800&sensor=false&mapt' |
102
|
|
|
. 'ype=roadmap" width="300" height="800" alt="User" />'; |
103
|
|
|
$this->assertEquals($expected, $html); |
104
|
|
|
|
105
|
|
|
$html = $instance->StaticMap(310, 810); |
106
|
|
|
$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
107
|
|
|
. '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
108
|
|
|
. '558&zoom=13&size=310x810&sensor=false&mapt' |
109
|
|
|
. 'ype=roadmap" width="310" height="810" alt="User" />'; |
110
|
|
|
$this->assertEquals($expected, $html); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
public function testStaticMapVaryTerrain() { |
115
|
|
|
$instance = $this->getInstance(); |
116
|
|
|
$instance->Lat = 13.8188931; |
117
|
|
|
$instance->Lon = 100.5005558; |
118
|
|
|
$html = $instance->StaticMap(300, 800, null, 'satellite'); |
119
|
|
|
$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
120
|
|
|
. '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
121
|
|
|
. '558&zoom=13&size=300x800&sensor=false&mapt' |
122
|
|
|
. 'ype=satellite" width="300" height="800" alt="User" />'; |
123
|
|
|
$this->assertEquals($expected, $html); |
124
|
|
|
|
125
|
|
|
$html = $instance->StaticMap(300, 800, null, 'terrain'); |
|
|
|
|
126
|
|
|
$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
|
|
|
|
127
|
|
|
. '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
128
|
|
|
. '558&zoom=13&size=300x800&sensor=false&mapt' |
129
|
|
|
. 'ype=terrain" width="300" height="800" alt="User" />'; |
130
|
|
|
|
131
|
|
|
$html = $instance->StaticMap(300, 800, null, 'hybrid'); |
132
|
|
|
$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
133
|
|
|
. '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
134
|
|
|
. '558&zoom=13&size=300x800&sensor=false&mapt' |
135
|
|
|
. 'ype=hybrid" width="300" height="800" alt="User" />'; |
136
|
|
|
$this->assertEquals($expected, $html); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
public function testStaticMapVaryZoom() { |
141
|
|
|
$instance = $this->getInstance(); |
142
|
|
|
|
143
|
|
|
$html = $instance->StaticMap(300, 800, 2); |
144
|
|
|
$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
145
|
|
|
. '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
146
|
|
|
. '558&zoom=2&size=300x800&sensor=false&mapt' |
147
|
|
|
. 'ype=roadmap" width="300" height="800" alt="User" />'; |
148
|
|
|
$this->assertEquals($expected, $html); |
149
|
|
|
|
150
|
|
|
$html = $instance->StaticMap(300, 800, 12); |
151
|
|
|
$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
152
|
|
|
. '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
153
|
|
|
. '558&zoom=12&size=300x800&sensor=false&mapt' |
154
|
|
|
. 'ype=roadmap" width="300" height="800" alt="User" />'; |
155
|
|
|
$this->assertEquals($expected, $html); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
private function getInstance() { |
159
|
|
|
$instance = new Member(); |
160
|
|
|
$instance->Lat = 13.8188931; |
161
|
|
|
$instance->Lon = 100.5005558; |
162
|
|
|
$instance->FirstName = 'Test'; |
163
|
|
|
$instance->Surname = 'User'; |
164
|
|
|
return $instance; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
} |
168
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.