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 ()
@@ -214,20 +215,27 @@ 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
233
241
public function test_ajax_namespace ()
@@ -249,6 +257,28 @@ public function test_ajax_namespace()
249
257
$ this ->assertEquals ([['label ' => 'syntax (wiki) ' , 'value ' => 'wiki:syntax ' ]], $ page ->handleAjax ());
250
258
}
251
259
260
+ public function test_ajax_namespace_multiple ()
261
+ {
262
+ global $ INPUT ;
263
+
264
+ $ page = new Page (
265
+ [
266
+ 'autocomplete ' => [
267
+ 'mininput ' => 2 ,
268
+ 'maxresult ' => 5 ,
269
+ 'namespace ' => '(wiki|foo) ' ,
270
+ 'postfix ' => '' ,
271
+ ],
272
+ ]
273
+ );
274
+
275
+ $ INPUT ->set ('search ' , 'ynt ' );
276
+ $ this ->assertEquals ([
277
+ ['label ' => 'syntax (wiki) ' , 'value ' => 'wiki:syntax ' ],
278
+ ['label ' => 'test_special.characters (foo:syntax) ' , 'value ' => 'foo:syntax:test_special.characters ' ]
279
+ ], $ page ->handleAjax ());
280
+ }
281
+
252
282
public function test_ajax_postfix ()
253
283
{
254
284
global $ INPUT ;
@@ -268,4 +298,60 @@ public function test_ajax_postfix()
268
298
$ this ->assertEquals ([['label ' => 'dokuwiki (wiki) ' , 'value ' => 'wiki:dokuwiki ' ]], $ page ->handleAjax ());
269
299
}
270
300
301
+ /**
302
+ * Test simple namespace matching in autocompletion
303
+ *
304
+ * @return void
305
+ */
306
+ public function test_namespace_matching_simple ()
307
+ {
308
+ $ page = new Page ();
309
+
310
+ $ this ->assertTrue ($ page ->nsMatch ('foo:start ' , 'foo ' ));
311
+ $ this ->assertFalse ($ page ->nsMatch ('start#foo ' , 'foo ' ));
312
+ $ this ->assertFalse ($ page ->nsMatch ('ns:foo ' , ':foo ' ));
313
+ $ this ->assertTrue ($ page ->nsMatch ('ns:foo:start ' , 'foo ' ));
314
+ $ this ->assertTrue ($ page ->nsMatch ('ns:foo:start#headline ' , 'foo ' ));
315
+ $ this ->assertTrue ($ page ->nsMatch ('foo-bar:start ' , 'foo-bar ' ));
316
+ $ this ->assertTrue ($ page ->nsMatch ('foo-bar:start-with_special.chars ' , 'foo-bar ' ));
317
+ $ this ->assertTrue ($ page ->nsMatch ('foo.bar:start ' , 'foo.bar ' ));
318
+ $ this ->assertFalse ($ page ->nsMatch ('ns:foo.bar ' , 'foo.bar ' ));
319
+ $ this ->assertTrue ($ page ->nsMatch ('ns:foo.bar:start ' , 'foo.bar ' ));
320
+ $ this ->assertFalse ($ page ->nsMatch ('ns:foo_bar:start ' , ':foo_bar ' ));
321
+ $ this ->assertTrue ($ page ->nsMatch ('8bar:start ' , '8bar ' ));
322
+ $ this ->assertTrue ($ page ->nsMatch ('ns:8bar:start ' , '8bar ' ));
323
+ $ this ->assertFalse ($ page ->nsMatch ('ns:98bar:start ' , '8bar ' ));
324
+ }
325
+
326
+ /**
327
+ * Test regex namespace matching in autocompletion
328
+ *
329
+ * @return void
330
+ */
331
+ public function test_namespace_matching_regex ()
332
+ {
333
+ $ page = new Page ();
334
+
335
+ $ namespace = '/(foo:|^:foo:|(?::|^)bar:|foo:bar|foo-bar:|^:foo_bar:|foo\.bar:|(?::|^)8bar:)/ ' ;
336
+
337
+ $ this ->assertTrue ($ page ->nsMatch ('foo:start ' , $ namespace ));
338
+ $ this ->assertFalse ($ page ->nsMatch ('start#foo ' , $ namespace ));
339
+ $ this ->assertFalse ($ page ->nsMatch ('ns:foo ' , $ namespace ));
340
+ $ this ->assertTrue ($ page ->nsMatch ('bar:foo ' , $ namespace ));
341
+ $ this ->assertTrue ($ page ->nsMatch ('ns:foo:start ' , $ namespace ));
342
+ $ this ->assertTrue ($ page ->nsMatch ('ns:foo:start#headline ' , $ namespace ));
343
+ $ this ->assertTrue ($ page ->nsMatch ('foo-bar:start ' , $ namespace ));
344
+ $ this ->assertTrue ($ page ->nsMatch ('foo-bar:start-with_special.chars ' , $ namespace ));
345
+ $ this ->assertTrue ($ page ->nsMatch ('foo.bar:start ' , $ namespace ));
346
+ $ this ->assertFalse ($ page ->nsMatch ('ns:foo.bar ' , $ namespace ));
347
+ $ this ->assertTrue ($ page ->nsMatch ('ns:foo.bar:start ' , $ namespace ));
348
+ $ this ->assertFalse ($ page ->nsMatch ('ns:foo_bar:start ' , $ namespace ));
349
+ $ this ->assertTrue ($ page ->nsMatch ('8bar:start ' , $ namespace ));
350
+ $ this ->assertTrue ($ page ->nsMatch ('ns:8bar:start ' , $ namespace ));
351
+ $ this ->assertFalse ($ page ->nsMatch ('ns:98bar:start ' , $ namespace ));
352
+
353
+ $ namespace = '/^:systems:[^:]+:components:([^:]+:){1,2}$/ ' ;
354
+ $ this ->assertTrue ($ page ->nsMatch ('systems:system1:components:sub1:sub2:start ' , $ namespace ));
355
+ $ this ->assertFalse ($ page ->nsMatch ('systems:system1:components:sub1:sub2:sub3:start ' , $ namespace ));
356
+ }
271
357
}
0 commit comments