From 2663ee5cce76ccb4da2c7abb05a023000fcb7066 Mon Sep 17 00:00:00 2001 From: "Misha M.-Kupriyanov" Date: Thu, 4 Sep 2025 12:50:55 +0200 Subject: [PATCH] chore(Application.php): conditionally load files search script in simplesettings context lets ensure that script addition happens in proper context inspired by https://github.com/IONOS-Productivity/nc-server/blob/e68ddae1e3c1e4532043f07bbc1bd9d1c96aa8a1/apps/files/lib/Controller/ViewController.php#L188 Signed-off-by: Misha M.-Kupriyanov Co-authored-by: Tatjana Kaschperko Lindt --- lib/AppInfo/Application.php | 1 - lib/Controller/PageController.php | 2 ++ tests/Controller/PageControllerTest.php | 30 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index b320a27..52235ea 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -34,7 +34,6 @@ class Application extends App implements IBootstrap { /** @psalm-suppress PossiblyUnusedMethod */ public function __construct() { parent::__construct(self::APP_ID); - \OCP\Util::addScript('files', 'search'); } public function register(IRegistrationContext $context): void { diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 1eedc0d..7ad8556 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -107,6 +107,8 @@ public function index(): TemplateResponse { $this->getCustomClientURL() ); + Util::addScript('files', 'search'); + return new TemplateResponse( Application::APP_ID, 'index', diff --git a/tests/Controller/PageControllerTest.php b/tests/Controller/PageControllerTest.php index ddc3f30..89ba419 100644 --- a/tests/Controller/PageControllerTest.php +++ b/tests/Controller/PageControllerTest.php @@ -210,6 +210,23 @@ protected function setUp(): void { $this->l10nFactory->expects($this->atMost(1)) ->method('getLanguages') ->willReturn($this->mockAvailableLanguages); + + $this->resetUtilState(); + } + + protected function tearDown(): void { + $this->resetUtilState(); + parent::tearDown(); + } + + /** + * Reset Util script and style state for clean test isolation + */ + private function resetUtilState(): void { + \OC_Util::$scripts = []; + \OC_Util::$styles = []; + self::invokePrivate(\OCP\Util::class, 'scripts', [[]]); + self::invokePrivate(\OCP\Util::class, 'scriptDeps', [[]]); } /** @@ -395,4 +412,17 @@ public function testIndexProvidesInitialStateWithCustomClientURLs() { $this->controller->index(); } + + public function testFileSearchScriptInjection(): void { + $scripts = Util::getScripts(); + + $this->assertNotContains('files/js/search', $scripts, 'File search script should NOT be injected'); + + $this->controller->index(); + + $scripts = Util::getScripts(); + + $this->assertContains('files/l10n/en', $scripts, 'File search script i18n should be injected'); + $this->assertContains('files/js/search', $scripts, 'File search script should be injected'); + } }