-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathIcsControllerTest.php
More file actions
executable file
·214 lines (183 loc) · 7.94 KB
/
IcsControllerTest.php
File metadata and controls
executable file
·214 lines (183 loc) · 7.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
namespace TransformStudios\Events\Tests\Feature;
use Illuminate\Support\Carbon;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades\Entry;
use TransformStudios\Events\Tests\TestCase;
class IcsControllerTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
Entry::make()
->collection('events')
->slug('single-event')
->id('the-id')
->data([
'title' => 'Single Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
'address' => '123 Main St',
'location' => 'The Location',
'coordinates' => [
'latitude' => 40,
'longitude' => 50,
],
'description' => 'The description',
])->save();
}
#[Test]
public function can_create_single_day_event_ics_file()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));
$response = $this->get(route('statamic.events.ics.show', [
'date' => now()->toDateString(),
'event' => 'the-id',
]))->assertDownload('single-event.ics');
$content = $response->streamedContent();
$this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent());
$this->assertStringContainsString('LOCATION:123 Main St', $content);
$this->assertStringContainsString('DESCRIPTION:The description', $content);
$this->assertStringContainsString('GEO:40;50', $content);
}
#[Test]
public function can_create_single_day_recurring_event_ics_file()
{
Carbon::setTestNow(now()->addDay()->setTimeFromTimeString('10:00'));
Entry::make()
->collection('events')
->slug('recurring-event')
->id('the-recurring-id')
->data([
'title' => 'Recurring Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
'recurrence' => 'weekly',
'location' => 'The Location',
'description' => 'The description',
])->save();
$response = $this->get(route('statamic.events.ics.show', [
'date' => now()->toDateString(),
'event' => 'the-recurring-id',
]))->assertDownload('recurring-event.ics');
$this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent());
$this->assertStringContainsString('LOCATION:The Location', $response->streamedContent());
$this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent());
$this->get(route('statamic.events.ics.show', [
'date' => now()->addDay()->toDateString(),
'event' => 'the-recurring-id',
]))->assertStatus(404);
}
#[Test]
public function can_create_ics_with_single_date_recurrence()
{
Carbon::setTestNow(now()->addDay()->setTimeFromTimeString('10:00'));
Entry::make()
->collection('events')
->slug('recurring-event')
->id('the-recurring-id')
->data([
'title' => 'Recurring Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
'recurrence' => 'weekly',
'location' => 'The Location',
'description' => 'The description',
])->save();
$response = $this->get(route('statamic.events.ics.show', [
'date' => now()->toDateString(),
'event' => 'the-recurring-id',
]))->assertDownload('recurring-event.ics');
$this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent());
$this->assertStringContainsString('LOCATION:The Location', $response->streamedContent());
$this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent());
}
#[Test]
public function can_create_ics_with_recurrence()
{
Carbon::setTestNow(now()->addDay()->setTimeFromTimeString('10:00'));
Entry::make()
->collection('events')
->slug('recurring-event')
->id('the-recurring-id')
->data([
'title' => 'Recurring Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
'recurrence' => 'weekly',
'location' => 'The Location',
'description' => 'The description',
])->save();
$response = $this->get(route('statamic.events.ics.show', [
'event' => 'the-recurring-id',
]))->assertDownload('recurring-event.ics');
$this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent());
$this->assertStringContainsString('LOCATION:The Location', $response->streamedContent());
$this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent());
}
#[Test]
public function can_create_single_day_multiday_event_ics_file()
{
Carbon::setTestNow(now());
Entry::make()
->slug('multi-day-event')
->collection('events')
->id('the-multi-day-event')
->data([
'title' => 'Multi-day Event',
'multi_day' => true,
'location' => 'The Location',
'description' => 'The description',
'days' => [
[
'date' => now()->toDateString(),
'start_time' => '19:00',
'end_time' => '21:00',
],
[
'date' => now()->addDay()->toDateString(),
'start_time' => '11:00',
'end_time' => '15:00',
],
[
'date' => now()->addDays(2)->toDateString(),
'start_time' => '11:00',
'end_time' => '15:00',
],
],
])->save();
$this->get(route('statamic.events.ics.show', [
'date' => now()->addDays(3)->toDateString(),
'event' => 'the-multi-day-event',
]))->assertStatus(404);
$response = $this->get(route('statamic.events.ics.show', [
'date' => now()->addDay()->toDateString(),
'event' => 'the-multi-day-event',
]))->assertDownload('multi-day-event.ics');
$this->assertStringContainsString('DTSTART:'.now()->addDay()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent());
$this->assertStringContainsString('LOCATION:The Location', $response->streamedContent());
$this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent());
}
#[Test]
public function throws404_error_when_event_does_not_occur_on_date()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));
$this->get(route('statamic.events.ics.show', [
'date' => now()->addDay()->toDateString(),
'event' => 'the-id',
]))->assertStatus(404);
}
#[Test]
public function throws404_error_when_event_does_not_exist()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));
$this->get(route('statamic.events.ics.show', [
'date' => now()->addDay()->toDateString(),
'event' => 'does-not-exist',
]))->assertStatus(404);
}
}