|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Maps\Test; |
|
4
|
|
|
|
|
5
|
|
|
use DataValues\Geo\Values\LatLongValue; |
|
6
|
|
|
use Jeroen\SimpleGeocoder\Geocoders\InMemoryGeocoder; |
|
7
|
|
|
use Maps\Elements\Line; |
|
8
|
|
|
use Maps\LineParser; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @covers \Maps\LineParser |
|
12
|
|
|
* @licence GNU GPL v2+ |
|
13
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
14
|
|
|
*/ |
|
15
|
|
|
class LineParserTest extends \PHPUnit_Framework_TestCase { |
|
16
|
|
|
|
|
17
|
|
|
public function setUp() { |
|
18
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) { |
|
19
|
|
|
$this->markTestSkipped( 'MediaWiki is not available' ); |
|
20
|
|
|
} |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function testGivenOneCoordinate_lineWithOneCoordinateIsReturned() { |
|
24
|
|
|
$parser = $this->newParser(); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertEquals( |
|
27
|
|
|
new Line( [ new LatLongValue( 4, 2 ) ] ), |
|
28
|
|
|
$parser->parse( '4,2' ) |
|
29
|
|
|
); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @return LineParser |
|
34
|
|
|
*/ |
|
35
|
|
|
private function newParser() { |
|
36
|
|
|
$parser = new LineParser(); |
|
37
|
|
|
|
|
38
|
|
|
$parser->setGeocoder( |
|
39
|
|
|
new InMemoryGeocoder( |
|
40
|
|
|
[ |
|
41
|
|
|
'4,2' => new LatLongValue( 4, 2 ), |
|
42
|
|
|
'2,3' => new LatLongValue( 2, 3 ), |
|
43
|
|
|
] |
|
44
|
|
|
) |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
return $parser; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testGivenTwoCoordinates_lineWithBothCoordinateIsReturned() { |
|
51
|
|
|
$parser = $this->newParser(); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertEquals( |
|
54
|
|
|
new Line( |
|
55
|
|
|
[ |
|
56
|
|
|
new LatLongValue( 4, 2 ), |
|
57
|
|
|
new LatLongValue( 2, 3 ) |
|
58
|
|
|
] |
|
59
|
|
|
), |
|
60
|
|
|
$parser->parse( '4,2:2,3' ) |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testTitleAndTextGetSetWhenPresent() { |
|
65
|
|
|
$parser = $this->newParser(); |
|
66
|
|
|
|
|
67
|
|
|
$expectedLine = new Line( |
|
68
|
|
|
[ |
|
69
|
|
|
new LatLongValue( 4, 2 ), |
|
70
|
|
|
new LatLongValue( 2, 3 ) |
|
71
|
|
|
] |
|
72
|
|
|
); |
|
73
|
|
|
$expectedLine->setTitle( 'title' ); |
|
74
|
|
|
$expectedLine->setText( 'text' ); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertEquals( |
|
77
|
|
|
$expectedLine, |
|
78
|
|
|
$parser->parse( '4,2:2,3~title~text' ) |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|