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