1313use OCA \Polls \Db \Share ;
1414use OCA \Polls \Db \ShareMapper ;
1515use OCA \Polls \Exceptions \InvalidShareTypeException ;
16+ use OCA \Polls \Model \Settings \SystemSettings ;
1617use OCA \Polls \Service \ShareService ;
1718use OCA \Polls \Tests \Unit \UnitTestCase ;
1819use OCA \Polls \UserSession ;
@@ -25,12 +26,23 @@ class ShareServiceTest extends UnitTestCase {
2526 private PollMapper $ pollMapper ;
2627 private ISession $ session ;
2728 private UserSession $ userSession ;
29+ private SystemSettings $ originalSystemSettings ;
2830
2931 private Poll $ poll ;
3032 private Share $ userShare ;
3133
3234 protected function setUp (): void {
3335 parent ::setUp ();
36+
37+ // Save the real SystemSettings and replace it with a permissive mock so
38+ // that PERMISSION_SHARE_ADD / PERMISSION_SHARE_ADD_EXTERNAL are not
39+ // blocked by core IAppConfig group-restriction settings in the CI env.
40+ $ this ->originalSystemSettings = Server::get (SystemSettings::class);
41+ $ settingsMock = $ this ->createMock (SystemSettings::class);
42+ $ settingsMock ->method ('getShareCreateAllowed ' )->willReturn (true );
43+ $ settingsMock ->method ('getExternalShareCreationAllowed ' )->willReturn (true );
44+ \OC ::$ server ->registerService (SystemSettings::class, fn () => $ settingsMock );
45+
3446 $ this ->session = Server::get (ISession::class);
3547 $ this ->userSession = Server::get (UserSession::class);
3648 $ this ->shareService = Server::get (ShareService::class);
@@ -60,10 +72,15 @@ protected function tearDown(): void {
6072 $ this ->pollMapper ->delete ($ this ->poll );
6173 } catch (\Exception ) {
6274 }
75+ // Restore the real SystemSettings so other test classes are unaffected
76+ $ original = $ this ->originalSystemSettings ;
77+ \OC ::$ server ->registerService (SystemSettings::class, fn () => $ original );
6378 }
6479
6580 private function login (): void {
6681 $ this ->userSession ->cleanSession ();
82+ // Set the core Nextcloud user session so IUserSession::isLoggedIn() returns true
83+ \OC_User::setUserId ('admin ' );
6784 $ this ->session ->set (UserSession::SESSION_KEY_SHARE_TOKEN , $ this ->userShare ->getToken ());
6885 $ this ->session ->set (UserSession::SESSION_KEY_USER_ID , 'admin ' );
6986 }
0 commit comments