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