@@ -1077,6 +1077,7 @@ public function testGetAccessList() {
1077
1077
public function testSendMailNotificationWithSameUserAndUserEmail () {
1078
1078
$ provider = $ this ->getInstance ();
1079
1079
$ user = $ this ->createMock (IUser::class);
1080
+ $ this ->settingsManager ->expects ($ this ->any ())->method ('replyToInitiator ' )->willReturn (true );
1080
1081
$ this ->userManager
1081
1082
->expects ($ this ->once ())
1082
1083
->method ('get ' )
@@ -1175,6 +1176,7 @@ public function testSendMailNotificationWithSameUserAndUserEmail() {
1175
1176
public function testSendMailNotificationWithDifferentUserAndNoUserEmail () {
1176
1177
$ provider = $ this ->getInstance ();
1177
1178
$ initiatorUser = $ this ->createMock (IUser::class);
1179
+ $ this ->settingsManager ->expects ($ this ->any ())->method ('replyToInitiator ' )->willReturn (true );
1178
1180
$ this ->userManager
1179
1181
->expects ($ this ->once ())
1180
1182
->method ('get ' )
@@ -1260,4 +1262,188 @@ public function testSendMailNotificationWithDifferentUserAndNoUserEmail() {
1260
1262
null ,
1261
1263
]);
1262
1264
}
1265
+
1266
+ public function testSendMailNotificationWithSameUserAndUserEmailAndReplyToDesactivate () {
1267
+ $ provider = $ this ->getInstance ();
1268
+ $ user = $ this ->createMock (IUser::class);
1269
+ $ this ->settingsManager ->expects ($ this ->any ())->method ('replyToInitiator ' )->willReturn (false );
1270
+ $ this ->userManager
1271
+ ->expects ($ this ->once ())
1272
+ ->method ('get ' )
1273
+ ->with ('OwnerUser ' )
1274
+ ->willReturn ($ user );
1275
+ $ user
1276
+ ->expects ($ this ->once ())
1277
+ ->method ('getDisplayName ' )
1278
+ ->willReturn ('Mrs. Owner User ' );
1279
+ $ message = $ this ->createMock (Message::class);
1280
+ $ this ->mailer
1281
+ ->expects ($ this ->once ())
1282
+ ->method ('createMessage ' )
1283
+ ->willReturn ($ message );
1284
+ $ template = $ this ->createMock (IEMailTemplate::class);
1285
+ $ this ->mailer
1286
+ ->expects ($ this ->once ())
1287
+ ->method ('createEMailTemplate ' )
1288
+ ->willReturn ($ template );
1289
+ $ template
1290
+ ->expects ($ this ->once ())
1291
+ ->method ('addHeader ' );
1292
+ $ template
1293
+ ->expects ($ this ->once ())
1294
+ ->method ('addHeading ' )
1295
+ ->with ('Mrs. Owner User shared »file.txt« with you ' );
1296
+ $ template
1297
+ ->expects ($ this ->once ())
1298
+ ->method ('addBodyText ' )
1299
+ ->with (
1300
+ 'Mrs. Owner User shared »file.txt« with you. Click the button below to open it. ' ,
1301
+ 'Mrs. Owner User shared »file.txt« with you. '
1302
+ );
1303
+ $ template
1304
+ ->expects ($ this ->once ())
1305
+ ->method ('addBodyButton ' )
1306
+ ->with (
1307
+ 'Open »file.txt« ' ,
1308
+ 'https://example.com/file.txt '
1309
+ );
1310
+ $ message
1311
+ ->expects ($ this ->once ())
1312
+ ->method ('setTo ' )
1313
+ ->with (['john@doe.com ' ]);
1314
+ $ this ->defaults
1315
+ ->expects ($ this ->once ())
1316
+ ->method ('getName ' )
1317
+ ->willReturn ('UnitTestCloud ' );
1318
+ $ message
1319
+ ->expects ($ this ->once ())
1320
+ ->method ('setFrom ' )
1321
+ ->with ([
1322
+ \OCP \Util::getDefaultEmailAddress ('UnitTestCloud ' ) => 'UnitTestCloud '
1323
+ ]);
1324
+ $ user
1325
+ ->expects ($ this ->once ())
1326
+ ->method ('getEMailAddress ' )
1327
+ ->willReturn ('owner@example.com ' );
1328
+ $ message
1329
+ ->expects ($ this ->never ())
1330
+ ->method ('setReplyTo ' );
1331
+ $ template
1332
+ ->expects ($ this ->once ())
1333
+ ->method ('addFooter ' )
1334
+ ->with ('' );
1335
+ $ template
1336
+ ->expects ($ this ->once ())
1337
+ ->method ('setSubject ' )
1338
+ ->with ('Mrs. Owner User shared »file.txt« with you ' );
1339
+ $ message
1340
+ ->expects ($ this ->once ())
1341
+ ->method ('useTemplate ' )
1342
+ ->with ($ template );
1343
+ $ this ->mailer
1344
+ ->expects ($ this ->once ())
1345
+ ->method ('send ' )
1346
+ ->with ($ message );
1347
+
1348
+ self ::invokePrivate (
1349
+ $ provider ,
1350
+ 'sendMailNotification ' ,
1351
+ [
1352
+ 'file.txt ' ,
1353
+ 'https://example.com/file.txt ' ,
1354
+ 'OwnerUser ' ,
1355
+ 'john@doe.com ' ,
1356
+ null ,
1357
+ ]);
1358
+ }
1359
+
1360
+ public function testSendMailNotificationWithDifferentUserAndNoUserEmailAndReplyToDesactivate () {
1361
+ $ provider = $ this ->getInstance ();
1362
+ $ initiatorUser = $ this ->createMock (IUser::class);
1363
+ $ this ->settingsManager ->expects ($ this ->any ())->method ('replyToInitiator ' )->willReturn (false );
1364
+ $ this ->userManager
1365
+ ->expects ($ this ->once ())
1366
+ ->method ('get ' )
1367
+ ->with ('InitiatorUser ' )
1368
+ ->willReturn ($ initiatorUser );
1369
+ $ initiatorUser
1370
+ ->expects ($ this ->once ())
1371
+ ->method ('getDisplayName ' )
1372
+ ->willReturn ('Mr. Initiator User ' );
1373
+ $ message = $ this ->createMock (Message::class);
1374
+ $ this ->mailer
1375
+ ->expects ($ this ->once ())
1376
+ ->method ('createMessage ' )
1377
+ ->willReturn ($ message );
1378
+ $ template = $ this ->createMock (IEMailTemplate::class);
1379
+ $ this ->mailer
1380
+ ->expects ($ this ->once ())
1381
+ ->method ('createEMailTemplate ' )
1382
+ ->willReturn ($ template );
1383
+ $ template
1384
+ ->expects ($ this ->once ())
1385
+ ->method ('addHeader ' );
1386
+ $ template
1387
+ ->expects ($ this ->once ())
1388
+ ->method ('addHeading ' )
1389
+ ->with ('Mr. Initiator User shared »file.txt« with you ' );
1390
+ $ template
1391
+ ->expects ($ this ->once ())
1392
+ ->method ('addBodyText ' )
1393
+ ->with (
1394
+ 'Mr. Initiator User shared »file.txt« with you. Click the button below to open it. ' ,
1395
+ 'Mr. Initiator User shared »file.txt« with you. '
1396
+ );
1397
+ $ template
1398
+ ->expects ($ this ->once ())
1399
+ ->method ('addBodyButton ' )
1400
+ ->with (
1401
+ 'Open »file.txt« ' ,
1402
+ 'https://example.com/file.txt '
1403
+ );
1404
+ $ message
1405
+ ->expects ($ this ->once ())
1406
+ ->method ('setTo ' )
1407
+ ->with (['john@doe.com ' ]);
1408
+ $ this ->defaults
1409
+ ->expects ($ this ->once ())
1410
+ ->method ('getName ' )
1411
+ ->willReturn ('UnitTestCloud ' );
1412
+ $ message
1413
+ ->expects ($ this ->once ())
1414
+ ->method ('setFrom ' )
1415
+ ->with ([
1416
+ \OCP \Util::getDefaultEmailAddress ('UnitTestCloud ' ) => 'UnitTestCloud '
1417
+ ]);
1418
+ $ message
1419
+ ->expects ($ this ->never ())
1420
+ ->method ('setReplyTo ' );
1421
+ $ template
1422
+ ->expects ($ this ->once ())
1423
+ ->method ('addFooter ' )
1424
+ ->with ('' );
1425
+ $ template
1426
+ ->expects ($ this ->once ())
1427
+ ->method ('setSubject ' )
1428
+ ->with ('Mr. Initiator User shared »file.txt« with you ' );
1429
+ $ message
1430
+ ->expects ($ this ->once ())
1431
+ ->method ('useTemplate ' )
1432
+ ->with ($ template );
1433
+ $ this ->mailer
1434
+ ->expects ($ this ->once ())
1435
+ ->method ('send ' )
1436
+ ->with ($ message );
1437
+
1438
+ self ::invokePrivate (
1439
+ $ provider ,
1440
+ 'sendMailNotification ' ,
1441
+ [
1442
+ 'file.txt ' ,
1443
+ 'https://example.com/file.txt ' ,
1444
+ 'InitiatorUser ' ,
1445
+ 'john@doe.com ' ,
1446
+ null ,
1447
+ ]);
1448
+ }
1263
1449
}
0 commit comments