1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maps\Tests\Integration\Semantic; |
4
|
|
|
|
5
|
|
|
use Maps\SemanticMW\ValueDescriptions\AreaDescription; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use SMWDIGeoCoord; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers \Maps\SemanticMW\ValueDescriptions\AreaDescription |
11
|
|
|
* |
12
|
|
|
* @licence GNU GPL v2+ |
13
|
|
|
* @author Jeroen De Dauw < [email protected] > |
14
|
|
|
*/ |
15
|
|
|
class AreaDescriptionTest extends TestCase { |
16
|
|
|
|
17
|
|
|
public function setUp(): void { |
18
|
|
|
if ( !defined( 'SMW_VERSION' ) ) { |
19
|
|
|
$this->markTestSkipped( 'SMW is not available' ); |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testGetBoundingBox() { |
24
|
|
|
$area = new AreaDescription( |
25
|
|
|
new SMWDIGeoCoord( 0, 5 ), |
26
|
|
|
SMW_CMP_EQ, |
27
|
|
|
'10 km' |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
$this->assertEquals( |
31
|
|
|
[ |
32
|
|
|
'north' => 0.089932160591873, |
33
|
|
|
'east' => 5.089932160591873, |
34
|
|
|
'south' => -0.089932160591873, |
35
|
|
|
'west' => 4.9100678394081 |
36
|
|
|
], |
37
|
|
|
$area->getBoundingBox() |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testGetSQLCondition() { |
42
|
|
|
$area = new AreaDescription( |
43
|
|
|
new SMWDIGeoCoord( 0, 5 ), |
44
|
|
|
SMW_CMP_EQ, |
45
|
|
|
'10 km' |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$this->assertSame( |
49
|
|
|
'geo_table.lat_field < \'0.089932160591873\' AND geo_table.lat_field > \'-0.089932160591873\' ' |
50
|
|
|
. 'AND geo_table.long_field < \'5.0899321605919\' AND geo_table.long_field > \'4.9100678394081\'', |
51
|
|
|
$area->getSQLCondition( 'geo_table', [ 'id_field', 'lat_field', 'long_field' ], wfGetDB( DB_MASTER ) ) |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testWhenComparatorIsNotSupported_getSQLConditionReturnsFalse() { |
56
|
|
|
$area = new AreaDescription( |
57
|
|
|
new SMWDIGeoCoord( 0, 5 ), |
58
|
|
|
SMW_CMP_LIKE, |
59
|
|
|
'10 km' |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$this->assertFalse( |
63
|
|
|
$area->getSQLCondition( 'geo_table', [ 'id_field', 'lat_field', 'long_field' ], wfGetDB( DB_MASTER ) ) |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testGetQueryString() { |
68
|
|
|
$area = new AreaDescription( |
69
|
|
|
new SMWDIGeoCoord( 1, 5 ), |
70
|
|
|
SMW_CMP_EQ, |
71
|
|
|
'10 km' |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
$this->assertSame( |
75
|
|
|
'[[1° 0\' 0.00" N, 5° 0\' 0.00" E (10 km)]]', |
76
|
|
|
$area->getQueryString() |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|