1515use OCA \DAV \CalDAV \PublicCalendarRoot ;
1616use OCA \DAV \Connector \Sabre \Principal ;
1717use OCP \EventDispatcher \IEventDispatcher ;
18+ use OCP \IAppConfig ;
1819use OCP \ICacheFactory ;
1920use OCP \IConfig ;
2021use OCP \IDBConnection ;
2122use OCP \IGroupManager ;
2223use OCP \IL10N ;
24+ use OCP \IUser ;
2325use OCP \IUserManager ;
2426use OCP \Security \ISecureRandom ;
2527use OCP \Server ;
2628use PHPUnit \Framework \MockObject \MockObject ;
2729use Psr \Log \LoggerInterface ;
30+ use Sabre \DAV \Exception \NotFound ;
2831use Test \TestCase ;
2932
3033/**
3639#[\PHPUnit \Framework \Attributes \Group(name: 'DB ' )]
3740class PublicCalendarRootTest extends TestCase {
3841 public const UNIT_TEST_USER = '' ;
42+ private const DISABLED_USER_PRINCIPAL = 'principals/users/disabled-caldav-unit-test ' ;
3943 private CalDavBackend $ backend ;
4044 private PublicCalendarRoot $ publicCalendarRoot ;
4145 private IL10N &MockObject $ l10n ;
4246 private Principal &MockObject $ principal ;
4347 protected IUserManager &MockObject $ userManager ;
4448 protected IGroupManager &MockObject $ groupManager ;
4549 protected IConfig &MockObject $ config ;
50+ protected IAppConfig &MockObject $ appConfig ;
4651 private ISecureRandom $ random ;
4752 private LoggerInterface &MockObject $ logger ;
4853 protected ICacheFactory &MockObject $ cacheFactory ;
@@ -87,9 +92,10 @@ protected function setUp(): void {
8792 );
8893 $ this ->l10n = $ this ->createMock (IL10N ::class);
8994 $ this ->config = $ this ->createMock (IConfig::class);
95+ $ this ->appConfig = $ this ->createMock (IAppConfig::class);
9096
9197 $ this ->publicCalendarRoot = new PublicCalendarRoot ($ this ->backend ,
92- $ this ->l10n , $ this ->config , $ this ->logger );
98+ $ this ->l10n , $ this ->config , $ this ->appConfig , $ this -> logger , $ this -> userManager );
9399 }
94100
95101 protected function tearDown (): void {
@@ -106,7 +112,10 @@ protected function tearDown(): void {
106112 ->withAnyParameters ()
107113 ->willReturn ([]);
108114
109- $ books = $ this ->backend ->getCalendarsForUser (self ::UNIT_TEST_USER );
115+ $ books = array_merge (
116+ $ this ->backend ->getCalendarsForUser (self ::UNIT_TEST_USER ),
117+ $ this ->backend ->getCalendarsForUser (self ::DISABLED_USER_PRINCIPAL ),
118+ );
110119 foreach ($ books as $ book ) {
111120 $ this ->backend ->deleteCalendar ($ book ['id ' ], true );
112121 }
@@ -136,10 +145,32 @@ public function testGetChildren(): void {
136145 $ this ->assertSame ([], $ calendarResults );
137146 }
138147
139- protected function createPublicCalendar (): Calendar {
140- $ this ->backend ->createCalendar (self ::UNIT_TEST_USER , 'Example ' , []);
148+ public function testGetChildHidesCalendarOfDisabledUser (): void {
149+ $ calendar = $ this ->createPublicCalendar (self ::DISABLED_USER_PRINCIPAL );
150+ $ publicUri = $ calendar ->getPublishStatus ();
151+
152+ $ this ->mockDisabledOwner ();
153+ $ this ->setHideDisabledUserShares (true );
154+
155+ $ this ->expectException (NotFound::class);
156+ $ this ->publicCalendarRoot ->getChild ($ publicUri );
157+ }
158+
159+ public function testGetChildServesCalendarOfDisabledUserWhenHidingIsDisabled (): void {
160+ $ calendar = $ this ->createPublicCalendar (self ::DISABLED_USER_PRINCIPAL );
161+ $ publicUri = $ calendar ->getPublishStatus ();
162+
163+ $ this ->mockDisabledOwner ();
164+ $ this ->setHideDisabledUserShares (false );
165+
166+ $ calendarResult = $ this ->publicCalendarRoot ->getChild ($ publicUri );
167+ $ this ->assertEquals ($ calendar , $ calendarResult );
168+ }
169+
170+ protected function createPublicCalendar (string $ principal = self ::UNIT_TEST_USER ): Calendar {
171+ $ this ->backend ->createCalendar ($ principal , 'Example ' , []);
141172
142- $ calendarInfo = $ this ->backend ->getCalendarsForUser (self :: UNIT_TEST_USER )[0 ];
173+ $ calendarInfo = $ this ->backend ->getCalendarsForUser ($ principal )[0 ];
143174 $ calendar = new PublicCalendar ($ this ->backend , $ calendarInfo , $ this ->l10n , $ this ->config , $ this ->logger );
144175 $ publicUri = $ calendar ->setPublishStatus (true );
145176
@@ -148,4 +179,18 @@ protected function createPublicCalendar(): Calendar {
148179
149180 return $ calendar ;
150181 }
182+
183+ private function mockDisabledOwner (): void {
184+ $ disabledUser = $ this ->createMock (IUser::class);
185+ $ disabledUser ->method ('isEnabled ' )
186+ ->willReturn (false );
187+ $ this ->userManager ->method ('get ' )
188+ ->willReturn ($ disabledUser );
189+ }
190+
191+ private function setHideDisabledUserShares (bool $ hide ): void {
192+ $ this ->appConfig ->method ('getValueBool ' )
193+ ->with ('files_sharing ' , 'hide_disabled_user_shares ' , 'yes ' )
194+ ->willReturn ($ hide );
195+ }
151196}
0 commit comments