From b1f6283f6e260a5bd106d9b1209d4504955578f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 10 Jun 2025 13:10:35 +0200 Subject: [PATCH] fix(tests): Fix files_sharing tests conflicting with other tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../Listener/LoadAdditionalListenerTest.php | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/apps/files_sharing/tests/Listener/LoadAdditionalListenerTest.php b/apps/files_sharing/tests/Listener/LoadAdditionalListenerTest.php index cd3fb0568fa..75bee35d58a 100644 --- a/apps/files_sharing/tests/Listener/LoadAdditionalListenerTest.php +++ b/apps/files_sharing/tests/Listener/LoadAdditionalListenerTest.php @@ -16,6 +16,7 @@ use OCP\EventDispatcher\Event; use OCP\IConfig; use OCP\L10N\IFactory; use OCP\Share\IManager; +use OCP\Util; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -37,6 +38,21 @@ class LoadAdditionalListenerTest extends TestCase { $this->factory = $this->createMock(IFactory::class); $this->initialStateService = $this->createMock(InitialStateService::class); $this->config = $this->createMock(IConfig::class); + + /* Empty static array to avoid inter-test conflicts */ + \OC_Util::$styles = []; + self::invokePrivate(Util::class, 'scripts', [[]]); + self::invokePrivate(Util::class, 'scriptDeps', [[]]); + self::invokePrivate(Util::class, 'scriptsInit', [[]]); + } + + protected function tearDown(): void { + parent::tearDown(); + + \OC_Util::$styles = []; + self::invokePrivate(Util::class, 'scripts', [[]]); + self::invokePrivate(Util::class, 'scriptDeps', [[]]); + self::invokePrivate(Util::class, 'scriptsInit', [[]]); } public function testHandleIgnoresNonMatchingEvent(): void { @@ -61,7 +77,7 @@ class LoadAdditionalListenerTest extends TestCase { $this->overwriteService(InitialStateService::class, $this->initialStateService); $this->overwriteService(IConfig::class, $this->config); - $scriptsBefore = \OCP\Util::getScripts(); + $scriptsBefore = Util::getScripts(); $this->assertNotContains('files_sharing/l10n/language_mock', $scriptsBefore); $this->assertNotContains('files_sharing/js/additionalScripts', $scriptsBefore); $this->assertNotContains('files_sharing/js/init', $scriptsBefore); @@ -71,14 +87,12 @@ class LoadAdditionalListenerTest extends TestCase { $listener->handle($this->event); // assert array $scripts contains the expected scripts - $scriptsAfter = \OCP\Util::getScripts(); + $scriptsAfter = Util::getScripts(); $this->assertContains('files_sharing/l10n/language_mock', $scriptsAfter); $this->assertContains('files_sharing/js/additionalScripts', $scriptsAfter); $this->assertNotContains('files_sharing/js/init', $scriptsAfter); $this->assertContains('files_sharing/css/icons', \OC_Util::$styles); - - $this->assertTrue(true); } public function testHandleWithLoadAdditionalScriptsEventWithShareApiEnabled(): void { @@ -92,17 +106,15 @@ class LoadAdditionalListenerTest extends TestCase { $this->overwriteService(IConfig::class, $this->config); $this->overwriteService(IFactory::class, $this->factory); - $scriptsBefore = \OCP\Util::getScripts(); + $scriptsBefore = Util::getScripts(); $this->assertNotContains('files_sharing/js/init', $scriptsBefore); // Util static methods can't be easily mocked, so just ensure no exceptions $listener->handle($this->event); - $scriptsAfter = \OCP\Util::getScripts(); + $scriptsAfter = Util::getScripts(); // assert array $scripts contains the expected scripts $this->assertContains('files_sharing/js/init', $scriptsAfter); - - $this->assertTrue(true); } }