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;
10use DokuWikiTest;
11
12/**
13 * Tests for the syntax component of the today plugin
14 *
15 * @group plugin_today
16 * @group plugins
17 */
18class SyntaxTest extends DokuWikiTest {
19    protected $pluginsEnabled = ['today'];
20
21    public static function parseMatchTestDataProvider () {
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     * @param $input
37     * @param $expectedOutput
38     * @param $msg
39     */
40    public function testParseMatch($input, $expectedOutput, $msg) {
41        // arrange
42        /** @var syntax_plugin_today $syntax */
43        $syntax = plugin_load('syntax', 'today');
44
45        // act
46        $actualOutput = $syntax->handle($input, 5, 1, new Doku_Handler());
47
48        // assert
49        self::assertEquals($expectedOutput, $actualOutput, $msg);
50    }
51
52    public function testRendererXHTML() {
53        /** @var syntax_plugin_today $syntax */
54        $syntax = plugin_load('syntax', 'today');
55        $testData = [
56            'namespace' => 'name:space',
57        ];
58        $today = date('Y-m-d');
59
60        $mockRenderer = $this->createMock(Doku_Renderer::class);
61        $mockRenderer->expects(self::once())
62            ->method('internallink')
63            ->with($testData['namespace'] . ':' . $today, 'today');
64
65        $actualStatus = $syntax->render('xhtml', $mockRenderer, $testData);
66
67        self::assertTrue($actualStatus);
68    }
69
70    public function testRendererMeta() {
71        /** @var syntax_plugin_today $syntax */
72        $syntax = plugin_load('syntax', 'today');
73        $testData = [
74            'namespace' => 'name:space',
75        ];
76        $mockRenderer = $this->createMock(Doku_Renderer::class);
77        $mockRenderer->expects(self::never())
78            ->method('internallink');
79
80        $actualStatus = $syntax->render('meta', $mockRenderer, $testData);
81
82        self::assertFalse($actualStatus);
83    }
84}
85