1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace Maps\Tests\Integration\DataAccess\GeoJsonStore; |
6
|
|
|
|
7
|
|
|
use Maps\DataAccess\GeoJsonStore\SubObjectBuilder; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers \Maps\DataAccess\GeoJsonStore\SubObjectBuilder |
12
|
|
|
*/ |
13
|
|
|
class SubObjectBuilderTest extends TestCase { |
14
|
|
|
|
15
|
|
|
public function setUp(): void { |
16
|
|
|
if ( !defined( 'SMW_VERSION' ) ) { |
17
|
|
|
$this->markTestSkipped( 'SMW is not available' ); |
18
|
|
|
} |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testEmptyGeoJson() { |
22
|
|
|
$objects = $this->newBuilder()->getSubObjectsFromGeoJson( '{"type": "FeatureCollection", "features": []}' ); |
23
|
|
|
|
24
|
|
|
$this->assertSame( [], $objects ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
private function newBuilder(): SubObjectBuilder { |
28
|
|
|
return new SubObjectBuilder( \Title::newFromText( 'GeoJson:TestGeoJson' ) ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testPoint() { |
32
|
|
|
$objects = $this->newBuilder()->getSubObjectsFromGeoJson( |
33
|
|
|
<<<'EOD' |
34
|
|
|
{ |
35
|
|
|
"type": "FeatureCollection", |
36
|
|
|
"features": [ |
37
|
|
|
{ |
38
|
|
|
"type": "Feature", |
39
|
|
|
"geometry": { |
40
|
|
|
"type": "Point", |
41
|
|
|
"coordinates": [ |
42
|
|
|
13.388729, |
43
|
|
|
52.516524 |
44
|
|
|
] |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
] |
48
|
|
|
} |
49
|
|
|
EOD |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
$this->assertCount( 1, $objects ); |
53
|
|
|
$this->assertSame( 'Point_1', $objects[0]->getName() ); |
54
|
|
|
|
55
|
|
|
$this->assertEquals( |
56
|
|
|
[ |
57
|
|
|
'HasCoordinates' => [ new \SMWDIGeoCoord( 52.516524, 13.388729 ) ], |
58
|
|
|
], |
59
|
|
|
$objects[0]->getValues() |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testPointWithTitleAndDescription() { |
64
|
|
|
$objects = $this->newBuilder()->getSubObjectsFromGeoJson( |
65
|
|
|
<<<'EOD' |
66
|
|
|
{ |
67
|
|
|
"type": "FeatureCollection", |
68
|
|
|
"features": [ |
69
|
|
|
{ |
70
|
|
|
"type": "Feature", |
71
|
|
|
"properties": { |
72
|
|
|
"title": "Berlin", |
73
|
|
|
"description": "The capital of Germany" |
74
|
|
|
}, |
75
|
|
|
"geometry": { |
76
|
|
|
"type": "Point", |
77
|
|
|
"coordinates": [ |
78
|
|
|
13.388729, |
79
|
|
|
52.516524 |
80
|
|
|
] |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
] |
84
|
|
|
} |
85
|
|
|
EOD |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$this->assertCount( 1, $objects ); |
89
|
|
|
|
90
|
|
|
$this->assertEquals( |
91
|
|
|
[ |
92
|
|
|
'HasCoordinates' => [ new \SMWDIGeoCoord( 52.516524, 13.388729 ) ], |
93
|
|
|
'HasTitle' => [ new \SMWDIBlob( 'Berlin' ) ], |
94
|
|
|
'HasDescription' => [ new \SMWDIBlob( 'The capital of Germany' ) ], |
95
|
|
|
], |
96
|
|
|
$objects[0]->getValues() |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|