|
@@ -5,6 +5,13 @@ use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
|
|
|
|
final class BooleanSearchTest extends \PHPUnit\Framework\TestCase {
|
|
final class BooleanSearchTest extends \PHPUnit\Framework\TestCase {
|
|
|
|
|
|
|
|
|
|
+ public function __construct(string $name) {
|
|
|
|
|
+ parent::__construct($name);
|
|
|
|
|
+ if (!FreshRSS_Context::hasSystemConf()) {
|
|
|
|
|
+ FreshRSS_Context::initSystem();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* `FreshRSS_BooleanSearch::prepend()` is used to restrict an existing search with an extra condition,
|
|
* `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.
|
|
* such as the maximum publication date of the “mark as read → articles older than one day/week” action.
|
|
@@ -31,10 +38,19 @@ final class BooleanSearchTest extends \PHPUnit\Framework\TestCase {
|
|
|
self::assertSame($expectedValues, $values);
|
|
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}> */
|
|
/** @return list<list{string}> */
|
|
|
public static function provideTooLongOrTooDeepSearches(): array {
|
|
public static function provideTooLongOrTooDeepSearches(): array {
|
|
|
- $tooLong = str_repeat('ab ', 1400); // Long enough to exceed the maximum search length
|
|
|
|
|
- $tooDeep = str_repeat('(', 40) . 'ab' . str_repeat(')', 40); // Deeper than the maximum parentheses depth
|
|
|
|
|
|
|
+ $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 [
|
|
return [
|
|
|
[$tooLong],
|
|
[$tooLong],
|
|
|
[$tooDeep],
|
|
[$tooDeep],
|
|
@@ -44,7 +60,6 @@ final class BooleanSearchTest extends \PHPUnit\Framework\TestCase {
|
|
|
#[DataProvider('provideTooLongOrTooDeepSearches')]
|
|
#[DataProvider('provideTooLongOrTooDeepSearches')]
|
|
|
public function test_constructor_rejectsTooLongOrTooDeepSearches(string $input): void {
|
|
public function test_constructor_rejectsTooLongOrTooDeepSearches(string $input): void {
|
|
|
self::expectException(Minz_BadRequestException::class);
|
|
self::expectException(Minz_BadRequestException::class);
|
|
|
- // Tests run at the default PHP memory limit; a brute-force 1400-deep search would consume too much memory
|
|
|
|
|
new FreshRSS_BooleanSearch($input);
|
|
new FreshRSS_BooleanSearch($input);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|