Completed
Push — oldjunk ( 6d7aaf...37c282 )
by Jeroen De
02:36
created

DisplayMapTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 79
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A testMapIdIsSet() 0 6 1
A parse() 0 5 1
A testServiceSelectionWorks() 0 6 1
A testSingleCoordinatesAreIncluded() 0 6 1
A testMultipleCoordinatesAreIncluded() 0 6 1
A testWhenValidZoomIsSpecified_itGetsUsed() 0 6 1
A testWhenZoomIsNotSpecifiedAndThereIsOnlyOneLocation_itIsDefaulted() 0 6 1
A testWhenZoomIsNotSpecifiedAndThereAreMultipleLocations_itIsDefaulted() 0 6 1
A testWhenZoomIsInvalid_itIsDefaulted() 0 6 1
A testTagIsRendered() 0 6 1
A testTagServiceParameterIsUsed() 0 6 1
1
<?php
2
3
namespace Maps\Test;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * @licence GNU GPL v2+
9
 * @author Jeroen De Dauw < [email protected] >
10
 */
11
class DisplayMapTest extends TestCase {
12
13
	public function testMapIdIsSet() {
14
		$this->assertContains(
15
			'id="map_leaflet_',
16
			$this->parse( '{{#display_map:1,1|service=leaflet}}' )
17
		);
18
	}
19
20
	private function parse( string $textToParse ): string {
21
		$parser = new \Parser();
22
23
		return $parser->parse( $textToParse, \Title::newMainPage(), new \ParserOptions() )->getText();
24
	}
25
26
	public function testServiceSelectionWorks() {
27
		$this->assertContains(
28
			'maps-googlemaps3',
29
			$this->parse( '{{#display_map:1,1|service=google}}' )
30
		);
31
	}
32
33
	public function testSingleCoordinatesAreIncluded() {
34
		$this->assertContains(
35
			'"lat":1,"lon":1',
36
			$this->parse( '{{#display_map:1,1}}' )
37
		);
38
	}
39
40
	public function testMultipleCoordinatesAreIncluded() {
41
		$result = $this->parse( '{{#display_map:1,1; 4,2}}' );
42
43
		$this->assertContains( '"lat":1,"lon":1', $result );
44
		$this->assertContains( '"lat":4,"lon":2', $result );
45
	}
46
47
	public function testWhenValidZoomIsSpecified_itGetsUsed() {
48
		$this->assertContains(
49
			'"zoom":5',
50
			$this->parse( '{{#display_map:1,1|service=google|zoom=5}}' )
51
		);
52
	}
53
54
	public function testWhenZoomIsNotSpecifiedAndThereIsOnlyOneLocation_itIsDefaulted() {
55
		$this->assertContains(
56
			'"zoom":' . $GLOBALS['egMapsGMaps3Zoom'],
57
			$this->parse( '{{#display_map:1,1|service=google}}' )
58
		);
59
	}
60
61
	public function testWhenZoomIsNotSpecifiedAndThereAreMultipleLocations_itIsDefaulted() {
62
		$this->assertContains(
63
			'"zoom":false',
64
			$this->parse( '{{#display_map:1,1;2,2|service=google}}' )
65
		);
66
	}
67
68
	public function testWhenZoomIsInvalid_itIsDefaulted() {
69
		$this->assertContains(
70
			'"zoom":' . $GLOBALS['egMapsGMaps3Zoom'],
71
			$this->parse( '{{#display_map:1,1|service=google|zoom=tomato}}' )
72
		);
73
	}
74
75
	public function testTagIsRendered() {
76
		$this->assertContains(
77
			'"lat":1,"lon":1',
78
			$this->parse( '<display_map>1,1</display_map>' )
79
		);
80
	}
81
82
	public function testTagServiceParameterIsUsed() {
83
		$this->assertContains(
84
			'maps-googlemaps3',
85
			$this->parse( '<display_map service="google">1,1</display_map>' )
86
		);
87
	}
88
89
}