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'); + } }