BooleanSearchTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. declare(strict_types=1);
  3. use PHPUnit\Framework\Attributes\DataProvider;
  4. final class BooleanSearchTest extends \PHPUnit\Framework\TestCase {
  5. /**
  6. * `FreshRSS_BooleanSearch::prepend()` is used to restrict an existing search with an extra condition,
  7. * such as the maximum publication date of the “mark as read → articles older than one day/week” action.
  8. * @return list<array{string,string,list<string|int>}>
  9. */
  10. public static function providePrependMaxPubdate(): array {
  11. return [
  12. ['', '(e.date <= ?)', [1700000000]],
  13. ['intitle:sale', '(e.date <= ?) AND ((e.title LIKE ?))', [1700000000, '%sale%']],
  14. ['intitle:a OR intitle:b', '(e.date <= ?) AND ((e.title LIKE ?) OR (e.title LIKE ?))', [1700000000, '%a%', '%b%']],
  15. ];
  16. }
  17. /** @param list<string|int> $expectedValues */
  18. #[DataProvider('providePrependMaxPubdate')]
  19. public function test_prepend_restrictsTheSearchInsteadOfWideningIt(string $input, string $expectedSql, array $expectedValues): void {
  20. $booleanSearch = new FreshRSS_BooleanSearch($input);
  21. $maxPubdate = new FreshRSS_Search('');
  22. $maxPubdate->setMaxPubdate(1700000000);
  23. $booleanSearch->prepend($maxPubdate);
  24. [$values, $sql] = FreshRSS_EntryDAO::sqlBooleanSearch('e.', $booleanSearch);
  25. self::assertSame($expectedSql, trim($sql));
  26. self::assertSame($expectedValues, $values);
  27. }
  28. }