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