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
|
|
|
|