123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927 |
- <?php
- namespace Test\Calendar;
- use OC\AppFramework\Bootstrap\Coordinator;
- use OC\Calendar\Manager;
- use OCP\AppFramework\Utility\ITimeFactory;
- use OCP\Calendar\ICalendar;
- use OCP\Calendar\ICalendarIsShared;
- use OCP\Calendar\ICalendarIsWritable;
- use OCP\Calendar\ICreateFromString;
- use OCP\Calendar\IHandleImipMessage;
- use PHPUnit\Framework\MockObject\MockObject;
- use Psr\Container\ContainerInterface;
- use Psr\Log\LoggerInterface;
- use Sabre\VObject\Component\VCalendar;
- use Sabre\VObject\Document;
- use Sabre\VObject\Reader;
- use Test\TestCase;
- interface ITestCalendar extends ICreateFromString, IHandleImipMessage, ICalendarIsShared, ICalendarIsWritable {
- }
- class ManagerTest extends TestCase {
-
- private $coordinator;
-
- private $container;
-
- private $logger;
-
- private $manager;
-
- private $time;
- private VCalendar $vCalendar1a;
- protected function setUp(): void {
- parent::setUp();
- $this->coordinator = $this->createMock(Coordinator::class);
- $this->container = $this->createMock(ContainerInterface::class);
- $this->logger = $this->createMock(LoggerInterface::class);
- $this->time = $this->createMock(ITimeFactory::class);
- $this->manager = new Manager(
- $this->coordinator,
- $this->container,
- $this->logger,
- $this->time,
- );
-
- $this->vCalendar1a = new VCalendar();
-
- $vEvent = $this->vCalendar1a->add('VEVENT', []);
- $vEvent->UID->setValue('96a0e6b1-d886-4a55-a60d-152b31401dcc');
- $vEvent->add('DTSTART', '20240701T080000', ['TZID' => 'America/Toronto']);
- $vEvent->add('DTEND', '20240701T090000', ['TZID' => 'America/Toronto']);
- $vEvent->add('SUMMARY', 'Test Event');
- $vEvent->add('ORGANIZER', 'mailto:organizer@testing.com', ['CN' => 'Organizer']);
- $vEvent->add('ATTENDEE', 'mailto:attendee1@testing.com', [
- 'CN' => 'Attendee One',
- 'CUTYPE' => 'INDIVIDUAL',
- 'PARTSTAT' => 'NEEDS-ACTION',
- 'ROLE' => 'REQ-PARTICIPANT',
- 'RSVP' => 'TRUE'
- ]);
- }
-
- public function testSearch($search1, $search2, $expected): void {
-
- $calendar1 = $this->createMock(ICalendar::class);
- $calendar1->method('getKey')->willReturn('simple:1');
- $calendar1->expects($this->once())
- ->method('search')
- ->with('', [], [], null, null)
- ->willReturn($search1);
-
- $calendar2 = $this->createMock(ICalendar::class);
- $calendar2->method('getKey')->willReturn('simple:2');
- $calendar2->expects($this->once())
- ->method('search')
- ->with('', [], [], null, null)
- ->willReturn($search2);
- $this->manager->registerCalendar($calendar1);
- $this->manager->registerCalendar($calendar2);
- $result = $this->manager->search('');
- $this->assertEquals($expected, $result);
- }
-
- public function testSearchOptions($search1, $search2, $expected): void {
-
- $calendar1 = $this->createMock(ICalendar::class);
- $calendar1->method('getKey')->willReturn('simple:1');
- $calendar1->expects($this->once())
- ->method('search')
- ->with('searchTerm', ['SUMMARY', 'DESCRIPTION'],
- ['timerange' => ['start' => null, 'end' => null]], 5, 20)
- ->willReturn($search1);
-
- $calendar2 = $this->createMock(ICalendar::class);
- $calendar2->method('getKey')->willReturn('simple:2');
- $calendar2->expects($this->once())
- ->method('search')
- ->with('searchTerm', ['SUMMARY', 'DESCRIPTION'],
- ['timerange' => ['start' => null, 'end' => null]], 5, 20)
- ->willReturn($search2);
- $this->manager->registerCalendar($calendar1);
- $this->manager->registerCalendar($calendar2);
- $result = $this->manager->search('searchTerm', ['SUMMARY', 'DESCRIPTION'],
- ['timerange' => ['start' => null, 'end' => null]], 5, 20);
- $this->assertEquals($expected, $result);
- }
- public function searchProvider() {
- $search1 = [
- [
- 'id' => 1,
- 'data' => 'foobar',
- ],
- [
- 'id' => 2,
- 'data' => 'barfoo',
- ]
- ];
- $search2 = [
- [
- 'id' => 3,
- 'data' => 'blablub',
- ],
- [
- 'id' => 4,
- 'data' => 'blubbla',
- ]
- ];
- $expected = [
- [
- 'id' => 1,
- 'data' => 'foobar',
- 'calendar-key' => 'simple:1',
- ],
- [
- 'id' => 2,
- 'data' => 'barfoo',
- 'calendar-key' => 'simple:1',
- ],
- [
- 'id' => 3,
- 'data' => 'blablub',
- 'calendar-key' => 'simple:2',
- ],
- [
- 'id' => 4,
- 'data' => 'blubbla',
- 'calendar-key' => 'simple:2',
- ]
- ];
- return [
- [
- $search1,
- $search2,
- $expected
- ]
- ];
- }
- public function testRegisterUnregister(): void {
-
- $calendar1 = $this->createMock(ICalendar::class);
- $calendar1->method('getKey')->willReturn('key1');
-
- $calendar2 = $this->createMock(ICalendar::class);
- $calendar2->method('getKey')->willReturn('key2');
- $this->manager->registerCalendar($calendar1);
- $this->manager->registerCalendar($calendar2);
- $result = $this->manager->getCalendars();
- $this->assertCount(2, $result);
- $this->assertContains($calendar1, $result);
- $this->assertContains($calendar2, $result);
- $this->manager->unregisterCalendar($calendar1);
- $result = $this->manager->getCalendars();
- $this->assertCount(1, $result);
- $this->assertContains($calendar2, $result);
- }
- public function testGetCalendars(): void {
-
- $calendar1 = $this->createMock(ICalendar::class);
- $calendar1->method('getKey')->willReturn('key1');
-
- $calendar2 = $this->createMock(ICalendar::class);
- $calendar2->method('getKey')->willReturn('key2');
- $this->manager->registerCalendar($calendar1);
- $this->manager->registerCalendar($calendar2);
- $result = $this->manager->getCalendars();
- $this->assertCount(2, $result);
- $this->assertContains($calendar1, $result);
- $this->assertContains($calendar2, $result);
- $this->manager->clear();
- $result = $this->manager->getCalendars();
- $this->assertCount(0, $result);
- }
- public function testEnabledIfNot(): void {
- $isEnabled = $this->manager->isEnabled();
- $this->assertFalse($isEnabled);
- }
- public function testIfEnabledIfSo(): void {
-
- $calendar = $this->createMock(ICalendar::class);
- $this->manager->registerCalendar($calendar);
- $isEnabled = $this->manager->isEnabled();
- $this->assertTrue($isEnabled);
- }
- public function testHandleImipRequestWithNoCalendars(): void {
-
-
- $manager = $this->getMockBuilder(Manager::class)
- ->setConstructorArgs([
- $this->coordinator,
- $this->container,
- $this->logger,
- $this->time
- ])
- ->onlyMethods(['getCalendarsForPrincipal'])
- ->getMock();
- $manager->expects(self::once())
- ->method('getCalendarsForPrincipal')
- ->willReturn([]);
-
- $this->logger->expects(self::once())->method('warning')
- ->with('iMip message could not be processed because user has no calendars');
-
- $principalUri = 'principals/user/attendee1';
- $sender = 'organizer@testing.com';
- $recipient = 'attendee1@testing.com';
- $calendar = $this->vCalendar1a;
- $calendar->add('METHOD', 'REQUEST');
-
- $result = $manager->handleIMipRequest($principalUri, $sender, $recipient, $calendar->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipRequestWithNoMethod(): void {
-
- $userCalendar = $this->createMock(ITestCalendar::class);
-
-
- $manager = $this->getMockBuilder(Manager::class)
- ->setConstructorArgs([
- $this->coordinator,
- $this->container,
- $this->logger,
- $this->time
- ])
- ->onlyMethods(['getCalendarsForPrincipal'])
- ->getMock();
- $manager->expects(self::once())
- ->method('getCalendarsForPrincipal')
- ->willReturn([$userCalendar]);
-
- $this->logger->expects(self::once())->method('warning')
- ->with('iMip message contains an incorrect or invalid method');
-
- $principalUri = 'principals/user/attendee1';
- $sender = 'organizer@testing.com';
- $recipient = 'attendee1@testing.com';
- $calendar = $this->vCalendar1a;
-
- $result = $manager->handleIMipRequest($principalUri, $sender, $recipient, $calendar->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipRequestWithInvalidMethod(): void {
-
- $userCalendar = $this->createMock(ITestCalendar::class);
-
-
- $manager = $this->getMockBuilder(Manager::class)
- ->setConstructorArgs([
- $this->coordinator,
- $this->container,
- $this->logger,
- $this->time
- ])
- ->onlyMethods(['getCalendarsForPrincipal'])
- ->getMock();
- $manager->expects(self::once())
- ->method('getCalendarsForPrincipal')
- ->willReturn([$userCalendar]);
-
- $this->logger->expects(self::once())->method('warning')
- ->with('iMip message contains an incorrect or invalid method');
-
- $principalUri = 'principals/user/attendee1';
- $sender = 'organizer@testing.com';
- $recipient = 'attendee1@testing.com';
- $calendar = $this->vCalendar1a;
- $calendar->add('METHOD', 'CANCEL');
-
- $result = $manager->handleIMipRequest($principalUri, $sender, $recipient, $calendar->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipRequestWithNoEvent(): void {
-
- $userCalendar = $this->createMock(ITestCalendar::class);
-
-
- $manager = $this->getMockBuilder(Manager::class)
- ->setConstructorArgs([
- $this->coordinator,
- $this->container,
- $this->logger,
- $this->time
- ])
- ->onlyMethods(['getCalendarsForPrincipal'])
- ->getMock();
- $manager->expects(self::once())
- ->method('getCalendarsForPrincipal')
- ->willReturn([$userCalendar]);
-
- $this->logger->expects(self::once())->method('warning')
- ->with('iMip message contains no event');
-
- $principalUri = 'principals/user/attendee1';
- $sender = 'organizer@testing.com';
- $recipient = 'attendee1@testing.com';
- $calendar = $this->vCalendar1a;
- $calendar->add('METHOD', 'REQUEST');
- $calendar->remove('VEVENT');
-
- $result = $manager->handleIMipRequest($principalUri, $sender, $recipient, $calendar->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipRequestWithNoUid(): void {
-
- $userCalendar = $this->createMock(ITestCalendar::class);
-
-
- $manager = $this->getMockBuilder(Manager::class)
- ->setConstructorArgs([
- $this->coordinator,
- $this->container,
- $this->logger,
- $this->time
- ])
- ->onlyMethods(['getCalendarsForPrincipal'])
- ->getMock();
- $manager->expects(self::once())
- ->method('getCalendarsForPrincipal')
- ->willReturn([$userCalendar]);
-
- $this->logger->expects(self::once())->method('warning')
- ->with('iMip message event dose not contains a UID');
-
- $principalUri = 'principals/user/attendee1';
- $sender = 'organizer@testing.com';
- $recipient = 'attendee1@testing.com';
- $calendar = $this->vCalendar1a;
- $calendar->add('METHOD', 'REQUEST');
- $calendar->VEVENT->remove('UID');
-
- $result = $manager->handleIMipRequest($principalUri, $sender, $recipient, $calendar->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipRequestWithNoAttendee(): void {
-
- $userCalendar = $this->createMock(ITestCalendar::class);
-
-
- $manager = $this->getMockBuilder(Manager::class)
- ->setConstructorArgs([
- $this->coordinator,
- $this->container,
- $this->logger,
- $this->time
- ])
- ->onlyMethods(['getCalendarsForPrincipal'])
- ->getMock();
- $manager->expects(self::once())
- ->method('getCalendarsForPrincipal')
- ->willReturn([$userCalendar]);
-
- $this->logger->expects(self::once())->method('warning')
- ->with('iMip message event dose not contains any attendees');
-
- $principalUri = 'principals/user/attendee1';
- $sender = 'organizer@testing.com';
- $recipient = 'attendee1@testing.com';
- $calendar = $this->vCalendar1a;
- $calendar->add('METHOD', 'REQUEST');
- $calendar->VEVENT->remove('ATTENDEE');
-
- $result = $manager->handleIMipRequest($principalUri, $sender, $recipient, $calendar->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipRequestWithInvalidAttendee(): void {
-
- $userCalendar = $this->createMock(ITestCalendar::class);
-
-
- $manager = $this->getMockBuilder(Manager::class)
- ->setConstructorArgs([
- $this->coordinator,
- $this->container,
- $this->logger,
- $this->time
- ])
- ->onlyMethods(['getCalendarsForPrincipal'])
- ->getMock();
- $manager->expects(self::once())
- ->method('getCalendarsForPrincipal')
- ->willReturn([$userCalendar]);
-
- $this->logger->expects(self::once())->method('warning')
- ->with('iMip message event does not contain a attendee that matches the recipient');
-
- $principalUri = 'principals/user/attendee1';
- $sender = 'organizer@testing.com';
- $recipient = 'attendee2@testing.com';
- $calendar = $this->vCalendar1a;
- $calendar->add('METHOD', 'REQUEST');
-
- $result = $manager->handleIMipRequest($principalUri, $sender, $recipient, $calendar->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipRequestWithNoMatch(): void {
-
- $userCalendar = $this->createMock(ITestCalendar::class);
- $userCalendar->expects(self::once())
- ->method('isDeleted')
- ->willReturn(false);
- $userCalendar->expects(self::once())
- ->method('isWritable')
- ->willReturn(true);
- $userCalendar->expects(self::once())
- ->method('isShared')
- ->willReturn(false);
- $userCalendar->expects(self::once())
- ->method('search')
- ->willReturn([]);
-
-
- $manager = $this->getMockBuilder(Manager::class)
- ->setConstructorArgs([
- $this->coordinator,
- $this->container,
- $this->logger,
- $this->time
- ])
- ->onlyMethods(['getCalendarsForPrincipal'])
- ->getMock();
- $manager->expects(self::once())
- ->method('getCalendarsForPrincipal')
- ->willReturn([$userCalendar]);
-
- $this->logger->expects(self::once())->method('warning')
- ->with('iMip message event could not be processed because the no corresponding event was found in any calendar');
-
- $principalUri = 'principals/user/attendee1';
- $sender = 'organizer@testing.com';
- $recipient = 'attendee1@testing.com';
- $calendar = $this->vCalendar1a;
- $calendar->add('METHOD', 'REQUEST');
-
- $result = $manager->handleIMipRequest($principalUri, $sender, $recipient, $calendar->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipRequest(): void {
-
- $userCalendar = $this->createMock(ITestCalendar::class);
- $userCalendar->expects(self::once())
- ->method('isDeleted')
- ->willReturn(false);
- $userCalendar->expects(self::once())
- ->method('isWritable')
- ->willReturn(true);
- $userCalendar->expects(self::once())
- ->method('isShared')
- ->willReturn(false);
- $userCalendar->expects(self::once())
- ->method('search')
- ->willReturn([['uri' => 'principals/user/attendee1/personal']]);
-
-
- $manager = $this->getMockBuilder(Manager::class)
- ->setConstructorArgs([
- $this->coordinator,
- $this->container,
- $this->logger,
- $this->time
- ])
- ->onlyMethods(['getCalendarsForPrincipal'])
- ->getMock();
- $manager->expects(self::once())
- ->method('getCalendarsForPrincipal')
- ->willReturn([$userCalendar]);
-
- $principalUri = 'principals/user/attendee1';
- $sender = 'organizer@testing.com';
- $recipient = 'attendee1@testing.com';
- $calendar = $this->vCalendar1a;
- $calendar->add('METHOD', 'REQUEST');
-
- $userCalendar->expects(self::once())
- ->method('handleIMipMessage')
- ->with('', $calendar->serialize());
-
- $result = $manager->handleIMipRequest($principalUri, $sender, $recipient, $calendar->serialize());
- $this->assertTrue($result);
- }
- public function testHandleImipReplyWrongMethod(): void {
- $principalUri = 'principals/user/linus';
- $sender = 'pierre@general-store.com';
- $recipient = 'linus@stardew-tent-living.com';
- $calendarData = $this->getVCalendarReply();
- $calendarData->METHOD = 'REQUEST';
- $this->logger->expects(self::once())
- ->method('warning');
- $this->time->expects(self::never())
- ->method('getTime');
- $result = $this->manager->handleIMipReply($principalUri, $sender, $recipient, $calendarData->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipReplyOrganizerNotRecipient(): void {
- $principalUri = 'principals/user/linus';
- $recipient = 'pierre@general-store.com';
- $sender = 'linus@stardew-tent-living.com';
- $calendarData = $this->getVCalendarReply();
- $this->logger->expects(self::once())
- ->method('warning');
- $this->time->expects(self::never())
- ->method('getTime');
- $result = $this->manager->handleIMipReply($principalUri, $sender, $recipient, $calendarData->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipReplyDateInThePast(): void {
- $principalUri = 'principals/user/linus';
- $sender = 'pierre@general-store.com';
- $recipient = 'linus@stardew-tent-living.com';
- $calendarData = $this->getVCalendarReply();
- $calendarData->VEVENT->DTSTART = new \DateTime('2013-04-07');
- $this->time->expects(self::once())
- ->method('getTime')
- ->willReturn(time());
- $this->logger->expects(self::once())
- ->method('warning');
- $result = $this->manager->handleIMipReply($principalUri, $sender, $recipient, $calendarData->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipReplyNoCalendars(): void {
-
- $manager = $this->getMockBuilder(Manager::class)
- ->setConstructorArgs([
- $this->coordinator,
- $this->container,
- $this->logger,
- $this->time
- ])
- ->setMethods([
- 'getCalendarsForPrincipal'
- ])
- ->getMock();
- $principalUri = 'principals/user/linus';
- $sender = 'pierre@general-store.com';
- $recipient = 'linus@stardew-tent-living.com';
- $calendarData = $this->getVCalendarReply();
- $this->time->expects(self::once())
- ->method('getTime')
- ->willReturn(1628374233);
- $manager->expects(self::once())
- ->method('getCalendarsForPrincipal')
- ->willReturn([]);
- $this->logger->expects(self::once())
- ->method('warning');
- $result = $manager->handleIMipReply($principalUri, $sender, $recipient, $calendarData->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipReplyEventNotFound(): void {
-
- $manager = $this->getMockBuilder(Manager::class)
- ->setConstructorArgs([
- $this->coordinator,
- $this->container,
- $this->logger,
- $this->time
- ])
- ->setMethods([
- 'getCalendarsForPrincipal'
- ])
- ->getMock();
- $calendar = $this->createMock(ITestCalendar::class);
- $principalUri = 'principals/user/linus';
- $sender = 'pierre@general-store.com';
- $recipient = 'linus@stardew-tent-living.com';
- $calendarData = $this->getVCalendarReply();
- $this->time->expects(self::once())
- ->method('getTime')
- ->willReturn(1628374233);
- $manager->expects(self::once())
- ->method('getCalendarsForPrincipal')
- ->willReturn([$calendar]);
- $calendar->expects(self::once())
- ->method('search')
- ->willReturn([]);
- $this->logger->expects(self::once())
- ->method('info');
- $calendar->expects(self::never())
- ->method('handleIMipMessage');
- $result = $manager->handleIMipReply($principalUri, $sender, $recipient, $calendarData->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipReply(): void {
-
- $manager = $this->getMockBuilder(Manager::class)
- ->setConstructorArgs([
- $this->coordinator,
- $this->container,
- $this->logger,
- $this->time
- ])
- ->setMethods([
- 'getCalendarsForPrincipal'
- ])
- ->getMock();
- $calendar = $this->createMock(ITestCalendar::class);
- $principalUri = 'principals/user/linus';
- $sender = 'pierre@general-store.com';
- $recipient = 'linus@stardew-tent-living.com';
- $calendarData = $this->getVCalendarReply();
- $this->time->expects(self::once())
- ->method('getTime')
- ->willReturn(1628374233);
- $manager->expects(self::once())
- ->method('getCalendarsForPrincipal')
- ->willReturn([$calendar]);
- $calendar->expects(self::once())
- ->method('search')
- ->willReturn([['uri' => 'testname.ics']]);
- $calendar->expects(self::once())
- ->method('handleIMipMessage')
- ->with('testname.ics', $calendarData->serialize());
- $result = $manager->handleIMipReply($principalUri, $sender, $recipient, $calendarData->serialize());
- $this->assertTrue($result);
- }
- public function testHandleImipCancelWrongMethod(): void {
- $principalUri = 'principals/user/pierre';
- $sender = 'linus@stardew-tent-living.com';
- $recipient = 'pierre@general-store.com';
- $replyTo = null;
- $calendarData = $this->getVCalendarCancel();
- $calendarData->METHOD = 'REQUEST';
- $this->logger->expects(self::once())
- ->method('warning');
- $this->time->expects(self::never())
- ->method('getTime');
- $result = $this->manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipCancelAttendeeNotRecipient(): void {
- $principalUri = '/user/admin';
- $sender = 'linus@stardew-tent-living.com';
- $recipient = 'leah@general-store.com';
- $replyTo = null;
- $calendarData = $this->getVCalendarCancel();
- $this->logger->expects(self::once())
- ->method('warning');
- $this->time->expects(self::never())
- ->method('getTime');
- $result = $this->manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipCancelDateInThePast(): void {
- $principalUri = 'principals/user/pierre';
- $sender = 'linus@stardew-tent-living.com';
- $recipient = 'pierre@general-store.com';
- $replyTo = null;
- $calendarData = $this->getVCalendarCancel();
- $calendarData->VEVENT->DTSTART = new \DateTime('2013-04-07');
- $this->time->expects(self::once())
- ->method('getTime')
- ->willReturn(time());
- $this->logger->expects(self::once())
- ->method('warning');
- $result = $this->manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipCancelNoCalendars(): void {
-
- $manager = $this->getMockBuilder(Manager::class)
- ->setConstructorArgs([
- $this->coordinator,
- $this->container,
- $this->logger,
- $this->time
- ])
- ->setMethods([
- 'getCalendarsForPrincipal'
- ])
- ->getMock();
- $principalUri = 'principals/user/pierre';
- $sender = 'linus@stardew-tent-living.com';
- $recipient = 'pierre@general-store.com';
- $replyTo = null;
- $calendarData = $this->getVCalendarCancel();
- $this->time->expects(self::once())
- ->method('getTime')
- ->willReturn(1628374233);
- $manager->expects(self::once())
- ->method('getCalendarsForPrincipal')
- ->with($principalUri)
- ->willReturn([]);
- $this->logger->expects(self::once())
- ->method('warning');
- $result = $manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize());
- $this->assertFalse($result);
- }
- public function testHandleImipCancelOrganiserInReplyTo(): void {
-
- $manager = $this->getMockBuilder(Manager::class)
- ->setConstructorArgs([
- $this->coordinator,
- $this->container,
- $this->logger,
- $this->time
- ])
- ->setMethods([
- 'getCalendarsForPrincipal'
- ])
- ->getMock();
- $principalUri = 'principals/user/pierre';
- $sender = 'clint@stardew-blacksmiths.com';
- $recipient = 'pierre@general-store.com';
- $replyTo = 'linus@stardew-tent-living.com';
- $calendar = $this->createMock(ITestCalendar::class);
- $calendarData = $this->getVCalendarCancel();
- $this->time->expects(self::once())
- ->method('getTime')
- ->willReturn(1628374233);
- $manager->expects(self::once())
- ->method('getCalendarsForPrincipal')
- ->with($principalUri)
- ->willReturn([$calendar]);
- $calendar->expects(self::once())
- ->method('search')
- ->willReturn([['uri' => 'testname.ics']]);
- $calendar->expects(self::once())
- ->method('handleIMipMessage')
- ->with('testname.ics', $calendarData->serialize());
- $result = $manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize());
- $this->assertTrue($result);
- }
- public function testHandleImipCancel(): void {
-
- $manager = $this->getMockBuilder(Manager::class)
- ->setConstructorArgs([
- $this->coordinator,
- $this->container,
- $this->logger,
- $this->time
- ])
- ->setMethods([
- 'getCalendarsForPrincipal'
- ])
- ->getMock();
- $principalUri = 'principals/user/pierre';
- $sender = 'linus@stardew-tent-living.com';
- $recipient = 'pierre@general-store.com';
- $replyTo = null;
- $calendar = $this->createMock(ITestCalendar::class);
- $calendarData = $this->getVCalendarCancel();
- $this->time->expects(self::once())
- ->method('getTime')
- ->willReturn(1628374233);
- $manager->expects(self::once())
- ->method('getCalendarsForPrincipal')
- ->with($principalUri)
- ->willReturn([$calendar]);
- $calendar->expects(self::once())
- ->method('search')
- ->willReturn([['uri' => 'testname.ics']]);
- $calendar->expects(self::once())
- ->method('handleIMipMessage')
- ->with('testname.ics', $calendarData->serialize());
- $result = $manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize());
- $this->assertTrue($result);
- }
-
- private function getVCalendarReply(): Document {
- $data = <<<EOF
- BEGIN:VCALENDAR
- PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN
- VERSION:2.0
- CALSCALE:GREGORIAN
- METHOD:REPLY
- BEGIN:VEVENT
- DTSTART;VALUE=DATE:20210820
- DTEND;VALUE=DATE:20220821
- DTSTAMP:20210812T100040Z
- ORGANIZER;CN=admin:mailto:linus@stardew-tent-living.com
- UID:dcc733bf-b2b2-41f2-a8cf-550ae4b67aff
- ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN=pierr
- e@general-store.com;X-NUM-GUESTS=0:mailto:pierre@general-store.com
- CREATED:20220812T100021Z
- DESCRIPTION:
- LAST-MODIFIED:20220812T100040Z
- LOCATION:
- SEQUENCE:3
- STATUS:CONFIRMED
- SUMMARY:berry basket
- TRANSP:OPAQUE
- END:VEVENT
- END:VCALENDAR
- EOF;
- return Reader::read($data);
- }
- private function getVCalendarCancel(): Document {
- $data = <<<EOF
- BEGIN:VCALENDAR
- PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN
- VERSION:2.0
- CALSCALE:GREGORIAN
- METHOD:CANCEL
- BEGIN:VEVENT
- DTSTART;VALUE=DATE:20210820
- DTEND;VALUE=DATE:20220821
- DTSTAMP:20210812T100040Z
- ORGANIZER;CN=admin:mailto:linus@stardew-tent-living.com
- UID:dcc733bf-b2b2-41f2-a8cf-550ae4b67aff
- ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN=pierr
- e@general-store.com;X-NUM-GUESTS=0:mailto:pierre@general-store.com
- CREATED:20220812T100021Z
- DESCRIPTION:
- LAST-MODIFIED:20220812T100040Z
- LOCATION:
- SEQUENCE:3
- STATUS:CANCELLED
- SUMMARY:berry basket
- TRANSP:OPAQUE
- END:VEVENT
- END:VCALENDAR
- EOF;
- return Reader::read($data);
- }
- }
|