1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768 |
- <?php
- /**
- * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
- * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
- * SPDX-License-Identifier: AGPL-3.0-only
- */
- namespace OCA\DAV\Tests\unit\CalDAV\Schedule;
- use OC\L10N\L10N;
- use OC\L10N\LazyL10N;
- use OC\URLGenerator;
- use OCA\DAV\CalDAV\EventReader;
- use OCA\DAV\CalDAV\Schedule\IMipService;
- use OCP\AppFramework\Utility\ITimeFactory;
- use OCP\IConfig;
- use OCP\IDBConnection;
- use OCP\L10N\IFactory as L10NFactory;
- use OCP\Security\ISecureRandom;
- use PHPUnit\Framework\MockObject\MockObject;
- use Sabre\VObject\Component\VCalendar;
- use Sabre\VObject\Property\ICalendar\DateTime;
- use Test\TestCase;
- class IMipServiceTest extends TestCase {
- /** @var URLGenerator|MockObject */
- private $urlGenerator;
- /** @var IConfig|MockObject */
- private $config;
- /** @var IDBConnection|MockObject */
- private $db;
- /** @var ISecureRandom|MockObject */
- private $random;
- /** @var L10NFactory|MockObject */
- private $l10nFactory;
- /** @var L10N|MockObject */
- private $l10n;
- /** @var ITimeFactory|MockObject */
- private $timeFactory;
- /** @var IMipService */
- private $service;
- /** @var VCalendar */
- private $vCalendar1a;
- /** @var VCalendar */
- private $vCalendar1b;
- /** @var VCalendar */
- private $vCalendar2;
- /** @var VCalendar */
- private $vCalendar3;
- /** @var DateTime DateTime object that will be returned by DateTime() or DateTime('now') */
- public static $datetimeNow;
- protected function setUp(): void {
- $this->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->timeFactory = $this->createMock(ITimeFactory::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,
- $this->timeFactory
- );
- // construct calendar with a 1 hour event and same start/end time zones
- $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', 'Testing 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'
- ]);
- // construct calendar with a 1 hour event and different start/end time zones
- $this->vCalendar1b = new VCalendar();
- $vEvent = $this->vCalendar1b->add('VEVENT', []);
- $vEvent->UID->setValue('96a0e6b1-d886-4a55-a60d-152b31401dcc');
- $vEvent->add('DTSTART', '20240701T080000', ['TZID' => 'America/Toronto']);
- $vEvent->add('DTEND', '20240701T090000', ['TZID' => 'America/Vancouver']);
- $vEvent->add('SUMMARY', 'Testing 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'
- ]);
- // construct calendar with a full day event
- $this->vCalendar2 = new VCalendar();
- // time zone component
- $vTimeZone = $this->vCalendar2->add('VTIMEZONE');
- $vTimeZone->add('TZID', 'America/Toronto');
- // event component
- $vEvent = $this->vCalendar2->add('VEVENT', []);
- $vEvent->UID->setValue('96a0e6b1-d886-4a55-a60d-152b31401dcc');
- $vEvent->add('DTSTART', '20240701');
- $vEvent->add('DTEND', '20240702');
- $vEvent->add('SUMMARY', 'Testing 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'
- ]);
- // construct calendar with a multi day event
- $this->vCalendar3 = new VCalendar();
- // time zone component
- $vTimeZone = $this->vCalendar3->add('VTIMEZONE');
- $vTimeZone->add('TZID', 'America/Toronto');
- // event component
- $vEvent = $this->vCalendar3->add('VEVENT', []);
- $vEvent->UID->setValue('96a0e6b1-d886-4a55-a60d-152b31401dcc');
- $vEvent->add('DTSTART', '20240701');
- $vEvent->add('DTEND', '20240706');
- $vEvent->add('SUMMARY', 'Testing 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 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 {
-
- // construct l10n return(s)
- $this->l10n->method('l')->willReturnCallback(
- function ($v1, $v2, $v3) {
- return match (true) {
- $v1 === 'time' && $v2 == (new \DateTime('20240701T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'short'] => '8:00 AM',
- $v1 === 'time' && $v2 == (new \DateTime('20240701T090000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'short'] => '9:00 AM',
- $v1 === 'date' && $v2 == (new \DateTime('20240701T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'full'] => 'July 1, 2024'
- };
- }
- );
- $this->l10n->method('t')->willReturnMap([
- ['In a %1$s on %2$s between %3$s - %4$s', ['day', 'July 1, 2024', '8:00 AM', '9:00 AM (America/Toronto)'], 'In a day on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)']
- ]);
- // construct time factory return(s)
- $this->timeFactory->method('getDateTime')->willReturnCallback(
- function ($v1, $v2) {
- return match (true) {
- $v1 == 'now' && $v2 == null => (new \DateTime('20240630T000000'))
- };
- }
- );
- /** test singleton partial day event*/
- $vCalendar = clone $this->vCalendar1a;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // define expected output
- $expected = [
- 'meeting_when' => $this->service->generateWhenString($eventReader),
- 'meeting_description' => '',
- 'meeting_title' => 'Testing Event',
- 'meeting_location' => '',
- 'meeting_url' => '',
- 'meeting_url_html' => '',
- ];
- // generate actual output
- $actual = $this->service->buildBodyData($vCalendar->VEVENT[0], null);
- // test output
- $this->assertEquals($expected, $actual);
- }
- public function testBuildBodyDataUpdate(): void {
-
- // construct l10n return(s)
- $this->l10n->method('l')->willReturnCallback(
- function ($v1, $v2, $v3) {
- return match (true) {
- $v1 === 'time' && $v2 == (new \DateTime('20240701T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'short'] => '8:00 AM',
- $v1 === 'time' && $v2 == (new \DateTime('20240701T090000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'short'] => '9:00 AM',
- $v1 === 'date' && $v2 == (new \DateTime('20240701T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'full'] => 'July 1, 2024'
- };
- }
- );
- $this->l10n->method('t')->willReturnMap([
- ['In a %1$s on %2$s between %3$s - %4$s', ['day', 'July 1, 2024', '8:00 AM', '9:00 AM (America/Toronto)'], 'In a day on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)']
- ]);
- // construct time factory return(s)
- $this->timeFactory->method('getDateTime')->willReturnCallback(
- function ($v1, $v2) {
- return match (true) {
- $v1 == 'now' && $v2 == null => (new \DateTime('20240630T000000'))
- };
- }
- );
- /** test singleton partial day event*/
- $vCalendarNew = clone $this->vCalendar1a;
- $vCalendarOld = clone $this->vCalendar1a;
- // construct event reader
- $eventReaderNew = new EventReader($vCalendarNew, $vCalendarNew->VEVENT[0]->UID->getValue());
- // alter old event label/title
- $vCalendarOld->VEVENT[0]->SUMMARY->setValue('Testing Singleton Event');
- // define expected output
- $expected = [
- 'meeting_when' => $this->service->generateWhenString($eventReaderNew),
- 'meeting_description' => '',
- 'meeting_title' => 'Testing Event',
- 'meeting_location' => '',
- 'meeting_url' => '',
- 'meeting_url_html' => '',
- 'meeting_when_html' => $this->service->generateWhenString($eventReaderNew),
- 'meeting_title_html' => sprintf("<span style='text-decoration: line-through'>%s</span><br />%s", 'Testing Singleton Event', 'Testing Event'),
- 'meeting_description_html' => '',
- 'meeting_location_html' => ''
- ];
- // generate actual output
- $actual = $this->service->buildBodyData($vCalendarNew->VEVENT[0], $vCalendarOld->VEVENT[0]);
- // test output
- $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);
- }
- public function testGenerateWhenStringSingular(): void {
-
- // construct l10n return(s)
- $this->l10n->method('l')->willReturnCallback(
- function ($v1, $v2, $v3) {
- return match (true) {
- $v1 === 'time' && $v2 == (new \DateTime('20240701T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'short'] => '8:00 AM',
- $v1 === 'time' && $v2 == (new \DateTime('20240701T090000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'short'] => '9:00 AM',
- $v1 === 'date' && $v2 == (new \DateTime('20240701T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'full'] => 'July 1, 2024',
- $v1 === 'date' && $v2 == (new \DateTime('20240701T000000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'full'] => 'July 1, 2024'
- };
- }
- );
- $this->l10n->method('t')->willReturnMap([
- ['In a %1$s on %2$s for the entire day', ['day', 'July 1, 2024'], 'In a day on July 1, 2024 for the entire day'],
- ['In a %1$s on %2$s between %3$s - %4$s', ['day', 'July 1, 2024', '8:00 AM', '9:00 AM (America/Toronto)'], 'In a day on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['In %1$s %2$s on %3$s for the entire day', [2, 'days', 'July 1, 2024'], 'In 2 days on July 1, 2024 for the entire day'],
- ['In %1$s %2$s on %3$s between %4$s - %5$s', [2, 'days', 'July 1, 2024', '8:00 AM', '9:00 AM (America/Toronto)'], 'In 2 days on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['In a %1$s on %2$s for the entire day', ['week', 'July 1, 2024'], 'In a week on July 1, 2024 for the entire day'],
- ['In a %1$s on %2$s between %3$s - %4$s', ['week', 'July 1, 2024', '8:00 AM', '9:00 AM (America/Toronto)'], 'In a week on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['In %1$s %2$s on %3$s for the entire day', [2, 'weeks', 'July 1, 2024'], 'In 2 weeks on July 1, 2024 for the entire day'],
- ['In %1$s %2$s on %3$s between %4$s - %5$s', [2, 'weeks', 'July 1, 2024', '8:00 AM', '9:00 AM (America/Toronto)'], 'In 2 weeks on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['In a %1$s on %2$s for the entire day', ['month', 'July 1, 2024'], 'In a month on July 1, 2024 for the entire day'],
- ['In a %1$s on %2$s between %3$s - %4$s', ['month', 'July 1, 2024', '8:00 AM', '9:00 AM (America/Toronto)'], 'In a month on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['In %1$s %2$s on %3$s for the entire day', [2, 'months', 'July 1, 2024'], 'In 2 months on July 1, 2024 for the entire day'],
- ['In %1$s %2$s on %3$s between %4$s - %5$s', [2, 'months', 'July 1, 2024', '8:00 AM', '9:00 AM (America/Toronto)'], 'In 2 months on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['In a %1$s on %2$s for the entire day', ['year', 'July 1, 2024'], 'In a year on July 1, 2024 for the entire day'],
- ['In a %1$s on %2$s between %3$s - %4$s', ['year', 'July 1, 2024', '8:00 AM', '9:00 AM (America/Toronto)'], 'In a year on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['In %1$s %2$s on %3$s for the entire day', [2, 'years', 'July 1, 2024'], 'In 2 years on July 1, 2024 for the entire day'],
- ['In %1$s %2$s on %3$s between %4$s - %5$s', [2, 'years', 'July 1, 2024', '8:00 AM', '9:00 AM (America/Toronto)'], 'In 2 years on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)']
- ]);
- // construct time factory return(s)
- $this->timeFactory->method('getDateTime')->willReturnOnConsecutiveCalls(
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240621T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240621T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240614T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240614T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240530T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240530T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240430T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240430T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20230630T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20230630T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20220630T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20220630T170000', (new \DateTimeZone('America/Toronto'))))
- );
- /** test patrial day event in 1 day*/
- $vCalendar = clone $this->vCalendar1a;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a day on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event in 1 day*/
- $vCalendar = clone $this->vCalendar2;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a day on July 1, 2024 for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test patrial day event in 2 days*/
- $vCalendar = clone $this->vCalendar1a;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 days on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event in 2 days*/
- $vCalendar = clone $this->vCalendar2;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 days on July 1, 2024 for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test patrial day event in 1 week*/
- $vCalendar = clone $this->vCalendar1a;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a week on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event in 1 week*/
- $vCalendar = clone $this->vCalendar2;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a week on July 1, 2024 for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test patrial day event in 2 weeks*/
- $vCalendar = clone $this->vCalendar1a;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 weeks on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event in 2 weeks*/
- $vCalendar = clone $this->vCalendar2;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 weeks on July 1, 2024 for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test patrial day event in 1 month*/
- $vCalendar = clone $this->vCalendar1a;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a month on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event in 1 month*/
- $vCalendar = clone $this->vCalendar2;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a month on July 1, 2024 for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test patrial day event in 2 months*/
- $vCalendar = clone $this->vCalendar1a;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 months on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event in 2 months*/
- $vCalendar = clone $this->vCalendar2;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 months on July 1, 2024 for the entire day',
- $this->service->generateWhenString($eventReader)
- );
-
- /** test patrial day event in 1 year*/
- $vCalendar = clone $this->vCalendar1a;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a year on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event in 1 year*/
- $vCalendar = clone $this->vCalendar2;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a year on July 1, 2024 for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test patrial day event in 2 years*/
- $vCalendar = clone $this->vCalendar1a;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 years on July 1, 2024 between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event in 2 years*/
- $vCalendar = clone $this->vCalendar2;
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 years on July 1, 2024 for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- }
- public function testGenerateWhenStringRecurringDaily(): void {
-
- // construct l10n return maps
- $this->l10n->method('l')->willReturnCallback(
- function ($v1, $v2, $v3) {
- return match (true) {
- $v1 === 'time' && $v2 == (new \DateTime('20240701T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'short'] => '8:00 AM',
- $v1 === 'time' && $v2 == (new \DateTime('20240701T090000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'short'] => '9:00 AM',
- $v1 === 'date' && $v2 == (new \DateTime('20240713T080000', (new \DateTimeZone('UTC')))) && $v3 == ['width' => 'long'] => 'July 13, 2024'
- };
- }
- );
- $this->l10n->method('t')->willReturnMap([
- ['Every Day for the entire day', [], 'Every Day for the entire day'],
- ['Every Day for the entire day until %1$s', ['July 13, 2024'], 'Every Day for the entire day until July 13, 2024'],
- ['Every Day between %1$s - %2$s', ['8:00 AM', '9:00 AM (America/Toronto)'], 'Every Day between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['Every Day between %1$s - %2$s until %3$s', ['8:00 AM', '9:00 AM (America/Toronto)', 'July 13, 2024'], 'Every Day between 8:00 AM - 9:00 AM (America/Toronto) until July 13, 2024'],
- ['Every %1$d Days for the entire day', [3], 'Every 3 Days for the entire day'],
- ['Every %1$d Days for the entire day until %2$s', [3, 'July 13, 2024'], 'Every 3 Days for the entire day until July 13, 2024'],
- ['Every %1$d Days between %2$s - %3$s', [3, '8:00 AM', '9:00 AM (America/Toronto)'], 'Every 3 Days between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['Every %1$d Days between %2$s - %3$s until %4$s', [3, '8:00 AM', '9:00 AM (America/Toronto)', 'July 13, 2024'], 'Every 3 Days between 8:00 AM - 9:00 AM (America/Toronto) until July 13, 2024'],
- ['Could not generate event recurrence statement', [], 'Could not generate event recurrence statement'],
- ]);
- /** test partial day event with every day interval and no conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=1;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Day between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test partial day event with every day interval and conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=1;UNTIL=20240713T080000Z');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Day between 8:00 AM - 9:00 AM (America/Toronto) until July 13, 2024',
- $this->service->generateWhenString($eventReader)
- );
- /** test partial day event every 3rd day interval and no conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=3;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 3 Days between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test partial day event with every 3rd day interval and conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=3;UNTIL=20240713T080000Z');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 3 Days between 8:00 AM - 9:00 AM (America/Toronto) until July 13, 2024',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event with every day interval and no conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=1;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Day for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event with every day interval and conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=1;UNTIL=20240713T080000Z');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Day for the entire day until July 13, 2024',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event with every 3rd day interval and no conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=3;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 3 Days for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event with every 3rd day interval and conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=3;UNTIL=20240713T080000Z');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 3 Days for the entire day until July 13, 2024',
- $this->service->generateWhenString($eventReader)
- );
- }
- public function testGenerateWhenStringRecurringWeekly(): void {
-
- // construct l10n return maps
- $this->l10n->method('l')->willReturnCallback(
- function ($v1, $v2, $v3) {
- return match (true) {
- $v1 === 'time' && $v2 == (new \DateTime('20240701T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'short'] => '8:00 AM',
- $v1 === 'time' && $v2 == (new \DateTime('20240701T090000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'short'] => '9:00 AM',
- $v1 === 'date' && $v2 == (new \DateTime('20240722T080000', (new \DateTimeZone('UTC')))) && $v3 == ['width' => 'long'] => 'July 13, 2024'
- };
- }
- );
- $this->l10n->method('t')->willReturnMap([
- ['Every Week on %1$s for the entire day', ['Monday, Wednesday, Friday'], 'Every Week on Monday, Wednesday, Friday for the entire day'],
- ['Every Week on %1$s for the entire day until %2$s', ['Monday, Wednesday, Friday', 'July 13, 2024'], 'Every Week on Monday, Wednesday, Friday for the entire day until July 13, 2024'],
- ['Every Week on %1$s between %2$s - %3$s', ['Monday, Wednesday, Friday', '8:00 AM', '9:00 AM (America/Toronto)'], 'Every Week on Monday, Wednesday, Friday between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['Every Week on %1$s between %2$s - %3$s until %4$s', ['Monday, Wednesday, Friday', '8:00 AM', '9:00 AM (America/Toronto)', 'July 13, 2024'], 'Every Week on Monday, Wednesday, Friday between 8:00 AM - 9:00 AM (America/Toronto) until July 13, 2024'],
- ['Every %1$d Weeks on %2$s for the entire day', [2, 'Monday, Wednesday, Friday'], 'Every 2 Weeks on Monday, Wednesday, Friday for the entire day'],
- ['Every %1$d Weeks on %2$s for the entire day until %3$s', [2, 'Monday, Wednesday, Friday', 'July 13, 2024'], 'Every 2 Weeks on Monday, Wednesday, Friday for the entire day until July 13, 2024'],
- ['Every %1$d Weeks on %2$s between %3$s - %4$s', [2, 'Monday, Wednesday, Friday', '8:00 AM', '9:00 AM (America/Toronto)'], 'Every 2 Weeks on Monday, Wednesday, Friday between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['Every %1$d Weeks on %2$s between %3$s - %4$s until %5$s', [2, 'Monday, Wednesday, Friday', '8:00 AM', '9:00 AM (America/Toronto)', 'July 13, 2024'], 'Every 2 Weeks on Monday, Wednesday, Friday between 8:00 AM - 9:00 AM (America/Toronto) until July 13, 2024'],
- ['Could not generate event recurrence statement', [], 'Could not generate event recurrence statement'],
- ['Monday', [], 'Monday'],
- ['Wednesday', [], 'Wednesday'],
- ['Friday', [], 'Friday'],
- ]);
- /** test partial day event with every week interval on Mon, Wed, Fri and no conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=WEEKLY;BYDAY=MO,WE,FR');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Week on Monday, Wednesday, Friday between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test partial day event with every week interval on Mon, Wed, Fri and conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=WEEKLY;BYDAY=MO,WE,FR;UNTIL=20240722T080000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Week on Monday, Wednesday, Friday between 8:00 AM - 9:00 AM (America/Toronto) until July 13, 2024',
- $this->service->generateWhenString($eventReader)
- );
- /** test partial day event with every 2nd week interval on Mon, Wed, Fri and no conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=WEEKLY;BYDAY=MO,WE,FR;INTERVAL=2;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Weeks on Monday, Wednesday, Friday between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test partial day event with every 2nd week interval on Mon, Wed, Fri and conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=WEEKLY;BYDAY=MO,WE,FR;INTERVAL=2;UNTIL=20240722T080000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Weeks on Monday, Wednesday, Friday between 8:00 AM - 9:00 AM (America/Toronto) until July 13, 2024',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event with every week interval on Mon, Wed, Fri and no conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=WEEKLY;BYDAY=MO,WE,FR;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Week on Monday, Wednesday, Friday for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event with every week interval on Mon, Wed, Fri and conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=WEEKLY;BYDAY=MO,WE,FR;UNTIL=20240722T080000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Week on Monday, Wednesday, Friday for the entire day until July 13, 2024',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event with every 2nd week interval on Mon, Wed, Fri and no conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=WEEKLY;BYDAY=MO,WE,FR;INTERVAL=2;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Weeks on Monday, Wednesday, Friday for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event with every 2nd week interval on Mon, Wed, Fri and conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=WEEKLY;BYDAY=MO,WE,FR;INTERVAL=2;UNTIL=20240722T080000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Weeks on Monday, Wednesday, Friday for the entire day until July 13, 2024',
- $this->service->generateWhenString($eventReader)
- );
- }
- public function testGenerateWhenStringRecurringMonthly(): void {
-
- // construct l10n return maps
- $this->l10n->method('l')->willReturnCallback(
- function ($v1, $v2, $v3) {
- return match (true) {
- $v1 === 'time' && $v2 == (new \DateTime('20240701T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'short'] => '8:00 AM',
- $v1 === 'time' && $v2 == (new \DateTime('20240701T090000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'short'] => '9:00 AM',
- $v1 === 'date' && $v2 == (new \DateTime('20241231T080000', (new \DateTimeZone('UTC')))) && $v3 == ['width' => 'long'] => 'December 31, 2024'
- };
- }
- );
- $this->l10n->method('t')->willReturnMap([
- ['Every Month on the %1$s for the entire day', ['1, 8'], 'Every Month on the 1, 8 for the entire day'],
- ['Every Month on the %1$s for the entire day until %2$s', ['1, 8', 'December 31, 2024'], 'Every Month on the 1, 8 for the entire day until December 31, 2024'],
- ['Every Month on the %1$s between %2$s - %3$s', ['1, 8', '8:00 AM', '9:00 AM (America/Toronto)'], 'Every Month on the 1, 8 between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['Every Month on the %1$s between %2$s - %3$s until %4$s', ['1, 8', '8:00 AM', '9:00 AM (America/Toronto)', 'December 31, 2024'], 'Every Month on the 1, 8 between 8:00 AM - 9:00 AM (America/Toronto) until December 31, 2024'],
- ['Every %1$d Months on the %2$s for the entire day', [2, '1, 8'], 'Every 2 Months on the 1, 8 for the entire day'],
- ['Every %1$d Months on the %2$s for the entire day until %3$s', [2, '1, 8', 'December 31, 2024'], 'Every 2 Months on the 1, 8 for the entire day until December 31, 2024'],
- ['Every %1$d Months on the %2$s between %3$s - %4$s', [2, '1, 8', '8:00 AM', '9:00 AM (America/Toronto)'], 'Every 2 Months on the 1, 8 between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['Every %1$d Months on the %2$s between %3$s - %4$s until %5$s', [2, '1, 8', '8:00 AM', '9:00 AM (America/Toronto)', 'December 31, 2024'], 'Every 2 Months on the 1, 8 between 8:00 AM - 9:00 AM (America/Toronto) until December 31, 2024'],
- ['Every Month on the %1$s for the entire day', ['First Sunday, Saturday'], 'Every Month on the First Sunday, Saturday for the entire day'],
- ['Every Month on the %1$s for the entire day until %2$s', ['First Sunday, Saturday', 'December 31, 2024'], 'Every Month on the First Sunday, Saturday for the entire day until December 31, 2024'],
- ['Every Month on the %1$s between %2$s - %3$s', ['First Sunday, Saturday', '8:00 AM', '9:00 AM (America/Toronto)'], 'Every Month on the First Sunday, Saturday between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['Every Month on the %1$s between %2$s - %3$s until %4$s', ['First Sunday, Saturday', '8:00 AM', '9:00 AM (America/Toronto)', 'December 31, 2024'], 'Every Month on the First Sunday, Saturday between 8:00 AM - 9:00 AM (America/Toronto) until December 31, 2024'],
- ['Every %1$d Months on the %2$s for the entire day', [2, 'First Sunday, Saturday'], 'Every 2 Months on the First Sunday, Saturday for the entire day'],
- ['Every %1$d Months on the %2$s for the entire day until %3$s', [2, 'First Sunday, Saturday', 'December 31, 2024'], 'Every 2 Months on the First Sunday, Saturday for the entire day until December 31, 2024'],
- ['Every %1$d Months on the %2$s between %3$s - %4$s', [2, 'First Sunday, Saturday', '8:00 AM', '9:00 AM (America/Toronto)'], 'Every 2 Months on the First Sunday, Saturday between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['Every %1$d Months on the %2$s between %3$s - %4$s until %5$s', [2, 'First Sunday, Saturday', '8:00 AM', '9:00 AM (America/Toronto)', 'December 31, 2024'], 'Every 2 Months on the First Sunday, Saturday between 8:00 AM - 9:00 AM (America/Toronto) until December 31, 2024'],
- ['Could not generate event recurrence statement', [], 'Could not generate event recurrence statement'],
- ['Saturday', [], 'Saturday'],
- ['Sunday', [], 'Sunday'],
- ['First', [], 'First'],
- ]);
- /** test absolute partial day event with every month interval on 1st, 8th and no conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=MONTHLY;BYMONTHDAY=1,8;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Month on the 1, 8 between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test absolute partial day event with every Month interval on 1st, 8th and conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=MONTHLY;BYMONTHDAY=1,8;UNTIL=20241231T080000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Month on the 1, 8 between 8:00 AM - 9:00 AM (America/Toronto) until December 31, 2024',
- $this->service->generateWhenString($eventReader)
- );
- /** test absolute partial day event with every 2nd Month interval on 1st, 8th and no conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=MONTHLY;BYMONTHDAY=1,8;INTERVAL=2;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Months on the 1, 8 between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test absolute partial day event with every 2nd Month interval on 1st, 8th and conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=MONTHLY;BYMONTHDAY=1,8;INTERVAL=2;UNTIL=20241231T080000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Months on the 1, 8 between 8:00 AM - 9:00 AM (America/Toronto) until December 31, 2024',
- $this->service->generateWhenString($eventReader)
- );
- /** test absolute entire day event with every Month interval on 1st, 8th and no conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=MONTHLY;BYMONTHDAY=1,8;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Month on the 1, 8 for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test absolute entire day event with every Month interval on 1st, 8th and conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=MONTHLY;BYMONTHDAY=1,8;UNTIL=20241231T080000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Month on the 1, 8 for the entire day until December 31, 2024',
- $this->service->generateWhenString($eventReader)
- );
- /** test absolute entire day event with every 2nd Month interval on 1st, 8th and no conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=MONTHLY;BYMONTHDAY=1,8;INTERVAL=2;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Months on the 1, 8 for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test absolute entire day event with every 2nd Month interval on 1st, 8th and conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=MONTHLY;BYMONTHDAY=1,8;INTERVAL=2;UNTIL=20241231T080000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Months on the 1, 8 for the entire day until December 31, 2024',
- $this->service->generateWhenString($eventReader)
- );
- /** test relative partial day event with every month interval on the 1st Saturday, Sunday and no conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=MONTHLY;BYDAY=SU,SA;BYSETPOS=1;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Month on the First Sunday, Saturday between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test relative partial day event with every Month interval on the 1st Saturday, Sunday and conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=MONTHLY;BYDAY=SU,SA;BYSETPOS=1;UNTIL=20241231T080000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Month on the First Sunday, Saturday between 8:00 AM - 9:00 AM (America/Toronto) until December 31, 2024',
- $this->service->generateWhenString($eventReader)
- );
- /** test relative partial day event with every 2nd Month interval on the 1st Saturday, Sunday and no conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=MONTHLY;BYDAY=SU,SA;BYSETPOS=1;INTERVAL=2;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Months on the First Sunday, Saturday between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test relative partial day event with every 2nd Month interval on the 1st Saturday, Sunday and conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=MONTHLY;BYDAY=SU,SA;BYSETPOS=1;INTERVAL=2;UNTIL=20241231T080000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Months on the First Sunday, Saturday between 8:00 AM - 9:00 AM (America/Toronto) until December 31, 2024',
- $this->service->generateWhenString($eventReader)
- );
- /** test relative entire day event with every Month interval on the 1st Saturday, Sunday and no conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=MONTHLY;BYDAY=SU,SA;BYSETPOS=1;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Month on the First Sunday, Saturday for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test relative entire day event with every Month interval on the 1st Saturday, Sunday and conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=MONTHLY;BYDAY=SU,SA;BYSETPOS=1;UNTIL=20241231T080000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Month on the First Sunday, Saturday for the entire day until December 31, 2024',
- $this->service->generateWhenString($eventReader)
- );
- /** test relative entire day event with every 2nd Month interval on the 1st Saturday, Sunday and no conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=MONTHLY;BYDAY=SU,SA;BYSETPOS=1;INTERVAL=2;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Months on the First Sunday, Saturday for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test relative entire day event with every 2nd Month interval on the 1st Saturday, Sunday and conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=MONTHLY;BYDAY=SU,SA;BYSETPOS=1;INTERVAL=2;UNTIL=20241231T080000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Months on the First Sunday, Saturday for the entire day until December 31, 2024',
- $this->service->generateWhenString($eventReader)
- );
- }
- public function testGenerateWhenStringRecurringYearly(): void {
-
- // construct l10n return maps
- $this->l10n->method('l')->willReturnCallback(
- function ($v1, $v2, $v3) {
- return match (true) {
- $v1 === 'time' && $v2 == (new \DateTime('20240701T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'short'] => '8:00 AM',
- $v1 === 'time' && $v2 == (new \DateTime('20240701T090000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'short'] => '9:00 AM',
- $v1 === 'date' && $v2 == (new \DateTime('20260731T040000', (new \DateTimeZone('UTC')))) && $v3 == ['width' => 'long'] => 'July 31, 2026'
- };
- }
- );
- $this->l10n->method('t')->willReturnMap([
- ['Every Year in %1$s on the %2$s for the entire day', ['July', '1st'], 'Every Year in July on the 1st for the entire day'],
- ['Every Year in %1$s on the %2$s for the entire day until %3$s', ['July', '1st', 'July 31, 2026'], 'Every Year in July on the 1st for the entire day until July 31, 2026'],
- ['Every Year in %1$s on the %2$s between %3$s - %4$s', ['July', '1st', '8:00 AM', '9:00 AM (America/Toronto)'], 'Every Year in July on the 1st between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['Every Year in %1$s on the %2$s between %3$s - %4$s until %5$s', ['July', '1st', '8:00 AM', '9:00 AM (America/Toronto)', 'July 31, 2026'], 'Every Year in July on the 1st between 8:00 AM - 9:00 AM (America/Toronto) until July 31, 2026'],
- ['Every %1$d Years in %2$s on the %3$s for the entire day', [2, 'July', '1st'], 'Every 2 Years in July on the 1st for the entire day'],
- ['Every %1$d Years in %2$s on the %3$s for the entire day until %4$s', [2, 'July', '1st', 'July 31, 2026'], 'Every 2 Years in July on the 1st for the entire day until July 31, 2026'],
- ['Every %1$d Years in %2$s on the %3$s between %4$s - %5$s', [2, 'July', '1st', '8:00 AM', '9:00 AM (America/Toronto)'], 'Every 2 Years in July on the 1st between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['Every %1$d Years in %2$s on the %3$s between %4$s - %5$s until %6$s', [2, 'July', '1st', '8:00 AM', '9:00 AM (America/Toronto)', 'July 31, 2026'], 'Every 2 Years in July on the 1st between 8:00 AM - 9:00 AM (America/Toronto) until July 31, 2026'],
- ['Every Year in %1$s on the %2$s for the entire day', ['July', 'First Sunday, Saturday'], 'Every Year in July on the First Sunday, Saturday for the entire day'],
- ['Every Year in %1$s on the %2$s for the entire day until %3$s', ['July', 'First Sunday, Saturday', 'July 31, 2026'], 'Every Year in July on the First Sunday, Saturday for the entire day until July 31, 2026'],
- ['Every Year in %1$s on the %2$s between %3$s - %4$s', ['July', 'First Sunday, Saturday', '8:00 AM', '9:00 AM (America/Toronto)'], 'Every Year in July on the First Sunday, Saturday between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['Every Year in %1$s on the %2$s between %3$s - %4$s until %5$s', ['July', 'First Sunday, Saturday', '8:00 AM', '9:00 AM (America/Toronto)', 'July 31, 2026'], 'Every Year in July on the First Sunday, Saturday between 8:00 AM - 9:00 AM (America/Toronto) until July 31, 2026'],
- ['Every %1$d Years in %2$s on the %3$s for the entire day', [2, 'July', 'First Sunday, Saturday'], 'Every 2 Years in July on the First Sunday, Saturday for the entire day'],
- ['Every %1$d Years in %2$s on the %3$s for the entire day until %4$s', [2, 'July', 'First Sunday, Saturday', 'July 31, 2026'], 'Every 2 Years in July on the First Sunday, Saturday for the entire day until July 31, 2026'],
- ['Every %1$d Years in %2$s on the %3$s between %4$s - %5$s', [2, 'July', 'First Sunday, Saturday', '8:00 AM', '9:00 AM (America/Toronto)'], 'Every 2 Years in July on the First Sunday, Saturday between 8:00 AM - 9:00 AM (America/Toronto)'],
- ['Every %1$d Years in %2$s on the %3$s between %4$s - %5$s until %6$s', [2, 'July', 'First Sunday, Saturday', '8:00 AM', '9:00 AM (America/Toronto)', 'July 31, 2026'], 'Every 2 Years in July on the First Sunday, Saturday between 8:00 AM - 9:00 AM (America/Toronto) until July 31, 2026'],
- ['Could not generate event recurrence statement', [], 'Could not generate event recurrence statement'],
- ['July', [], 'July'],
- ['Saturday', [], 'Saturday'],
- ['Sunday', [], 'Sunday'],
- ['First', [], 'First'],
- ]);
- /** test absolute partial day event with every year interval on July 1 and no conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=YEARLY;BYMONTH=7;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Year in July on the 1st between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test absolute partial day event with every year interval on July 1 and conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=YEARLY;BYMONTH=7;UNTIL=20260731T040000Z');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Year in July on the 1st between 8:00 AM - 9:00 AM (America/Toronto) until July 31, 2026',
- $this->service->generateWhenString($eventReader)
- );
- /** test absolute partial day event with every 2nd year interval on July 1 and no conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=YEARLY;BYMONTH=7;INTERVAL=2;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Years in July on the 1st between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test absolute partial day event with every 2nd year interval on July 1 and conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=YEARLY;BYMONTH=7;INTERVAL=2;UNTIL=20260731T040000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Years in July on the 1st between 8:00 AM - 9:00 AM (America/Toronto) until July 31, 2026',
- $this->service->generateWhenString($eventReader)
- );
- /** test absolute entire day event with every year interval on July 1 and no conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=YEARLY;BYMONTH=7;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Year in July on the 1st for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test absolute entire day event with every year interval on July 1 and conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=YEARLY;BYMONTH=7;UNTIL=20260731T040000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Year in July on the 1st for the entire day until July 31, 2026',
- $this->service->generateWhenString($eventReader)
- );
- /** test absolute entire day event with every 2nd year interval on July 1 and no conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=YEARLY;BYMONTH=7;INTERVAL=2;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Years in July on the 1st for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test absolute entire day event with every 2nd year interval on July 1 and conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=YEARLY;BYMONTH=7;INTERVAL=2;UNTIL=20260731T040000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Years in July on the 1st for the entire day until July 31, 2026',
- $this->service->generateWhenString($eventReader)
- );
- /** test relative partial day event with every year interval on the 1st Saturday, Sunday in July and no conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=YEARLY;BYMONTH=7;BYDAY=SU,SA;BYSETPOS=1;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Year in July on the First Sunday, Saturday between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test relative partial day event with every year interval on the 1st Saturday, Sunday in July and conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=YEARLY;BYMONTH=7;BYDAY=SU,SA;BYSETPOS=1;UNTIL=20260731T040000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Year in July on the First Sunday, Saturday between 8:00 AM - 9:00 AM (America/Toronto) until July 31, 2026',
- $this->service->generateWhenString($eventReader)
- );
- /** test relative partial day event with every 2nd year interval on the 1st Saturday, Sunday in July and no conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=YEARLY;BYMONTH=7;BYDAY=SU,SA;BYSETPOS=1;INTERVAL=2;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Years in July on the First Sunday, Saturday between 8:00 AM - 9:00 AM (America/Toronto)',
- $this->service->generateWhenString($eventReader)
- );
- /** test relative partial day event with every 2nd year interval on the 1st Saturday, Sunday in July and conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=YEARLY;BYMONTH=7;BYDAY=SU,SA;BYSETPOS=1;INTERVAL=2;UNTIL=20260731T040000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Years in July on the First Sunday, Saturday between 8:00 AM - 9:00 AM (America/Toronto) until July 31, 2026',
- $this->service->generateWhenString($eventReader)
- );
- /** test relative entire day event with every year interval on the 1st Saturday, Sunday in July and no conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=YEARLY;BYMONTH=7;BYDAY=SU,SA;BYSETPOS=1;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Year in July on the First Sunday, Saturday for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test relative entire day event with every year interval on the 1st Saturday, Sunday in July and conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=YEARLY;BYMONTH=7;BYDAY=SU,SA;BYSETPOS=1;UNTIL=20260731T040000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every Year in July on the First Sunday, Saturday for the entire day until July 31, 2026',
- $this->service->generateWhenString($eventReader)
- );
- /** test relative entire day event with every 2nd year interval on the 1st Saturday, Sunday in July and no conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=YEARLY;BYMONTH=7;BYDAY=SU,SA;BYSETPOS=1;INTERVAL=2;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Years in July on the First Sunday, Saturday for the entire day',
- $this->service->generateWhenString($eventReader)
- );
- /** test relative entire day event with every 2nd year interval on the 1st Saturday, Sunday in July and conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=YEARLY;BYMONTH=7;BYDAY=SU,SA;BYSETPOS=1;INTERVAL=2;UNTIL=20260731T040000Z;');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'Every 2 Years in July on the First Sunday, Saturday for the entire day until July 31, 2026',
- $this->service->generateWhenString($eventReader)
- );
- }
- public function testGenerateWhenStringRecurringFixed(): void {
-
- // construct l10n return maps
- $this->l10n->method('l')->willReturnCallback(
- function ($v1, $v2, $v3) {
- return match (true) {
- $v1 === 'time' && $v2 == (new \DateTime('20240701T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'short'] => '8:00 AM',
- $v1 === 'time' && $v2 == (new \DateTime('20240701T090000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'short'] => '9:00 AM',
- $v1 === 'date' && $v2 == (new \DateTime('20240713T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'long'] => 'July 13, 2024'
- };
- }
- );
- $this->l10n->method('t')->willReturnMap([
- ['On specific dates for the entire day until %1$s', ['July 13, 2024'], 'On specific dates for the entire day until July 13, 2024'],
- ['On specific dates between %1$s - %2$s until %3$s', ['8:00 AM', '9:00 AM (America/Toronto)', 'July 13, 2024'], 'On specific dates between 8:00 AM - 9:00 AM (America/Toronto) until July 13, 2024'],
- ]);
- /** test partial day event with every day interval and conclusion*/
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RDATE', '20240703T080000,20240709T080000,20240713T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'On specific dates between 8:00 AM - 9:00 AM (America/Toronto) until July 13, 2024',
- $this->service->generateWhenString($eventReader)
- );
- /** test entire day event with every day interval and no conclusion*/
- $vCalendar = clone $this->vCalendar2;
- $vCalendar->VEVENT[0]->add('RDATE', '20240703T080000,20240709T080000,20240713T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'On specific dates for the entire day until July 13, 2024',
- $this->service->generateWhenString($eventReader)
- );
- }
- public function testGenerateOccurringStringWithRrule(): void {
-
- // construct l10n return(s)
- $this->l10n->method('l')->willReturnCallback(
- function ($v1, $v2, $v3) {
- return match (true) {
- $v1 === 'date' && $v2 == (new \DateTime('20240701T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'long'] => 'July 1, 2024',
- $v1 === 'date' && $v2 == (new \DateTime('20240703T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'long'] => 'July 3, 2024',
- $v1 === 'date' && $v2 == (new \DateTime('20240705T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'long'] => 'July 5, 2024'
- };
- }
- );
- $this->l10n->method('t')->willReturnMap([
- ['In a %1$s on %2$s', ['day', 'July 1, 2024'], 'In a day on July 1, 2024'],
- ['In a %1$s on %2$s then on %3$s', ['day', 'July 1, 2024', 'July 3, 2024'], 'In a day on July 1, 2024 then on July 3, 2024'],
- ['In a %1$s on %2$s then on %3$s and %4$s', ['day', 'July 1, 2024', 'July 3, 2024', 'July 5, 2024'], 'In a day on July 1, 2024 then on July 3, 2024 and July 5, 2024'],
- ['In %1$s %2$s on %3$s', [2, 'days', 'July 1, 2024'], 'In 2 days on July 1, 2024'],
- ['In %1$s %2$s on %3$s then on %4$s', [2, 'days', 'July 1, 2024', 'July 3, 2024'], 'In 2 days on July 1, 2024 then on July 3, 2024'],
- ['In %1$s %2$s on %3$s then on %4$s and %5$s', [2, 'days', 'July 1, 2024', 'July 3, 2024', 'July 5, 2024'], 'In 2 days on July 1, 2024 then on July 3, 2024 and July 5, 2024'],
- ]);
- // construct time factory return(s)
- $this->timeFactory->method('getDateTime')->willReturnOnConsecutiveCalls(
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- );
- /** test patrial day recurring event in 1 day with single occurrence remaining */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=1');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a day on July 1, 2024',
- $this->service->generateOccurringString($eventReader)
- );
- /** test patrial day recurring event in 1 day with two occurrences remaining */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=2');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a day on July 1, 2024 then on July 3, 2024',
- $this->service->generateOccurringString($eventReader)
- );
- /** test patrial day recurring event in 1 day with three occurrences remaining */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=3');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a day on July 1, 2024 then on July 3, 2024 and July 5, 2024',
- $this->service->generateOccurringString($eventReader)
- );
- /** test patrial day recurring event in 2 days with single occurrence remaining */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=1');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 days on July 1, 2024',
- $this->service->generateOccurringString($eventReader)
- );
- /** test patrial day recurring event in 2 days with two occurrences remaining */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=2');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 days on July 1, 2024 then on July 3, 2024',
- $this->service->generateOccurringString($eventReader)
- );
- /** test patrial day recurring event in 2 days with three occurrences remaining */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=3');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 days on July 1, 2024 then on July 3, 2024 and July 5, 2024',
- $this->service->generateOccurringString($eventReader)
- );
- }
- public function testGenerateOccurringStringWithRdate(): void {
-
- // construct l10n return(s)
- $this->l10n->method('l')->willReturnCallback(
- function ($v1, $v2, $v3) {
- return match (true) {
- $v1 === 'date' && $v2 == (new \DateTime('20240701T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'long'] => 'July 1, 2024',
- $v1 === 'date' && $v2 == (new \DateTime('20240703T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'long'] => 'July 3, 2024',
- $v1 === 'date' && $v2 == (new \DateTime('20240705T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'long'] => 'July 5, 2024'
- };
- }
- );
- $this->l10n->method('t')->willReturnMap([
- ['In a %1$s on %2$s', ['day', 'July 1, 2024'], 'In a day on July 1, 2024'],
- ['In a %1$s on %2$s then on %3$s', ['day', 'July 1, 2024', 'July 3, 2024'], 'In a day on July 1, 2024 then on July 3, 2024'],
- ['In a %1$s on %2$s then on %3$s and %4$s', ['day', 'July 1, 2024', 'July 3, 2024', 'July 5, 2024'], 'In a day on July 1, 2024 then on July 3, 2024 and July 5, 2024'],
- ['In %1$s %2$s on %3$s', [2, 'days', 'July 1, 2024'], 'In 2 days on July 1, 2024'],
- ['In %1$s %2$s on %3$s then on %4$s', [2, 'days', 'July 1, 2024', 'July 3, 2024'], 'In 2 days on July 1, 2024 then on July 3, 2024'],
- ['In %1$s %2$s on %3$s then on %4$s and %5$s', [2, 'days', 'July 1, 2024', 'July 3, 2024', 'July 5, 2024'], 'In 2 days on July 1, 2024 then on July 3, 2024 and July 5, 2024'],
- ]);
- // construct time factory return(s)
- $this->timeFactory->method('getDateTime')->willReturnOnConsecutiveCalls(
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- );
- /** test patrial day recurring event in 1 day with single occurrence remaining */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RDATE', '20240701T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a day on July 1, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 1 day with single occurrence remaining'
- );
- /** test patrial day recurring event in 1 day with two occurrences remaining */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RDATE', '20240701T080000,20240703T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a day on July 1, 2024 then on July 3, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 1 day with two occurrences remaining'
- );
- /** test patrial day recurring event in 1 day with three occurrences remaining */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RDATE', '20240701T080000,20240703T080000,20240705T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a day on July 1, 2024 then on July 3, 2024 and July 5, 2024',
- $this->service->generateOccurringString($eventReader),
- ''
- );
- /** test patrial day recurring event in 2 days with single occurrences remaining */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RDATE', '20240701T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 days on July 1, 2024',
- $this->service->generateOccurringString($eventReader),
- ''
- );
- /** test patrial day recurring event in 2 days with two occurrences remaining */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RDATE', '20240701T080000');
- $vCalendar->VEVENT[0]->add('RDATE', '20240703T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 days on July 1, 2024 then on July 3, 2024',
- $this->service->generateOccurringString($eventReader),
- ''
- );
- /** test patrial day recurring event in 2 days with three occurrences remaining */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RDATE', '20240701T080000');
- $vCalendar->VEVENT[0]->add('RDATE', '20240703T080000');
- $vCalendar->VEVENT[0]->add('RDATE', '20240705T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 days on July 1, 2024 then on July 3, 2024 and July 5, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 2 days with three occurrences remaining'
- );
- }
- public function testGenerateOccurringStringWithOneExdate(): void {
-
- // construct l10n return(s)
- $this->l10n->method('l')->willReturnCallback(
- function ($v1, $v2, $v3) {
- return match (true) {
- $v1 === 'date' && $v2 == (new \DateTime('20240701T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'long'] => 'July 1, 2024',
- $v1 === 'date' && $v2 == (new \DateTime('20240705T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'long'] => 'July 5, 2024',
- $v1 === 'date' && $v2 == (new \DateTime('20240707T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'long'] => 'July 7, 2024'
- };
- }
- );
- $this->l10n->method('t')->willReturnMap([
- ['In a %1$s on %2$s', ['day', 'July 1, 2024'], 'In a day on July 1, 2024'],
- ['In a %1$s on %2$s then on %3$s', ['day', 'July 1, 2024', 'July 5, 2024'], 'In a day on July 1, 2024 then on July 5, 2024'],
- ['In a %1$s on %2$s then on %3$s and %4$s', ['day', 'July 1, 2024', 'July 5, 2024', 'July 7, 2024'], 'In a day on July 1, 2024 then on July 5, 2024 and July 7, 2024'],
- ['In %1$s %2$s on %3$s', [2, 'days', 'July 1, 2024'], 'In 2 days on July 1, 2024'],
- ['In %1$s %2$s on %3$s then on %4$s', [2, 'days', 'July 1, 2024', 'July 5, 2024'], 'In 2 days on July 1, 2024 then on July 5, 2024'],
- ['In %1$s %2$s on %3$s then on %4$s and %5$s', [2, 'days', 'July 1, 2024', 'July 5, 2024', 'July 7, 2024'], 'In 2 days on July 1, 2024 then on July 5, 2024 and July 7, 2024'],
- ]);
- // construct time factory return(s)
- $this->timeFactory->method('getDateTime')->willReturnOnConsecutiveCalls(
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- );
- /** test patrial day recurring event in 1 day with single occurrence remaining and one exception */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=1');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240703T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a day on July 1, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 1 day with single occurrence remaining and one exception'
- );
- /** test patrial day recurring event in 1 day with two occurrences remaining and one exception */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=2');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240703T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a day on July 1, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 1 day with two occurrences remaining and one exception'
- );
- /** test patrial day recurring event in 1 day with three occurrences remaining and one exception */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=3');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240703T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a day on July 1, 2024 then on July 5, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 1 day with three occurrences remaining and one exception'
- );
- /** test patrial day recurring event in 1 day with four occurrences remaining and one exception */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=4');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240703T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a day on July 1, 2024 then on July 5, 2024 and July 7, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 1 day with four occurrences remaining and one exception'
- );
- /** test patrial day recurring event in 2 days with single occurrences remaining and one exception */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=1');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240703T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 days on July 1, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 2 days with single occurrences remaining and one exception'
- );
- /** test patrial day recurring event in 2 days with two occurrences remaining and one exception */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=2');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240703T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 days on July 1, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 2 days with two occurrences remaining and one exception'
- );
- /** test patrial day recurring event in 2 days with three occurrences remaining and one exception */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=3');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240703T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 days on July 1, 2024 then on July 5, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 2 days with three occurrences remaining and one exception'
- );
- /** test patrial day recurring event in 2 days with four occurrences remaining and one exception */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=4');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240703T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 days on July 1, 2024 then on July 5, 2024 and July 7, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 2 days with four occurrences remaining and one exception'
- );
- }
- public function testGenerateOccurringStringWithTwoExdate(): void {
-
- // construct l10n return(s)
- $this->l10n->method('l')->willReturnCallback(
- function ($v1, $v2, $v3) {
- return match (true) {
- $v1 === 'date' && $v2 == (new \DateTime('20240701T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'long'] => 'July 1, 2024',
- $v1 === 'date' && $v2 == (new \DateTime('20240705T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'long'] => 'July 5, 2024',
- $v1 === 'date' && $v2 == (new \DateTime('20240709T080000', (new \DateTimeZone('America/Toronto')))) && $v3 == ['width' => 'long'] => 'July 9, 2024'
- };
- }
- );
- $this->l10n->method('t')->willReturnMap([
- ['In a %1$s on %2$s', ['day', 'July 1, 2024'], 'In a day on July 1, 2024'],
- ['In a %1$s on %2$s then on %3$s', ['day', 'July 1, 2024', 'July 5, 2024'], 'In a day on July 1, 2024 then on July 5, 2024'],
- ['In a %1$s on %2$s then on %3$s and %4$s', ['day', 'July 1, 2024', 'July 5, 2024', 'July 9, 2024'], 'In a day on July 1, 2024 then on July 5, 2024 and July 9, 2024'],
- ['In %1$s %2$s on %3$s', [2, 'days', 'July 1, 2024'], 'In 2 days on July 1, 2024'],
- ['In %1$s %2$s on %3$s then on %4$s', [2, 'days', 'July 1, 2024', 'July 5, 2024'], 'In 2 days on July 1, 2024 then on July 5, 2024'],
- ['In %1$s %2$s on %3$s then on %4$s and %5$s', [2, 'days', 'July 1, 2024', 'July 5, 2024', 'July 9, 2024'], 'In 2 days on July 1, 2024 then on July 5, 2024 and July 9, 2024'],
- ]);
- // construct time factory return(s)
- $this->timeFactory->method('getDateTime')->willReturnOnConsecutiveCalls(
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))),
- );
- /** test patrial day recurring event in 1 day with single occurrence remaining and two exception */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=1');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240703T080000');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240707T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a day on July 1, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 1 day with single occurrence remaining and two exception'
- );
- /** test patrial day recurring event in 1 day with two occurrences remaining and two exception */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=2');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240703T080000');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240707T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a day on July 1, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 1 day with two occurrences remaining and two exception'
- );
- /** test patrial day recurring event in 1 day with three occurrences remaining and two exception */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=3');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240703T080000');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240707T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a day on July 1, 2024 then on July 5, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 1 day with three occurrences remaining and two exception'
- );
- /** test patrial day recurring event in 1 day with four occurrences remaining and two exception */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=5');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240703T080000');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240707T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In a day on July 1, 2024 then on July 5, 2024 and July 9, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 1 day with four occurrences remaining and two exception'
- );
- /** test patrial day recurring event in 2 days with single occurrences remaining and two exception */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=1');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240703T080000');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240707T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 days on July 1, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 2 days with single occurrences remaining and two exception'
- );
- /** test patrial day recurring event in 2 days with two occurrences remaining and two exception */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=2');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240703T080000');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240707T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 days on July 1, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 2 days with two occurrences remaining and two exception'
- );
- /** test patrial day recurring event in 2 days with three occurrences remaining and two exception */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=3');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240703T080000');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240707T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 days on July 1, 2024 then on July 5, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 2 days with three occurrences remaining and two exception'
- );
- /** test patrial day recurring event in 2 days with five occurrences remaining and two exception */
- $vCalendar = clone $this->vCalendar1a;
- $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=DAILY;INTERVAL=2;COUNT=5');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240703T080000');
- $vCalendar->VEVENT[0]->add('EXDATE', '20240707T080000');
- // construct event reader
- $eventReader = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue());
- // test output
- $this->assertEquals(
- 'In 2 days on July 1, 2024 then on July 5, 2024 and July 9, 2024',
- $this->service->generateOccurringString($eventReader),
- 'test patrial day recurring event in 2 days with five occurrences remaining and two exception'
- );
- }
- }
|