1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maps\Test; |
4
|
|
|
|
5
|
|
|
use DataValues\LatLongValue; |
6
|
|
|
use Maps\Elements\Location; |
7
|
|
|
use Maps\LocationParser; |
8
|
|
|
use Title; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers Maps\LocationParser |
12
|
|
|
* @licence GNU GPL v2+ |
13
|
|
|
* @author Jeroen De Dauw < [email protected] > |
14
|
|
|
*/ |
15
|
|
|
class LocationParserTest extends \ValueParsers\Test\StringValueParserTest { |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @see ValueParserTestBase::validInputProvider |
19
|
|
|
* |
20
|
|
|
* @since 3.0 |
21
|
|
|
* |
22
|
|
|
* @return array |
23
|
|
|
*/ |
24
|
|
|
public function validInputProvider() { |
25
|
|
|
$argLists = array(); |
26
|
|
|
|
27
|
|
|
$valid = array( |
28
|
|
|
'55.7557860 N, 37.6176330 W' => array( 55.7557860, -37.6176330 ), |
29
|
|
|
'55.7557860, -37.6176330' => array( 55.7557860, -37.6176330 ), |
30
|
|
|
'55 S, 37.6176330 W' => array( -55, -37.6176330 ), |
31
|
|
|
'-55, -37.6176330' => array( -55, -37.6176330 ), |
32
|
|
|
'5.5S,37W ' => array( -5.5, -37 ), |
33
|
|
|
'-5.5,-37 ' => array( -5.5, -37 ), |
34
|
|
|
'4,2' => array( 4, 2 ), |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
foreach ( $valid as $value => $expected ) { |
38
|
|
|
$expected = new Location( new LatLongValue( $expected[0], $expected[1] ) ); |
39
|
|
|
$argLists[] = array( (string)$value, $expected ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$location = new Location( new LatLongValue( 4, 2 ) ); |
43
|
|
|
$location->setTitle( 'Title' ); |
44
|
|
|
$location->setText( 'some description' ); |
45
|
|
|
$argLists[] = array( '4,2~Title~some description', $location ); |
46
|
|
|
|
47
|
|
|
return $argLists; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @see ValueParserTestBase::getParserClass |
52
|
|
|
* |
53
|
|
|
* @since 3.0 |
54
|
|
|
* |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
protected function getParserClass() { |
58
|
|
|
return 'Maps\LocationParser'; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @see ValueParserTestBase::requireDataValue |
63
|
|
|
* |
64
|
|
|
* @since 3.0 |
65
|
|
|
* |
66
|
|
|
* @return boolean |
67
|
|
|
*/ |
68
|
|
|
protected function requireDataValue() { |
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @dataProvider titleProvider |
74
|
|
|
*/ |
75
|
|
|
public function testGivenTitleThatIsNotLink_titleIsSetAndLinkIsNot( $title ) { |
76
|
|
|
$parser = new LocationParser(); |
77
|
|
|
$location = $parser->parse( '4,2~' . $title ); |
78
|
|
|
|
79
|
|
|
$this->assertTitleAndLinkAre( $location, $title, '' ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function titleProvider() { |
83
|
|
|
return array( |
84
|
|
|
array( '' ), |
85
|
|
|
array( 'Title' ), |
86
|
|
|
array( 'Some title' ), |
87
|
|
|
array( 'link' ), |
88
|
|
|
array( 'links:foo' ), |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
protected function assertTitleAndLinkAre( Location $location, $title, $link ) { |
93
|
|
|
$this->assertHasJsonKeyWithValue( $location, 'title', $title ); |
94
|
|
|
$this->assertHasJsonKeyWithValue( $location, 'link', $link ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
protected function assertHasJsonKeyWithValue( Location $polygon, $key, $value ) { |
98
|
|
|
$json = $polygon->getJSONObject(); |
99
|
|
|
|
100
|
|
|
$this->assertArrayHasKey( $key, $json ); |
101
|
|
|
$this->assertEquals( |
102
|
|
|
$value, |
103
|
|
|
$json[$key] |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @dataProvider linkProvider |
109
|
|
|
*/ |
110
|
|
|
public function testGivenTitleThatIsLink_linkIsSetAndTitleIsNot( $link ) { |
111
|
|
|
$parser = new LocationParser(); |
112
|
|
|
$location = $parser->parse( '4,2~link:' . $link ); |
113
|
|
|
|
114
|
|
|
$this->assertTitleAndLinkAre( $location, '', $link ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function linkProvider() { |
118
|
|
|
return array( |
119
|
|
|
array( 'https://semantic-mediawiki.org' ), |
120
|
|
|
array( 'http://www.semantic-mediawiki.org' ), |
121
|
|
|
array( 'irc://freenode.net' ), |
122
|
|
|
); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @dataProvider titleLinkProvider |
127
|
|
|
*/ |
128
|
|
|
// public function testGivenPageTitleAsLink_pageTitleIsTurnedIntoUrl( $link ) { |
129
|
|
|
// $parser = new LocationParser(); |
130
|
|
|
// $location = $parser->parse( '4,2~link:' . $link ); |
131
|
|
|
// |
132
|
|
|
// $linkUrl = Title::newFromText( $link )->getFullURL(); |
133
|
|
|
// $this->assertTitleAndLinkAre( $location, '', $linkUrl ); |
134
|
|
|
// } |
135
|
|
|
// |
136
|
|
|
// public function titleLinkProvider() { |
137
|
|
|
// return array( |
138
|
|
|
// array( 'Foo' ), |
139
|
|
|
// array( 'Some_Page' ), |
140
|
|
|
// ); |
141
|
|
|
// } |
142
|
|
|
|
143
|
|
|
} |
144
|
|
|
|