aboutsummaryrefslogtreecommitdiff
path: root/tests/app
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2026-01-03 16:52:33 +0100
committerGravatar GitHub <noreply@github.com> 2026-01-03 16:52:33 +0100
commit252703305758e2ed0e6257ae94fdb3b4b90f7184 (patch)
tree058b449bda17aef10eefbaadd38741161b47cb2b /tests/app
parentf0769d6e557320c6af93f7f589f9dbf05a96ca47 (diff)
Fix unwanted expansion of user queries in some cases (#8395)
fix https://github.com/FreshRSS/FreshRSS/issues/8378
Diffstat (limited to 'tests/app')
-rw-r--r--tests/app/Models/SearchTest.php108
1 files changed, 97 insertions, 11 deletions
diff --git a/tests/app/Models/SearchTest.php b/tests/app/Models/SearchTest.php
index 9e107a79d..09db13205 100644
--- a/tests/app/Models/SearchTest.php
+++ b/tests/app/Models/SearchTest.php
@@ -243,11 +243,11 @@ final class SearchTest extends \PHPUnit\Framework\TestCase {
}
/**
- * @param list<array{search:string}> $queries
+ * @param list<array{search:string,name?:string}> $queries
* @param array{0:string,1:list<string|int>} $expectedResult
*/
- #[DataProvider('provideSavedQueryIdExpansion')]
- public static function test__construct_whenInputContainsSavedQueryIds_expandsSavedSearches(array $queries, string $input, array $expectedResult): void {
+ #[DataProvider('provideSavedQueriesExpansion')]
+ public static function test__construct_whenInputContainsSavedQueries_expandsSavedSearches(array $queries, string $input, array $expectedResult): void {
$previousUserConf = FreshRSS_Context::hasUserConf() ? FreshRSS_Context::userConf() : null;
$newUserConf = $previousUserConf instanceof FreshRSS_UserConfiguration ? clone $previousUserConf : clone FreshRSS_UserConfiguration::default();
$newUserConf->queries = $queries;
@@ -266,14 +266,36 @@ final class SearchTest extends \PHPUnit\Framework\TestCase {
/**
* @return array<string,array{0:list<array{search:string}>,1:string,2:array{0:string,1:list<string|int>}}>
*/
- public static function provideSavedQueryIdExpansion(): array {
+ public static function provideSavedQueriesExpansion(): array {
return [
- 'expanded single group' => [
+ 'not found ID' => [
[
['search' => 'author:Alice'],
['search' => 'intitle:World'],
],
- 'S:0,1',
+ 'S:3',
+ [
+ '',
+ [],
+ ],
+ ],
+ 'not found name' => [
+ [
+ ['search' => 'author:Alice', 'name' => 'First'],
+ ['search' => 'intitle:World', 'name' => 'Second'],
+ ],
+ 'search:Third',
+ [
+ '',
+ [],
+ ],
+ ],
+ 'expanded single group name' => [
+ [
+ ['search' => 'author:Alice', 'name' => 'First'],
+ ['search' => 'intitle:World', 'name' => 'Second'],
+ ],
+ 'search:First OR search:Second',
[
'((e.author LIKE ? )) OR ((e.title LIKE ? ))',
['%Alice%', '%World%'],
@@ -286,7 +308,7 @@ final class SearchTest extends \PHPUnit\Framework\TestCase {
['search' => 'inurl:Example'],
['search' => 'author:Bob'],
],
- 'S:0,1 OR S:2,3',
+ 'S:0,1 OR S:2,3,5',
[
'((e.author LIKE ? )) OR ((e.title LIKE ? )) OR ((e.link LIKE ? )) OR ((e.author LIKE ? ))',
['%Alice%', '%World%', '%Example%', '%Bob%'],
@@ -970,9 +992,9 @@ final class SearchTest extends \PHPUnit\Framework\TestCase {
}
#[DataProvider('provideBooleanSearchToString')]
- public static function testBooleanSearch__toString(string $input, string $expected): void {
+ public static function testBooleanSearchToString(string $input, string $expected): void {
$search = new FreshRSS_BooleanSearch($input);
- self::assertSame($expected, $search->__toString());
+ self::assertSame($expected, $search->toString());
}
/**
@@ -1023,6 +1045,70 @@ final class SearchTest extends \PHPUnit\Framework\TestCase {
];
}
+ /**
+ * @param list<array{search:string,name?:string}> $queries
+ */
+ #[DataProvider('provideBooleanSearchToStringExpansion')]
+ public static function testBooleanSearchToStringExpansion(array $queries, string $input,
+ string $expectedNotExpanded, string $expectedExpanded): void {
+ $previousUserConf = FreshRSS_Context::hasUserConf() ? FreshRSS_Context::userConf() : null;
+ $newUserConf = $previousUserConf instanceof FreshRSS_UserConfiguration ? clone $previousUserConf : clone FreshRSS_UserConfiguration::default();
+ $newUserConf->queries = $queries;
+ FreshRSS_Context::setUserConf($newUserConf);
+
+ try {
+ $booleanSearch = new FreshRSS_BooleanSearch($input);
+ self::assertSame($expectedNotExpanded, $booleanSearch->toString(expandUserQueries: false));
+ self::assertSame($expectedExpanded, $booleanSearch->toString());
+ } finally {
+ FreshRSS_Context::setUserConf($previousUserConf);
+ }
+ }
+
+ /**
+ * @return array<string,array{0:list<array{search:string,name?:string}>,1:string,2:string,3:string}>
+ */
+ public static function provideBooleanSearchToStringExpansion(): array {
+ return [
+ 'Not found ID' => [
+ [
+ ['search' => 'author:Alice'],
+ ['search' => 'intitle:World'],
+ ],
+ 'S:3 S:4,5 ',
+ 'S:3 S:4,5',
+ '',
+ ],
+ 'Not found name' => [
+ [
+ ['search' => 'author:Alice', 'name' => 'First'],
+ ['search' => 'intitle:World', 'name' => 'Second'],
+ ],
+ 'search:Third ',
+ 'search:Third',
+ '',
+ ],
+ 'Found IDs' => [
+ [
+ ['search' => 'author:Alice', 'name' => 'First'],
+ ['search' => 'intitle:World', 'name' => 'Second'],
+ ],
+ 'S:0,1 ',
+ 'S:0,1',
+ 'author:Alice OR intitle:World',
+ ],
+ 'Found names' => [
+ [
+ ['search' => 'author:Alice', 'name' => 'First'],
+ ['search' => 'intitle:World', 'name' => 'Second'],
+ ],
+ 'search:First search:Second ',
+ 'search:First search:Second',
+ 'author:Alice intitle:World',
+ ],
+ ];
+ }
+
#[DataProvider('provideHasSameOperators')]
public function testHasSameOperators(string $input1, string $input2, bool $expected): void {
$search1 = new FreshRSS_Search($input1);
@@ -1047,7 +1133,7 @@ final class SearchTest extends \PHPUnit\Framework\TestCase {
$searchToEnforce = new FreshRSS_Search($enforceInput);
$newBooleanSearch = $booleanSearch->enforce($searchToEnforce);
self::assertNotSame($booleanSearch, $newBooleanSearch);
- self::assertSame($expectedOutput, $newBooleanSearch->__toString());
+ self::assertSame($expectedOutput, $newBooleanSearch->toString());
}
/**
@@ -1081,7 +1167,7 @@ final class SearchTest extends \PHPUnit\Framework\TestCase {
$searchToRemove = new FreshRSS_Search($removeInput);
$newBooleanSearch = $booleanSearch->remove($searchToRemove);
self::assertNotSame($booleanSearch, $newBooleanSearch);
- self::assertSame($expectedOutput, $newBooleanSearch->__toString());
+ self::assertSame($expectedOutput, $newBooleanSearch->toString());
}
/**