xref: /plugin/today/_test/SyntaxTodayTest.php (revision c2de205a397cb4b27109538cf7248712fb4aa6e0)
18fb84481SMichael Große<?php
28fb84481SMichael Große
38fb84481SMichael Großedeclare(strict_types=1);
48fb84481SMichael Große
58fb84481SMichael Großenamespace dokuwiki\plugin\today\test;
68fb84481SMichael Große
78fb84481SMichael Großeuse Doku_Handler;
88fb84481SMichael Großeuse dokuwiki\test\mock\Doku_Renderer;
98fb84481SMichael Großeuse syntax_plugin_today_today;
108fb84481SMichael Großeuse DokuWikiTest;
118fb84481SMichael Große
128fb84481SMichael Große/**
138fb84481SMichael Große * Tests for the `{today name:space}` syntax component of the today plugin
148fb84481SMichael Große *
158fb84481SMichael Große * @group plugin_today
168fb84481SMichael Große * @group plugins
178fb84481SMichael Große */
188fb84481SMichael Großefinal class SyntaxTodayTest extends DokuWikiTest {
198fb84481SMichael Große    protected $pluginsEnabled = ['today'];
208fb84481SMichael Große
218fb84481SMichael Große    public static function parseMatchTestDataProvider(): iterable {
22*c2de205aSMichael Große        yield 'no format' =>
238fb84481SMichael Große            [
248fb84481SMichael Große                '{today name:space}',
258fb84481SMichael Große                [
268fb84481SMichael Große                    'namespace' => 'name:space',
27*c2de205aSMichael Große                    'format' => null,
288fb84481SMichael Große                ],
29*c2de205aSMichael Große                'name:space:' . date('Y-m-d'),
30*c2de205aSMichael Große            ];
31*c2de205aSMichael Große
32*c2de205aSMichael Große        yield 'custom format' => [
33*c2de205aSMichael Große            '{today name:space Y:Y-m-d}',
34*c2de205aSMichael Große            [
35*c2de205aSMichael Große                'namespace' => 'name:space',
36*c2de205aSMichael Große                'format' => 'Y:Y-m-d',
378fb84481SMichael Große            ],
38*c2de205aSMichael Große            'name:space:' . date('Y:Y-m-d')
398fb84481SMichael Große        ];
408fb84481SMichael Große    }
418fb84481SMichael Große
428fb84481SMichael Große    /**
438fb84481SMichael Große     * @dataProvider parseMatchTestDataProvider
448fb84481SMichael Große     */
45*c2de205aSMichael Große    public function testParseMatch(string $input, array $expectedPluginInstructionData, string $expectedPageId): void {
468fb84481SMichael Große        /** @var syntax_plugin_today_today $syntax */
478fb84481SMichael Große        $syntax = plugin_load('syntax', 'today_today');
488fb84481SMichael Große
49*c2de205aSMichael Große        $actualPluginInstructionData = $syntax->handle($input, 5, 1, new Doku_Handler());
508fb84481SMichael Große
51*c2de205aSMichael Große        self::assertEquals($expectedPluginInstructionData, $actualPluginInstructionData);
528fb84481SMichael Große
538fb84481SMichael Große        $mockRenderer = $this->createMock(Doku_Renderer::class);
548fb84481SMichael Große        $mockRenderer->expects(self::once())
558fb84481SMichael Große            ->method('internallink')
56*c2de205aSMichael Große            ->with($expectedPageId, 'today');
578fb84481SMichael Große
58*c2de205aSMichael Große        $actualStatus = $syntax->render('xhtml', $mockRenderer, $actualPluginInstructionData);
598fb84481SMichael Große
608fb84481SMichael Große        self::assertTrue($actualStatus);
618fb84481SMichael Große    }
628fb84481SMichael Große
638fb84481SMichael Große    public function testRendererMeta(): void {
648fb84481SMichael Große        /** @var syntax_plugin_today_today $syntax */
658fb84481SMichael Große        $syntax = plugin_load('syntax', 'today_today');
668fb84481SMichael Große        $testData = [
678fb84481SMichael Große            'namespace' => 'name:space',
688fb84481SMichael Große        ];
698fb84481SMichael Große        $mockRenderer = $this->createMock(Doku_Renderer::class);
708fb84481SMichael Große        $mockRenderer->expects(self::never())
718fb84481SMichael Große            ->method('internallink');
728fb84481SMichael Große
738fb84481SMichael Große        $actualStatus = $syntax->render('meta', $mockRenderer, $testData);
748fb84481SMichael Große
758fb84481SMichael Große        self::assertFalse($actualStatus);
768fb84481SMichael Große    }
778fb84481SMichael Große}
78