1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maps\Tests\Integration\MediaWiki\ParserHooks; |
4
|
|
|
|
5
|
|
|
use DataValues\Geo\Parsers\LatLongParser; |
6
|
|
|
use Maps\Elements\Location; |
7
|
|
|
use Maps\MediaWiki\ParserHooks\FindDestinationFunction; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers FindDestinationFunction |
11
|
|
|
* |
12
|
|
|
* @licence GNU GPL v2+ |
13
|
|
|
* @author Jeroen De Dauw < [email protected] > |
14
|
|
|
*/ |
15
|
|
|
class FinddestinationTest extends ParserHookTest { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string[] |
19
|
|
|
*/ |
20
|
|
|
private $locations = [ |
21
|
|
|
'4,2', |
22
|
|
|
'4.2,-42', |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
private $bearings = [ |
26
|
|
|
1, |
27
|
|
|
42, |
28
|
|
|
-42, |
29
|
|
|
0, |
30
|
|
|
4.2, |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
private $distances = [ |
34
|
|
|
'42' => 42, |
35
|
|
|
'0' => 0, |
36
|
|
|
'42 m' => 42, |
37
|
|
|
'42 km' => 42000, |
38
|
|
|
'4.2 km' => 4200, |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @see ParserHookTest::parametersProvider |
43
|
|
|
*/ |
44
|
|
|
public function parametersProvider() { |
45
|
|
|
$paramLists = []; |
46
|
|
|
|
47
|
|
|
$paramLists[] = [ |
48
|
|
|
'location' => '4,2', |
49
|
|
|
'bearing' => '1', |
50
|
|
|
'distance' => '42 km' |
51
|
|
|
]; |
52
|
|
|
|
53
|
|
|
return $this->arrayWrap( $paramLists ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @see ParserHookTest::processingProvider |
58
|
|
|
*/ |
59
|
|
|
public function processingProvider() { |
60
|
|
|
$argLists = []; |
61
|
|
|
|
62
|
|
|
$coordinateParser = new LatLongParser(); |
63
|
|
|
|
64
|
|
|
foreach ( $this->distances as $distance => $expectedDistance ) { |
65
|
|
|
foreach ( $this->bearings as $bearing ) { |
66
|
|
|
foreach ( $this->locations as $locationString ) { |
67
|
|
|
$values = [ |
68
|
|
|
'distance' => (string)$distance, |
69
|
|
|
'bearing' => (string)$bearing, |
70
|
|
|
'location' => (string)$locationString, |
71
|
|
|
]; |
72
|
|
|
|
73
|
|
|
$expected = [ |
74
|
|
|
'distance' => $expectedDistance, |
75
|
|
|
'bearing' => (float)$bearing, |
76
|
|
|
'location' => new Location( $coordinateParser->parse( $locationString )->getValue() ), |
77
|
|
|
]; |
78
|
|
|
|
79
|
|
|
$argLists[] = [ $values, $expected ]; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $argLists; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @see ParserHookTest::getInstance |
89
|
|
|
*/ |
90
|
|
|
protected function getInstance() { |
91
|
|
|
return new \Maps\MediaWiki\ParserHooks\FindDestinationFunction(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
} |