diff options
author | SebastianKrupinski <krupinskis05@gmail.com> | 2024-10-21 14:08:43 -0400 |
---|---|---|
committer | SebastianKrupinski <krupinskis05@gmail.com> | 2024-10-21 14:08:43 -0400 |
commit | de22119775cd01ebf39df5afdb48d97fd5b8945a (patch) | |
tree | 40d823c6b96bcfb7782dfb8440dacd42602ce187 /apps/dav/tests/unit | |
parent | 4d8d11d2f79da348644e0902e78a2f000498cd52 (diff) | |
download | nextcloud-server-fix/issue-48732-exdate-rdate-property-instances.tar.gz nextcloud-server-fix/issue-48732-exdate-rdate-property-instances.zip |
fix: RDATE and EXDATE property instancesfix/issue-48732-exdate-rdate-property-instances
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
Diffstat (limited to 'apps/dav/tests/unit')
-rw-r--r-- | apps/dav/tests/unit/CalDAV/EventReaderTest.php | 27 | ||||
-rw-r--r-- | apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php | 427 |
2 files changed, 447 insertions, 7 deletions
diff --git a/apps/dav/tests/unit/CalDAV/EventReaderTest.php b/apps/dav/tests/unit/CalDAV/EventReaderTest.php index 3c94147efb4..74cc22dff75 100644 --- a/apps/dav/tests/unit/CalDAV/EventReaderTest.php +++ b/apps/dav/tests/unit/CalDAV/EventReaderTest.php @@ -533,6 +533,15 @@ class EventReaderTest extends TestCase { // test set by constructor $this->assertTrue($er->recurringConcludes()); + /** test rdate (multiple property instances) recurrance */ + $vCalendar = clone $this->vCalendar1a; + $vCalendar->VEVENT[0]->add('RDATE', '20240703'); + $vCalendar->VEVENT[0]->add('RDATE', '20240705'); + // construct event reader + $er = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue()); + // test set by constructor + $this->assertTrue($er->recurringConcludes()); + /** test rrule and rdate recurrance with rdate as last date */ $vCalendar = clone $this->vCalendar1a; $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=WEEKLY;COUNT=6;BYDAY=MO,WE,FR'); @@ -578,6 +587,15 @@ class EventReaderTest extends TestCase { // test set by constructor $this->assertEquals(2, $er->recurringConcludesAfter()); + /** test rdate (multiple property instances) recurrance */ + $vCalendar = clone $this->vCalendar1a; + $vCalendar->VEVENT[0]->add('RDATE', '20240703'); + $vCalendar->VEVENT[0]->add('RDATE', '20240705'); + // construct event reader + $er = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue()); + // test set by constructor + $this->assertEquals(2, $er->recurringConcludesAfter()); + /** test rrule and rdate recurrance */ $vCalendar = clone $this->vCalendar1a; $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=WEEKLY;COUNT=6;BYDAY=MO,WE,FR'); @@ -624,6 +642,15 @@ class EventReaderTest extends TestCase { // test set by constructor $this->assertEquals((new \DateTime('20240705T000000', (new DateTimeZone('America/Toronto')))), $er->recurringConcludesOn()); + /** test rdate (multiple property instances) recurrance */ + $vCalendar = clone $this->vCalendar1a; + $vCalendar->VEVENT[0]->add('RDATE', '20240703'); + $vCalendar->VEVENT[0]->add('RDATE', '20240705'); + // construct event reader + $er = new EventReader($vCalendar, $vCalendar->VEVENT[0]->UID->getValue()); + // test set by constructor + $this->assertEquals((new \DateTime('20240705T000000', (new DateTimeZone('America/Toronto')))), $er->recurringConcludesOn()); + /** test rrule and rdate recurrance with rdate as last date */ $vCalendar = clone $this->vCalendar1a; $vCalendar->VEVENT[0]->add('RRULE', 'FREQ=WEEKLY;COUNT=6;BYDAY=MO,WE,FR'); diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php index ef5a0b17c6e..f1c003625b2 100644 --- a/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php +++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php @@ -1248,7 +1248,7 @@ class IMipServiceTest extends TestCase { } - public function testGenerateOccurringString(): void { + public function testGenerateOccurringStringWithRrule(): void { // construct l10n return(s) $this->l10n->method('l')->willReturnCallback( @@ -1285,7 +1285,7 @@ class IMipServiceTest extends TestCase { (new \DateTime('20240628T170000', (new \DateTimeZone('America/Toronto')))), ); - /** test patrial day recurring event in 1 day with single occurance remaining */ + /** 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 @@ -1296,7 +1296,7 @@ class IMipServiceTest extends TestCase { $this->service->generateOccurringString($eventReader) ); - /** test patrial day recurring event in 1 day with two occurances remaining */ + /** 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 @@ -1307,7 +1307,7 @@ class IMipServiceTest extends TestCase { $this->service->generateOccurringString($eventReader) ); - /** test patrial day recurring event in 1 day with three occurances remaining */ + /** 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 @@ -1318,7 +1318,7 @@ class IMipServiceTest extends TestCase { $this->service->generateOccurringString($eventReader) ); - /** test patrial day recurring event in 2 days with single occurance remaining */ + /** 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 @@ -1329,7 +1329,7 @@ class IMipServiceTest extends TestCase { $this->service->generateOccurringString($eventReader) ); - /** test patrial day recurring event in 2 days with two occurances remaining */ + /** 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 @@ -1340,7 +1340,7 @@ class IMipServiceTest extends TestCase { $this->service->generateOccurringString($eventReader) ); - /** test patrial day recurring event in 2 days with three occurances remaining */ + /** 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 @@ -1352,4 +1352,417 @@ class IMipServiceTest extends TestCase { ); } + 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' + ); + } + } |