1<?php
2
3namespace dokuwiki\plugin\bureaucracyau\test;
4
5/**
6 * @group plugin_bureaucracyau
7 * @group plugins
8 */
9class syntax_plugin_bureaucracyau_fieldusers_test extends BureaucracyauTest
10{
11
12    /**
13     * Create some users
14     */
15    public function setUp()
16    {
17        parent::setUp();
18
19        /** @var \DokuWiki_Auth_Plugin $auth */
20        global $auth;
21
22        $auth->createUser('user1', '54321', 'user1Name', 'user1@example.com');
23        $auth->createUser('user2', '543210', 'user2Name', 'user2@example.com');
24        $auth->createUser('mwuser', '12345', 'Wiki User', 'me@example.com', ['group1', 'group2']);
25    }
26
27    public function dataProvider()
28    {
29        return [
30            [
31                'users:@@users@@',
32                'users users',
33                'user1, user2',
34                'users:user1, user2',
35                [],
36                'default substitution',
37            ],
38            [
39                'users:@@users@@',
40                'users users',
41                '',
42                'users:',
43                ['users'],
44                'error for empty substitution',
45            ],
46            [
47                'users:@@users(;)@@',
48                'users users',
49                'user1, user2',
50                'users:user1;user2',
51                [],
52                'custom delimiter',
53            ],
54            [
55                "users:@@users(\n)@@",
56                'users users',
57                'user1, user2',
58                "users:user1\nuser2",
59                [],
60                'newline delimiter',
61            ],
62            [
63                'users:@@users()@@',
64                'users users',
65                'user1, user2',
66                'users:user1user2',
67                [],
68                'empty delimiter',
69            ],
70            [
71                'users:@@users.name@@',
72                'users users',
73                'user1, user2',
74                'users:user1Name, user2Name',
75                [],
76                'names substitution default delitmiter',
77            ],
78            [
79                'users:@@users(;).name@@',
80                'users users',
81                'user1, user2',
82                'users:user1Name;user2Name',
83                [],
84                'names substitution custom delitmiter',
85            ],
86            [
87                'users:@@users.mail@@',
88                'users users',
89                'user1, user2',
90                'users:user1@example.com, user2@example.com',
91                [],
92                'mail substitution default delitmiter',
93            ],
94            [
95                "mails:@@users.mail@@\n\nnames:@@users(\n).name@@",
96                'users users',
97                'user1, user2',
98                "mails:user1@example.com, user2@example.com\n\nnames:user1Name\nuser2Name",
99                [],
100                'multiple replacements',
101            ],
102            [
103                'users:@@users@@',
104                'users users',
105                'not_existing1, not_existing2',
106                'users:not_existing1, not_existing2',
107                ['users'],
108                'unknown users should cause errors',
109            ],
110            [
111                'users:@@users.unknown_attribute@@',
112                'users users',
113                'user1, user2',
114                'users:@@users.unknown_attribute@@',
115                [],
116                'non existant attribute is not replaced',
117            ],
118            [
119                'users:@@*]]@@',  // the label must be something to break a regex when not properly quoted
120                'users "*]]"',
121                'user1, user2',
122                'users:user1, user2',
123                [],
124                'ensure label desn\'t break regex',
125            ],
126            [
127                'users:@@tHis Is UsEr@@',
128                'users "tHis Is UsEr"',
129                'user1, user2',
130                'users:user1, user2',
131                [],
132                'label with spaces and mixed case',
133            ],
134        ];
135    }
136
137    /**
138     * @dataProvider dataProvider
139     *
140     * @param string $templateSyntax
141     * @param string $formSyntax
142     * @param string $postedValue value of 'users' field
143     * @param string $expectedWikiText
144     * @param string $expectedValidationErrors
145     * @param string $msg
146     *
147     */
148    public function test_field_users(
149        $templateSyntax,
150        $formSyntax,
151        $postedValue,
152        $expectedWikiText,
153        $expectedValidationErrors,
154        $msg
155    ) {
156        $actualValidationErrors = [];
157
158        $actualWikiText = parent::send_form_action_template(
159            $formSyntax,
160            $templateSyntax,
161            $actualValidationErrors,
162            $postedValue
163        );
164
165        $this->assertEquals($expectedWikiText, $actualWikiText, $msg);
166        $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg);
167    }
168}
169