3535use OCP \AppFramework \Utility \ITimeFactory ;
3636use OCP \Defaults ;
3737use OCP \IConfig ;
38- use OCP \IUserManager ;
38+ use OCP \IUser ;
39+ use OCP \IUserSession ;
3940use OCP \Mail \IAttachment ;
4041use OCP \Mail \IEMailTemplate ;
4142use OCP \Mail \IMailer ;
@@ -68,8 +69,11 @@ class IMipPluginTest extends TestCase {
6869 /** @var IConfig|MockObject */
6970 private $ config ;
7071
71- /** @var IUserManager|MockObject */
72- private $ userManager ;
72+ /** @var IUserSession|MockObject */
73+ private $ userSession ;
74+
75+ /** @var IUser|MockObject */
76+ private $ user ;
7377
7478 /** @var IMipPlugin */
7579 private $ plugin ;
@@ -107,8 +111,16 @@ protected function setUp(): void {
107111 $ this ->timeFactory ->method ('getTime ' )->willReturn (1496912528 ); // 2017-01-01
108112
109113 $ this ->config = $ this ->createMock (IConfig::class);
114+
115+ $ this ->user = $ this ->createMock (IUser::class);
116+ /*
117+ $this->user->method('getUID');
118+ $this->user->method('getDisplayName');
119+ */
110120
111- $ this ->userManager = $ this ->createMock (IUserManager::class);
121+ $ this ->userSession = $ this ->createMock (IUserSession::class);
122+ $ this ->userSession ->method ('getUser ' )
123+ ->willReturn ($ this ->user );
112124
113125 $ this ->defaults = $ this ->createMock (Defaults::class);
114126 $ this ->defaults ->method ('getName ' )
@@ -124,8 +136,7 @@ protected function setUp(): void {
124136 $ this ->logger ,
125137 $ this ->timeFactory ,
126138 $ this ->defaults ,
127- $ this ->userManager ,
128- 'user123 ' ,
139+ $ this ->userSession ,
129140 $ this ->service ,
130141 $ this ->eventComparisonService
131142 );
@@ -213,8 +224,15 @@ public function testParsingSingle(): void {
213224 ->method ('buildBodyData ' )
214225 ->with ($ newVevent , $ oldVEvent )
215226 ->willReturn ($ data );
216- $ this ->userManager ->expects (self ::never ())
217- ->method ('getDisplayName ' );
227+ $ this ->user ->expects (self ::any ())
228+ ->method ('getUID ' )
229+ ->willReturn ('user1 ' );
230+ $ this ->user ->expects (self ::any ())
231+ ->method ('getDisplayName ' )
232+ ->willReturn ('Mr. Wizard ' );
233+ $ this ->userSession ->expects (self ::any ())
234+ ->method ('getUser ' )
235+ ->willReturn ($ this ->user );
218236 $ this ->service ->expects (self ::once ())
219237 ->method ('getFrom ' );
220238 $ this ->service ->expects (self ::once ())
@@ -307,8 +325,15 @@ public function testAttendeeIsResource(): void {
307325 ->willReturn (true );
308326 $ this ->service ->expects (self ::never ())
309327 ->method ('buildBodyData ' );
310- $ this ->userManager ->expects (self ::never ())
311- ->method ('getDisplayName ' );
328+ $ this ->user ->expects (self ::any ())
329+ ->method ('getUID ' )
330+ ->willReturn ('user1 ' );
331+ $ this ->user ->expects (self ::any ())
332+ ->method ('getDisplayName ' )
333+ ->willReturn ('Mr. Wizard ' );
334+ $ this ->userSession ->expects (self ::any ())
335+ ->method ('getUser ' )
336+ ->willReturn ($ this ->user );
312337 $ this ->service ->expects (self ::never ())
313338 ->method ('getFrom ' );
314339 $ this ->service ->expects (self ::never ())
@@ -331,7 +356,6 @@ public function testAttendeeIsResource(): void {
331356 $ this ->assertEquals ('1.0 ' , $ message ->getScheduleStatus ());
332357 }
333358
334-
335359 public function testParsingRecurrence (): void {
336360 $ message = new Message ();
337361 $ message ->method = 'REQUEST ' ;
@@ -404,9 +428,15 @@ public function testParsingRecurrence(): void {
404428 ->method ('buildBodyData ' )
405429 ->with ($ newVevent , null )
406430 ->willReturn ($ data );
407- $ this ->userManager ->expects (self ::once ())
431+ $ this ->user ->expects (self ::any ())
432+ ->method ('getUID ' )
433+ ->willReturn ('user1 ' );
434+ $ this ->user ->expects (self ::any ())
408435 ->method ('getDisplayName ' )
409436 ->willReturn ('Mr. Wizard ' );
437+ $ this ->userSession ->expects (self ::any ())
438+ ->method ('getUser ' )
439+ ->willReturn ($ this ->user );
410440 $ this ->service ->expects (self ::once ())
411441 ->method ('getFrom ' );
412442 $ this ->service ->expects (self ::once ())
@@ -529,8 +559,15 @@ public function testFailedDelivery(): void {
529559 ->method ('buildBodyData ' )
530560 ->with ($ newVevent , null )
531561 ->willReturn ($ data );
532- $ this ->userManager ->expects (self ::never ())
533- ->method ('getDisplayName ' );
562+ $ this ->user ->expects (self ::any ())
563+ ->method ('getUID ' )
564+ ->willReturn ('user1 ' );
565+ $ this ->user ->expects (self ::any ())
566+ ->method ('getDisplayName ' )
567+ ->willReturn ('Mr. Wizard ' );
568+ $ this ->userSession ->expects (self ::any ())
569+ ->method ('getUser ' )
570+ ->willReturn ($ this ->user );
534571 $ this ->service ->expects (self ::once ())
535572 ->method ('getFrom ' );
536573 $ this ->service ->expects (self ::once ())
@@ -618,8 +655,15 @@ public function testNoOldEvent(): void {
618655 ->method ('buildBodyData ' )
619656 ->with ($ newVevent , null )
620657 ->willReturn ($ data );
621- $ this ->userManager ->expects (self ::never ())
622- ->method ('getDisplayName ' );
658+ $ this ->user ->expects (self ::any ())
659+ ->method ('getUID ' )
660+ ->willReturn ('user1 ' );
661+ $ this ->user ->expects (self ::any ())
662+ ->method ('getDisplayName ' )
663+ ->willReturn ('Mr. Wizard ' );
664+ $ this ->userSession ->expects (self ::any ())
665+ ->method ('getUser ' )
666+ ->willReturn ($ this ->user );
623667 $ this ->service ->expects (self ::once ())
624668 ->method ('getFrom ' );
625669 $ this ->service ->expects (self ::once ())
@@ -704,9 +748,15 @@ public function testNoButtons(): void {
704748 ->method ('buildBodyData ' )
705749 ->with ($ newVevent , null )
706750 ->willReturn ($ data );
707- $ this ->userManager ->expects (self ::once ())
751+ $ this ->user ->expects (self ::any ())
752+ ->method ('getUID ' )
753+ ->willReturn ('user1 ' );
754+ $ this ->user ->expects (self ::any ())
708755 ->method ('getDisplayName ' )
709756 ->willReturn ('Mr. Wizard ' );
757+ $ this ->userSession ->expects (self ::any ())
758+ ->method ('getUser ' )
759+ ->willReturn ($ this ->user );
710760 $ this ->service ->expects (self ::once ())
711761 ->method ('getFrom ' );
712762 $ this ->service ->expects (self ::once ())
0 commit comments