Completed
Push — AUTOMATED_TESTING ( b401db...19cb04 )
by Gordon
11:46
created

MappableDataTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 171
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3
Metric Value
wmc 9
lcom 2
cbo 3
dl 0
loc 171
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpOnce() 0 7 1
A setUp() 0 4 1
B testGetRenderableMapSetNoMarkerValues() 0 30 1
B testSetMarkerTemplateValues() 0 31 1
A testStaticMapChangeLocation() 0 11 1
A testStaticMapVarySize() 0 18 1
B testStaticMapVaryTerrain() 0 24 1
A testStaticMapVaryZoom() 0 17 1
A getInstance() 0 8 1
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
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&amp;markers=13.8188931%2C100.5005'
152
				  . '558&amp;zoom=2&amp;size=300x800&amp;sensor=false&amp;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&amp;markers=13.8188931%2C100.5005'
159
				  . '558&amp;zoom=12&amp;size=300x800&amp;sensor=false&amp;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