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