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