1<?php
2
3/**
4 * DokuWiki Comment Syntax Plugin tests
5 *
6 * @group plugin_commentsyntax
7 * @group plugins
8 */
9class plugin_commentsyntax_test extends DokuWikiTest
10{
11    protected $pluginsEnabled = array('commentsyntax');
12
13    public static function setUpBeforeClass() : void
14    {
15        parent::setUpBeforeClass();
16      //TestUtils::rcopy(dirname(DOKU_CONF), dirname(__FILE__).'/conf');
17    }
18
19    public function setup() : void
20    {
21        global $conf;
22        parent::setup();
23        $conf ['plugin']['commentsyntax']['use_cstyle_nest']   = 1;
24        $conf ['plugin']['commentsyntax']['use_oneline_style'] = 1;
25        $conf ['plugin']['commentsyntax']['log_invalid_macro'] = 0;
26    }
27
28    // remove newlines from string
29    private function normalizeLineEndings($s, $eol = '')
30    {
31        return str_replace(["\r", "\n"], $eol, $s);
32    }
33
34    private function getHTML($text)
35    {
36        $instructions = p_get_instructions($text);
37        $xhtml = p_render('xhtml', $instructions, $info);
38        return $this->normalizeLineEndings($xhtml);
39    }
40
41    /**
42     * C-style comment syntax
43     */
44    function test_cstyle_syntax()
45    {
46        $text = "\nWiki /* comment out */ text\n";
47        $expectHtml = '<p>Wiki text</p>';
48        $this->assertEquals($expectHtml, $this->getHtml($text));
49
50        $text = <<<'EOS'
51              * item 1
52            /** item 2  omit this line! */
53              * item 3
54
55            EOS;
56        $expectHtml = '<ul>'
57            .'<li class="level1"><div class="li"> item 1</div></li>'
58            .'<li class="level1"><div class="li"> item 3</div></li>'
59            .'</ul>';
60        $this->assertEquals($expectHtml, $this->getHtml($text));
61
62        // nested comment
63        $text = <<<'EOS'
64            /** item 1
65            /** item 2  omit this line! */
66              * item 3   */
67              * item 4
68
69            EOS;
70        $expectHtml = '<ul>'
71            .'<li class="level1"><div class="li"> item 4</div></li>'
72            .'</ul>';
73        $this->assertEquals($expectHtml, $this->getHtml($text));
74    }
75
76    /**
77     * One line comment
78     */
79    function test_oneline_syntax()
80    {
81        $text = "\nWiki text // allow slash (/) in one line comment\n";
82        $expectHtml = '<p>Wiki text</p>';
83        $this->assertEquals($expectHtml, $this->getHtml($text));
84
85        $text = "\nWiki //text// // allow slash (/) in one line comment\n";
86        $expectHtml = '<p>Wiki <em>text</em></p>';
87        $this->assertEquals($expectHtml, $this->getHtml($text));
88    }
89}
90// vim:set fileencoding=utf-8 :
91