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 yield 'no format' => 23 [ 24 '{today name:space}', 25 [ 26 'namespace' => 'name:space', 27 'format' => null, 28 ], 29 'name:space:' . date('Y-m-d'), 30 ]; 31 32 yield 'custom format' => [ 33 '{today name:space Y:Y-m-d}', 34 [ 35 'namespace' => 'name:space', 36 'format' => 'Y:Y-m-d', 37 ], 38 'name:space:' . date('Y:Y-m-d') 39 ]; 40 } 41 42 /** 43 * @dataProvider parseMatchTestDataProvider 44 */ 45 public function testParseMatch(string $input, array $expectedPluginInstructionData, string $expectedPageId): void { 46 /** @var syntax_plugin_today_today $syntax */ 47 $syntax = plugin_load('syntax', 'today_today'); 48 49 $actualPluginInstructionData = $syntax->handle($input, 5, 1, new Doku_Handler()); 50 51 self::assertEquals($expectedPluginInstructionData, $actualPluginInstructionData); 52 53 $mockRenderer = $this->createMock(Doku_Renderer::class); 54 $mockRenderer->expects(self::once()) 55 ->method('internallink') 56 ->with($expectedPageId, 'today'); 57 58 $actualStatus = $syntax->render('xhtml', $mockRenderer, $actualPluginInstructionData); 59 60 self::assertTrue($actualStatus); 61 } 62 63 public function testRendererMeta(): void { 64 /** @var syntax_plugin_today_today $syntax */ 65 $syntax = plugin_load('syntax', 'today_today'); 66 $testData = [ 67 'namespace' => 'name:space', 68 ]; 69 $mockRenderer = $this->createMock(Doku_Renderer::class); 70 $mockRenderer->expects(self::never()) 71 ->method('internallink'); 72 73 $actualStatus = $syntax->render('meta', $mockRenderer, $testData); 74 75 self::assertFalse($actualStatus); 76 } 77} 78