|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\DataValues\Geo\Parsers; |
|
4
|
|
|
|
|
5
|
|
|
use DataValues\Geo\Parsers\DdCoordinateParser; |
|
6
|
|
|
use DataValues\Geo\Values\LatLongValue; |
|
7
|
|
|
use ValueParsers\Test\StringValueParserTest; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @covers DataValues\Geo\Parsers\DdCoordinateParser |
|
11
|
|
|
* |
|
12
|
|
|
* @group ValueParsers |
|
13
|
|
|
* @group DataValueExtensions |
|
14
|
|
|
* |
|
15
|
|
|
* @license GPL-2.0+ |
|
16
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
17
|
|
|
*/ |
|
18
|
|
|
class DdCoordinateParserTest extends StringValueParserTest { |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @see ValueParserTestBase::getInstance |
|
22
|
|
|
* |
|
23
|
|
|
* @return DdCoordinateParser |
|
24
|
|
|
*/ |
|
25
|
|
|
protected function getInstance() { |
|
26
|
|
|
return new DdCoordinateParser(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @see ValueParserTestBase::validInputProvider |
|
31
|
|
|
*/ |
|
32
|
|
|
public function validInputProvider() { |
|
33
|
|
|
$argLists = []; |
|
34
|
|
|
|
|
35
|
|
|
// TODO: test with different parser options |
|
36
|
|
|
|
|
37
|
|
|
$valid = [ |
|
38
|
|
|
// Whitespace |
|
39
|
|
|
"1°N 1°E\n" => [ 1, 1 ], |
|
40
|
|
|
' 1°N 1°E ' => [ 1, 1 ], |
|
41
|
|
|
|
|
42
|
|
|
'55.7557860° N, 37.6176330° W' => [ 55.7557860, -37.6176330 ], |
|
43
|
|
|
'55.7557860°, -37.6176330°' => [ 55.7557860, -37.6176330 ], |
|
44
|
|
|
'55° S, 37.6176330 ° W' => [ -55, -37.6176330, 0.000001 ], |
|
45
|
|
|
'-55°, -37.6176330 °' => [ -55, -37.6176330, 0.000001 ], |
|
46
|
|
|
'5.5°S,37°W ' => [ -5.5, -37, 0.1 ], |
|
47
|
|
|
'-5.5°,-37° ' => [ -5.5, -37, 0.1 ], |
|
48
|
|
|
|
|
49
|
|
|
// Coordinate strings without separator: |
|
50
|
|
|
'55.7557860° N 37.6176330° W' => [ 55.7557860, -37.6176330 ], |
|
51
|
|
|
'55.7557860° -37.6176330°' => [ 55.7557860, -37.6176330 ], |
|
52
|
|
|
'55° S 37.6176330 ° W' => [ -55, -37.6176330 ], |
|
53
|
|
|
'-55° -37.6176330 °' => [ -55, -37.6176330 ], |
|
54
|
|
|
'5.5°S 37°W ' => [ -5.5, -37 ], |
|
55
|
|
|
'-5.5° -37° ' => [ -5.5, -37 ], |
|
56
|
|
|
|
|
57
|
|
|
// Coordinate string starting with direction character: |
|
58
|
|
|
'N5.5° W37°' => [ 5.5, -37 ], |
|
59
|
|
|
'S 5.5° E 37°' => [ -5.5, 37 ], |
|
60
|
|
|
]; |
|
61
|
|
|
|
|
62
|
|
|
foreach ( $valid as $value => $expected ) { |
|
63
|
|
|
$expected = new LatLongValue( $expected[0], $expected[1] ); |
|
64
|
|
|
$argLists[] = [ (string)$value, $expected ]; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $argLists; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @see StringValueParserTest::invalidInputProvider |
|
72
|
|
|
*/ |
|
73
|
|
|
public function invalidInputProvider() { |
|
74
|
|
|
$argLists = parent::invalidInputProvider(); |
|
75
|
|
|
|
|
76
|
|
|
$invalid = [ |
|
77
|
|
|
'~=[,,_,,]:3', |
|
78
|
|
|
'ohi there', |
|
79
|
|
|
]; |
|
80
|
|
|
|
|
81
|
|
|
foreach ( $invalid as $value ) { |
|
82
|
|
|
$argLists[] = [ $value ]; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $argLists; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|