Completed
Push — merge-sm ( 35fc19 )
by Jeroen De
09:25
created

SMGeoCoordsValueTest::assertIsCorrectCoordValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SM\Test;
4
5
use SMAreaValueDescription;
6
use SMGeoCoordsValue;
7
use SMGeoCoordsValueDescription;
8
use SMW\DataValueFactory;
9
use SMWDataItem;
10
use SMWDIGeoCoord;
11
12
/**
13
 * @covers SMGeoCoordsValue
14
 *
15
 * @group SemanticMaps
16
 * @group SMWExtension
17
 *
18
 * @licence GNU GPL v2+
19
 * @author Jeroen De Dauw < [email protected] >
20
 */
21
class SMGeoCoordsValueTest extends \PHPUnit_Framework_TestCase {
22
23
	public function testConstruct() {
24
		$geoDI = new SMWDIGeoCoord( 23, 42 );
25
26
		/**
27
		 * @var SMGeoCoordsValue $geoValue
28
		 */
29
		$geoValue = DataValueFactory::newDataItemValue( $geoDI );
30
31
		$this->assertInstanceOf( SMGeoCoordsValue::class, $geoValue );
32
33
		$this->assertEquals( $geoDI, $geoValue->getDataItem() );
34
		$this->assertEquals( '23° 0\' 0", 42° 0\' 0"', $geoValue->getShortWikiText() );
35
	}
36
37
	/**
38
	 * @dataProvider coordinateProvider
39
	 */
40
	public function testGetQueryDescription( $lat, $long, $serialization ) {
41
		$geoValue = $this->newInstance();
42
43
		$description = $geoValue->getQueryDescription( $serialization );
44
45
		$this->assertIsCorrectCoordValue( $description, $lat, $long );
46
	}
47
48
	protected function assertIsCorrectCoordValue( $description, $lat, $long ) {
49
		/**
50
		 * @var SMGeoCoordsValueDescription $description
51
		 */
52
		$this->assertInstanceOf( SMGeoCoordsValueDescription::class, $description );
53
		$this->assertEquals( $lat, $description->getDataItem()->getLatitude() );
54
		$this->assertEquals( $long, $description->getDataItem()->getLongitude() );
55
	}
56
57
	protected function newInstance() {
58
		return new SMGeoCoordsValue( SMWDataItem::TYPE_GEO );
59
	}
60
61
	public function coordinateProvider() {
62
		return [
63
			[
64
				23,
65
				42,
66
				'23° 0\' 0", 42° 0\' 0"',
67
			],
68
			[
69
				0,
70
				0,
71
				'0° 0\' 0", 0° 0\' 0"',
72
			],
73
			[
74
				-23.5,
75
				-42.5,
76
				'-23° 30\' 0", -42° 30\' 0"',
77
			],
78
		];
79
	}
80
81
	/**
82
	 * @dataProvider coordinateWithDistanceProvider
83
	 */
84
	public function testGetQueryDescriptionForArea( $serialization ) {
85
		$geoValue = $this->newInstance();
86
87
		$description = $geoValue->getQueryDescription( $serialization );
88
89
		$this->assertInstanceOf( SMAreaValueDescription::class, $description );
90
	}
91
92
	public function coordinateWithDistanceProvider() {
93
		return [
94
			[
95
				'23° 0\' 0", 42° 0\' 0"(1km)',
96
				1000,
97
			],
98
			[
99
				'0° 0\' 0", 0° 0\' 0" ( 1 m )',
100
				1,
101
			],
102
			[
103
				'-23° 30\' 0", -42° 30\' 0" (9001m)',
104
				9001,
105
			],
106
		];
107
	}
108
109
}
110