urlGenerator = $this->createMock(URLGenerator::class); $this->config = $this->createMock(IConfig::class); $this->db = $this->createMock(IDBConnection::class); $this->random = $this->createMock(ISecureRandom::class); $this->l10nFactory = $this->createMock(L10NFactory::class); $this->l10n = $this->createMock(LazyL10N::class); $this->l10nFactory->expects(self::once()) ->method('findGenericLanguage') ->willReturn('en'); $this->l10nFactory->expects(self::once()) ->method('get') ->with('dav', 'en') ->willReturn($this->l10n); $this->service = new IMipService( $this->urlGenerator, $this->config, $this->db, $this->random, $this->l10nFactory ); } public function testGetFrom(): void { $senderName = "Detective McQueen"; $default = "Twin Lakes Police Department - Darkside Division"; $expected = "Detective McQueen via Twin Lakes Police Department - Darkside Division"; $this->l10n->expects(self::once()) ->method('t') ->willReturn($expected); $actual = $this->service->getFrom($senderName, $default); $this->assertEquals($expected, $actual); } public function testBuildBodyDataCreated(): void { $vCalendar = new VCalendar(); $oldVevent = null; $newVevent = new VEvent($vCalendar, 'two', [ 'UID' => 'uid-1234', 'SEQUENCE' => 3, 'LAST-MODIFIED' => 789456, 'SUMMARY' => 'Second Breakfast', 'DTSTART' => new \DateTime('2016-01-01 00:00:00'), 'RECURRENCE-ID' => new \DateTime('2016-01-01 00:00:00') ]); $expected = [ 'meeting_when' => $this->service->generateWhenString($newVevent), 'meeting_description' => '', 'meeting_title' => 'Second Breakfast', 'meeting_location' => '', 'meeting_url' => '', 'meeting_url_html' => '', ]; $actual = $this->service->buildBodyData($newVevent, $oldVevent); $this->assertEquals($expected, $actual); } public function testBuildBodyDataUpdate(): void { $vCalendar = new VCalendar(); $oldVevent = new VEvent($vCalendar, 'two', [ 'UID' => 'uid-1234', 'SEQUENCE' => 1, 'LAST-MODIFIED' => 456789, 'SUMMARY' => 'Elevenses', 'DTSTART' => new \DateTime('2016-01-01 00:00:00'), 'RECURRENCE-ID' => new \DateTime('2016-01-01 00:00:00') ]); $oldVevent->add('ORGANIZER', 'mailto:gandalf@wiz.ard'); $oldVevent->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']); $newVevent = new VEvent($vCalendar, 'two', [ 'UID' => 'uid-1234', 'SEQUENCE' => 3, 'LAST-MODIFIED' => 789456, 'SUMMARY' => 'Second Breakfast', 'DTSTART' => new \DateTime('2016-01-01 00:00:00'), 'RECURRENCE-ID' => new \DateTime('2016-01-01 00:00:00') ]); $expected = [ 'meeting_when' => $this->service->generateWhenString($newVevent), 'meeting_description' => '', 'meeting_title' => 'Second Breakfast', 'meeting_location' => '', 'meeting_url' => '', 'meeting_url_html' => '', 'meeting_when_html' => $this->service->generateWhenString($newVevent), 'meeting_title_html' => sprintf("%s
%s", 'Elevenses', 'Second Breakfast'), 'meeting_description_html' => '', 'meeting_location_html' => '' ]; $actual = $this->service->buildBodyData($newVevent, $oldVevent); $this->assertEquals($expected, $actual); } public function testGenerateWhenStringHourlyEvent(): void { $vCalendar = new VCalendar(); $vevent = new VEvent($vCalendar, 'two', [ 'UID' => 'uid-1234', 'SEQUENCE' => 1, 'LAST-MODIFIED' => 456789, 'SUMMARY' => 'Elevenses', 'TZID' => 'Europe/Vienna', 'DTSTART' => (new \DateTime('2016-01-01 08:00:00'))->setTimezone(new \DateTimeZone('Europe/Vienna')), 'DTEND' => (new \DateTime('2016-01-01 09:00:00'))->setTimezone(new \DateTimeZone('Europe/Vienna')), ]); $this->l10n->expects(self::exactly(3)) ->method('l') ->withConsecutive( ['weekdayName', (new \DateTime('2016-01-01 08:00:00'))->setTimezone(new \DateTimeZone('Europe/Vienna')), ['width' => 'abbreviated']], ['datetime', (new \DateTime('2016-01-01 08:00:00'))->setTimezone(new \DateTimeZone('Europe/Vienna')), ['width' => 'medium|short']], ['time', (new \DateTime('2016-01-01 09:00:00'))->setTimezone(new \DateTimeZone('Europe/Vienna')), ['width' => 'short']] )->willReturnOnConsecutiveCalls( 'Fr.', '01.01. 08:00', '09:00' ); $expected = 'Fr., 01.01. 08:00 - 09:00 (Europe/Vienna)'; $actual = $this->service->generateWhenString($vevent); $this->assertEquals($expected, $actual); } public function testGetLastOccurrenceRRULE(): void { $vCalendar = new VCalendar(); $vCalendar->add('VEVENT', [ 'UID' => 'uid-1234', 'LAST-MODIFIED' => 123456, 'SEQUENCE' => 2, 'SUMMARY' => 'Fellowship meeting', 'DTSTART' => new \DateTime('2016-01-01 00:00:00'), 'RRULE' => 'FREQ=DAILY;INTERVAL=1;UNTIL=20160201T000000Z', ]); $occurrence = $this->service->getLastOccurrence($vCalendar); $this->assertEquals(1454284800, $occurrence); } public function testGetLastOccurrenceEndDate(): void { $vCalendar = new VCalendar(); $vCalendar->add('VEVENT', [ 'UID' => 'uid-1234', 'LAST-MODIFIED' => 123456, 'SEQUENCE' => 2, 'SUMMARY' => 'Fellowship meeting', 'DTSTART' => new \DateTime('2016-01-01 00:00:00'), 'DTEND' => new \DateTime('2017-01-01 00:00:00'), ]); $occurrence = $this->service->getLastOccurrence($vCalendar); $this->assertEquals(1483228800, $occurrence); } public function testGetLastOccurrenceDuration(): void { $vCalendar = new VCalendar(); $vCalendar->add('VEVENT', [ 'UID' => 'uid-1234', 'LAST-MODIFIED' => 123456, 'SEQUENCE' => 2, 'SUMMARY' => 'Fellowship meeting', 'DTSTART' => new \DateTime('2016-01-01 00:00:00'), 'DURATION' => 'P12W', ]); $occurrence = $this->service->getLastOccurrence($vCalendar); $this->assertEquals(1458864000, $occurrence); } public function testGetLastOccurrenceAllDay(): void { $vCalendar = new VCalendar(); $vEvent = $vCalendar->add('VEVENT', [ 'UID' => 'uid-1234', 'LAST-MODIFIED' => 123456, 'SEQUENCE' => 2, 'SUMMARY' => 'Fellowship meeting', 'DTSTART' => new \DateTime('2016-01-01 00:00:00'), ]); // rewrite from DateTime to Date $vEvent->DTSTART['VALUE'] = 'DATE'; $occurrence = $this->service->getLastOccurrence($vCalendar); $this->assertEquals(1451692800, $occurrence); } public function testGetLastOccurrenceFallback(): void { $vCalendar = new VCalendar(); $vCalendar->add('VEVENT', [ 'UID' => 'uid-1234', 'LAST-MODIFIED' => 123456, 'SEQUENCE' => 2, 'SUMMARY' => 'Fellowship meeting', 'DTSTART' => new \DateTime('2016-01-01 00:00:00'), ]); $occurrence = $this->service->getLastOccurrence($vCalendar); $this->assertEquals(1451606400, $occurrence); } }