Completed
Push — merge-sm ( 298269...51d805 )
by Jeroen De
74:10 queued 66:02
created

coordinateWithDistanceProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 16
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
 * @licence GNU GPL v2+
16
 * @author Jeroen De Dauw < [email protected] >
17
 */
18
class SMGeoCoordsValueTest extends \PHPUnit_Framework_TestCase {
19
20
	public function setUp() {
21
		if ( !defined( 'SMW_VERSION' ) ) {
22
			$this->markTestSkipped( 'SMW is not available' );
23
		}
24
	}
25
26
	public function testFail() {
27
		$this->assertSame( 1, 2 );
28
	}
29
30
	public function testConstruct() {
31
		$geoDI = new SMWDIGeoCoord( 23, 42 );
32
33
		/**
34
		 * @var SMGeoCoordsValue $geoValue
35
		 */
36
		$geoValue = DataValueFactory::newDataItemValue( $geoDI );
37
38
		$this->assertInstanceOf( SMGeoCoordsValue::class, $geoValue );
39
40
		$this->assertEquals( $geoDI, $geoValue->getDataItem() );
41
		$this->assertEquals( '23° 0\' 0", 42° 0\' 0"', $geoValue->getShortWikiText() );
42
	}
43
44
	/**
45
	 * @dataProvider coordinateProvider
46
	 */
47
	public function testGetQueryDescription( $lat, $long, $serialization ) {
48
		$geoValue = $this->newInstance();
49
50
		$description = $geoValue->getQueryDescription( $serialization );
51
52
		$this->assertIsCorrectCoordValue( $description, $lat, $long );
53
	}
54
55
	protected function assertIsCorrectCoordValue( $description, $lat, $long ) {
56
		/**
57
		 * @var SMGeoCoordsValueDescription $description
58
		 */
59
		$this->assertInstanceOf( SMGeoCoordsValueDescription::class, $description );
60
		$this->assertEquals( $lat, $description->getDataItem()->getLatitude() );
61
		$this->assertEquals( $long, $description->getDataItem()->getLongitude() );
62
	}
63
64
	protected function newInstance() {
65
		return new SMGeoCoordsValue( SMWDataItem::TYPE_GEO );
66
	}
67
68
	public function coordinateProvider() {
69
		return [
70
			[
71
				23,
72
				42,
73
				'23° 0\' 0", 42° 0\' 0"',
74
			],
75
			[
76
				0,
77
				0,
78
				'0° 0\' 0", 0° 0\' 0"',
79
			],
80
			[
81
				-23.5,
82
				-42.5,
83
				'-23° 30\' 0", -42° 30\' 0"',
84
			],
85
		];
86
	}
87
88
	/**
89
	 * @dataProvider coordinateWithDistanceProvider
90
	 */
91
	public function testGetQueryDescriptionForArea( $serialization ) {
92
		$geoValue = $this->newInstance();
93
94
		$description = $geoValue->getQueryDescription( $serialization );
95
96
		$this->assertInstanceOf( SMAreaValueDescription::class, $description );
97
	}
98
99
	public function coordinateWithDistanceProvider() {
100
		return [
101
			[
102
				'23° 0\' 0", 42° 0\' 0"(1km)',
103
				1000,
104
			],
105
			[
106
				'0° 0\' 0", 0° 0\' 0" ( 1 m )',
107
				1,
108
			],
109
			[
110
				'-23° 30\' 0", -42° 30\' 0" (9001m)',
111
				9001,
112
			],
113
		];
114
	}
115
116
}
117