summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/bureaucracy/_test/field_user.test.php
blob: a7ade9b5cad755babd1eeeeb005f709e60cff95f (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php

namespace dokuwiki\plugin\bureaucracy\test;

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

    /**
     * Create some users
     */
    public function setUp(): void
    {
        parent::setUp();

        /** @var \DokuWiki_Auth_Plugin $auth */
        global $auth;

        $auth->createUser("user1", "54321", "user1Name", "user1@example.com");
        $auth->createUser("user2", "543210", "user2Name", "user2@example.com");
        $auth->createUser("mwuser", "12345", "Wiki User", "wikiuser@example.com", ['group1', 'group2']);
    }

    public function dataProvider()
    {
        return [
            [
                'user:@@user@@',
                'user user',
                'mwuser',
                'user:mwuser',
                [],
                'default substitution',
            ],
            [
                'user:@@user@@',
                'user user',
                '',
                'user:',
                ['user'],
                'error for empty substitution',
            ],
            [
                'user:@@user@@',
                'user user !',
                '',
                'user:',
                [],
                'ok for empty substitution in optional field',
            ],
            [
                'user:@@user.name@@',
                'user user',
                'mwuser',
                'user:Wiki User',
                [],
                'name substitution',
            ],
            [
                'user:@@user.mail@@',
                'user user',
                'mwuser',
                'user:wikiuser@example.com',
                [],
                'mail substitution',
            ],
            [
                'user:@@user.grps@@',
                'user user',
                'mwuser',
                'user:group1, group2',
                [],
                'groups substitution',
            ],
            [
                'user:@@user.grps(;)@@',
                'user user',
                'mwuser',
                'user:group1;group2',
                [],
                'groups substitution custom delimiter',
            ],
            [
                'user:@@user.grps())@@',
                'user user',
                'mwuser',
                'user:group1)group2',
                [],
                'groups substitution custom delimiter with brackets',
            ],
            [
                'user:@@user.no_sutch_attribute@@',
                'user user',
                'mwuser',
                'user:@@user.no_sutch_attribute@@',
                [],
                'template unknown attribute substitution',
            ],
            [
                'user:##user##',
                'user user',
                'mwuser',
                'user:mwuser',
                [],
                'hash substitution',
            ],
            [
                'user:##user.mail##',
                'user user',
                'mwuser',
                'user:wikiuser@example.com',
                [],
                'hash substitution with attribute',
            ],
            [
                'user:##user@@',
                'user user',
                'mwuser',
                'user:##user@@',
                [],
                'hash substitution sign mismatch',
            ],
            [
                "user:@@user@@\n\nmail:@@user.mail@@\n\ngrps:@@user.grps(\n)@@",
                'user user',
                'mwuser',
                "user:mwuser\n\nmail:wikiuser@example.com\n\ngrps:group1\ngroup2",
                [],
                'multiple replacements',
            ],
            [
                "grps1:@@user.grps(\n)@@\n\ngrps2:@@user.grps(())@@",
                'user user',
                'mwuser',
                "grps1:group1\ngroup2\n\ngrps2:group1()group2",
                [],
                'groups twice',
            ],
            [
                'grps:@@user.grps(end))@@',
                'user user',
                'mwuser',
                'grps:group1end)group2',
                [],
                'groups special glue',
            ],
            [
                'grps:@@user.grps()@@',
                'user user',
                'mwuser',
                'grps:group1group2',
                [],
                'groups with empty delimiter',
            ],
            [
                'user:@@user@@',
                'user user',
                'non_existant_user',
                'user:non_existant_user',
                ['user'],
                'error for non existant user',
            ],
            [
                'user:@@user.name@@',
                'user user',
                'non_existant_user',
                'user:@@user.name@@',
                ['user'],
                'error for non existant user with attribute',
            ],
        ];
    }


    /**
     * @dataProvider dataProvider
     *
     * @param string $templateSyntax
     * @param string $formSyntax
     * @param string $postedValue value of 'user' field
     * @param string $expectedWikiText
     * @param string $expectedValidationErrors
     * @param string $msg
     *
     */
    public function test_field_user(
        $templateSyntax,
        $formSyntax,
        $postedValue,
        $expectedWikiText,
        $expectedValidationErrors,
        $msg
    ) {
        $actualValidationErrors = [];

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

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