Passed
Push — zeroRounding ( 491d2a...2f1015 )
by no
35:13 queued 21:46
created

LatLongParserTest::getParserClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Tests\DataValues\Geo\Parsers;
4
5
use DataValues\Geo\Parsers\LatLongParser;
6
use DataValues\Geo\Values\LatLongValue;
7
use ValueParsers\Test\StringValueParserTest;
8
9
/**
10
 * @covers DataValues\Geo\Parsers\LatLongParser
11
 *
12
 * @group ValueParsers
13
 * @group DataValueExtensions
14
 *
15
 * @license GPL-2.0+
16
 * @author Jeroen De Dauw < [email protected] >
17
 */
18
class LatLongParserTest extends StringValueParserTest {
19
20
	/**
21
	 * @see ValueParserTestBase::getInstance
22
	 *
23
	 * @return LatLongParser
24
	 */
25
	protected function getInstance() {
26
		return new LatLongParser();
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
			// Float
43
			'55.7557860 N, 37.6176330 W' => [ 55.7557860, -37.6176330 ],
44
			'55.7557860, -37.6176330' => [ 55.7557860, -37.6176330 ],
45
			'55 S, 37.6176330 W' => [ -55, -37.6176330 ],
46
			'-55, -37.6176330' => [ -55, -37.6176330 ],
47
			'5.5S,37W ' => [ -5.5, -37 ],
48
			'-5.5,-37 ' => [ -5.5, -37 ],
49
			'4,2' => [ 4, 2, 1 ],
50
			'5.5S 37W ' => [ -5.5, -37 ],
51
			'-5.5 -37 ' => [ -5.5, -37 ],
52
			'4 2' => [ 4, 2, 1 ],
53
			'S5.5 W37 ' => [ -5.5, -37 ],
54
55
			// DD
56
			'55.7557860° N, 37.6176330° W' => [ 55.7557860, -37.6176330 ],
57
			'55.7557860°, -37.6176330°' => [ 55.7557860, -37.6176330 ],
58
			'55° S, 37.6176330 ° W' => [ -55, -37.6176330 ],
59
			'-55°, -37.6176330 °' => [ -55, -37.6176330 ],
60
			'5.5°S,37°W ' => [ -5.5, -37 ],
61
			'-5.5°,-37° ' => [ -5.5, -37 ],
62
			'-55° -37.6176330 °' => [ -55, -37.6176330 ],
63
			'5.5°S 37°W ' => [ -5.5, -37 ],
64
			'-5.5 ° -37 ° ' => [ -5.5, -37 ],
65
			'S5.5° W37°' => [ -5.5, -37 ],
66
67
			// DMS
68
			'55° 45\' 20.8296", 37° 37\' 3.4788"' => [ 55.755786, 37.6176330000 ],
69
			'55° 45\' 20.8296", -37° 37\' 3.4788"' => [ 55.755786, -37.6176330000 ],
70
			'-55° 45\' 20.8296", -37° 37\' 3.4788"' => [ -55.755786, -37.6176330000 ],
71
			'-55° 45\' 20.8296", 37° 37\' 3.4788"' => [ -55.755786, 37.6176330000 ],
72
			'55° 0\' 0", 37° 0\' 0"' => [ 55, 37 ],
73
			'55° 30\' 0", 37° 30\' 0"' => [ 55.5, 37.5 ],
74
			'55° 0\' 18", 37° 0\' 18"' => [ 55.005, 37.005 ],
75
			'0° 0\' 0", 0° 0\' 0"' => [ 0, 0 ],
76
			'0° 0\' 18" N, 0° 0\' 18" E' => [ 0.005, 0.005 ],
77
			' 0° 0\' 18" S  , 0°  0\' 18"  W ' => [ -0.005, -0.005 ],
78
			'0° 0′ 18″ N, 0° 0′ 18″ E' => [ 0.005, 0.005 ],
79
			'0° 0\' 18" N  0° 0\' 18" E' => [ 0.005, 0.005 ],
80
			' 0 ° 0 \' 18 " S   0 °  0 \' 18 "  W ' => [ -0.005, -0.005 ],
81
			'0° 0′ 18″ N 0° 0′ 18″ E' => [ 0.005, 0.005 ],
82
			'N 0° 0\' 18" E 0° 0\' 18"' => [ 0.005, 0.005 ],
83
84
			// DM
85
			'55° 0\', 37° 0\'' => [ 55, 37 ],
86
			'55° 30\', 37° 30\'' => [ 55.5, 37.5 ],
87
			'0° 0\', 0° 0\'' => [ 0, 0 ],
88
			'-55° 30\', -37° 30\'' => [ -55.5, -37.5 ],
89
			'0° 0.3\' S, 0° 0.3\' W' => [ -0.005, -0.005 ],
90
			'-55° 30′, -37° 30′' => [ -55.5, -37.5 ],
91
			'-55 ° 30 \' -37 ° 30 \'' => [ -55.5, -37.5 ],
92
			'0° 0.3\' S 0° 0.3\' W' => [ -0.005, -0.005 ],
93
			'-55° 30′ -37° 30′' => [ -55.5, -37.5 ],
94
			'S 0° 0.3\' W 0° 0.3\'' => [ -0.005, -0.005 ],
95
		];
96
97
		foreach ( $valid as $value => $expected ) {
98
			$expected = new LatLongValue( $expected[0], $expected[1] );
99
			$argLists[] = [ (string)$value, $expected ];
100
		}
101
102
		return $argLists;
103
	}
104
105
	/**
106
	 * @see StringValueParserTest::invalidInputProvider
107
	 */
108
	public function invalidInputProvider() {
109
		$argLists = parent::invalidInputProvider();
110
111
		$invalid = [
112
			'~=[,,_,,]:3',
113
			'ohi there',
114
		];
115
116
		foreach ( $invalid as $value ) {
117
			$argLists[] = [ $value ];
118
		}
119
120
		return $argLists;
121
	}
122
123
}
124