|
1 | 1 | <?php |
2 | 2 |
|
3 | | -namespace TransformStudios\Events\Tests\Feature; |
4 | | - |
5 | 3 | use Illuminate\Support\Carbon; |
6 | | -use PHPUnit\Framework\Attributes\Test; |
7 | 4 | use Statamic\Facades\Entry; |
8 | 5 | use TransformStudios\Events\Tags\Events; |
9 | | -use TransformStudios\Events\Tests\TestCase; |
10 | | - |
11 | | -class EventsOffsetTest extends TestCase |
12 | | -{ |
13 | | - private Events $tag; |
14 | | - |
15 | | - protected function setUp(): void |
16 | | - { |
17 | | - parent::setUp(); |
18 | | - |
19 | | - Entry::make() |
20 | | - ->collection('events') |
21 | | - ->slug('recurring-event') |
22 | | - ->id('recurring-event') |
23 | | - ->data([ |
24 | | - 'title' => 'Recurring Event', |
25 | | - 'start_date' => Carbon::now()->toDateString(), |
26 | | - 'start_time' => '11:00', |
27 | | - 'end_time' => '12:00', |
28 | | - 'recurrence' => 'weekly', |
29 | | - 'categories' => ['one'], |
30 | | - ])->save(); |
31 | | - |
32 | | - $this->tag = app(Events::class); |
33 | | - } |
34 | | - |
35 | | - #[Test] |
36 | | - public function can_offset_upcoming_occurrences() |
37 | | - { |
38 | | - Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); |
39 | | - |
40 | | - $this->tag |
41 | | - ->setContext([]) |
42 | | - ->setParameters([ |
43 | | - 'collection' => 'events', |
44 | | - 'limit' => 5, |
45 | | - 'offset' => 2, |
46 | | - ]); |
47 | | - |
48 | | - $occurrences = $this->tag->upcoming(); |
49 | | - |
50 | | - $this->assertCount(3, $occurrences); |
51 | | - } |
52 | | - |
53 | | - #[Test] |
54 | | - public function can_offset_between_occurrences() |
55 | | - { |
56 | | - Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); |
57 | | - |
58 | | - $this->tag->setContext([]) |
59 | | - ->setParameters([ |
60 | | - 'collection' => 'events', |
61 | | - 'from' => Carbon::now()->toDateString(), |
62 | | - 'to' => Carbon::now()->addWeek(3), |
63 | | - 'offset' => 2, |
64 | | - ]); |
65 | | - |
66 | | - $occurrences = $this->tag->between(); |
67 | | - |
68 | | - $this->assertCount(2, $occurrences); |
69 | | - } |
70 | | - |
71 | | - #[Test] |
72 | | - public function can_offset_today_occurrences() |
73 | | - { |
74 | | - Carbon::setTestNow(now()->setTimeFromTimeString('12:01')); |
75 | | - |
76 | | - Entry::make() |
77 | | - ->collection('events') |
78 | | - ->slug('single-event') |
79 | | - ->data([ |
80 | | - 'title' => 'Single Event', |
81 | | - 'start_date' => Carbon::now()->toDateString(), |
82 | | - 'start_time' => '13:00', |
83 | | - 'end_time' => '15:00', |
84 | | - ])->save(); |
85 | | - |
86 | | - $this->tag->setContext([]) |
87 | | - ->setParameters([ |
88 | | - 'collection' => 'events', |
89 | | - 'offset' => 1, |
90 | | - ]); |
91 | | - |
92 | | - $this->assertCount(1, $this->tag->today()); |
93 | | - |
94 | | - $this->tag->setContext([]) |
95 | | - ->setParameters([ |
96 | | - 'collection' => 'events', |
97 | | - 'ignore_finished' => true, |
98 | | - 'offset' => 1, |
99 | | - ]); |
100 | | - |
101 | | - $this->assertCount(0, $this->tag->today()); |
102 | | - } |
103 | | - |
104 | | - #[Test] |
105 | | - public function can_offset_single_day_occurrences() |
106 | | - { |
107 | | - Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); |
108 | | - |
109 | | - $this->tag->setContext([]) |
110 | | - ->setParameters([ |
111 | | - 'collection' => 'events', |
112 | | - 'offset' => 1, |
113 | | - ]); |
114 | | - |
115 | | - $this->assertCount(0, $this->tag->today()); |
116 | | - } |
117 | | -} |
| 6 | + |
| 7 | +beforeEach(function () { |
| 8 | + Entry::make() |
| 9 | + ->collection('events') |
| 10 | + ->slug('recurring-event') |
| 11 | + ->id('recurring-event') |
| 12 | + ->data([ |
| 13 | + 'title' => 'Recurring Event', |
| 14 | + 'start_date' => Carbon::now()->toDateString(), |
| 15 | + 'start_time' => '11:00', |
| 16 | + 'end_time' => '12:00', |
| 17 | + 'recurrence' => 'weekly', |
| 18 | + 'categories' => ['one'], |
| 19 | + ])->save(); |
| 20 | + |
| 21 | + $this->tag = app(Events::class); |
| 22 | +}); |
| 23 | + |
| 24 | +test('can offset upcoming occurrences', function () { |
| 25 | + Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); |
| 26 | + |
| 27 | + $this->tag |
| 28 | + ->setContext([]) |
| 29 | + ->setParameters([ |
| 30 | + 'collection' => 'events', |
| 31 | + 'limit' => 5, |
| 32 | + 'offset' => 2, |
| 33 | + ]); |
| 34 | + |
| 35 | + $occurrences = $this->tag->upcoming(); |
| 36 | + |
| 37 | + expect($occurrences)->toHaveCount(3); |
| 38 | +}); |
| 39 | + |
| 40 | +test('can offset between occurrences', function () { |
| 41 | + Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); |
| 42 | + |
| 43 | + $this->tag->setContext([]) |
| 44 | + ->setParameters([ |
| 45 | + 'collection' => 'events', |
| 46 | + 'from' => Carbon::now()->toDateString(), |
| 47 | + 'to' => Carbon::now()->addWeek(3), |
| 48 | + 'offset' => 2, |
| 49 | + ]); |
| 50 | + |
| 51 | + $occurrences = $this->tag->between(); |
| 52 | + |
| 53 | + expect($occurrences)->toHaveCount(2); |
| 54 | +}); |
| 55 | + |
| 56 | +test('can offset today occurrences', function () { |
| 57 | + Carbon::setTestNow(now()->setTimeFromTimeString('12:01')); |
| 58 | + |
| 59 | + Entry::make() |
| 60 | + ->collection('events') |
| 61 | + ->slug('single-event') |
| 62 | + ->data([ |
| 63 | + 'title' => 'Single Event', |
| 64 | + 'start_date' => Carbon::now()->toDateString(), |
| 65 | + 'start_time' => '13:00', |
| 66 | + 'end_time' => '15:00', |
| 67 | + ])->save(); |
| 68 | + |
| 69 | + $this->tag->setContext([]) |
| 70 | + ->setParameters([ |
| 71 | + 'collection' => 'events', |
| 72 | + 'offset' => 1, |
| 73 | + ]); |
| 74 | + |
| 75 | + expect($this->tag->today())->toHaveCount(1); |
| 76 | + |
| 77 | + $this->tag->setContext([]) |
| 78 | + ->setParameters([ |
| 79 | + 'collection' => 'events', |
| 80 | + 'ignore_finished' => true, |
| 81 | + 'offset' => 1, |
| 82 | + ]); |
| 83 | + |
| 84 | + expect($this->tag->today())->toHaveCount(0); |
| 85 | +}); |
| 86 | + |
| 87 | +test('can offset single day occurrences', function () { |
| 88 | + Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); |
| 89 | + |
| 90 | + $this->tag->setContext([]) |
| 91 | + ->setParameters([ |
| 92 | + 'collection' => 'events', |
| 93 | + 'offset' => 1, |
| 94 | + ]); |
| 95 | + |
| 96 | + expect($this->tag->today())->toHaveCount(0); |
| 97 | +}); |
0 commit comments