-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathEventsOffsetTest.php
More file actions
117 lines (94 loc) · 3.02 KB
/
EventsOffsetTest.php
File metadata and controls
117 lines (94 loc) · 3.02 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
<?php
namespace TransformStudios\Events\Tests\Feature;
use Illuminate\Support\Carbon;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades\Entry;
use TransformStudios\Events\Tags\Events;
use TransformStudios\Events\Tests\TestCase;
class EventsOffsetTest extends TestCase
{
private Events $tag;
protected function setUp(): void
{
parent::setUp();
Entry::make()
->collection('events')
->slug('recurring-event')
->id('recurring-event')
->data([
'title' => 'Recurring Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '11:00',
'end_time' => '12:00',
'recurrence' => 'weekly',
'categories' => ['one'],
])->save();
$this->tag = app(Events::class);
}
#[Test]
public function can_offset_upcoming_occurrences()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));
$this->tag
->setContext([])
->setParameters([
'collection' => 'events',
'limit' => 5,
'offset' => 2,
]);
$occurrences = $this->tag->upcoming();
$this->assertCount(3, $occurrences);
}
#[Test]
public function can_offset_between_occurrences()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));
$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'from' => Carbon::now()->toDateString(),
'to' => Carbon::now()->addWeek(3),
'offset' => 2,
]);
$occurrences = $this->tag->between();
$this->assertCount(2, $occurrences);
}
#[Test]
public function can_offset_today_occurrences()
{
Carbon::setTestNow(now()->setTimeFromTimeString('12:01'));
Entry::make()
->collection('events')
->slug('single-event')
->data([
'title' => 'Single Event',
'start_date' => Carbon::now()->toDateString(),
'start_time' => '13:00',
'end_time' => '15:00',
])->save();
$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'offset' => 1,
]);
$this->assertCount(1, $this->tag->today());
$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'ignore_finished' => true,
'offset' => 1,
]);
$this->assertCount(0, $this->tag->today());
}
#[Test]
public function can_offset_single_day_occurrences()
{
Carbon::setTestNow(now()->setTimeFromTimeString('10:00'));
$this->tag->setContext([])
->setParameters([
'collection' => 'events',
'offset' => 1,
]);
$this->assertCount(0, $this->tag->today());
}
}