Completed
Push — MediaWikiFileUrlFinderTest ( d58bee )
by Jeroen De
03:36
created

CoordinateValueTest::coordinateProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

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