-
-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathSettingsTest.php
298 lines (293 loc) · 9.42 KB
/
SettingsTest.php
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php
namespace Miraheze\Config\Tests\ManageWiki;
class SettingsTest extends ManageWikiTestCase {
public function getSchema(): array {
return [
'type' => 'array',
'additionalProperties' => false,
'patternProperties' => [
self::REGEX_CONFIG => [
'type' => 'array',
'additionalProperties' => false,
'properties' => [
'associativeKey' => [
'type' => 'string',
'description' => 'the associative array key. Only used if you are setting the associative value.',
],
'name' => [
'type' => 'string',
'description' => 'the displayed name of the setting on Special:ManageWiki/settings.',
'pattern' => self::REGEX_READABLE,
'required' => true,
],
'from' => [
'type' => 'string',
'description' => "a text entry of which extension is required for this setting to work. If added by MediaWiki core, use 'mediawiki'.",
'required' => true,
],
'global' => [
'type' => 'boolean',
'description' => 'set to true if the setting is added by MediaWiki core or a global extension or skin.',
],
'type' => [
'description' => 'configuration type.',
'anyOf' => [
[
'const' => 'check',
'description' => 'adds a checkbox.',
],
[
'const' => 'database',
'description' => 'adds a textbox with input validation, verifying that its value is a valid database name.',
],
[
'const' => 'float',
'description' => 'adds a textbox with float validation (requires: minfloat and maxfloat which are minimum and maximum float values).',
],
[
'const' => 'integer',
'description' => 'adds a textbox with integer validation (requires: minint and maxint which are minimum and maximum integer values).',
],
[
'const' => 'integers',
'description' => 'see above, just supports multiple and does not require a min or max integer value.',
],
[
'const' => 'language',
'description' => 'adds a dropdown for language selection (all which are known to MediaWiki).',
],
[
'const' => 'list',
'description' => 'adds a list of options (requires: options which is an array in form of display => internal value).',
],
[
'const' => 'list-multi',
'description' => 'see above, just that multiple can be selected.',
],
[
'const' => 'list-multi-bool',
'description' => 'see above, just outputs are $this => $bool.',
],
[
'const' => 'matrix',
'description' => 'adds an array of "columns" and "rows". Columns are the top array and rows will be the values.',
],
[
'const' => 'preferences',
'description' => 'adds a drop down selection box for selecting multiple user preferences.',
],
[
'const' => 'skin',
'description' => 'adds a drop down selection box for selecting a single enabled skin.',
],
[
'const' => 'skins',
'description' => 'adds a drop down selection box for selecting multiple enabled skins.',
],
[
'const' => 'text',
'description' => 'adds a single line text entry.',
],
[
'const' => 'texts',
'description' => 'see above, except multiple text values for inserting into a configuration array.',
],
[
'const' => 'timezone',
'description' => 'adds a dropdown for timezone selection.',
],
[
'const' => 'url',
'description' => 'adds a single line text entry which requires a full URL.',
],
[
'const' => 'user',
'description' => 'adds an autocomplete text box to select a single user on the wiki.',
],
[
'const' => 'users',
'description' => 'see above, except multiple users.',
],
[
'const' => 'usergroups',
'description' => 'adds a drop down selection box for selecting multiple user groups.',
],
[
'const' => 'userrights',
'description' => 'adds a drop down selection box for selecting multiple user rights.',
],
[
'const' => 'wikipage',
'description' => 'add a textbox which will return an autocomplete drop-down list of wikipages. Returns standardised MediaWiki pages.',
],
[
'const' => 'wikipages',
'description' => 'see above, except multiple wikipages.',
],
],
'required' => true,
],
'overridedefault' => [
'required' => true,
'description' => 'a string/array override default when no existing value exist.',
],
'help' => [
'type' => 'string',
'description' => 'string providing help information for the setting.',
'pattern' => self::REGEX_READABLE,
'required' => true,
],
'exists' => [
'type' => 'boolean',
],
'allopts' => [
'type' => 'array',
'additionalProperties' => false,
'items' => [
'type' => 'string',
],
],
'options' => [
'type' => 'array',
'patternProperties' => [
self::REGEX_READABLE => []
]
],
'minint' => [
'type' => 'integer',
],
'maxint' => [
'type' => 'integer',
],
'section' => [
'type' => 'string',
'description' => 'string name of groupings for settings.',
'required' => true,
],
'requires' => [
'type' => 'array',
'additionalProperties' => false,
'properties' => [
'activeusers' => [
'type' => 'integer',
'description' => 'max integer amount of active users a wiki may have in order to be able to modify this setting.',
],
'articles' => [
'type' => 'integer',
'description' => 'max integer amount of articles a wiki may have in order to be able to modify this setting.',
],
'extensions' => [
'type' => 'array',
'description' => "array of extensions that must be enabled in order to modify this setting. Different from 'from'. Only use if requires more then one extension.",
'items' => [
'anyOf' => [
[
'type' => 'string'
],
[
'type' => 'array',
'items' => [
'type' => 'string'
],
],
]
]
],
'pages' => [
'type' => 'integer',
'description' => 'max integer amount of pages a wiki may have in order to be able to modify this setting.',
],
'permissions' => [
'type' => 'array',
'description' => 'array of permissions a user must have to be able to modify this setting. Regardless of this value, a user must always have the managewiki permission.',
'items' => [
'type' => 'string'
]
],
'visibility' => [
'type' => 'array',
'additionalProperties' => false,
'properties' => [
'state' => [
'type' => 'string',
'description' => "Can be either 'private' or 'public'. If set to 'private' this setting will only be visible on private wikis. If set to 'public' it will only be visible on public wikis.",
'enum' => [
'private',
'public',
],
],
'permissions' => [
'type' => 'array',
'description' => "Set to an array of permissions required for the setting to be visible.",
'items' => [
'type' => 'string',
],
],
],
],
'settings' => [
'type' => 'array',
],
],
],
'script' => [
'type' => 'array',
'properties' => [
'type' => 'array',
'additionalProperties' => false,
'patternProperties' => [
'update' => 'boolean',
],
],
],
],
],
],
];
}
/** @covers $wgManageWikiSettings */
public function testManageWikiSettings() {
global $wgManageWikiSettings, $IP, $wgPasswordSender, $wmgSharedUploadDBname, $wmgUploadHostname, $wi;
$IP = '';
$wgPasswordSender = '';
$wmgSharedUploadDBname = '';
$wmgUploadHostname = '';
$wi = $this->mockMirahezeFunctions();
require_once __DIR__ . '/../../ManageWikiSettings.php';
$this->assertSchema( $wgManageWikiSettings );
}
/** @inheritDoc */
public function configProvider(): array {
return [
'A valid configuration should be passed the validation.' => [
[
'wgAbuseFilterActions' => [
'name' => 'AbuseFilter Actions',
'from' => 'abusefilter',
'type' => 'list-multi-bool',
'overridedefault' => [
'block' => true,
],
'section' => 'anti-spam',
'help' => 'Lorem ipsum.',
]
],
''
],
'An invalid configuration should not be passed the validation.' => [
[
'wgAbuseFilterActions' => [
'type' => 'check',
]
],
implode( "\n", [
'[wgAbuseFilterActions.name] The property name is required',
'[wgAbuseFilterActions.from] The property from is required',
'[wgAbuseFilterActions.overridedefault] The property overridedefault is required',
'[wgAbuseFilterActions.help] The property help is required',
'[wgAbuseFilterActions.section] The property section is required',
] ),
],
];
}
}