10
10
/**
11
11
* Testing the Page Type
12
12
*
13
- * @group plugin_structp
13
+ * @group plugin_struct
14
14
* @group plugins
15
15
*/
16
16
class PageTest extends StructTest
@@ -21,13 +21,14 @@ public function setUp(): void
21
21
parent ::setUp ();
22
22
23
23
saveWikiText ('syntax ' , 'dummy ' , 'test ' );
24
+ saveWikiText ('foo:syntax:test_special.characters ' , 'dummy text ' , 'dummy summary ' );
24
25
25
26
// make sure the search index is initialized
26
27
idx_addPage ('wiki:syntax ' );
27
28
idx_addPage ('syntax ' );
28
29
idx_addPage ('wiki:welcome ' );
29
30
idx_addPage ('wiki:dokuwiki ' );
30
-
31
+ idx_addPage ( ' foo:syntax:test_special.characters ' );
31
32
}
32
33
33
34
public function test_sort ()
@@ -204,7 +205,7 @@ public function test_ajax_default()
204
205
'autocomplete ' => [
205
206
'mininput ' => 2 ,
206
207
'maxresult ' => 5 ,
207
- 'namespace ' => '' ,
208
+ 'filter ' => '' ,
208
209
'postfix ' => '' ,
209
210
],
210
211
]
@@ -214,22 +215,33 @@ public function test_ajax_default()
214
215
$ this ->assertEquals (
215
216
[
216
217
['label ' => 'syntax ' , 'value ' => 'syntax ' ],
217
- ['label ' => 'syntax (wiki) ' , 'value ' => 'wiki:syntax ' ]
218
+ ['label ' => 'syntax (wiki) ' , 'value ' => 'wiki:syntax ' ],
219
+ ['label ' => 'test_special.characters (foo:syntax) ' , 'value ' => 'foo:syntax:test_special.characters ' ],
218
220
], $ page ->handleAjax ()
219
221
);
220
222
221
223
$ INPUT ->set ('search ' , 'ynt ' );
222
224
$ this ->assertEquals (
223
225
[
224
226
['label ' => 'syntax ' , 'value ' => 'syntax ' ],
225
- ['label ' => 'syntax (wiki) ' , 'value ' => 'wiki:syntax ' ]
227
+ ['label ' => 'syntax (wiki) ' , 'value ' => 'wiki:syntax ' ],
228
+ ['label ' => 'test_special.characters (foo:syntax) ' , 'value ' => 'foo:syntax:test_special.characters ' ],
226
229
], $ page ->handleAjax ()
227
230
);
228
231
229
232
$ INPUT ->set ('search ' , 's ' ); // under mininput
230
233
$ this ->assertEquals ([], $ page ->handleAjax ());
234
+
235
+ $ INPUT ->set ('search ' , 'test_special.char ' ); // special characters in id
236
+ $ this ->assertEquals ([
237
+ ['label ' => 'test_special.characters (foo:syntax) ' , 'value ' => 'foo:syntax:test_special.characters ' ]
238
+ ], $ page ->handleAjax ());
231
239
}
232
240
241
+ /**
242
+ * Test deprecated option namespace
243
+ * @return void
244
+ */
233
245
public function test_ajax_namespace ()
234
246
{
235
247
global $ INPUT ;
@@ -249,6 +261,32 @@ public function test_ajax_namespace()
249
261
$ this ->assertEquals ([['label ' => 'syntax (wiki) ' , 'value ' => 'wiki:syntax ' ]], $ page ->handleAjax ());
250
262
}
251
263
264
+ public function test_ajax_filter_multiple ()
265
+ {
266
+ global $ INPUT ;
267
+
268
+ $ page = new Page (
269
+ [
270
+ 'autocomplete ' => [
271
+ 'mininput ' => 2 ,
272
+ 'maxresult ' => 5 ,
273
+ 'filter ' => '(wiki|foo) ' ,
274
+ 'postfix ' => '' ,
275
+ ],
276
+ ]
277
+ );
278
+
279
+ $ INPUT ->set ('search ' , 'ynt ' );
280
+ $ this ->assertEquals ([
281
+ ['label ' => 'syntax (wiki) ' , 'value ' => 'wiki:syntax ' ],
282
+ ['label ' => 'test_special.characters (foo:syntax) ' , 'value ' => 'foo:syntax:test_special.characters ' ]
283
+ ], $ page ->handleAjax ());
284
+ }
285
+
286
+ /**
287
+ * Test deprecated option postfix
288
+ * @return void
289
+ */
252
290
public function test_ajax_postfix ()
253
291
{
254
292
global $ INPUT ;
@@ -266,6 +304,74 @@ public function test_ajax_postfix()
266
304
267
305
$ INPUT ->set ('search ' , 'oku ' );
268
306
$ this ->assertEquals ([['label ' => 'dokuwiki (wiki) ' , 'value ' => 'wiki:dokuwiki ' ]], $ page ->handleAjax ());
307
+
308
+ $ page = new Page (
309
+ [
310
+ 'autocomplete ' => [
311
+ 'mininput ' => 2 ,
312
+ 'maxresult ' => 5 ,
313
+ 'namespace ' => 'wiki ' ,
314
+ 'postfix ' => 'iki ' ,
315
+ ],
316
+ ]
317
+ );
318
+
319
+ $ INPUT ->set ('search ' , 'oku ' );
320
+ $ this ->assertEquals ([['label ' => 'dokuwiki (wiki) ' , 'value ' => 'wiki:dokuwiki ' ]], $ page ->handleAjax ());
321
+ }
322
+
323
+ /**
324
+ * Test simple filter matching in autocompletion
325
+ *
326
+ * @return void
327
+ */
328
+ public function test_filter_matching_simple ()
329
+ {
330
+ $ page = new Page ();
331
+
332
+ $ this ->assertTrue ($ page ->filterMatch ('foo:start ' , 'foo ' ));
333
+ $ this ->assertTrue ($ page ->filterMatch ('start#foo ' , 'foo ' ));
334
+ $ this ->assertFalse ($ page ->filterMatch ('ns:foo ' , ':foo ' ));
335
+ $ this ->assertTrue ($ page ->filterMatch ('foo-bar:start ' , 'foo-bar ' ));
336
+ $ this ->assertTrue ($ page ->filterMatch ('foo-bar:start-with_special.chars ' , 'foo-bar ' ));
337
+ $ this ->assertTrue ($ page ->filterMatch ('foo.bar:start ' , 'foo.bar ' ));
338
+ $ this ->assertTrue ($ page ->filterMatch ('ns:foo.bar ' , 'foo.bar ' ));
339
+ $ this ->assertTrue ($ page ->filterMatch ('ns:foo.bar:start ' , 'foo.bar ' ));
340
+ $ this ->assertFalse ($ page ->filterMatch ('ns:foo_bar:start ' , ':foo_bar ' ));
341
+ $ this ->assertTrue ($ page ->filterMatch ('8bar:start ' , '8bar ' ));
342
+ $ this ->assertTrue ($ page ->filterMatch ('ns:8bar:start ' , '8bar ' ));
343
+ $ this ->assertTrue ($ page ->filterMatch ('ns:98bar:start ' , '8bar ' ));
269
344
}
270
345
346
+ /**
347
+ * Test pattern matching in autocompletion
348
+ *
349
+ * @return void
350
+ */
351
+ public function test_filter_matching_regex ()
352
+ {
353
+ $ page = new Page ();
354
+
355
+ $ filter = '(foo:|^:foo:|(?::|^)bar:|foo:bar|foo-bar:|^:foo_bar:|foo\.bar:|(?::|^)8bar:) ' ;
356
+
357
+ $ this ->assertTrue ($ page ->filterMatch ('foo:start ' , $ filter ));
358
+ $ this ->assertFalse ($ page ->filterMatch ('start#foo ' , $ filter ));
359
+ $ this ->assertFalse ($ page ->filterMatch ('ns:foo ' , $ filter ));
360
+ $ this ->assertTrue ($ page ->filterMatch ('bar:foo ' , $ filter ));
361
+ $ this ->assertTrue ($ page ->filterMatch ('ns:foo:start ' , $ filter ));
362
+ $ this ->assertTrue ($ page ->filterMatch ('ns:foo:start#headline ' , $ filter ));
363
+ $ this ->assertTrue ($ page ->filterMatch ('foo-bar:start ' , $ filter ));
364
+ $ this ->assertTrue ($ page ->filterMatch ('foo-bar:start-with_special.chars ' , $ filter ));
365
+ $ this ->assertTrue ($ page ->filterMatch ('foo.bar:start ' , $ filter ));
366
+ $ this ->assertFalse ($ page ->filterMatch ('ns:foo.bar ' , $ filter ));
367
+ $ this ->assertTrue ($ page ->filterMatch ('ns:foo.bar:start ' , $ filter ));
368
+ $ this ->assertFalse ($ page ->filterMatch ('ns:foo_bar:start ' , $ filter ));
369
+ $ this ->assertTrue ($ page ->filterMatch ('8bar:start ' , $ filter ));
370
+ $ this ->assertTrue ($ page ->filterMatch ('ns:8bar:start ' , $ filter ));
371
+ $ this ->assertFalse ($ page ->filterMatch ('ns:98bar:start ' , $ filter ));
372
+
373
+ $ filter = '^:systems:[^:]+:components:([^:]+:){1,2}[^:]+$ ' ;
374
+ $ this ->assertTrue ($ page ->filterMatch ('systems:system1:components:sub1:sub2:start ' , $ filter ));
375
+ $ this ->assertFalse ($ page ->filterMatch ('systems:system1:components:sub1:sub2:sub3:start ' , $ filter ));
376
+ }
271
377
}
0 commit comments