Completed
Push — MediaWikiFileUrlFinderTest ( d58bee...394f02 )
by Jeroen De
08:48
created

testTitleAndTextGetSetWhenPresent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Maps\Tests\Integration\parsers;
4
5
use DataValues\Geo\Values\LatLongValue;
6
use Jeroen\SimpleGeocoder\Geocoders\InMemoryGeocoder;
7
use Maps\Elements\Line;
8
use Maps\Presentation\WikitextParsers\LineParser;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * @covers \Maps\Presentation\WikitextParsers\LineParser
13
 * @licence GNU GPL v2+
14
 * @author Jeroen De Dauw < [email protected] >
15
 */
16
class LineParserTest extends TestCase {
17
18
	public function testGivenOneCoordinate_lineWithOneCoordinateIsReturned() {
19
		$parser = $this->newParser();
20
21
		$this->assertEquals(
22
			new Line( [ new LatLongValue( 4, 2 ) ] ),
23
			$parser->parse( '4,2' )
24
		);
25
	}
26
27
	/**
28
	 * @return \Maps\Presentation\WikitextParsers\LineParser
29
	 */
30
	private function newParser() {
31
		$parser = new LineParser();
32
33
		$parser->setGeocoder(
34
			new InMemoryGeocoder(
35
				[
36
					'4,2' => new LatLongValue( 4, 2 ),
37
					'2,3' => new LatLongValue( 2, 3 ),
38
				]
39
			)
40
		);
41
42
		return $parser;
43
	}
44
45
	public function testGivenTwoCoordinates_lineWithBothCoordinateIsReturned() {
46
		$parser = $this->newParser();
47
48
		$this->assertEquals(
49
			new Line(
50
				[
51
					new LatLongValue( 4, 2 ),
52
					new LatLongValue( 2, 3 )
53
				]
54
			),
55
			$parser->parse( '4,2:2,3' )
56
		);
57
	}
58
59
	public function testTitleAndTextGetSetWhenPresent() {
60
		$parser = $this->newParser();
61
62
		$expectedLine = new Line(
63
			[
64
				new LatLongValue( 4, 2 ),
65
				new LatLongValue( 2, 3 )
66
			]
67
		);
68
		$expectedLine->setTitle( 'title' );
69
		$expectedLine->setText( 'text' );
70
71
		$this->assertEquals(
72
			$expectedLine,
73
			$parser->parse( '4,2:2,3~title~text' )
74
		);
75
	}
76
77
}
78