xref: /plugin/dwtimeline/_test/OptionsParserTest.php (revision 545c554be65100e9bb5eff6d4aa54c829680442a)
1*545c554bSsaggi-dw<?php
2*545c554bSsaggi-dw
3*545c554bSsaggi-dwnamespace dokuwiki\plugin\dwtimeline\test;
4*545c554bSsaggi-dw
5*545c554bSsaggi-dwuse DokuWikiTest;
6*545c554bSsaggi-dwuse syntax_plugin_dwtimeline_dwtimeline;
7*545c554bSsaggi-dw
8*545c554bSsaggi-dwclass OptionsParserTest extends DokuWikiTest
9*545c554bSsaggi-dw{
10*545c554bSsaggi-dw    protected $pluginsEnabled = ['dwtimeline'];
11*545c554bSsaggi-dw
12*545c554bSsaggi-dw    public function test_quoted_and_unquoted_values()
13*545c554bSsaggi-dw    {
14*545c554bSsaggi-dw        $sx   = new syntax_plugin_dwtimeline_dwtimeline();
15*545c554bSsaggi-dw        $data = $sx->getTitleMatches('title="Release 2025-05-14" align=vert data=2025');
16*545c554bSsaggi-dw
17*545c554bSsaggi-dw        $this->assertSame(hsc('Release 2025-05-14'), $data['title']);
18*545c554bSsaggi-dw        $this->assertSame('vert', $data['align']);
19*545c554bSsaggi-dw        $this->assertStringContainsString('data-point="2025"', $data['data']);
20*545c554bSsaggi-dw    }
21*545c554bSsaggi-dw
22*545c554bSsaggi-dw    public function test_values_with_quotes_and_escapes()
23*545c554bSsaggi-dw    {
24*545c554bSsaggi-dw        $sx = new syntax_plugin_dwtimeline_dwtimeline();
25*545c554bSsaggi-dw        // test quotes
26*545c554bSsaggi-dw        $data = $sx->getTitleMatches('title="He said \"Hi\" & it\'s fine"');
27*545c554bSsaggi-dw
28*545c554bSsaggi-dw        $this->assertSame(hsc('He said "Hi" & it\'s fine'), $data['title']);
29*545c554bSsaggi-dw    }
30*545c554bSsaggi-dw
31*545c554bSsaggi-dw    public function test_flag_and_empty_value()
32*545c554bSsaggi-dw    {
33*545c554bSsaggi-dw        $sx   = new syntax_plugin_dwtimeline_dwtimeline();
34*545c554bSsaggi-dw        $data = $sx->getTitleMatches("foo style=''");
35*545c554bSsaggi-dw
36*545c554bSsaggi-dw        $this->assertArrayHasKey('foo', $data);
37*545c554bSsaggi-dw        $this->assertSame('', $data['foo']);
38*545c554bSsaggi-dw        $this->assertSame('', $data['style']); // style is empty
39*545c554bSsaggi-dw    }
40*545c554bSsaggi-dw
41*545c554bSsaggi-dw    public function test_internal_external_interwiki_email_links()
42*545c554bSsaggi-dw    {
43*545c554bSsaggi-dw        $sx = new syntax_plugin_dwtimeline_dwtimeline();
44*545c554bSsaggi-dw
45*545c554bSsaggi-dw        // intern
46*545c554bSsaggi-dw        $this->assertSame('wiki:start', $sx->getLink('[[wiki:start|Go]]'));
47*545c554bSsaggi-dw        // extern (bracketed)
48*545c554bSsaggi-dw        $this->assertSame('https://example.com', $sx->getLink('[[https://example.com|x]]'));
49*545c554bSsaggi-dw        // raw URL (fallback)
50*545c554bSsaggi-dw        $this->assertSame('https://example.com', $sx->getLink('See https://example.com now'));
51*545c554bSsaggi-dw        // interwiki
52*545c554bSsaggi-dw        $this->assertSame('doku>interwiki', $sx->getLink('[[doku>interwiki]]'));
53*545c554bSsaggi-dw        // email
54*545c554bSsaggi-dw        $this->assertSame('mailto:test@example.com', $sx->getLink('test@example.com'));
55*545c554bSsaggi-dw    }
56*545c554bSsaggi-dw
57*545c554bSsaggi-dw    public function test_regression_unmatched_groups_do_not_warn()
58*545c554bSsaggi-dw    {
59*545c554bSsaggi-dw        $sx   = new syntax_plugin_dwtimeline_dwtimeline();
60*545c554bSsaggi-dw        $data = $sx->getTitleMatches('title=foo bar');
61*545c554bSsaggi-dw        $this->assertSame(hsc('foo'), $data['title']);
62*545c554bSsaggi-dw        $this->assertArrayHasKey('bar', $data);
63*545c554bSsaggi-dw        $this->assertSame('', $data['bar']);
64*545c554bSsaggi-dw    }
65*545c554bSsaggi-dw
66*545c554bSsaggi-dw    public function test_interwiki_in_milestone_title()
67*545c554bSsaggi-dw    {
68*545c554bSsaggi-dw        saveWikiText(
69*545c554bSsaggi-dw            'playground:src',
70*545c554bSsaggi-dw            '====== T ======
71*545c554bSsaggi-dw===== M =====',
72*545c554bSsaggi-dw            'setup'
73*545c554bSsaggi-dw        );
74*545c554bSsaggi-dw
75*545c554bSsaggi-dw        $html = p_render(
76*545c554bSsaggi-dw            'xhtml',
77*545c554bSsaggi-dw            p_get_instructions('<milestone title="X" link="[[doku>interwiki]]"></milestone>'),
78*545c554bSsaggi-dw            $info
79*545c554bSsaggi-dw        );
80*545c554bSsaggi-dw
81*545c554bSsaggi-dw        $this->assertStringContainsString('class="interwiki iw_doku"', $html);
82*545c554bSsaggi-dw    }
83*545c554bSsaggi-dw}
84