@@ -39,6 +39,8 @@ class SharesUpdatedListenerTest extends \Test\TestCase {
3939 private LoggerInterface &MockObject $ logger ;
4040 private $ clockFn ;
4141
42+ private int $ time = 0 ;
43+
4244 protected function setUp (): void {
4345 parent ::setUp ();
4446
@@ -50,7 +52,7 @@ protected function setUp(): void {
5052 $ this ->userConfig = new MockUserConfig ();
5153 $ this ->clock = $ this ->createMock (ClockInterface::class);
5254 $ this ->clockFn = function () {
53- return new \DateTimeImmutable (' @0 ' );
55+ return new \DateTimeImmutable (" @ { $ this -> time }" );
5456 };
5557 $ this ->clock ->method ('now ' )
5658 ->willReturnCallback (function () {
@@ -161,6 +163,36 @@ public static function shareMarkAfterTimeProvider(): array {
161163 ];
162164 }
163165
166+ public function testCutoffSpansMultipleHandleInvocations (): void {
167+ $ share = $ this ->createMock (IShare::class);
168+ $ user1 = $ this ->createUser ('user1 ' , '' );
169+
170+ $ this ->manager ->method ('getUsersForShare ' )
171+ ->willReturn ([$ user1 ]);
172+
173+ $ event = new ShareCreatedEvent ($ share );
174+ $ this ->sharesUpdatedListener ->setCutOffMarkTime (4 );
175+
176+ // First handle at t=0: firstRun=0, elapsed=0 < 0.5 → callback runs
177+ $ this ->shareRecipientUpdater
178+ ->expects ($ this ->exactly (2 ))
179+ ->method ('updateForAddedShare ' );
180+
181+ $ this ->assertFalse (
182+ $ this ->userConfig ->getValueBool ($ user1 ->getUID (), 'files_sharing ' , ConfigLexicon::USER_NEEDS_SHARE_REFRESH )
183+ );
184+
185+ $ this ->sharesUpdatedListener ->handle ($ event );
186+ $ this ->time = 1 ;
187+ $ this ->sharesUpdatedListener ->handle ($ event );
188+ $ this ->time = 4 ;
189+ $ this ->sharesUpdatedListener ->handle ($ event );
190+
191+ $ this ->assertTrue (
192+ $ this ->userConfig ->getValueBool ($ user1 ->getUID (), 'files_sharing ' , ConfigLexicon::USER_NEEDS_SHARE_REFRESH )
193+ );
194+ }
195+
164196 #[DataProvider('shareMarkAfterTimeProvider ' )]
165197 public function testShareMarkAfterTime (float $ cutOff , int $ expectedCount ) {
166198 $ share = $ this ->createMock (IShare::class);
0 commit comments