Completed
Push — master ( 4427e6...cf958e )
by Jeroen De
03:32 queued 11s
created

GoogleMapsTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 46
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 5 1
A testGoogleMapsKmlFiltersInvalidFileNames() 0 8 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
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\Tests\Integration\Parser;
6
7
use MediaWiki\MediaWikiServices;
8
use PHPUnit\Framework\TestCase;
9
10
class GoogleMapsTest extends TestCase {
11
12
	private function parse( string $textToParse ): string {
13
		$parser = MediaWikiServices::getInstance()->getParser();
14
15
		return $parser->parse( $textToParse, \Title::newMainPage(), new \ParserOptions() )->getText();
16
	}
17
18
	public function testGoogleMapsKmlFiltersInvalidFileNames() {
19
		$this->assertContains(
20
			'"kml":["ValidFile.kml"],',
21
			$this->parse(
22
				"{{#google_maps:kml=, ,ValidFile.kml ,}}"
23
			)
24
		);
25
	}
26
27
	public function testWhenValidZoomIsSpecified_itGetsUsed() {
28
		$this->assertContains(
29
			'"zoom":5',
30
			$this->parse( '{{#google_maps:1,1|zoom=5}}' )
31
		);
32
	}
33
34
	public function testWhenZoomIsNotSpecifiedAndThereIsOnlyOneLocation_itIsDefaulted() {
35
		$this->assertContains(
36
			'"zoom":' . $GLOBALS['egMapsGMaps3Zoom'],
37
			$this->parse( '{{#google_maps:1,1}}' )
38
		);
39
	}
40
41
	public function testWhenZoomIsNotSpecifiedAndThereAreMultipleLocations_itIsDefaulted() {
42
		$this->assertContains(
43
			'"zoom":false',
44
			$this->parse( '{{#google_maps:1,1;2,2}}' )
45
		);
46
	}
47
48
	public function testWhenZoomIsInvalid_itIsDefaulted() {
49
		$this->assertContains(
50
			'"zoom":' . $GLOBALS['egMapsGMaps3Zoom'],
51
			$this->parse( '{{#google_maps:1,1|zoom=tomato}}' )
52
		);
53
	}
54
55
}
56