summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/CoordinatesTest.php
blob: 9ee324fe22208a66eb50b3d8d70e62d6b1f54b98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php

namespace Maps\Tests\Integration\MediaWiki\ParserHooks;

use DataValues\Geo\Values\LatLongValue;
use Maps\MediaWiki\ParserHooks\CoordinatesFunction;
use ParamProcessor\ParamDefinition;

/**
 * @covers CoordinatesFunction
 *
 * @licence GNU GPL v2+
 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 */
class CoordinatesTest extends ParserHookTest {

	/**
	 * @see ParserHookTest::parametersProvider
	 */
	public function parametersProvider() {
		$paramLists = [];

		$paramLists[] = [
			[
				'location' => '4,2',
				'format' => 'dms',
				'directional' => 'no',
			],
			'4° 0\' 0.00", 2° 0\' 0.00"'
		];

		$paramLists[] = [
			[
				'location' => '55 S, 37.6176330 W',
				'format' => 'dms',
				'directional' => 'no',
			],
			'-55° 0\' 0.00", -37° 37\' 3.48"'
		];

		$paramLists[] = [
			[
				'location' => '4,2',
				'format' => 'float',
				'directional' => 'no',
			],
			'4, 2'
		];

		$paramLists[] = [
			[
				'location' => '-4,-2',
				'format' => 'float',
				'directional' => 'yes',
			],
			'4 S, 2 W'
		];

		$paramLists[] = [
			[
				'location' => '55 S, 37.6176330 W',
				'directional' => 'yes',
			],
			'55° 0\' 0.00" S, 37° 37\' 3.48" W'
		];

		return $paramLists;
	}

	/**
	 * @see ParserHookTest::processingProvider
	 */
	public function processingProvider() {
		$definitions = ParamDefinition::getCleanDefinitions( $this->getInstance()->getParamDefinitions() );
		$argLists = [];

		$values = [
			'location' => '4,2',
		];

		$expected = [
			'location' => new LatLongValue( 4, 2 ),
		];

		$argLists[] = [ $values, $expected ];

		$values = [
			'location' => '4,2',
			'directional' => $definitions['directional']->getDefault() ? 'no' : 'yes',
			'format' => 'dd',
		];

		$expected = [
			'location' => new LatLongValue( 4, 2 ),
			'directional' => !$definitions['directional']->getDefault(),
			'format' => 'dd',
		];

		$argLists[] = [ $values, $expected ];

		$values = [
			'location' => '4,2',
			'directional' => $definitions['directional']->getDefault() ? 'NO' : 'YES',
			'format' => ' DD ',
		];

		$expected = [
			'location' => new LatLongValue( 4, 2 ),
			'directional' => !$definitions['directional']->getDefault(),
			'format' => 'dd',
		];

		$argLists[] = [ $values, $expected ];

		return $argLists;
	}

	/**
	 * @see ParserHookTest::getInstance
	 */
	protected function getInstance() {
		return new \Maps\MediaWiki\ParserHooks\CoordinatesFunction();
	}

}