Files
FreshRSS/tests/app/Models/BooleanSearchTest.php
T
Alexandre Alapetite fd3f75b3a2 Require PHP 8.2+ (#9470)
Drop PHP 8.1 (EOL December 2025), drop Ubuntu 22.04 (EOL May 2027, and there is now 24.04 and 26.04 LTS).
PHP 8.1 is already EOL, and Debian, Alpine, Fedora, Red Hat, Synology have dropped PHP 8.1 already.
See https://github.com/FreshRSS/FreshRSS/discussions/5474#discussioncomment-16791937

With PHP 8.6 around the corner and in particular a relevant `FILTER_FLAG_GLOBAL_RANGE` in PHP 8.2+.
* https://www.php.net/releases/8.2
* https://www.php.net/filter.constants.validation#constant.filter-flag-global-range
* https://www.php.net/class.sensitiveparameter
* https://php.watch/versions/8.2/readonly-classes
* https://www.php.net/function.ini-parse-quantity

Allows updating to PHPUnit 11.x instead of 10.x
https://phpunit.de/supported-versions.html

Contributes to https://github.com/FreshRSS/FreshRSS/issues/9475

* Add regression test for FILTER_FLAG_GLOBAL_RANGE
https://github.com/FreshRSS/FreshRSS/pull/9470#discussion_r4371168720
2026-10-26 21:02:32 +01:00

69 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
use PHPUnit\Framework\Attributes\DataProvider;
final class BooleanSearchTest extends \PHPUnit\Framework\TestCase {
#[\Override]
protected function setUp(): void {
if (!FreshRSS_Context::hasSystemConf()) {
FreshRSS_Context::initSystem();
}
}
/**
* `FreshRSS_BooleanSearch::prepend()` is used to restrict an existing search with an extra condition,
* such as the maximum publication date of the “mark as read → articles older than one day/week” action.
* @return list<array{string,string,list<string|int>}>
*/
public static function providePrependMaxPubdate(): array {
return [
['', '(e.date <= ?)', [1700000000]],
['intitle:sale', '(e.date <= ?) AND ((e.title LIKE ?))', [1700000000, '%sale%']],
['intitle:a OR intitle:b', '(e.date <= ?) AND ((e.title LIKE ?) OR (e.title LIKE ?))', [1700000000, '%a%', '%b%']],
];
}
/** @param list<string|int> $expectedValues */
#[DataProvider('providePrependMaxPubdate')]
public function test_prepend_restrictsTheSearchInsteadOfWideningIt(string $input, string $expectedSql, array $expectedValues): void {
$booleanSearch = new FreshRSS_BooleanSearch($input);
$maxPubdate = new FreshRSS_Search('');
$maxPubdate->setMaxPubdate(1700000000);
$booleanSearch->prepend($maxPubdate);
[$values, $sql] = FreshRSS_EntryDAO::sqlBooleanSearch('e.', $booleanSearch);
self::assertSame($expectedSql, trim($sql));
self::assertSame($expectedValues, $values);
}
public function test_constructor_acceptsSearchesAtTheLimits(): void {
$input = str_repeat('a', FreshRSS_Context::systemConf()->limits['max_search_length']);
self::assertSame($input, (string)new FreshRSS_BooleanSearch($input));
$input = str_repeat('(', FreshRSS_Context::systemConf()->limits['max_search_parentheses_depth']) . 'ab' .
str_repeat(')', FreshRSS_Context::systemConf()->limits['max_search_parentheses_depth']);
self::assertSame('ab', (string)new FreshRSS_BooleanSearch($input));
}
/** @return list<list{string}> */
public static function provideTooLongOrTooDeepSearches(): array {
if (!FreshRSS_Context::hasSystemConf()) {
FreshRSS_Context::initSystem();
}
$tooLong = str_repeat('a', FreshRSS_Context::systemConf()->limits['max_search_length'] + 1);
$tooDeep = str_repeat('(', FreshRSS_Context::systemConf()->limits['max_search_parentheses_depth'] + 1) . 'ab' .
str_repeat(')', FreshRSS_Context::systemConf()->limits['max_search_parentheses_depth'] + 1);
return [
[$tooLong],
[$tooDeep],
];
}
#[DataProvider('provideTooLongOrTooDeepSearches')]
public function test_constructor_rejectsTooLongOrTooDeepSearches(string $input): void {
self::expectException(Minz_BadRequestException::class);
new FreshRSS_BooleanSearch($input);
}
}