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

LeafletTest::parse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\Tests\Integration\Parser;
6
7
use Maps\Tests\MapsTestFactory;
8
use Maps\Tests\TestDoubles\ImageValueObject;
9
use MediaWiki\MediaWikiServices;
10
use PHPUnit\Framework\TestCase;
11
12
class LeafletTest extends TestCase {
13
14
	private function parse( string $textToParse ): string {
15
		$parser = MediaWikiServices::getInstance()->getParser();
16
17
		return $parser->parse( $textToParse, \Title::newMainPage(), new \ParserOptions() )->getText();
18
	}
19
20
	public function testLeafletImageLayersIgnoresNotFoundImages() {
21
		$this->assertContains(
22
			'"imageLayers":[]',
23
			$this->parse(
24
				"{{#leaflet:image layers=404.png}}"
25
			)
26
		);
27
	}
28
29
	public function testLeafletImageLayersIgnoresImageUrls() {
30
		$this->assertContains(
31
			'"imageLayers":[]',
32
			$this->parse(
33
				"{{#leaflet:image layers=https://user-images.githubusercontent.com/62098559/76514021-3fa9be80-647d-11ea-82ae-715420a5c432.png}}"
34
			)
35
		);
36
	}
37
38
	public function testLeafletImageLayer() {
39
		$factory = MapsTestFactory::newTestInstance();
40
41
		$factory->imageRepo->addImage(
42
			'MyImage.png',
43
			new ImageValueObject( '/tmp/example/image.png', 40, 20 )
44
		);
45
46
		$html = $this->parse( "{{#leaflet:image layers=MyImage.png}}" );
47
48
		$this->assertContains( '"name":"MyImage.png"', $html );
49
		$this->assertContains( '"url":"/tmp/example/image.png"', $html );
50
		$this->assertContains( '"width":100', $html );
51
		$this->assertContains( '"height":50', $html );
52
	}
53
54
}
55