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->assertStringContainsString( '<div id="map_', $content ); |
45
|
|
|
$this->assertStringContainsString( 'Capital of Belgium', $content ); |
46
|
|
|
$this->assertStringContainsString( 'example.com', $content ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testLeafletQueryWithGeoJson() { |
50
|
|
|
$this->createDataPages(); |
51
|
|
|
|
52
|
|
|
$content = $this->getResultForQuery( '{{#ask:[[Coordinates::+]]|?Coordinates|format=leaflet|geojson=TestGeoJson}}' ); |
53
|
|
|
|
54
|
|
|
$this->assertStringContainsString( '<div id="map_leaflet_', $content ); |
55
|
|
|
$this->assertStringContainsString( '"GeoJsonSource":"TestGeoJson"', $content ); |
56
|
|
|
$this->assertStringContainsString( '"GeoJsonRevisionId":', $content ); |
57
|
|
|
$this->assertStringContainsString( '"geojson":{"type":"FeatureCollection"', $content ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function getResultForQuery( string $query ): string { |
61
|
|
|
$this->pageCreator->createPage( |
62
|
|
|
'MapQuery', |
63
|
|
|
$query |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
// TODO: saner way |
67
|
|
|
return $this->contentFetcher->getPageContent( 'MapQuery' )->getParserOutput( Title::newFromText( 'MapQuery' ) )->getText(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
private function createDataPages() { |
71
|
|
|
$this->pageCreator->createPage( |
72
|
|
|
'GeoJson:TestGeoJson', |
73
|
|
|
'{"type": "FeatureCollection", "features": []}' |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$this->pageCreator->createPage( |
77
|
|
|
'Property:Coordinates', |
78
|
|
|
'[[Has type::Geographic coordinate|geographic coordinate]]' |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
$this->pageCreator->createPage( |
82
|
|
|
'Property:Description', |
83
|
|
|
'[[Has type::Text]]' |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
$this->pageCreator->createPage( |
87
|
|
|
'Property:URL', |
88
|
|
|
'[[Has type::URL]]' |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
$this->pageCreator->createPage( |
92
|
|
|
'Berlin', |
93
|
|
|
'[[Coordinates::52° 31\' 0", 13° 24\' 0"]] [[Description::Capital of Germany]] [[URL::http://example.com/Berlin]]' |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
$this->pageCreator->createPage( |
97
|
|
|
'Brussels', |
98
|
|
|
'[[Coordinates::50° 51\' 1", 4° 21\' 6"]] [[Description::Capital of Belgium]]' |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$this->pageCreator->createPage( |
102
|
|
|
'Hamburg', |
103
|
|
|
'[[Coordinates::53° 33\' 4", 9° 59\' 37"]]' |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testMapQueryWithTemplate() { |
108
|
|
|
$this->createDataPages(); |
109
|
|
|
|
110
|
|
|
$content = $this->getResultForQuery( '{{#ask:[[Coordinates::+]]|?Coordinates|format=map|template=Whatever}}' ); |
111
|
|
|
|
112
|
|
|
$this->assertStringContainsString( '<div id="map_', $content ); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
} |
116
|
|
|
|