Skip to content

Commit f482354

Browse files
committed
tests
1 parent f6073b7 commit f482354

3 files changed

Lines changed: 50 additions & 11 deletions

File tree

src/Types/Event.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,25 @@ public function toICalendarEvent(string|CarbonInterface $date): ?ICalendarEvent
103103

104104
$immutableDate = $this->toCarbonImmutable($date);
105105

106-
return ICalendarEvent::create($this->event->title)
106+
$iCalEvent = ICalendarEvent::create($this->event->title)
107107
->withoutTimezone()
108108
->uniqueIdentifier($this->event->id())
109109
->startsAt($immutableDate->setTimeFromTimeString($this->startTime()))
110-
->endsAt($immutableDate->setTimeFromTimeString($this->endTime()))
111-
->address($this->location($this->event))
112-
->description($this->event->description)
113-
->url($this->event->link);
110+
->endsAt($immutableDate->setTimeFromTimeString($this->endTime()));
111+
112+
if (!is_null($location = $this->location($this->event))) {
113+
$iCalEvent->address($location);
114+
}
115+
116+
if (!is_null($description = $this->event->description)) {
117+
$iCalEvent->description($description);
118+
}
119+
120+
if (!is_null($link = $this->event->link)) {
121+
$iCalEvent->url($link);
122+
}
123+
124+
return $iCalEvent;
114125
}
115126

116127
/**

src/Types/MultiDayEvent.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,24 @@ public function toICalendarEvent(string|CarbonInterface $date): ?ICalendarEvent
5959
$immutableDate = $this->toCarbonImmutable($date);
6060
$day = $this->getDayFromDate($immutableDate);
6161

62-
return ICalendarEvent::create($this->event->title)
62+
$iCalEvent = ICalendarEvent::create($this->event->title)
6363
->uniqueIdentifier($this->event->id())
6464
->startsAt($immutableDate->setTimeFromTimeString($day->start()))
65-
->endsAt($immutableDate->setTimeFromTimeString($day->end()))
66-
->address($this->location($this->event))
67-
->description($this->event->description)
68-
->url($this->event->link);
65+
->endsAt($immutableDate->setTimeFromTimeString($day->end()));
66+
67+
if (! is_null($location = $this->location($this->event))) {
68+
$iCalEvent->address($location);
69+
}
70+
71+
if (! is_null($description = $this->event->description)) {
72+
$iCalEvent->description($description);
73+
}
74+
75+
if (! is_null($link = $this->event->link)) {
76+
$iCalEvent->url($link);
77+
}
78+
79+
return $iCalEvent;
6980
}
7081

7182
/**

tests/Feature/IcsControllerTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ protected function setUp(): void
2323
'start_time' => '11:00',
2424
'end_time' => '12:00',
2525
'location' => 'The Location',
26+
'description' => 'The description',
27+
'link' => 'https://transformstudios.com'
2628
])->save();
2729
}
2830

@@ -38,6 +40,8 @@ public function can_create_single_day_event_ics_file()
3840

3941
$this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent());
4042
$this->assertStringContainsString('LOCATION:The Location', $response->streamedContent());
43+
$this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent());
44+
$this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent());
4145
}
4246

4347
#[Test]
@@ -55,6 +59,9 @@ public function can_create_single_day_recurring_event_ics_file()
5559
'start_time' => '11:00',
5660
'end_time' => '12:00',
5761
'recurrence' => 'weekly',
62+
'location' => 'The Location',
63+
'description' => 'The description',
64+
'link' => 'https://transformstudios.com'
5865
])->save();
5966

6067
$response = $this->get(route('statamic.events.ics.show', [
@@ -63,6 +70,9 @@ public function can_create_single_day_recurring_event_ics_file()
6370
]))->assertDownload('recurring-event.ics');
6471

6572
$this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent());
73+
$this->assertStringContainsString('LOCATION:The Location', $response->streamedContent());
74+
$this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent());
75+
$this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent());
6676

6777
$this->get(route('statamic.events.ics.show', [
6878
'date' => now()->addDay()->toDateString(),
@@ -75,13 +85,16 @@ public function can_create_single_day_multiday_event_ics_file()
7585
{
7686
Carbon::setTestNow(now());
7787

78-
$entry = Entry::make()
88+
Entry::make()
7989
->slug('multi-day-event')
8090
->collection('events')
8191
->id('the-multi-day-event')
8292
->data([
8393
'title' => 'Multi-day Event',
8494
'multi_day' => true,
95+
'location' => 'The Location',
96+
'description' => 'The description',
97+
'link' => 'https://transformstudios.com',
8598
'days' => [
8699
[
87100
'date' => now()->toDateString(),
@@ -112,6 +125,10 @@ public function can_create_single_day_multiday_event_ics_file()
112125
]))->assertDownload('multi-day-event.ics');
113126

114127
$this->assertStringContainsString('DTSTART:'.now()->addDay()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent());
128+
$this->assertStringContainsString('LOCATION:The Location', $response->streamedContent());
129+
$this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent());
130+
$this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent());
131+
115132
}
116133

117134
#[Test]

0 commit comments

Comments
 (0)