summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/bureaucracy/_test/replace_functions.test.php
blob: d4104debda94782d3a63c0a08be58fb584afe2bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php

namespace dokuwiki\plugin\bureaucracy\test;

use \Doku_Form;

/**
 * @group plugin_bureaucracy
 * @group plugins
 */
class bureaucracy_replace_functions_test extends BureaucracyTest
{

    public function dataProvider()
    {
        return [
            [
                '@curNS@',
                '',
                '',
                '@curNS@',
                [],
                '"@function@" shouldn\'t be replaced.',
            ],
            [
                '@curNS()@',
                '',
                '',
                '',
                [],
                '"@function()@" should return empty string.',
            ],
            [
                '(@noNS(test):page)@)', //test doubled bracket
                '',
                '',
                '(page)',
                [],
                '"@curNS(test:page))@" should return empty string.',
            ],
            [
                '@curNS(test:static:value)@',
                '',
                '',
                'static',
                [],
                '@curNS()@ doesn\'t work.',
            ],
            [
                '@curNS(@@page@@)@',
                'textbox page',
                'some:test:page',
                'test',
                [],
                '@curNS()@ doesn\'t work.',
            ],
            [
                '@getNS(@@page@@)@',
                'textbox page',
                'some:test:page',
                'some:test',
                [],
                '@getNS()@ doesn\'t work.',
            ],
            [
                '@getNS(test:static:value)@',
                '',
                '',
                'test:static',
                [],
                '@getNS()@ doesn\'t work.',
            ],
            [
                '@noNS(test:static:value)@',
                '',
                '',
                'value',
                [],
                '@noNS()@ doesn\'t work.',
            ],
            [
                '@noNS(@@page@@)@',
                'textbox page',
                'some:test:page',
                'page',
                [],
                '@noNS()@ doesn\'t work.',
            ]
        ];
    }

    /**
     * @dataProvider dataProvider
     *
     * @param string $templateSyntax
     * @param string $formSyntax
     * @param string $postedValue
     * @param string $expectedWikiText
     * @param string $expectedValidationErrors
     * @param string $msg
     *
     */
    public function test_NS_functions(
        $templateSyntax,
        $formSyntax,
        $postedValue,
        $expectedWikiText,
        $expectedValidationErrors,
        $msg
    ) {
        $actualValidationErrors = [];

        $actualWikiText = parent::send_form_action_template(
            $formSyntax,
            $templateSyntax,
            $actualValidationErrors,
            $postedValue
        );

        if (empty($expectedValidationErrors)) {
            $this->assertEquals($expectedWikiText, $actualWikiText, $msg);
        }
        $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg);
    }

    public function test_p_get_first_heading_function() {
        //create page with heading
        $wikitext = "====== Header 1 ======\n";
        $page = 'some:test:page';
        saveWikiText($page, $wikitext, 'summary');

        $actualValidationErrors = [];
        $actualWikiText = parent::send_form_action_template(
            'textbox page',
            '@p_get_first_heading(@@page@@)@',
            $actualValidationErrors,
            $page
        );

        $this->assertEquals('Header 1', $actualWikiText);
    }
}