76 lines
2.3 KiB
PHP
76 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Calendar;
|
|
|
|
use App\Services\Calendar\ICalendarParser;
|
|
use Illuminate\Support\Carbon;
|
|
use Tests\TestCase;
|
|
|
|
class ICalendarParserTest extends TestCase
|
|
{
|
|
public function test_it_parses_event_attendees_organizer_and_display_alarm(): void
|
|
{
|
|
Carbon::setTestNow(Carbon::parse('2026-06-12 12:00:00', 'Europe/Paris'));
|
|
|
|
$events = (new ICalendarParser)->parse(<<<'ICS'
|
|
BEGIN:VCALENDAR
|
|
VERSION:2.0
|
|
BEGIN:VEVENT
|
|
UID:event-test
|
|
SUMMARY:test
|
|
DTSTART;TZID=Europe/Paris:20260613T100000
|
|
DTEND;TZID=Europe/Paris:20260613T110000
|
|
ORGANIZER;CN=Alex Martin:mailto:alex@example.test
|
|
ATTENDEE;CN=Marie Durand:mailto:marie@example.test
|
|
BEGIN:VALARM
|
|
ACTION:DISPLAY
|
|
TRIGGER:-PT1H
|
|
DESCRIPTION:Rappel
|
|
END:VALARM
|
|
BEGIN:VALARM
|
|
ACTION:EMAIL
|
|
TRIGGER:-PT2H
|
|
DESCRIPTION:Rappel email
|
|
END:VALARM
|
|
END:VEVENT
|
|
END:VCALENDAR
|
|
ICS);
|
|
|
|
$this->assertCount(1, $events);
|
|
$this->assertSame('event-test', $events[0]->uid);
|
|
$this->assertSame('test', $events[0]->summary);
|
|
$this->assertSame([
|
|
['email' => 'alex@example.test', 'name' => 'Alex Martin'],
|
|
['email' => 'marie@example.test', 'name' => 'Marie Durand'],
|
|
], $events[0]->attendees);
|
|
$this->assertSame('DISPLAY', $events[0]->alarms[0]->action);
|
|
$this->assertSame(-60, $events[0]->alarms[0]->triggerMinutes);
|
|
$this->assertSame('EMAIL', $events[0]->alarms[1]->action);
|
|
}
|
|
|
|
public function test_it_parses_an_attendee_invited_through_a_circle(): void
|
|
{
|
|
$events = (new ICalendarParser)->parse(<<<'ICS'
|
|
BEGIN:VCALENDAR
|
|
VERSION:2.0
|
|
BEGIN:VEVENT
|
|
UID:circle-event
|
|
SUMMARY:Circle test
|
|
DTSTART;TZID=Europe/Paris:20260918T000000
|
|
DTEND;TZID=Europe/Paris:20260918T003000
|
|
ORGANIZER;CN=Camille Test:mailto:camille@example.test
|
|
ATTENDEE;CN=EquipeTest;CUTYPE=GROUP:mailto:circle+team@example.test
|
|
ATTENDEE;CN="Martin; Alex";CUTYPE=INDIVIDUAL;MEMBER="mailto:circle+team@example.test";PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.1:mailto:alex@example.test
|
|
END:VEVENT
|
|
END:VCALENDAR
|
|
ICS);
|
|
|
|
$this->assertCount(1, $events);
|
|
$this->assertSame([
|
|
['email' => 'camille@example.test', 'name' => 'Camille Test'],
|
|
['email' => 'circle+team@example.test', 'name' => 'EquipeTest'],
|
|
['email' => 'alex@example.test', 'name' => 'Martin; Alex'],
|
|
], $events[0]->attendees);
|
|
}
|
|
}
|