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

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