Completed
Push — AUTOMATED_TESTING ( 9cc382...c62760 )
by Gordon
12:06
created

MapExtensionTest::testUpdateCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
class MapExtensionTest extends SapphireTest {
4
	protected static $fixture_file = 'mappable/tests/mapextensions.yml';
5
6
	public function setUpOnce() {
7
		$this->requiredExtensions = array(
8
			'Member' => array('MapExtension')
9
		);
10
		parent::setupOnce();
11
	}
12
13
14
	public function testUpdateCMSFields() {
15
16
	}
17
18
19
	public function testGetMappableLatitude() {
20
		$instance = $this->getInstance();
21
		$instance->Lat = 42.1;
22
		$instance->write();
23
		$this->assertEquals(
24
			42.1,
25
			$instance->getMappableLatitude()
26
		);
27
	}
28
29
30
	public function testGetMappableLongitude() {
31
		$instance = $this->getInstance();
32
		$instance->Lon = 42.1;
33
		$this->assertEquals(
34
			42.1,
35
			$instance->getMappableLongitude()
36
		);
37
	}
38
39
40
	public function testgetMappableMapContent() {
41
42
	}
43
44
45
	public function testonBeforeWriteMapPinNotEdited() {
46
		$instance = $this->getInstance();
47
		$this->Lat = 0;
48
		$this->Lon = 0;
49
		$instance->write();
50
		$this->assertFalse($instance->MapPinEdited);
51
	}
52
53
	public function testonBeforeWriteMapPinEdited() {
54
		$instance = $this->getInstance();
55
56
		// north
57
		$this->showMapPinEdited($instance, 10, 0);
58
59
		// north west
60
		$this->showMapPinEdited($instance, 10, -10);
61
62
		// west
63
		$this->showMapPinEdited($instance, 0, -10);
64
65
		// south west
66
		$this->showMapPinEdited($instance, -10, -10);
67
68
		// south
69
		$this->showMapPinEdited($instance, -10, 0);
70
71
		// south east
72
		$this->showMapPinEdited($instance, -10, 10);
73
74
		// east
75
		$this->showMapPinEdited($instance, 0, 10);
76
77
		// north east
78
		$this->showMapPinEdited($instance, 10, 10);
79
80
	}
81
82
83
	// FIXME - use an actual file here
84
	public function testgetMappableMapPin() {
85
		$instance = $this->getInstance();
86
		$instance->MapPinIconID = 2;
87
		$pin1 = $instance->getMappableMapPin();
88
		$this->assertStringEndsWith('/assets/', $pin1);
0 ignored issues
show
Bug introduced by
The method assertStringEndsWith() does not seem to exist on object<MapExtensionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
89
90
91
		// Test the cached pin
92
		$pin2 = $instance->getMappableMapPin();
93
		$this->assertStringEndsWith('/assets/', $pin2);
0 ignored issues
show
Bug introduced by
The method assertStringEndsWith() does not seem to exist on object<MapExtensionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
94
		$this->assertEquals($pin1, $pin2);
95
	}
96
97
98
99
100
101
	public function testHasGeoWest() {
102
		$instance = $this->getInstance();
103
		$instance->Lon = -20;
104
		$this->assertTrue($instance->HasGeo());
105
	}
106
107
	public function testHasGeoEast() {
108
		$instance = $this->getInstance();
109
		$instance->Lon = 20;
110
		$this->assertTrue($instance->HasGeo());
111
	}
112
113
	public function testHasGeoNorth() {
114
		$instance = $this->getInstance();
115
		$instance->Lat = 20;
116
		$this->assertTrue($instance->HasGeo());
117
	}
118
119
	public function testHasGeoNorthWest() {
120
		$instance = $this->getInstance();
121
		$instance->Lat = 20;
122
		$instance->Lon = -20;
123
		$this->assertTrue($instance->HasGeo());
124
	}
125
126
	public function testHasGeoNortEast() {
127
		$instance = $this->getInstance();
128
		$instance->Lat = 20;
129
		$instance->Lon = 20;
130
		$this->assertTrue($instance->HasGeo());
131
	}
132
133
	public function testHasGeoSouth() {
134
		$instance = $this->getInstance();
135
		$instance->Lat = -20;
136
		$this->assertTrue($instance->HasGeo());
137
	}
138
139
	public function testHasGeoSouthWest() {
140
		$instance = $this->getInstance();
141
		$instance->Lat = -20;
142
		$instance->Lon = -20;
143
		$this->assertTrue($instance->HasGeo());
144
	}
145
146
	public function testHasGeoSouthEast() {
147
		$instance = $this->getInstance();
148
		$instance->Lat = -20;
149
		$instance->Lon = 20;
150
		$this->assertTrue($instance->HasGeo());
151
	}
152
153
	public function testHasGeoOrigin() {
154
		$instance = $this->getInstance();
155
		$instance->Lat = 0;
156
		$instance->Lon = 0;
157
		$this->assertFalse($instance->HasGeo());
158
	}
159
160
	public function testHasGeoOriginMapLayerExtension() {
161
		$instance = $this->getInstance();
162
		$instance->Lat = 0;
163
		$instance->Lon = 0;
164
		$this->assertFalse($instance->HasGeo());
165
		Page::add_extension('MapLayerExtension');
166
		Page::remove_extension('MapLayerExtension');
167
		$this->markTestSkipped('TODO');
0 ignored issues
show
Bug introduced by
The method markTestSkipped() does not seem to exist on object<MapExtensionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
168
	}
169
170
	public function testHasGeoOriginPointsOfInterestLayers() {
171
		$instance = $this->getInstance();
172
		$instance->Lat = 0;
173
		$instance->Lon = 0;
174
		$this->assertFalse($instance->HasGeo());
175
		$this->markTestSkipped('TODO');
0 ignored issues
show
Bug introduced by
The method markTestSkipped() does not seem to exist on object<MapExtensionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
176
	}
177
178
	public function testBasicMap() {
179
		$instance = $this->getInstance();
180
		$instance->Lat = 37.1;
181
		$instance->Lon = 28;
182
		$instance->Zoom = 12;
183
		$instance->MapPinEdited = true;
184
		$html = $instance->BasicMap()->forTemplate();
185
		echo $html;
186
	}
187
188
189
	public function testGetMapField() {
190
		$instance = $this->getInstance();
191
		$this->Lat = 37.1;
192
		$this->Lon = 28;
193
		$this->Zoom = 12;
194
		$mapField  = $instance->getMapField();
195
		$this->assertInstanceOf('LatLongField', $mapField);
196
		$this->fail('Check centre');
0 ignored issues
show
Bug introduced by
The method fail() does not seem to exist on object<MapExtensionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
197
	}
198
199
200
	public function testUseCompressedAssets() {
201
		$original = Config::inst()->get('Mappable', 'use_compressed_assets');
202
203
		$instance = $this->getInstance();
204
		Config::inst()->update('Mappable', 'use_compressed_assets', false);
205
		$this->assertFalse($instance->UseCompressedAssets());
206
207
		$instance = $this->getInstance();
208
		Config::inst()->update('Mappable', 'use_compressed_assets', true);
209
		$this->assertTrue($instance->UseCompressedAssets());
210
211
		Config::inst()->update('Mappable', 'use_compressed_assets', $original);
212
	}
213
214
215
	private function getInstance() {
216
		$instance = new Member();
217
		return $instance;
218
	}
219
220
	/**
221
	 * @param integer $lat
222
	 * @param integer $lon
223
	 */
224
	private function showMapPinEdited(&$instance, $lat, $lon) {
225
		$instance->Lat = $lat;
226
		$instance->Long = $lon;
227
		$instance->write();
228
		$this->assertTrue($instance->MapPinEdited);
229
	}
230
231
232
233
}
234