Completed
Pull Request — master (#23)
by no
04:44 queued 02:28
created

LatLongParserTest::invalidInputProvider()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
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
	 * @deprecated since DataValues Common 0.3, just use getInstance.
22
	 */
23
	protected function getParserClass() {
24
		throw new \LogicException( 'Should not be called, use getInstance' );
25
	}
26
27
	/**
28
	 * @see ValueParserTestBase::getInstance
29
	 *
30
	 * @return LatLongParser
31
	 */
32
	protected function getInstance() {
33
		return new LatLongParser();
34
	}
35
36
	/**
37
	 * @see ValueParserTestBase::validInputProvider
38
	 */
39
	public function validInputProvider() {
40
		$argLists = array();
41
42
		// TODO: test with different parser options
43
44
		$valid = array(
45
			// Whitespace
46
			"1N 1E\n" => array( 1, 1 ),
47
			' 1N 1E ' => array( 1, 1 ),
48
49
			// Float
50
			'55.7557860 N, 37.6176330 W' => array( 55.7557860, -37.6176330 ),
51
			'55.7557860, -37.6176330' => array( 55.7557860, -37.6176330 ),
52
			'55 S, 37.6176330 W' => array( -55, -37.6176330 ),
53
			'-55, -37.6176330' => array( -55, -37.6176330 ),
54
			'5.5S,37W ' => array( -5.5, -37 ),
55
			'-5.5,-37 ' => array( -5.5, -37 ),
56
			'4,2' => array( 4, 2, 1 ),
57
			'5.5S 37W ' => array( -5.5, -37 ),
58
			'-5.5 -37 ' => array( -5.5, -37 ),
59
			'4 2' => array( 4, 2, 1 ),
60
			'S5.5 W37 ' => array( -5.5, -37 ),
61
62
			// DD
63
			'55.7557860° N, 37.6176330° W' => array( 55.7557860, -37.6176330 ),
64
			'55.7557860°, -37.6176330°' => array( 55.7557860, -37.6176330 ),
65
			'55° S, 37.6176330 ° W' => array( -55, -37.6176330 ),
66
			'-55°, -37.6176330 °' => array( -55, -37.6176330 ),
67
			'5.5°S,37°W ' => array( -5.5, -37 ),
68
			'-5.5°,-37° ' => array( -5.5, -37 ),
69
			'-55° -37.6176330 °' => array( -55, -37.6176330 ),
70
			'5.5°S 37°W ' => array( -5.5, -37 ),
71
			'-5.5 ° -37 ° ' => array( -5.5, -37 ),
72
			'S5.5° W37°' => array( -5.5, -37 ),
73
74
			// DMS
75
			'55° 45\' 20.8296", 37° 37\' 3.4788"' => array( 55.755786, 37.6176330000 ),
76
			'55° 45\' 20.8296", -37° 37\' 3.4788"' => array( 55.755786, -37.6176330000 ),
77
			'-55° 45\' 20.8296", -37° 37\' 3.4788"' => array( -55.755786, -37.6176330000 ),
78
			'-55° 45\' 20.8296", 37° 37\' 3.4788"' => array( -55.755786, 37.6176330000 ),
79
			'55° 0\' 0", 37° 0\' 0"' => array( 55, 37 ),
80
			'55° 30\' 0", 37° 30\' 0"' => array( 55.5, 37.5 ),
81
			'55° 0\' 18", 37° 0\' 18"' => array( 55.005, 37.005 ),
82
			'0° 0\' 0", 0° 0\' 0"' => array( 0, 0 ),
83
			'0° 0\' 18" N, 0° 0\' 18" E' => array( 0.005, 0.005 ),
84
			' 0° 0\' 18" S  , 0°  0\' 18"  W ' => array( -0.005, -0.005 ),
85
			'0° 0′ 18″ N, 0° 0′ 18″ E' => array( 0.005, 0.005 ),
86
			'0° 0\' 18" N  0° 0\' 18" E' => array( 0.005, 0.005 ),
87
			' 0 ° 0 \' 18 " S   0 °  0 \' 18 "  W ' => array( -0.005, -0.005 ),
88
			'0° 0′ 18″ N 0° 0′ 18″ E' => array( 0.005, 0.005 ),
89
			'N 0° 0\' 18" E 0° 0\' 18"' => array( 0.005, 0.005 ),
90
91
			// DM
92
			'55° 0\', 37° 0\'' => array( 55, 37 ),
93
			'55° 30\', 37° 30\'' => array( 55.5, 37.5 ),
94
			'0° 0\', 0° 0\'' => array( 0, 0 ),
95
			'-55° 30\', -37° 30\'' => array( -55.5, -37.5 ),
96
			'0° 0.3\' S, 0° 0.3\' W' => array( -0.005, -0.005 ),
97
			'-55° 30′, -37° 30′' => array( -55.5, -37.5 ),
98
			'-55 ° 30 \' -37 ° 30 \'' => array( -55.5, -37.5 ),
99
			'0° 0.3\' S 0° 0.3\' W' => array( -0.005, -0.005 ),
100
			'-55° 30′ -37° 30′' => array( -55.5, -37.5 ),
101
			'S 0° 0.3\' W 0° 0.3\'' => array( -0.005, -0.005 ),
102
		);
103
104
		foreach ( $valid as $value => $expected ) {
105
			$expected = new LatLongValue( $expected[0], $expected[1] );
106
			$argLists[] = array( (string)$value, $expected );
107
		}
108
109
		return $argLists;
110
	}
111
112
	/**
113
	 * @see StringValueParserTest::invalidInputProvider
114
	 */
115
	public function invalidInputProvider() {
116
		$argLists = parent::invalidInputProvider();
117
118
		$invalid = array(
119
			'~=[,,_,,]:3',
120
			'ohi there',
121
		);
122
123
		foreach ( $invalid as $value ) {
124
			$argLists[] = array( $value );
125
		}
126
127
		return $argLists;
128
	}
129
130
}
131