3434use OCA \Activity \UserSettings ;
3535use OCP \Activity \IEvent ;
3636use OCP \Activity \IManager ;
37+ use OCP \IAppConfig ;
3738use OCP \IConfig ;
3839use OCP \IDateTimeFormatter ;
3940use OCP \IDBConnection ;
@@ -65,6 +66,7 @@ class MailQueueHandlerTest extends TestCase {
6566 protected IFactory &MockObject $ lFactory ;
6667 protected IManager &MockObject $ activityManager ;
6768 protected IValidator &MockObject $ richObjectValidator ;
69+ protected IAppConfig &MockObject $ appConfig ;
6870 protected IConfig &MockObject $ config ;
6971 protected MockObject &LoggerInterface $ logger ;
7072
@@ -81,6 +83,7 @@ protected function setUp(): void {
8183 $ app = self ::getUniqueID ('MailQueueHandlerTest ' , 10 );
8284 $ this ->userManager = $ this ->createMock (IUserManager::class);
8385 $ this ->lFactory = $ this ->createMock (IFactory::class);
86+ $ this ->appConfig = $ this ->createMock (IAppConfig::class);
8487 $ this ->config = $ this ->createMock (IConfig::class);
8588 $ this ->logger = $ this ->createMock (LoggerInterface::class);
8689 $ this ->dateTimeFormatter = $ this ->createMock (IDateTimeFormatter::class);
@@ -141,6 +144,7 @@ protected function setUp(): void {
141144 $ this ->lFactory ,
142145 $ this ->activityManager ,
143146 $ this ->richObjectValidator ,
147+ $ this ->appConfig ,
144148 $ this ->config ,
145149 $ this ->logger ,
146150 $ this ->data ,
@@ -300,6 +304,10 @@ public function testSendEmailToUser(): void {
300304 public function testSendEmailsDeletesQueueOnMailerFailure (): void {
301305 $ maxTime = 200 ;
302306
307+ $ this ->appConfig ->method ('getValueBool ' )
308+ ->with ('activity ' , 'enable_email ' , true )
309+ ->willReturn (true );
310+
303311 $ template = $ this ->createMock (IEMailTemplate::class);
304312 $ this ->mailer ->method ('createEMailTemplate ' )
305313 ->willReturn ($ template );
@@ -340,6 +348,10 @@ public function testSendEmailsDeletesQueueOnMailerFailure(): void {
340348 public function testSendEmailsDeletesQueueOnSendReturnFalse (): void {
341349 $ maxTime = 200 ;
342350
351+ $ this ->appConfig ->method ('getValueBool ' )
352+ ->with ('activity ' , 'enable_email ' , true )
353+ ->willReturn (true );
354+
343355 $ template = $ this ->createMock (IEMailTemplate::class);
344356 $ this ->mailer ->method ('createEMailTemplate ' )
345357 ->willReturn ($ template );
@@ -370,6 +382,27 @@ public function testSendEmailsDeletesQueueOnSendReturnFalse(): void {
370382 }
371383 }
372384
385+ public function testSendEmailsSkipsWhenAdminEmailDisabled (): void {
386+ $ maxTime = 200 ;
387+
388+ $ this ->appConfig ->method ('getValueBool ' )
389+ ->with ('activity ' , 'enable_email ' , true )
390+ ->willReturn (false );
391+
392+ $ this ->mailer ->expects ($ this ->never ())
393+ ->method ('send ' );
394+
395+ $ result = $ this ->mailQueueHandler ->sendEmails (3 , $ maxTime );
396+
397+ $ this ->assertSame (0 , $ result );
398+
399+ // Queue must be untouched so emails can be sent if admin re-enables the toggle
400+ foreach (['user1 ' , 'user2 ' , 'user3 ' ] as $ user ) {
401+ [$ data ,] = self ::invokePrivate ($ this ->mailQueueHandler , 'getItemsForUser ' , [$ user , $ maxTime ]);
402+ $ this ->assertNotEmpty ($ data , "Queue entries for $ user must survive when email is globally disabled " );
403+ }
404+ }
405+
373406 /**
374407 * @param array $users
375408 * @param int $maxTime
0 commit comments