From cf8caba88dcd237f0dc272a55d84b94ec160ac77 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 2 Nov 2025 09:25:53 +0000 Subject: [PATCH 1/5] Initial plan From f4a50d2cb3d7e96605a514d85e185d6f794964c3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 2 Nov 2025 09:44:46 +0000 Subject: [PATCH 2/5] Fix: Respect search.searchForSolutionId config with Elasticsearch/OpenSearch Co-authored-by: thorsten <45284+thorsten@users.noreply.github.com> --- phpmyfaq/src/phpMyFAQ/Search.php | 2 +- tests/phpMyFAQ/SearchTest.php | 69 +++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/phpmyfaq/src/phpMyFAQ/Search.php b/phpmyfaq/src/phpMyFAQ/Search.php index 6ac823e4d9..8ab437ddf0 100755 --- a/phpmyfaq/src/phpMyFAQ/Search.php +++ b/phpmyfaq/src/phpMyFAQ/Search.php @@ -77,7 +77,7 @@ public function getCategoryId(): ?int */ public function search(string $searchTerm, bool $allLanguages = true): array { - if (is_numeric($searchTerm)) { + if (is_numeric($searchTerm) && $this->configuration->get('search.searchForSolutionId')) { return $this->searchDatabase($searchTerm, $allLanguages); } diff --git a/tests/phpMyFAQ/SearchTest.php b/tests/phpMyFAQ/SearchTest.php index ace5f3aca3..8c6a1774fa 100644 --- a/tests/phpMyFAQ/SearchTest.php +++ b/tests/phpMyFAQ/SearchTest.php @@ -54,8 +54,10 @@ public function testGetCategoryId(): void /** * @throws Exception */ - public function testSearchWithNumericTerm(): void + public function testSearchWithNumericTermWhenSolutionIdSearchEnabled(): void { + $this->configuration->set('search.searchForSolutionId', 'true'); + $this->search = $this->getMockBuilder(Search::class) ->setConstructorArgs([$this->configuration]) ->onlyMethods(['searchDatabase']) @@ -69,6 +71,71 @@ public function testSearchWithNumericTerm(): void $this->assertEquals([], $this->search->search('123')); } + /** + * @throws Exception + */ + public function testSearchWithNumericTermWhenSolutionIdSearchDisabled(): void + { + $this->configuration->set('search.searchForSolutionId', 'false'); + $this->configuration->set('search.enableElasticsearch', 'false'); + $this->configuration->set('search.enableOpenSearch', 'false'); + + $this->search = $this->getMockBuilder(Search::class) + ->setConstructorArgs([$this->configuration]) + ->onlyMethods(['searchDatabase']) + ->getMock(); + + $this->search->expects($this->once()) + ->method('searchDatabase') + ->with('123', true) + ->willReturn([]); + + $this->assertEquals([], $this->search->search('123')); + } + + /** + * @throws Exception + */ + public function testSearchWithNumericTermWhenElasticsearchEnabledAndSolutionIdSearchDisabled(): void + { + $this->configuration->set('search.searchForSolutionId', 'false'); + $this->configuration->set('search.enableElasticsearch', 'true'); + + $this->search = $this->getMockBuilder(Search::class) + ->setConstructorArgs([$this->configuration]) + ->onlyMethods(['searchElasticsearch']) + ->getMock(); + + $this->search->expects($this->once()) + ->method('searchElasticsearch') + ->with('123', true) + ->willReturn([]); + + $this->assertEquals([], $this->search->search('123')); + } + + /** + * @throws Exception + */ + public function testSearchWithNumericTermWhenOpenSearchEnabledAndSolutionIdSearchDisabled(): void + { + $this->configuration->set('search.searchForSolutionId', 'false'); + $this->configuration->set('search.enableElasticsearch', 'false'); + $this->configuration->set('search.enableOpenSearch', 'true'); + + $this->search = $this->getMockBuilder(Search::class) + ->setConstructorArgs([$this->configuration]) + ->onlyMethods(['searchOpenSearch']) + ->getMock(); + + $this->search->expects($this->once()) + ->method('searchOpenSearch') + ->with('123', true) + ->willReturn([]); + + $this->assertEquals([], $this->search->search('123')); + } + /** * @throws Exception */ From 49c321f803708f4ff2585e8f4467c98ea7456dff Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 2 Nov 2025 09:49:48 +0000 Subject: [PATCH 3/5] Add clarifying comment to test for numeric search behavior Co-authored-by: thorsten <45284+thorsten@users.noreply.github.com> --- tests/phpMyFAQ/SearchTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/phpMyFAQ/SearchTest.php b/tests/phpMyFAQ/SearchTest.php index 8c6a1774fa..d2c7b4589b 100644 --- a/tests/phpMyFAQ/SearchTest.php +++ b/tests/phpMyFAQ/SearchTest.php @@ -73,6 +73,9 @@ public function testSearchWithNumericTermWhenSolutionIdSearchEnabled(): void /** * @throws Exception + * When solution ID search is disabled and no search engines are enabled, + * numeric searches should fall through to searchDatabase() which will + * perform a full-text search (not a solution ID search). */ public function testSearchWithNumericTermWhenSolutionIdSearchDisabled(): void { From ea222f4b3bccd989911f7a449e43e669321eec6e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 2 Nov 2025 09:50:56 +0000 Subject: [PATCH 4/5] Clarify test comment about searchDatabase parameters Co-authored-by: thorsten <45284+thorsten@users.noreply.github.com> --- tests/phpMyFAQ/SearchTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/phpMyFAQ/SearchTest.php b/tests/phpMyFAQ/SearchTest.php index d2c7b4589b..0364ef5d37 100644 --- a/tests/phpMyFAQ/SearchTest.php +++ b/tests/phpMyFAQ/SearchTest.php @@ -75,7 +75,10 @@ public function testSearchWithNumericTermWhenSolutionIdSearchEnabled(): void * @throws Exception * When solution ID search is disabled and no search engines are enabled, * numeric searches should fall through to searchDatabase() which will - * perform a full-text search (not a solution ID search). + * perform a full-text search (not a solution ID search). The database + * search classes check the configuration internally to determine the + * search type. The second parameter (true) indicates search across all + * languages, not the search type. */ public function testSearchWithNumericTermWhenSolutionIdSearchDisabled(): void { From 64e6e39dfd105f0776f6cb1ade8d8eb4d0bf15cb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 2 Nov 2025 10:05:55 +0000 Subject: [PATCH 5/5] Fix failing tests: Use reflection to set config values properly Co-authored-by: thorsten <45284+thorsten@users.noreply.github.com> --- tests/phpMyFAQ/SearchTest.php | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/tests/phpMyFAQ/SearchTest.php b/tests/phpMyFAQ/SearchTest.php index 0364ef5d37..4768c9cb75 100644 --- a/tests/phpMyFAQ/SearchTest.php +++ b/tests/phpMyFAQ/SearchTest.php @@ -7,6 +7,7 @@ use phpMyFAQ\Database\Sqlite3; use phpMyFAQ\Plugin\PluginException; use PHPUnit\Framework\TestCase; +use ReflectionClass; use stdClass; class SearchTest extends TestCase @@ -39,6 +40,19 @@ protected function tearDown(): void $this->search->deleteAllSearchTerms(); } + /** + * Helper method to set configuration values for testing using reflection + */ + private function setConfigValue(string $key, mixed $value): void + { + $reflection = new ReflectionClass($this->configuration); + $property = $reflection->getProperty('config'); + $property->setAccessible(true); + $config = $property->getValue($this->configuration); + $config[$key] = $value; + $property->setValue($this->configuration, $config); + } + public function testSetCategoryId(): void { $this->search->setCategoryId(1); @@ -56,7 +70,7 @@ public function testGetCategoryId(): void */ public function testSearchWithNumericTermWhenSolutionIdSearchEnabled(): void { - $this->configuration->set('search.searchForSolutionId', 'true'); + $this->setConfigValue('search.searchForSolutionId', 'true'); $this->search = $this->getMockBuilder(Search::class) ->setConstructorArgs([$this->configuration]) @@ -82,9 +96,9 @@ public function testSearchWithNumericTermWhenSolutionIdSearchEnabled(): void */ public function testSearchWithNumericTermWhenSolutionIdSearchDisabled(): void { - $this->configuration->set('search.searchForSolutionId', 'false'); - $this->configuration->set('search.enableElasticsearch', 'false'); - $this->configuration->set('search.enableOpenSearch', 'false'); + $this->setConfigValue('search.searchForSolutionId', 'false'); + $this->setConfigValue('search.enableElasticsearch', 'false'); + $this->setConfigValue('search.enableOpenSearch', 'false'); $this->search = $this->getMockBuilder(Search::class) ->setConstructorArgs([$this->configuration]) @@ -104,8 +118,8 @@ public function testSearchWithNumericTermWhenSolutionIdSearchDisabled(): void */ public function testSearchWithNumericTermWhenElasticsearchEnabledAndSolutionIdSearchDisabled(): void { - $this->configuration->set('search.searchForSolutionId', 'false'); - $this->configuration->set('search.enableElasticsearch', 'true'); + $this->setConfigValue('search.searchForSolutionId', 'false'); + $this->setConfigValue('search.enableElasticsearch', 'true'); $this->search = $this->getMockBuilder(Search::class) ->setConstructorArgs([$this->configuration]) @@ -125,9 +139,9 @@ public function testSearchWithNumericTermWhenElasticsearchEnabledAndSolutionIdSe */ public function testSearchWithNumericTermWhenOpenSearchEnabledAndSolutionIdSearchDisabled(): void { - $this->configuration->set('search.searchForSolutionId', 'false'); - $this->configuration->set('search.enableElasticsearch', 'false'); - $this->configuration->set('search.enableOpenSearch', 'true'); + $this->setConfigValue('search.searchForSolutionId', 'false'); + $this->setConfigValue('search.enableElasticsearch', 'false'); + $this->setConfigValue('search.enableOpenSearch', 'true'); $this->search = $this->getMockBuilder(Search::class) ->setConstructorArgs([$this->configuration])