1<?php 2 3declare(strict_types=1); 4 5namespace dokuwiki\plugin\simplemap\test; 6 7use Doku_Handler; 8use dokuwiki\test\mock\Doku_Renderer; 9use syntax_plugin_simplemap; 10use DokuWikiTest; 11 12/** 13 * Tests for the syntax component of the simplemap plugin 14 * 15 * @group plugin_simplemap 16 * @group plugins 17 */ 18class SyntaxTest extends DokuWikiTest { 19 protected $pluginsEnabled = ['simplemap']; 20 21 public static function parseMatchTestDataProvider () { 22 return [ 23 [ 24 '{{simplemap>osm?lat=50.234&long=13.123}}', 25 [ 26 'type' => 'osm', 27 'lat' => '50.234', 28 'long' => '13.123', 29 ], 30 'simple example' 31 ], 32 ]; 33 } 34 35 /** 36 * @dataProvider parseMatchTestDataProvider 37 * 38 * @param $input 39 * @param $expectedOutput 40 * @param $msg 41 */ 42 public function testParseMatch($input, $expectedOutput, $msg) { 43 // arrange 44 /** @var syntax_plugin_simplemap $syntax */ 45 $syntax = plugin_load('syntax', 'simplemap'); 46 47 // act 48 $actualOutput = $syntax->handle($input, 5, 1, new Doku_Handler()); 49 50 // assert 51 self::assertEquals($expectedOutput, $actualOutput, $msg); 52 } 53 54 public function testRendererXHTML() { 55 /** @var syntax_plugin_simplemap $syntax */ 56 $syntax = plugin_load('syntax', 'simplemap'); 57 $testData = [ 58 'type' => 'osm', 59 'lat' => '50.234', 60 'long' => '13.123', 61 ]; 62 $mockRenderer = new Doku_Renderer(); 63 64 $actualStatus = $syntax->render('xhtml', $mockRenderer, $testData); 65 66 self::assertTrue($actualStatus); 67 $expectedHTML = '<iframe width="425" height="350" src="https://www.openstreetmap.org/export/embed.html?bbox=13.119%2C50.232%2C13.127%2C50.236&layer=mapnik&marker=50.234%2C13.123"></iframe><br><a href="https://www.openstreetmap.org/#map=14/50.234/13.123" target="_blank">View Larger Map</a>'; 68 self::assertSame($expectedHTML, $mockRenderer->doc); 69 } 70 71 public function testRendererMeta() { 72 /** @var syntax_plugin_simplemap $syntax */ 73 $syntax = plugin_load('syntax', 'simplemap'); 74 $testData = [ 75 'type' => 'osm', 76 'lat' => '50.234', 77 'long' => '13.123', 78 ]; 79 $mockRenderer = new Doku_Renderer(); 80 81 $actualStatus = $syntax->render('meta', $mockRenderer, $testData); 82 83 self::assertFalse($actualStatus); 84 self::assertSame('', $mockRenderer->doc); 85 } 86} 87