1010/**
1111 * Testing the Page Type
1212 *
13- * @group plugin_structp
13+ * @group plugin_struct
1414 * @group plugins
1515 */
1616class PageTest extends StructTest
@@ -21,13 +21,14 @@ public function setUp(): void
2121 parent ::setUp ();
2222
2323 saveWikiText ('syntax ' , 'dummy ' , 'test ' );
24+ saveWikiText ('foo:syntax:test_special.characters ' , 'dummy text ' , 'dummy summary ' );
2425
2526 // make sure the search index is initialized
2627 idx_addPage ('wiki:syntax ' );
2728 idx_addPage ('syntax ' );
2829 idx_addPage ('wiki:welcome ' );
2930 idx_addPage ('wiki:dokuwiki ' );
30-
31+ idx_addPage ( ' foo:syntax:test_special.characters ' );
3132 }
3233
3334 public function test_sort ()
@@ -204,7 +205,7 @@ public function test_ajax_default()
204205 'autocomplete ' => [
205206 'mininput ' => 2 ,
206207 'maxresult ' => 5 ,
207- 'namespace ' => '' ,
208+ 'filter ' => '' ,
208209 'postfix ' => '' ,
209210 ],
210211 ]
@@ -214,22 +215,33 @@ public function test_ajax_default()
214215 $ this ->assertEquals (
215216 [
216217 ['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 ' ],
218220 ], $ page ->handleAjax ()
219221 );
220222
221223 $ INPUT ->set ('search ' , 'ynt ' );
222224 $ this ->assertEquals (
223225 [
224226 ['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 ' ],
226229 ], $ page ->handleAjax ()
227230 );
228231
229232 $ INPUT ->set ('search ' , 's ' ); // under mininput
230233 $ 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 ());
231239 }
232240
241+ /**
242+ * Test deprecated option namespace
243+ * @return void
244+ */
233245 public function test_ajax_namespace ()
234246 {
235247 global $ INPUT ;
@@ -249,6 +261,32 @@ public function test_ajax_namespace()
249261 $ this ->assertEquals ([['label ' => 'syntax (wiki) ' , 'value ' => 'wiki:syntax ' ]], $ page ->handleAjax ());
250262 }
251263
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+ */
252290 public function test_ajax_postfix ()
253291 {
254292 global $ INPUT ;
@@ -266,6 +304,74 @@ public function test_ajax_postfix()
266304
267305 $ INPUT ->set ('search ' , 'oku ' );
268306 $ 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 ' ));
269344 }
270345
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+ }
271377}
0 commit comments