1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace Maps\Tests\Integration\Parser; |
6
|
|
|
|
7
|
|
|
use Maps\GeoJsonPages\GeoJsonContent; |
8
|
|
|
use MediaWiki\MediaWikiServices; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @licence GNU GPL v2+ |
13
|
|
|
* @author Jeroen De Dauw < [email protected] > |
14
|
|
|
*/ |
15
|
|
|
class DisplayMapTest extends TestCase { |
16
|
|
|
|
17
|
|
|
private $originalHeight; |
18
|
|
|
private $originalWidth; |
19
|
|
|
|
20
|
|
|
public function setUp(): void { |
21
|
|
|
$this->originalHeight = $GLOBALS['egMapsMapHeight']; |
22
|
|
|
$this->originalWidth = $GLOBALS['egMapsMapWidth']; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function tearDown(): void { |
26
|
|
|
$GLOBALS['egMapsMapHeight'] = $this->originalHeight; |
27
|
|
|
$GLOBALS['egMapsMapWidth'] = $this->originalWidth; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testMapIdIsSet() { |
31
|
|
|
$this->assertStringContainsString( |
32
|
|
|
'id="map_leaflet_', |
33
|
|
|
$this->parse( '{{#display_map:1,1|service=leaflet}}' ) |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
private function parse( string $textToParse ): string { |
38
|
|
|
$parser = MediaWikiServices::getInstance()->getParser(); |
39
|
|
|
|
40
|
|
|
return $parser->parse( $textToParse, \Title::newMainPage(), new \ParserOptions() )->getText(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testServiceSelectionWorks() { |
44
|
|
|
$this->assertStringContainsString( |
45
|
|
|
'maps-googlemaps3', |
46
|
|
|
$this->parse( '{{#display_map:1,1|service=google}}' ) |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testSingleCoordinatesAreIncluded() { |
51
|
|
|
$this->assertStringContainsString( |
52
|
|
|
'"lat":1,"lon":1', |
53
|
|
|
$this->parse( '{{#display_map:1,1}}' ) |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testMultipleCoordinatesAreIncluded() { |
58
|
|
|
$result = $this->parse( '{{#display_map:1,1; 4,2}}' ); |
59
|
|
|
|
60
|
|
|
$this->assertStringContainsString( '"lat":1,"lon":1', $result ); |
61
|
|
|
$this->assertStringContainsString( '"lat":4,"lon":2', $result ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testTagIsRendered() { |
65
|
|
|
$this->assertStringContainsString( |
66
|
|
|
'"lat":1,"lon":1', |
67
|
|
|
$this->parse( '<display_map>1,1</display_map>' ) |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testTagServiceParameterIsUsed() { |
72
|
|
|
$this->assertStringContainsString( |
73
|
|
|
'maps-googlemaps3', |
74
|
|
|
$this->parse( '<display_map service="google">1,1</display_map>' ) |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testWhenThereAreNoLocations_locationsArrayIsEmpty() { |
79
|
|
|
$this->assertStringContainsString( |
80
|
|
|
'"locations":[]', |
81
|
|
|
$this->parse( '{{#display_map:}}' ) |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testLocationTitleGetsIncluded() { |
86
|
|
|
$this->assertStringContainsString( |
87
|
|
|
'"title":"title', |
88
|
|
|
$this->parse( '{{#display_map:1,1~title}}' ) |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testLocationDescriptionGetsIncluded() { |
93
|
|
|
$this->assertStringContainsString( |
94
|
|
|
'such description', |
95
|
|
|
$this->parse( '{{#display_map:1,1~title~such description}}' ) |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testRectangleDisplay() { |
100
|
|
|
$this->assertStringContainsString( |
101
|
|
|
'"title":"title', |
102
|
|
|
$this->parse( '{{#display_map:rectangles=1,1:2,2~title}}' ) |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function testCircleDisplay() { |
107
|
|
|
$this->assertStringContainsString( |
108
|
|
|
'"title":"title', |
109
|
|
|
$this->parse( '{{#display_map:circles=1,1:2~title}}' ) |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function testRectangleFillOpacityIsUsed() { |
114
|
|
|
$this->assertStringContainsString( |
115
|
|
|
'"fillOpacity":"fill opacity"', |
116
|
|
|
$this->parse( '{{#display_map:rectangles=1,1:2,2~title~text~color~opacity~thickness~fill color~fill opacity}}' ) |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function testRectangleFillColorIsUsed() { |
121
|
|
|
$this->assertStringContainsString( |
122
|
|
|
'"fillColor":"fill color"', |
123
|
|
|
$this->parse( '{{#display_map:rectangles=1,1:2,2~title~text~color~opacity~thickness~fill color~fill opacity}}' ) |
124
|
|
|
); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function testServiceSelectionWorksWhenItIsPrecededByMultipleParameters() { |
128
|
|
|
$this->assertStringContainsString( |
129
|
|
|
'maps-googlemaps3', |
130
|
|
|
$this->parse( |
131
|
|
|
"{{#display_map:rectangles=\n 1,1:2,2~title~text~color\n| scrollwheelzoom=off\n| service = google}}" |
132
|
|
|
) |
133
|
|
|
); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function testDimensionDefaultsAsInteger() { |
137
|
|
|
$GLOBALS['egMapsMapHeight'] = 420; |
138
|
|
|
$GLOBALS['egMapsMapWidth'] = 230; |
139
|
|
|
|
140
|
|
|
$this->assertStringContainsString( |
141
|
|
|
'height: 420px;', |
142
|
|
|
$this->parse( '{{#display_map:1,1}}' ) |
143
|
|
|
); |
144
|
|
|
|
145
|
|
|
$this->assertStringContainsString( |
146
|
|
|
'width: 230px;', |
147
|
|
|
$this->parse( '{{#display_map:1,1}}' ) |
148
|
|
|
); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
// TODO: need DI to test |
152
|
|
|
// public function testWhenLocationHasVisitedIconModifier_itIsUsed() { |
153
|
|
|
// $this->assertStringContainsString( |
154
|
|
|
// '"visitedicon":"VisitedIcon.png"', |
155
|
|
|
// $this->parse( '{{#display_map:1,1~title~text~icon~group~inline label~VisitedIcon.png}}' ) |
156
|
|
|
// ); |
157
|
|
|
// } |
158
|
|
|
// |
159
|
|
|
// public function testWhenLocationHasVisitedIconModifierWithNamespacePrefix_thePrefixGetsRemoved() { |
160
|
|
|
// $this->assertStringContainsString(MapsMapperTest |
161
|
|
|
// '"visitedicon":"VisitedIcon.png"', |
162
|
|
|
// $this->parse( '{{#display_map:1,1~title~text~icon~group~inline label~File:VisitedIcon.png}}' ) |
163
|
|
|
// ); |
164
|
|
|
// } |
165
|
|
|
// |
166
|
|
|
// public function testWhenVisitedIconParameterIsProvidedWithNamespacePrefix_thePrefixGetsRemoved() { |
167
|
|
|
// $this->assertStringContainsString( |
168
|
|
|
// '"visitedicon":"VisitedIcon.png"', |
169
|
|
|
// $this->parse( '{{#display_map:1,1|visitedicon=File:VisitedIcon.png}}' ) |
170
|
|
|
// ); |
171
|
|
|
// } |
172
|
|
|
// |
173
|
|
|
// public function testWhenLocationHasIconModifierWithNamespacePrefix_thePrefixGetsRemoved() { |
174
|
|
|
// $this->assertStringContainsString( |
175
|
|
|
// '"icon":"Icon.png"', |
176
|
|
|
// $this->parse( '{{#display_map:1,1~title~text~File:Icon.png}}' ) |
177
|
|
|
// ); |
178
|
|
|
// } |
179
|
|
|
|
180
|
|
|
public function testWhenIconParameterIsProvidedButEmpty_itIsDefaulted() { |
181
|
|
|
$this->assertStringContainsString( |
182
|
|
|
'"icon":"","inlineLabel":"Ghent', |
183
|
|
|
$this->parse( |
184
|
|
|
"{{#display_map:Gent, Belgie~The city Ghent~Ghent is awesome~ ~ ~Ghent}}" |
185
|
|
|
) |
186
|
|
|
); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
public function testWhenLocationHasNoTitleAndText_textFieldIsEmptyString() { |
190
|
|
|
$this->assertStringContainsString( |
191
|
|
|
'"text":""', |
192
|
|
|
$this->parse( '{{#display_map:1,1}}' ) |
193
|
|
|
); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function testGeoJsonSourceForFile() { |
197
|
|
|
$this->assertStringContainsString( |
198
|
|
|
'"GeoJsonSource":null,', |
199
|
|
|
$this->parse( |
200
|
|
|
"{{#display_map:geojson=404}}" |
201
|
|
|
) |
202
|
|
|
); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
public function testGeoJsonSourceForPage() { |
206
|
|
|
$page = new \WikiPage( \Title::newFromText( 'GeoJson:TestPageSource' ) ); |
207
|
|
|
$page->doEditContent( |
208
|
|
|
new GeoJsonContent( json_encode( [ |
209
|
|
|
'type' => 'FeatureCollection', |
210
|
|
|
'features' => [] |
211
|
|
|
] ) ), |
212
|
|
|
'' |
213
|
|
|
); |
214
|
|
|
|
215
|
|
|
$this->assertStringContainsString( |
216
|
|
|
'"GeoJsonSource":"TestPageSource",', |
217
|
|
|
$this->parse( |
218
|
|
|
"{{#display_map:geojson=TestPageSource}}" |
219
|
|
|
) |
220
|
|
|
); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
} |
224
|
|
|
|