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