Completed
Push — master ( 81538e...c2bf57 )
by Jeroen De
10:06
created

coordinateWithDistanceProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

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