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,12 @@ 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);
110116
111- $ this ->userManager = $ this ->createMock (IUserManager::class);
117+ $ this ->userSession = $ this ->createMock (IUserSession::class);
118+ $ this ->userSession ->method ('getUser ' )
119+ ->willReturn ($ this ->user );
112120
113121 $ this ->defaults = $ this ->createMock (Defaults::class);
114122 $ this ->defaults ->method ('getName ' )
@@ -124,8 +132,7 @@ protected function setUp(): void {
124132 $ this ->logger ,
125133 $ this ->timeFactory ,
126134 $ this ->defaults ,
127- $ this ->userManager ,
128- 'user123 ' ,
135+ $ this ->userSession ,
129136 $ this ->service ,
130137 $ this ->eventComparisonService
131138 );
@@ -213,8 +220,15 @@ public function testParsingSingle(): void {
213220 ->method ('buildBodyData ' )
214221 ->with ($ newVevent , $ oldVEvent )
215222 ->willReturn ($ data );
216- $ this ->userManager ->expects (self ::never ())
217- ->method ('getDisplayName ' );
223+ $ this ->user ->expects (self ::any ())
224+ ->method ('getUID ' )
225+ ->willReturn ('user1 ' );
226+ $ this ->user ->expects (self ::any ())
227+ ->method ('getDisplayName ' )
228+ ->willReturn ('Mr. Wizard ' );
229+ $ this ->userSession ->expects (self ::any ())
230+ ->method ('getUser ' )
231+ ->willReturn ($ this ->user );
218232 $ this ->service ->expects (self ::once ())
219233 ->method ('getFrom ' );
220234 $ this ->service ->expects (self ::once ())
@@ -307,8 +321,15 @@ public function testAttendeeIsResource(): void {
307321 ->willReturn (true );
308322 $ this ->service ->expects (self ::never ())
309323 ->method ('buildBodyData ' );
310- $ this ->userManager ->expects (self ::never ())
311- ->method ('getDisplayName ' );
324+ $ this ->user ->expects (self ::any ())
325+ ->method ('getUID ' )
326+ ->willReturn ('user1 ' );
327+ $ this ->user ->expects (self ::any ())
328+ ->method ('getDisplayName ' )
329+ ->willReturn ('Mr. Wizard ' );
330+ $ this ->userSession ->expects (self ::any ())
331+ ->method ('getUser ' )
332+ ->willReturn ($ this ->user );
312333 $ this ->service ->expects (self ::never ())
313334 ->method ('getFrom ' );
314335 $ this ->service ->expects (self ::never ())
@@ -331,7 +352,6 @@ public function testAttendeeIsResource(): void {
331352 $ this ->assertEquals ('1.0 ' , $ message ->getScheduleStatus ());
332353 }
333354
334-
335355 public function testParsingRecurrence (): void {
336356 $ message = new Message ();
337357 $ message ->method = 'REQUEST ' ;
@@ -404,9 +424,15 @@ public function testParsingRecurrence(): void {
404424 ->method ('buildBodyData ' )
405425 ->with ($ newVevent , null )
406426 ->willReturn ($ data );
407- $ this ->userManager ->expects (self ::once ())
427+ $ this ->user ->expects (self ::any ())
428+ ->method ('getUID ' )
429+ ->willReturn ('user1 ' );
430+ $ this ->user ->expects (self ::any ())
408431 ->method ('getDisplayName ' )
409432 ->willReturn ('Mr. Wizard ' );
433+ $ this ->userSession ->expects (self ::any ())
434+ ->method ('getUser ' )
435+ ->willReturn ($ this ->user );
410436 $ this ->service ->expects (self ::once ())
411437 ->method ('getFrom ' );
412438 $ this ->service ->expects (self ::once ())
@@ -529,8 +555,15 @@ public function testFailedDelivery(): void {
529555 ->method ('buildBodyData ' )
530556 ->with ($ newVevent , null )
531557 ->willReturn ($ data );
532- $ this ->userManager ->expects (self ::never ())
533- ->method ('getDisplayName ' );
558+ $ this ->user ->expects (self ::any ())
559+ ->method ('getUID ' )
560+ ->willReturn ('user1 ' );
561+ $ this ->user ->expects (self ::any ())
562+ ->method ('getDisplayName ' )
563+ ->willReturn ('Mr. Wizard ' );
564+ $ this ->userSession ->expects (self ::any ())
565+ ->method ('getUser ' )
566+ ->willReturn ($ this ->user );
534567 $ this ->service ->expects (self ::once ())
535568 ->method ('getFrom ' );
536569 $ this ->service ->expects (self ::once ())
@@ -618,8 +651,15 @@ public function testNoOldEvent(): void {
618651 ->method ('buildBodyData ' )
619652 ->with ($ newVevent , null )
620653 ->willReturn ($ data );
621- $ this ->userManager ->expects (self ::never ())
622- ->method ('getDisplayName ' );
654+ $ this ->user ->expects (self ::any ())
655+ ->method ('getUID ' )
656+ ->willReturn ('user1 ' );
657+ $ this ->user ->expects (self ::any ())
658+ ->method ('getDisplayName ' )
659+ ->willReturn ('Mr. Wizard ' );
660+ $ this ->userSession ->expects (self ::any ())
661+ ->method ('getUser ' )
662+ ->willReturn ($ this ->user );
623663 $ this ->service ->expects (self ::once ())
624664 ->method ('getFrom ' );
625665 $ this ->service ->expects (self ::once ())
@@ -704,9 +744,15 @@ public function testNoButtons(): void {
704744 ->method ('buildBodyData ' )
705745 ->with ($ newVevent , null )
706746 ->willReturn ($ data );
707- $ this ->userManager ->expects (self ::once ())
747+ $ this ->user ->expects (self ::any ())
748+ ->method ('getUID ' )
749+ ->willReturn ('user1 ' );
750+ $ this ->user ->expects (self ::any ())
708751 ->method ('getDisplayName ' )
709752 ->willReturn ('Mr. Wizard ' );
753+ $ this ->userSession ->expects (self ::any ())
754+ ->method ('getUser ' )
755+ ->willReturn ($ this ->user );
710756 $ this ->service ->expects (self ::once ())
711757 ->method ('getFrom ' );
712758 $ this ->service ->expects (self ::once ())
0 commit comments