1<?php
2
3namespace dokuwiki\plugin\bureaucracy\test;
4
5use \Doku_Form;
6
7/**
8 * @group plugin_bureaucracy
9 * @group plugins
10 */
11class bureaucracy_replace_functions_test extends BureaucracyTest
12{
13
14    public function dataProvider()
15    {
16        return [
17            [
18                '@curNS@',
19                '',
20                '',
21                '@curNS@',
22                [],
23                '"@function@" shouldn\'t be replaced.',
24            ],
25            [
26                '@curNS()@',
27                '',
28                '',
29                '',
30                [],
31                '"@function()@" should return empty string.',
32            ],
33            [
34                '(@noNS(test):page)@)', //test doubled bracket
35                '',
36                '',
37                '(page)',
38                [],
39                '"@curNS(test:page))@" should return empty string.',
40            ],
41            [
42                '@curNS(test:static:value)@',
43                '',
44                '',
45                'static',
46                [],
47                '@curNS()@ doesn\'t work.',
48            ],
49            [
50                '@curNS(@@page@@)@',
51                'textbox page',
52                'some:test:page',
53                'test',
54                [],
55                '@curNS()@ doesn\'t work.',
56            ],
57            [
58                '@getNS(@@page@@)@',
59                'textbox page',
60                'some:test:page',
61                'some:test',
62                [],
63                '@getNS()@ doesn\'t work.',
64            ],
65            [
66                '@getNS(test:static:value)@',
67                '',
68                '',
69                'test:static',
70                [],
71                '@getNS()@ doesn\'t work.',
72            ],
73            [
74                '@noNS(test:static:value)@',
75                '',
76                '',
77                'value',
78                [],
79                '@noNS()@ doesn\'t work.',
80            ],
81            [
82                '@noNS(@@page@@)@',
83                'textbox page',
84                'some:test:page',
85                'page',
86                [],
87                '@noNS()@ doesn\'t work.',
88            ]
89        ];
90    }
91
92    /**
93     * @dataProvider dataProvider
94     *
95     * @param string $templateSyntax
96     * @param string $formSyntax
97     * @param string $postedValue
98     * @param string $expectedWikiText
99     * @param string $expectedValidationErrors
100     * @param string $msg
101     *
102     */
103    public function test_NS_functions(
104        $templateSyntax,
105        $formSyntax,
106        $postedValue,
107        $expectedWikiText,
108        $expectedValidationErrors,
109        $msg
110    ) {
111        $actualValidationErrors = [];
112
113        $actualWikiText = parent::send_form_action_template(
114            $formSyntax,
115            $templateSyntax,
116            $actualValidationErrors,
117            $postedValue
118        );
119
120        if (empty($expectedValidationErrors)) {
121            $this->assertEquals($expectedWikiText, $actualWikiText, $msg);
122        }
123        $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg);
124    }
125
126    public function test_p_get_first_heading_function() {
127        //create page with heading
128        $wikitext = "====== Header 1 ======\n";
129        $page = 'some:test:page';
130        saveWikiText($page, $wikitext, 'summary');
131
132        $actualValidationErrors = [];
133        $actualWikiText = parent::send_form_action_template(
134            'textbox page',
135            '@p_get_first_heading(@@page@@)@',
136            $actualValidationErrors,
137            $page
138        );
139
140        $this->assertEquals('Header 1', $actualWikiText);
141    }
142}
143