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