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&markers=13.84%2C100.52' |
95
|
|
|
. '&zoom=13&size=300x800&sensor=false&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&markers=13.8188931%2C100.5005' |
107
|
|
|
. '558&zoom=13&size=300x800&sensor=false&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&markers=13.8188931%2C100.5005' |
114
|
|
|
. '558&zoom=13&size=310x810&sensor=false&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&markers=13.8188931%2C100.5005' |
127
|
|
|
. '558&zoom=13&size=300x800&sensor=false&mapt' |
128
|
|
|
. 'ype=satellite" width="300" height="800" alt="User" />'; |
129
|
|
|
$this->assertEquals($expected, $html); |
130
|
|
|
|
131
|
|
|
$html = $instance->StaticMap(300, 800, null, 'terrain'); |
|
|
|
|
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=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&markers=13.8188931%2C100.5005' |
140
|
|
|
. '558&zoom=13&size=300x800&sensor=false&mapt' |
141
|
|
|
. 'ype=hybrid" width="300" height="800" alt="User" />'; |
142
|
|
|
$this->assertEquals($expected, $html); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
public function testStaticMapVaryZoom() { |
147
|
|
|
$instance = $this->getInstance(); |
148
|
|
|
|
149
|
|
|
$html = $instance->StaticMap(300, 800, 2); |
150
|
|
|
$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
151
|
|
|
. '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
152
|
|
|
. '558&zoom=2&size=300x800&sensor=false&mapt' |
153
|
|
|
. 'ype=roadmap" width="300" height="800" alt="User" />'; |
154
|
|
|
$this->assertEquals($expected, $html); |
155
|
|
|
|
156
|
|
|
$html = $instance->StaticMap(300, 800, 12); |
157
|
|
|
$expected = '<img src="//maps.googleapis.com/maps/api/staticmap?center=' |
158
|
|
|
. '13.8188931%2C100.5005558&markers=13.8188931%2C100.5005' |
159
|
|
|
. '558&zoom=12&size=300x800&sensor=false&mapt' |
160
|
|
|
. 'ype=roadmap" width="300" height="800" alt="User" />'; |
161
|
|
|
$this->assertEquals($expected, $html); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
private function getInstance() { |
165
|
|
|
$instance = new Member(); |
166
|
|
|
$instance->Lat = 13.8188931; |
167
|
|
|
$instance->Lon = 100.5005558; |
168
|
|
|
$instance->FirstName = 'Test'; |
169
|
|
|
$instance->Surname = 'User'; |
170
|
|
|
return $instance; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
} |
174
|
|
|
|
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.