-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSingleDayEventsTest.php
More file actions
executable file
·146 lines (113 loc) · 4.48 KB
/
SingleDayEventsTest.php
File metadata and controls
executable file
·146 lines (113 loc) · 4.48 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
<?php
namespace TransformStudios\Events\Tests\Types;
use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Carbon\CarbonTimeZone;
use Statamic\Facades\Entry;
use TransformStudios\Events\EventFactory;
use TransformStudios\Events\Types\SingleDayEvent;
test('can create single event', function () {
$entry = Entry::make()
->collection('events')
->data([
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
'timezone' => 'America/Vancouver',
]);
$event = EventFactory::createFromEntry($entry);
expect($event instanceof SingleDayEvent)->toBeTrue();
expect($event->isRecurring())->toBeFalse();
expect($event->isMultiDay())->toBeFalse();
expect($event->hasEndTime())->toBeTrue();
expect($event->start()->timezone)->toEqual(new CarbonTimeZone('America/Vancouver'));
expect($event->end()->timezone)->toEqual(new CarbonTimeZone('America/Vancouver'));
});
test('can create single all day event', function () {
$entry = Entry::make()
->collection('events')
->data([
'start_date' => Carbon::now()->toDateString(),
'all_day' => true,
]);
$event = EventFactory::createFromEntry($entry);
expect($event instanceof SingleDayEvent)->toBeTrue();
expect($event->isAllDay())->toBeTrue();
});
test('end is end of day when no end time', function () {
Carbon::setTestNow(now());
$entry = Entry::make()
->collection('events')
->data([
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
]);
$event = EventFactory::createFromEntry($entry);
expect($event->endTime())->toEqual('23:59:59');
$nextOccurrences = $event->nextOccurrences();
expect($nextOccurrences[0]->has_end_time)->toBeFalse();
expect($nextOccurrences[0]->end)->toEqual(now()->endOfDay()->setMicrosecond(0));
});
test('empty occurrences if now after end date', function () {
$recurringEntry = Entry::make()
->collection('events')
->data([
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
]);
$event = EventFactory::createFromEntry($recurringEntry);
Carbon::setTestNow(now()->addDays(1));
$nextOccurrences = $event->nextOccurrences();
expect($nextOccurrences)->toBeEmpty();
});
test('can generate next day if now is before', function () {
$startDate = CarbonImmutable::now()->setTimeFromTimeString('11:00');
$recurringEntry = Entry::make()
->collection('events')
->data([
'start_date' => $startDate->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
]);
$event = EventFactory::createFromEntry($recurringEntry);
Carbon::setTestNow($startDate->setTimeFromTimeString('10:59:00'));
$nextOccurrences = $event->nextOccurrences(2);
expect($nextOccurrences)->toHaveCount(1);
expect($nextOccurrences->first()->start)->toEqual($startDate);
});
test('can generate next occurrence if now is during', function () {
$startDate = CarbonImmutable::now()->setTimeFromTimeString('11:00');
$single = Entry::make()
->collection('events')
->data([
'start_date' => $startDate->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
]);
$singleNoEndTime = Entry::make()
->collection('events')
->data([
'start_date' => $startDate->toDateString(),
'start_time' => '11:00',
]);
Carbon::setTestNow($startDate->addMinutes(10));
$event = EventFactory::createFromEntry($single);
$noEndTimeEvent = EventFactory::createFromEntry($singleNoEndTime);
$nextOccurrences = $event->nextOccurrences();
expect($nextOccurrences[0]->start)->toEqual($startDate);
expect($noEndTimeEvent->nextOccurrences()[0]->start)->toEqual($startDate);
});
test('can supplement no end time', function () {
$startDate = CarbonImmutable::now()->setTimeFromTimeString('11:00');
$noEndTimeEntry = Entry::make()
->collection('events')
->data([
'start_date' => $startDate->toDateString(),
'start_time' => '11:00',
]);
Carbon::setTestNow($startDate->addMinutes(10));
$event = EventFactory::createFromEntry($noEndTimeEntry);
$nextOccurrences = $event->nextOccurrences();
expect($nextOccurrences[0]->has_end_time)->toBeFalse();
});