-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathRecurringEventsTest.php
More file actions
executable file
·81 lines (65 loc) · 2.65 KB
/
RecurringEventsTest.php
File metadata and controls
executable file
·81 lines (65 loc) · 2.65 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
<?php
namespace TransformStudios\Events\Tests\Types;
use Carbon\Carbon;
use Statamic\Facades\Entry;
use TransformStudios\Events\EventFactory;
use TransformStudios\Events\Events;
use TransformStudios\Events\Types\RecurringEvent;
use TransformStudios\Events\Types\SingleDayEvent;
test('can create recurring event', function () {
$recurringEntry = Entry::make()
->collection('events')
->data([
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'recurrence' => 'daily',
]);
$event = EventFactory::createFromEntry($recurringEntry);
expect($event instanceof RecurringEvent)->toBeTrue();
expect($event->isRecurring())->toBeTrue();
expect($event->isMultiDay())->toBeFalse();
});
test('wont create recurring event when multi day', function () {
$recurringEntry = Entry::make()
->collection('events')
->data([
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'recurrence' => 'multi_day',
]);
$event = EventFactory::createFromEntry($recurringEntry);
expect($event instanceof SingleDayEvent)->toBeTrue();
expect($event->isRecurring())->toBeFalse();
expect($event->isMultiDay())->toBeFalse();
});
test('can show last occurrence when no end time', function () {
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));
$recurringEntry = tap(Entry::make()
->collection('events')
->data([
'start_date' => Carbon::now()->addDays(1)->toDateString(),
'start_time' => '22:00',
'recurrence' => 'daily',
'end_date' => Carbon::now()->addDays(2)->toDateString(),
'timezone' => 'America/Chicago',
]))->save();
$occurrences = Events::fromCollection(handle: 'events')
->between(Carbon::now(), Carbon::now()->addDays(5)->endOfDay());
expect($occurrences)->toHaveCount(2);
});
test('can generate monthly by day occurrences', function () {
Carbon::setTestNow(Carbon::parse('Jan 29 2025 10:00am'));
$recurringEntry = tap(Entry::make()
->collection('events')
->data([
'start_date' => Carbon::now()->addDays(1)->toDateString(),
'start_time' => '22:00',
'recurrence' => 'monthly',
'end_date' => Carbon::now()->addMonths(3)->toDateString(),
'timezone' => 'America/Chicago',
'specific_days' => ['first_sunday', 'last_wednesday'],
]))->save();
$occurrences = Events::fromCollection(handle: 'events')
->between(Carbon::now(), Carbon::now()->addMonths(4));
expect($occurrences)->toHaveCount(5);
});