4545use Sabre \VObject \Component \VCalendar ;
4646use Sabre \VObject \Component \VEvent ;
4747use Sabre \VObject \ITip \Message ;
48+ use Sabre \VObject \Property ;
4849use Test \TestCase ;
4950use function array_merge ;
5051
@@ -183,6 +184,13 @@ public function testParsingSingle(): void {
183184 'meeting_title ' => 'Fellowship meeting without (!) Boromir ' ,
184185 'attendee_name ' => 'frodo@hobb.it '
185186 ];
187+ $ attendees = $ newVevent ->select ('ATTENDEE ' );
188+ $ atnd = '' ;
189+ foreach ($ attendees as $ attendee ) {
190+ if (strcasecmp ($ attendee ->getValue (), $ message ->recipient ) === 0 ) {
191+ $ atnd = $ attendee ;
192+ }
193+ }
186194 $ this ->plugin ->setVCalendar ($ oldVCalendar );
187195 $ this ->service ->expects (self ::once ())
188196 ->method ('getLastOccurrence ' )
@@ -194,6 +202,14 @@ public function testParsingSingle(): void {
194202 $ this ->eventComparisonService ->expects (self ::once ())
195203 ->method ('findModified ' )
196204 ->willReturn (['new ' => [$ newVevent ], 'old ' => [$ oldVEvent ]]);
205+ $ this ->service ->expects (self ::once ())
206+ ->method ('getCurrentAttendee ' )
207+ ->with ($ message )
208+ ->willReturn ($ atnd );
209+ $ this ->service ->expects (self ::once ())
210+ ->method ('isRoomOrResource ' )
211+ ->with ($ atnd )
212+ ->willReturn (false );
197213 $ this ->service ->expects (self ::once ())
198214 ->method ('buildBodyData ' )
199215 ->with ($ newVevent , $ oldVEvent )
@@ -232,6 +248,91 @@ public function testParsingSingle(): void {
232248 $ this ->assertEquals ('1.1 ' , $ message ->getScheduleStatus ());
233249 }
234250
251+ public function testAttendeeIsResource (): void {
252+ $ message = new Message ();
253+ $ message ->method = 'REQUEST ' ;
254+ $ newVCalendar = new VCalendar ();
255+ $ newVevent = new VEvent ($ newVCalendar , 'one ' , array_merge ([
256+ 'UID ' => 'uid-1234 ' ,
257+ 'SEQUENCE ' => 1 ,
258+ 'SUMMARY ' => 'Fellowship meeting without (!) Boromir ' ,
259+ 'DTSTART ' => new \DateTime ('2016-01-01 00:00:00 ' )
260+ ], []));
261+ $ newVevent ->add ('ORGANIZER ' , 'mailto:gandalf@wiz.ard ' );
262+ $ newVevent ->add ('ATTENDEE ' , 'mailto: ' . 'the-shire@hobb.it ' , ['RSVP ' => 'TRUE ' , 'CN ' => 'The Shire ' , 'CUTYPE ' => 'ROOM ' ]);
263+ $ message ->message = $ newVCalendar ;
264+ $ message ->sender = 'mailto:gandalf@wiz.ard ' ;
265+ $ message ->senderName = 'Mr. Wizard ' ;
266+ $ message ->recipient = 'mailto: ' . 'the-shire@hobb.it ' ;
267+ // save the old copy in the plugin
268+ $ oldVCalendar = new VCalendar ();
269+ $ oldVEvent = new VEvent ($ oldVCalendar , 'one ' , [
270+ 'UID ' => 'uid-1234 ' ,
271+ 'SEQUENCE ' => 0 ,
272+ 'SUMMARY ' => 'Fellowship meeting ' ,
273+ 'DTSTART ' => new \DateTime ('2016-01-01 00:00:00 ' )
274+ ]);
275+ $ oldVEvent ->add ('ORGANIZER ' , 'mailto:gandalf@wiz.ard ' );
276+ $ oldVEvent ->add ('ATTENDEE ' , 'mailto: ' . 'the-shire@hobb.it ' , ['RSVP ' => 'TRUE ' , 'CN ' => 'The Shire ' , 'CUTYPE ' => 'ROOM ' ]);
277+ $ oldVEvent ->add ('ATTENDEE ' , 'mailto: ' . 'boromir@tra.it.or ' , ['RSVP ' => 'TRUE ' ]);
278+ $ oldVCalendar ->add ($ oldVEvent );
279+ $ data = ['invitee_name ' => 'Mr. Wizard ' ,
280+ 'meeting_title ' => 'Fellowship meeting without (!) Boromir ' ,
281+ 'attendee_name ' => 'frodo@hobb.it '
282+ ];
283+ $ attendees = $ newVevent ->select ('ATTENDEE ' );
284+ $ room = '' ;
285+ foreach ($ attendees as $ attendee ) {
286+ if (strcasecmp ($ attendee ->getValue (), $ message ->recipient ) === 0 ) {
287+ $ room = $ attendee ;
288+ }
289+ }
290+ $ this ->plugin ->setVCalendar ($ oldVCalendar );
291+ $ this ->service ->expects (self ::once ())
292+ ->method ('getLastOccurrence ' )
293+ ->willReturn ('1496912700 ' );
294+ $ this ->mailer ->expects (self ::once ())
295+ ->method ('validateMailAddress ' )
296+ ->with ('the-shire@hobb.it ' )
297+ ->willReturn (true );
298+ $ this ->eventComparisonService ->expects (self ::once ())
299+ ->method ('findModified ' )
300+ ->willReturn (['new ' => [$ newVevent ], 'old ' => [$ oldVEvent ]]);
301+ $ this ->service ->expects (self ::once ())
302+ ->method ('getCurrentAttendee ' )
303+ ->with ($ message )
304+ ->willReturn ($ room );
305+ $ this ->service ->expects (self ::once ())
306+ ->method ('isRoomOrResource ' )
307+ ->with ($ room )
308+ ->willReturn (true );
309+ $ this ->service ->expects (self ::never ())
310+ ->method ('buildBodyData ' );
311+ $ this ->userManager ->expects (self ::never ())
312+ ->method ('getDisplayName ' );
313+ $ this ->service ->expects (self ::never ())
314+ ->method ('getFrom ' );
315+ $ this ->service ->expects (self ::never ())
316+ ->method ('addSubjectAndHeading ' );
317+ $ this ->service ->expects (self ::never ())
318+ ->method ('addBulletList ' );
319+ $ this ->service ->expects (self ::never ())
320+ ->method ('getAttendeeRsvpOrReqForParticipant ' );
321+ $ this ->config ->expects (self ::never ())
322+ ->method ('getAppValue ' );
323+ $ this ->service ->expects (self ::never ())
324+ ->method ('createInvitationToken ' );
325+ $ this ->service ->expects (self ::never ())
326+ ->method ('addResponseButtons ' );
327+ $ this ->service ->expects (self ::never ())
328+ ->method ('addMoreOptionsButton ' );
329+ $ this ->mailer ->expects (self ::never ())
330+ ->method ('send ' );
331+ $ this ->plugin ->schedule ($ message );
332+ $ this ->assertEquals ('1.0 ' , $ message ->getScheduleStatus ());
333+ }
334+
335+
235336 public function testParsingRecurrence (): void {
236337 $ message = new Message ();
237338 $ message ->method = 'REQUEST ' ;
@@ -274,6 +375,13 @@ public function testParsingRecurrence(): void {
274375 'meeting_title ' => 'Elevenses ' ,
275376 'attendee_name ' => 'frodo@hobb.it '
276377 ];
378+ $ attendees = $ newVevent ->select ('ATTENDEE ' );
379+ $ atnd = '' ;
380+ foreach ($ attendees as $ attendee ) {
381+ if (strcasecmp ($ attendee ->getValue (), $ message ->recipient ) === 0 ) {
382+ $ atnd = $ attendee ;
383+ }
384+ }
277385 $ this ->plugin ->setVCalendar ($ oldVCalendar );
278386 $ this ->service ->expects (self ::once ())
279387 ->method ('getLastOccurrence ' )
@@ -285,6 +393,14 @@ public function testParsingRecurrence(): void {
285393 $ this ->eventComparisonService ->expects (self ::once ())
286394 ->method ('findModified ' )
287395 ->willReturn (['old ' => [] ,'new ' => [$ newVevent ]]);
396+ $ this ->service ->expects (self ::once ())
397+ ->method ('getCurrentAttendee ' )
398+ ->with ($ message )
399+ ->willReturn ($ atnd );
400+ $ this ->service ->expects (self ::once ())
401+ ->method ('isRoomOrResource ' )
402+ ->with ($ atnd )
403+ ->willReturn (false );
288404 $ this ->service ->expects (self ::once ())
289405 ->method ('buildBodyData ' )
290406 ->with ($ newVevent , null )
@@ -384,6 +500,13 @@ public function testFailedDelivery(): void {
384500 'meeting_title ' => 'Fellowship meeting without (!) Boromir ' ,
385501 'attendee_name ' => 'frodo@hobb.it '
386502 ];
503+ $ attendees = $ newVevent ->select ('ATTENDEE ' );
504+ $ atnd = '' ;
505+ foreach ($ attendees as $ attendee ) {
506+ if (strcasecmp ($ attendee ->getValue (), $ message ->recipient ) === 0 ) {
507+ $ atnd = $ attendee ;
508+ }
509+ }
387510 $ this ->plugin ->setVCalendar ($ oldVcalendar );
388511 $ this ->service ->expects (self ::once ())
389512 ->method ('getLastOccurrence ' )
@@ -395,6 +518,14 @@ public function testFailedDelivery(): void {
395518 $ this ->eventComparisonService ->expects (self ::once ())
396519 ->method ('findModified ' )
397520 ->willReturn (['old ' => [] ,'new ' => [$ newVevent ]]);
521+ $ this ->service ->expects (self ::once ())
522+ ->method ('getCurrentAttendee ' )
523+ ->with ($ message )
524+ ->willReturn ($ atnd );
525+ $ this ->service ->expects (self ::once ())
526+ ->method ('isRoomOrResource ' )
527+ ->with ($ atnd )
528+ ->willReturn (false );
398529 $ this ->service ->expects (self ::once ())
399530 ->method ('buildBodyData ' )
400531 ->with ($ newVevent , null )
@@ -458,7 +589,13 @@ public function testNoOldEvent(): void {
458589 'meeting_title ' => 'Fellowship meeting ' ,
459590 'attendee_name ' => 'frodo@hobb.it '
460591 ];
461-
592+ $ attendees = $ newVevent ->select ('ATTENDEE ' );
593+ $ atnd = '' ;
594+ foreach ($ attendees as $ attendee ) {
595+ if (strcasecmp ($ attendee ->getValue (), $ message ->recipient ) === 0 ) {
596+ $ atnd = $ attendee ;
597+ }
598+ }
462599 $ this ->service ->expects (self ::once ())
463600 ->method ('getLastOccurrence ' )
464601 ->willReturn ('1496912700 ' );
@@ -470,6 +607,14 @@ public function testNoOldEvent(): void {
470607 ->method ('findModified ' )
471608 ->with ($ newVCalendar , null )
472609 ->willReturn (['old ' => [] ,'new ' => [$ newVevent ]]);
610+ $ this ->service ->expects (self ::once ())
611+ ->method ('getCurrentAttendee ' )
612+ ->with ($ message )
613+ ->willReturn ($ atnd );
614+ $ this ->service ->expects (self ::once ())
615+ ->method ('isRoomOrResource ' )
616+ ->with ($ atnd )
617+ ->willReturn (false );
473618 $ this ->service ->expects (self ::once ())
474619 ->method ('buildBodyData ' )
475620 ->with ($ newVevent , null )
@@ -530,7 +675,13 @@ public function testNoButtons(): void {
530675 'meeting_title ' => 'Fellowship meeting ' ,
531676 'attendee_name ' => 'frodo@hobb.it '
532677 ];
533-
678+ $ attendees = $ newVevent ->select ('ATTENDEE ' );
679+ $ atnd = '' ;
680+ foreach ($ attendees as $ attendee ) {
681+ if (strcasecmp ($ attendee ->getValue (), $ message ->recipient ) === 0 ) {
682+ $ atnd = $ attendee ;
683+ }
684+ }
534685 $ this ->service ->expects (self ::once ())
535686 ->method ('getLastOccurrence ' )
536687 ->willReturn ('1496912700 ' );
@@ -542,6 +693,14 @@ public function testNoButtons(): void {
542693 ->method ('findModified ' )
543694 ->with ($ newVCalendar , null )
544695 ->willReturn (['old ' => [] ,'new ' => [$ newVevent ]]);
696+ $ this ->service ->expects (self ::once ())
697+ ->method ('getCurrentAttendee ' )
698+ ->with ($ message )
699+ ->willReturn ($ atnd );
700+ $ this ->service ->expects (self ::once ())
701+ ->method ('isRoomOrResource ' )
702+ ->with ($ atnd )
703+ ->willReturn (false );
545704 $ this ->service ->expects (self ::once ())
546705 ->method ('buildBodyData ' )
547706 ->with ($ newVevent , null )
0 commit comments