1<?php 2 3declare(strict_types=1); 4 5namespace dokuwiki\plugin\today\test; 6 7use Doku_Handler; 8use dokuwiki\test\mock\Doku_Renderer; 9use syntax_plugin_today_today; 10use DokuWikiTest; 11 12/** 13 * Tests for the `{today name:space}` syntax component of the today plugin 14 * 15 * @group plugin_today 16 * @group plugins 17 */ 18final class SyntaxTodayTest extends DokuWikiTest { 19 protected $pluginsEnabled = ['today']; 20 21 public static function parseMatchTestDataProvider(): iterable { 22 return [ 23 [ 24 '{today name:space}', 25 [ 26 'namespace' => 'name:space', 27 ], 28 'simple example' 29 ], 30 ]; 31 } 32 33 /** 34 * @dataProvider parseMatchTestDataProvider 35 */ 36 public function testParseMatch(string $input, array $expectedOutput, string $msg): void { 37 // arrange 38 /** @var syntax_plugin_today_today $syntax */ 39 $syntax = plugin_load('syntax', 'today_today'); 40 41 // act 42 $actualOutput = $syntax->handle($input, 5, 1, new Doku_Handler()); 43 44 // assert 45 self::assertEquals($expectedOutput, $actualOutput, $msg); 46 } 47 48 public function testRendererXHTML(): void { 49 /** @var syntax_plugin_today_today $syntax */ 50 $syntax = plugin_load('syntax', 'today_today'); 51 $testData = [ 52 'namespace' => 'name:space', 53 ]; 54 $today = date('Y-m-d'); 55 56 $mockRenderer = $this->createMock(Doku_Renderer::class); 57 $mockRenderer->expects(self::once()) 58 ->method('internallink') 59 ->with($testData['namespace'] . ':' . $today, 'today'); 60 61 $actualStatus = $syntax->render('xhtml', $mockRenderer, $testData); 62 63 self::assertTrue($actualStatus); 64 } 65 66 public function testRendererMeta(): void { 67 /** @var syntax_plugin_today_today $syntax */ 68 $syntax = plugin_load('syntax', 'today_today'); 69 $testData = [ 70 'namespace' => 'name:space', 71 ]; 72 $mockRenderer = $this->createMock(Doku_Renderer::class); 73 $mockRenderer->expects(self::never()) 74 ->method('internallink'); 75 76 $actualStatus = $syntax->render('meta', $mockRenderer, $testData); 77 78 self::assertFalse($actualStatus); 79 } 80} 81