1616use OCP \IConfig ;
1717use OCP \L10N \IFactory ;
1818use OCP \Share \IManager ;
19+ use OCP \Util ;
1920use PHPUnit \Framework \MockObject \MockObject ;
2021use Psr \Log \LoggerInterface ;
2122use Test \TestCase ;
@@ -37,6 +38,21 @@ protected function setUp(): void {
3738 $ this ->factory = $ this ->createMock (IFactory::class);
3839 $ this ->initialStateService = $ this ->createMock (InitialStateService::class);
3940 $ this ->config = $ this ->createMock (IConfig::class);
41+
42+ /* Empty static array to avoid inter-test conflicts */
43+ \OC_Util::$ styles = [];
44+ self ::invokePrivate (Util::class, 'scripts ' , [[]]);
45+ self ::invokePrivate (Util::class, 'scriptDeps ' , [[]]);
46+ self ::invokePrivate (Util::class, 'scriptsInit ' , [[]]);
47+ }
48+
49+ protected function tearDown (): void {
50+ parent ::tearDown ();
51+
52+ \OC_Util::$ styles = [];
53+ self ::invokePrivate (Util::class, 'scripts ' , [[]]);
54+ self ::invokePrivate (Util::class, 'scriptDeps ' , [[]]);
55+ self ::invokePrivate (Util::class, 'scriptsInit ' , [[]]);
4056 }
4157
4258 public function testHandleIgnoresNonMatchingEvent (): void {
@@ -61,7 +77,7 @@ public function testHandleWithLoadAdditionalScriptsEvent(): void {
6177 $ this ->overwriteService (InitialStateService::class, $ this ->initialStateService );
6278 $ this ->overwriteService (IConfig::class, $ this ->config );
6379
64- $ scriptsBefore = \ OCP \ Util::getScripts ();
80+ $ scriptsBefore = Util::getScripts ();
6581 $ this ->assertNotContains ('files_sharing/l10n/language_mock ' , $ scriptsBefore );
6682 $ this ->assertNotContains ('files_sharing/js/additionalScripts ' , $ scriptsBefore );
6783 $ this ->assertNotContains ('files_sharing/js/init ' , $ scriptsBefore );
@@ -71,14 +87,12 @@ public function testHandleWithLoadAdditionalScriptsEvent(): void {
7187 $ listener ->handle ($ this ->event );
7288
7389 // assert array $scripts contains the expected scripts
74- $ scriptsAfter = \ OCP \ Util::getScripts ();
90+ $ scriptsAfter = Util::getScripts ();
7591 $ this ->assertContains ('files_sharing/l10n/language_mock ' , $ scriptsAfter );
7692 $ this ->assertContains ('files_sharing/js/additionalScripts ' , $ scriptsAfter );
7793 $ this ->assertNotContains ('files_sharing/js/init ' , $ scriptsAfter );
7894
7995 $ this ->assertContains ('files_sharing/css/icons ' , \OC_Util::$ styles );
80-
81- $ this ->assertTrue (true );
8296 }
8397
8498 public function testHandleWithLoadAdditionalScriptsEventWithShareApiEnabled (): void {
@@ -92,17 +106,15 @@ public function testHandleWithLoadAdditionalScriptsEventWithShareApiEnabled(): v
92106 $ this ->overwriteService (IConfig::class, $ this ->config );
93107 $ this ->overwriteService (IFactory::class, $ this ->factory );
94108
95- $ scriptsBefore = \ OCP \ Util::getScripts ();
109+ $ scriptsBefore = Util::getScripts ();
96110 $ this ->assertNotContains ('files_sharing/js/init ' , $ scriptsBefore );
97111
98112 // Util static methods can't be easily mocked, so just ensure no exceptions
99113 $ listener ->handle ($ this ->event );
100114
101- $ scriptsAfter = \ OCP \ Util::getScripts ();
115+ $ scriptsAfter = Util::getScripts ();
102116
103117 // assert array $scripts contains the expected scripts
104118 $ this ->assertContains ('files_sharing/js/init ' , $ scriptsAfter );
105-
106- $ this ->assertTrue (true );
107119 }
108120}
0 commit comments