1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace Maps\Tests\System; |
6
|
|
|
|
7
|
|
|
use Maps\DataAccess\PageContentFetcher; |
8
|
|
|
use Maps\Tests\MapsTestFactory; |
9
|
|
|
use Maps\Tests\Util\PageCreator; |
10
|
|
|
use Maps\Tests\Util\TestFactory; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
use Title; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @licence GNU GPL v2+ |
16
|
|
|
* @author Jeroen De Dauw < [email protected] > |
17
|
|
|
*/ |
18
|
|
|
class SemanticQueryTest extends TestCase { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var PageCreator |
22
|
|
|
*/ |
23
|
|
|
private $pageCreator; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var PageContentFetcher |
27
|
|
|
*/ |
28
|
|
|
private $contentFetcher; |
29
|
|
|
|
30
|
|
|
public function setUp(): void { |
31
|
|
|
if ( !defined( 'SMW_VERSION' ) ) { |
32
|
|
|
$this->markTestSkipped( 'SMW is not available' ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$this->pageCreator = TestFactory::newInstance()->getPageCreator(); |
36
|
|
|
$this->contentFetcher = MapsTestFactory::newTestInstance()->getPageContentFetcher(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testMapQueryContainsMarkersWithInfo() { |
40
|
|
|
$this->createDataPages(); |
41
|
|
|
|
42
|
|
|
$content = $this->getResultForQuery( '{{#ask:[[Coordinates::+]]|?Coordinates|?Description|?URL|format=map}}' ); |
43
|
|
|
|
44
|
|
|
$this->assertContains( '<div id="map_', $content ); |
45
|
|
|
$this->assertContains( 'Capital of Belgium', $content ); |
46
|
|
|
$this->assertContains( 'example.com', $content ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testLeafletQueryWithGeoJson() { |
50
|
|
|
$this->skipOn131(); |
51
|
|
|
|
52
|
|
|
$this->createDataPages(); |
53
|
|
|
|
54
|
|
|
$content = $this->getResultForQuery( '{{#ask:[[Coordinates::+]]|?Coordinates|format=leaflet|geojson=TestGeoJson}}' ); |
55
|
|
|
|
56
|
|
|
$this->assertContains( '<div id="map_leaflet_', $content ); |
57
|
|
|
$this->assertContains( '"GeoJsonSource":"TestGeoJson"', $content ); |
58
|
|
|
$this->assertContains( '"GeoJsonRevisionId":', $content ); |
59
|
|
|
$this->assertContains( '"geojson":{"type":"FeatureCollection"', $content ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function skipOn131() { |
63
|
|
|
if ( version_compare( $GLOBALS['wgVersion'], '1.32c', '<' ) ) { |
64
|
|
|
$this->markTestSkipped(); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
private function getResultForQuery( string $query ): string { |
69
|
|
|
$this->pageCreator->createPage( |
70
|
|
|
'MapQuery', |
71
|
|
|
$query |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
// TODO: saner way |
75
|
|
|
return $this->contentFetcher->getPageContent( 'MapQuery' )->getParserOutput( Title::newFromText( 'MapQuery' ) )->getText(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
private function createDataPages() { |
79
|
|
|
$this->pageCreator->createPage( |
80
|
|
|
'GeoJson:TestGeoJson', |
81
|
|
|
'{"type": "FeatureCollection", "features": []}' |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$this->pageCreator->createPage( |
85
|
|
|
'Property:Coordinates', |
86
|
|
|
'[[Has type::Geographic coordinate|geographic coordinate]]' |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
$this->pageCreator->createPage( |
90
|
|
|
'Property:Description', |
91
|
|
|
'[[Has type::Text]]' |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
$this->pageCreator->createPage( |
95
|
|
|
'Property:URL', |
96
|
|
|
'[[Has type::URL]]' |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
$this->pageCreator->createPage( |
100
|
|
|
'Berlin', |
101
|
|
|
'[[Coordinates::52° 31\' 0", 13° 24\' 0"]] [[Description::Capital of Germany]] [[URL::http://example.com/Berlin]]' |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
$this->pageCreator->createPage( |
105
|
|
|
'Brussels', |
106
|
|
|
'[[Coordinates::50° 51\' 1", 4° 21\' 6"]] [[Description::Capital of Belgium]]' |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$this->pageCreator->createPage( |
110
|
|
|
'Hamburg', |
111
|
|
|
'[[Coordinates::53° 33\' 4", 9° 59\' 37"]]' |
112
|
|
|
); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
} |
116
|
|
|
|