A free, self-hostable news aggregator…
Fix search using user queries (#5669)
Alexandre Alapetite89a3d36c3e68
diff --git a/app/Models/BooleanSearch.php b/app/Models/BooleanSearch.phpindex 0a50464de..03fec4cb7 100644--- a/app/Models/BooleanSearch.php+++ b/app/Models/BooleanSearch.php@@ -90,10 +90,14 @@ class FreshRSS_BooleanSearch {}if (!empty($all_matches)) {+ $category_dao = FreshRSS_Factory::createCategoryDao();+ $feed_dao = FreshRSS_Factory::createFeedDao();+ $tag_dao = FreshRSS_Factory::createTagDao();+/** @var array<string,FreshRSS_UserQuery> */$queries = [];foreach (FreshRSS_Context::$user_conf->queries as $raw_query) {- $query = new FreshRSS_UserQuery($raw_query);+ $query = new FreshRSS_UserQuery($raw_query, $feed_dao, $category_dao, $tag_dao);$queries[] = $query;}diff --git a/app/Models/UserQuery.php b/app/Models/UserQuery.phpindex f5e45f6d2..2f7968315 100644--- a/app/Models/UserQuery.php+++ b/app/Models/UserQuery.php@@ -125,7 +125,7 @@ class FreshRSS_UserQuery {*/private function parseCategory(int $id): void {if ($this->category_dao === null) {- throw new FreshRSS_DAO_Exception('Category DAO is not loaded in UserQuery');+ $this->category_dao = FreshRSS_Factory::createCategoryDao();}$category = $this->category_dao->searchById($id);if ($category !== null) {@@ -143,7 +143,7 @@ class FreshRSS_UserQuery {*/private function parseFeed(int $id): void {if ($this->feed_dao === null) {- throw new FreshRSS_DAO_Exception('Feed DAO is not loaded in UserQuery');+ $this->feed_dao = FreshRSS_Factory::createFeedDao();}$feed = $this->feed_dao->searchById($id);if ($feed !== null) {@@ -160,8 +160,8 @@ class FreshRSS_UserQuery {* @throws FreshRSS_DAO_Exception*/private function parseTag(int $id): void {- if ($this->tag_dao == null) {- throw new FreshRSS_DAO_Exception('Tag DAO is not loaded in UserQuery');+ if ($this->tag_dao === null) {+ $this->tag_dao = FreshRSS_Factory::createTagDao();}$tag = $this->tag_dao->searchById($id);if ($tag !== null) {diff --git a/tests/app/Models/UserQueryTest.php b/tests/app/Models/UserQueryTest.phpindex aa66b1447..668327139 100644--- a/tests/app/Models/UserQueryTest.php+++ b/tests/app/Models/UserQueryTest.php@@ -19,14 +19,6 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {self::assertEquals('favorite', $user_query->getGetType());}- public function test__construct_whenCategoryQueryAndNoDao_throwsException(): void {- $this->expectException(FreshRSS_DAO_Exception::class);- $this->expectExceptionMessage('Category DAO is not loaded in UserQuery');-- $query = array('get' => 'c_1');- new FreshRSS_UserQuery($query);- }-public function test__construct_whenCategoryQuery_storesCategoryParameters(): void {$category_name = 'some category name';/** @var FreshRSS_Category&PHPUnit\Framework\MockObject\MockObject */@@ -47,14 +39,6 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {self::assertEquals('category', $user_query->getGetType());}- public function test__construct_whenFeedQueryAndNoDao_throwsException(): void {- $this->expectException(FreshRSS_DAO_Exception::class);- $this->expectExceptionMessage('Feed DAO is not loaded in UserQuery');-- $query = array('get' => 'f_1');- new FreshRSS_UserQuery($query);- }-public function test__construct_whenFeedQuery_storesFeedParameters(): void {$feed_name = 'some feed name';/** @var FreshRSS_Feed&PHPUnit\Framework\MockObject\MockObject */