@@ -284,13 +284,60 @@ public function provideMultipleSearch(): array {
284
284
);
285
285
}
286
286
287
+ /**
288
+ * @dataProvider provideAddOrParentheses
289
+ */
290
+ public function test__addOrParentheses (string $ input , string $ output ): void {
291
+ self ::assertEquals ($ output , FreshRSS_BooleanSearch::addOrParentheses ($ input ));
292
+ }
293
+
294
+ /** @return array<array{string,string}> */
295
+ public function provideAddOrParentheses (): array {
296
+ return [
297
+ ['ab ' , 'ab ' ],
298
+ ['ab cd ' , 'ab cd ' ],
299
+ ['!ab -cd ' , '!ab -cd ' ],
300
+ ['ab OR cd ' , '(ab) OR (cd) ' ],
301
+ ['!ab OR -cd ' , '(!ab) OR (-cd) ' ],
302
+ ['ab cd OR ef OR "gh ij" ' , '(ab cd) OR (ef) OR ("gh ij") ' ],
303
+ ['ab (!cd) ' , 'ab (!cd) ' ],
304
+ ];
305
+ }
306
+
307
+ /**
308
+ * @dataProvider provideconsistentOrParentheses
309
+ */
310
+ public function test__consistentOrParentheses (string $ input , string $ output ): void {
311
+ self ::assertEquals ($ output , FreshRSS_BooleanSearch::consistentOrParentheses ($ input ));
312
+ }
313
+
314
+ /** @return array<array{string,string}> */
315
+ public function provideconsistentOrParentheses (): array {
316
+ return [
317
+ ['ab cd ef ' , 'ab cd ef ' ],
318
+ ['(ab cd ef) ' , '(ab cd ef) ' ],
319
+ ['("ab cd" ef) ' , '("ab cd" ef) ' ],
320
+ ['"ab cd" (ef gh) "ij kl" ' , '"ab cd" (ef gh) "ij kl" ' ],
321
+ ['ab (!cd) ' , 'ab (!cd) ' ],
322
+ ['ab !(cd) ' , 'ab !(cd) ' ],
323
+ ['(ab) -(cd) ' , '(ab) -(cd) ' ],
324
+ ['ab cd OR ef OR "gh ij" ' , 'ab cd OR ef OR "gh ij" ' ],
325
+ ['"plain or text" OR (cd) ' , '("plain or text") OR (cd) ' ],
326
+ ['(ab) OR cd OR ef OR (gh) ' , '(ab) OR (cd) OR (ef) OR (gh) ' ],
327
+ ['(ab (cd OR ef)) OR gh OR ij OR (kl) ' , '(ab (cd OR ef)) OR (gh) OR (ij) OR (kl) ' ],
328
+ ['(ab (cd OR ef OR (gh))) OR ij ' , '(ab ((cd) OR (ef) OR (gh))) OR (ij) ' ],
329
+ ['(ab (!cd OR ef OR (gh))) OR ij ' , '(ab ((!cd) OR (ef) OR (gh))) OR (ij) ' ],
330
+ ['(ab !(cd OR ef OR !(gh))) OR ij ' , '(ab !((cd) OR (ef) OR !(gh))) OR (ij) ' ],
331
+ ];
332
+ }
333
+
287
334
/**
288
335
* @dataProvider provideParentheses
289
336
* @param array<string> $values
290
337
*/
291
- public function test__construct_parentheses (string $ input , string $ sql , array $ values ): void {
338
+ public function test__parentheses (string $ input , string $ sql , array $ values ): void {
292
339
[$ filterValues , $ filterSearch ] = FreshRSS_EntryDAOPGSQL::sqlBooleanSearch ('e. ' , new FreshRSS_BooleanSearch ($ input ));
293
- self ::assertEquals ($ sql, $ filterSearch );
340
+ self ::assertEquals (trim ( $ sql), trim ( $ filterSearch) );
294
341
self ::assertEquals ($ values , $ filterValues );
295
342
}
296
343
@@ -337,6 +384,69 @@ public function provideParentheses(): array {
337
384
'(e.title LIKE ? ) ' ,
338
385
['%"hello world"% ' ],
339
386
],
387
+ [
388
+ '(ab) OR (cd) OR (ef) ' ,
389
+ '(((e.title LIKE ? OR e.content LIKE ?) )) OR (((e.title LIKE ? OR e.content LIKE ?) )) OR (((e.title LIKE ? OR e.content LIKE ?) )) ' ,
390
+ ['%ab% ' , '%ab% ' , '%cd% ' , '%cd% ' , '%ef% ' , '%ef% ' ],
391
+ ],
392
+ [
393
+ '("plain or text") OR (cd) ' ,
394
+ '(((e.title LIKE ? OR e.content LIKE ?) )) OR (((e.title LIKE ? OR e.content LIKE ?) )) ' ,
395
+ ['%plain or text% ' , '%plain or text% ' , '%cd% ' , '%cd% ' ],
396
+ ],
397
+ [
398
+ '"plain or text" OR cd ' ,
399
+ '((e.title LIKE ? OR e.content LIKE ?) ) OR ((e.title LIKE ? OR e.content LIKE ?) ) ' ,
400
+ ['%plain or text% ' , '%plain or text% ' , '%cd% ' , '%cd% ' ],
401
+ ],
402
+ [
403
+ '"plain OR text" OR cd ' ,
404
+ '((e.title LIKE ? OR e.content LIKE ?) ) OR ((e.title LIKE ? OR e.content LIKE ?) ) ' ,
405
+ ['%plain OR text% ' , '%plain OR text% ' , '%cd% ' , '%cd% ' ],
406
+ ],
407
+ [
408
+ 'ab OR cd OR (ef) ' ,
409
+ '(((e.title LIKE ? OR e.content LIKE ?) )) OR (((e.title LIKE ? OR e.content LIKE ?) )) OR (((e.title LIKE ? OR e.content LIKE ?) )) ' ,
410
+ ['%ab% ' , '%ab% ' , '%cd% ' , '%cd% ' , '%ef% ' , '%ef% ' ],
411
+ ],
412
+ [
413
+ 'ab OR cd OR ef ' ,
414
+ '((e.title LIKE ? OR e.content LIKE ?) ) OR ((e.title LIKE ? OR e.content LIKE ?) ) OR ((e.title LIKE ? OR e.content LIKE ?) ) ' ,
415
+ ['%ab% ' , '%ab% ' , '%cd% ' , '%cd% ' , '%ef% ' , '%ef% ' ],
416
+ ],
417
+ [
418
+ '(ab) cd OR ef OR (gh) ' ,
419
+ '(((e.title LIKE ? OR e.content LIKE ?) )) AND (((e.title LIKE ? OR e.content LIKE ?) )) ' .
420
+ 'OR (((e.title LIKE ? OR e.content LIKE ?) )) OR (((e.title LIKE ? OR e.content LIKE ?) )) ' ,
421
+ ['%ab% ' , '%ab% ' , '%cd% ' , '%cd% ' , '%ef% ' , '%ef% ' , '%gh% ' , '%gh% ' ],
422
+ ],
423
+ [
424
+ '(ab) OR cd OR ef OR (gh) ' ,
425
+ '(((e.title LIKE ? OR e.content LIKE ?) )) OR (((e.title LIKE ? OR e.content LIKE ?) )) ' .
426
+ 'OR (((e.title LIKE ? OR e.content LIKE ?) )) OR (((e.title LIKE ? OR e.content LIKE ?) )) ' ,
427
+ ['%ab% ' , '%ab% ' , '%cd% ' , '%cd% ' , '%ef% ' , '%ef% ' , '%gh% ' , '%gh% ' ],
428
+ ],
429
+ [
430
+ 'ab OR (!(cd OR ef)) ' ,
431
+ '(((e.title LIKE ? OR e.content LIKE ?) )) OR (NOT (((e.title LIKE ? OR e.content LIKE ?) ) OR ((e.title LIKE ? OR e.content LIKE ?) ))) ' ,
432
+ ['%ab% ' , '%ab% ' , '%cd% ' , '%cd% ' , '%ef% ' , '%ef% ' ],
433
+ ],
434
+ [
435
+ 'ab !(cd OR ef) ' ,
436
+ '(((e.title LIKE ? OR e.content LIKE ?) )) AND NOT (((e.title LIKE ? OR e.content LIKE ?) ) OR ((e.title LIKE ? OR e.content LIKE ?) )) ' ,
437
+ ['%ab% ' , '%ab% ' , '%cd% ' , '%cd% ' , '%ef% ' , '%ef% ' ],
438
+ ],
439
+ [
440
+ 'ab OR !(cd OR ef) ' ,
441
+ '(((e.title LIKE ? OR e.content LIKE ?) )) OR NOT (((e.title LIKE ? OR e.content LIKE ?) ) OR ((e.title LIKE ? OR e.content LIKE ?) )) ' ,
442
+ ['%ab% ' , '%ab% ' , '%cd% ' , '%cd% ' , '%ef% ' , '%ef% ' ],
443
+ ],
444
+ [
445
+ '(ab (!cd OR ef OR (gh))) OR !(ij OR kl) ' ,
446
+ '((((e.title LIKE ? OR e.content LIKE ?) )) AND (((e.title NOT LIKE ? AND e.content NOT LIKE ? )) OR (((e.title LIKE ? OR e.content LIKE ?) )) ' .
447
+ 'OR (((e.title LIKE ? OR e.content LIKE ?) )))) OR NOT (((e.title LIKE ? OR e.content LIKE ?) ) OR ((e.title LIKE ? OR e.content LIKE ?) )) ' ,
448
+ ['%ab% ' , '%ab% ' , '%cd% ' , '%cd% ' , '%ef% ' , '%ef% ' , '%gh% ' , '%gh% ' , '%ij% ' , '%ij% ' , '%kl% ' , '%kl% ' ],
449
+ ],
340
450
];
341
451
}
342
452
}
0 commit comments