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