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 CoordinatesTest extends TestCase { |
12
|
|
|
|
13
|
|
|
private function parse( string $textToParse ): string { |
14
|
|
|
$parser = new \Parser(); |
15
|
|
|
|
16
|
|
|
return $parser->parse( $textToParse, \Title::newMainPage(), new \ParserOptions() )->getText(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testGivenInvalidCoordinates_errorIsShown() { |
20
|
|
|
$this->assertContains( |
21
|
|
|
'<span class="errorbox">', |
22
|
|
|
$this->parse( '{{#coordinates:nope}}' ) |
23
|
|
|
); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testGivenNoCoordinates_errorIsShown() { |
27
|
|
|
$this->assertContains( |
28
|
|
|
'<span class="errorbox">', |
29
|
|
|
$this->parse( '{{#coordinates:}}' ) |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testGivenValidCoordinates_theyAreFormatted() { |
34
|
|
|
$this->assertContains( |
35
|
|
|
'1° 0\' 0.00" N, 1° 0\' 0.00" E', |
36
|
|
|
$this->parse( '{{#coordinates:1,1}}' ) |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testGivenFormat_coordinatesAreConvertedToIt() { |
41
|
|
|
$this->assertContains( |
42
|
|
|
'1.000000° N, 1.000000° E', |
43
|
|
|
$this->parse( '{{#coordinates:1,1|format=dd}}' ) |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testGivenDirectionalParameter_itGetsUsed() { |
48
|
|
|
$this->assertContains( |
49
|
|
|
'1° 0\' 0.00", 1° 0\' 0.00"', |
50
|
|
|
$this->parse( '{{#coordinates:1,1|directional=no}}' ) |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testCoordinatesInNonDms_theyGetParsed() { |
55
|
|
|
$this->assertContains( |
56
|
|
|
'1° 20\' 13.20" N, 4° 12\' 0.00" W', |
57
|
|
|
$this->parse( '{{#coordinates:1.337°, -4.2°}}' ) |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testGivenInvalidFormat_defaultFormatGetsUsed() { |
62
|
|
|
$this->assertContains( |
63
|
|
|
'1° 0\' 0.00" N, 1° 0\' 0.00" E', |
64
|
|
|
$this->parse( '{{#coordinates:1,1|format=such}}' ) |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testRoundingWhenFormattingAsFloat() { |
69
|
|
|
$this->assertContains( |
70
|
|
|
'52.136945 N, 0.466722 W', |
71
|
|
|
$this->parse( '{{#coordinates:52.136945,-0.466722|format=float}}' ) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testRoundingWhenFormattingAsDMS() { |
76
|
|
|
$this->assertContains( |
77
|
|
|
'52° 8\' 13.00" N, 0° 28\' 0.20" W', |
78
|
|
|
$this->parse( '{{#coordinates:52.136945,-0.466722|format=dms}}' ) |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testRoundingWhenFormattingAsDD() { |
83
|
|
|
$this->assertContains( |
84
|
|
|
'52.136945° N, 0.466722° W', |
85
|
|
|
$this->parse( '{{#coordinates:52.136945,-0.466722|format=dd}}' ) |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testRoundingWhenFormattingAsDM() { |
90
|
|
|
$this->assertContains( |
91
|
|
|
'52° 8.2167\' N, 0° 28.0033\' W', |
92
|
|
|
$this->parse( '{{#coordinates:52.136945,-0.466722|format=dm}}' ) |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
} |