Completed
Push — leaflet-attribution ( 0121c0 )
by Peter
04:35
created

LineParserTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 68
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 2
A testGivenOneCoordinate_lineWithOneCoordinateIsReturned() 0 8 1
A newParser() 0 14 1
A testGivenTwoCoordinates_lineWithBothCoordinateIsReturned() 0 13 1
A testTitleAndTextGetSetWhenPresent() 0 17 1
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