|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +namespace TransformStudios\Events\Tests\Tags; |
| 4 | + |
3 | 5 | use Illuminate\Support\Carbon; |
4 | 6 | use Statamic\Facades\Cascade; |
5 | 7 | use Statamic\Facades\Entry; |
|
311 | 313 | expect($occurrences[0]->start->isAfter($occurrences[1]->start))->toBeTrue(); |
312 | 314 | expect($occurrences[1]->start->isAfter($occurrences[2]->start))->toBeTrue(); |
313 | 315 | }); |
| 316 | +test('can offset upcoming occurrences', function () { |
| 317 | + Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); |
| 318 | + |
| 319 | + $this->tag |
| 320 | + ->setContext([]) |
| 321 | + ->setParameters([ |
| 322 | + 'collection' => 'events', |
| 323 | + 'limit' => 5, |
| 324 | + 'offset' => 2, |
| 325 | + ]); |
| 326 | + |
| 327 | + $occurrences = $this->tag->upcoming(); |
| 328 | + |
| 329 | + expect($occurrences)->toHaveCount(3); |
| 330 | +}); |
| 331 | + |
| 332 | +test('can offset between occurrences', function () { |
| 333 | + Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); |
| 334 | + |
| 335 | + $this->tag->setContext([]) |
| 336 | + ->setParameters([ |
| 337 | + 'collection' => 'events', |
| 338 | + 'from' => Carbon::now()->toDateString(), |
| 339 | + 'to' => Carbon::now()->addWeek(3), |
| 340 | + 'offset' => 2, |
| 341 | + ]); |
| 342 | + |
| 343 | + $occurrences = $this->tag->between(); |
| 344 | + |
| 345 | + expect($occurrences)->toHaveCount(2); |
| 346 | +}); |
| 347 | + |
| 348 | +test('can offset today occurrences', function () { |
| 349 | + Carbon::setTestNow(now()->setTimeFromTimeString('12:01')); |
| 350 | + |
| 351 | + Entry::make() |
| 352 | + ->collection('events') |
| 353 | + ->slug('single-event') |
| 354 | + ->data([ |
| 355 | + 'title' => 'Single Event', |
| 356 | + 'start_date' => Carbon::now()->toDateString(), |
| 357 | + 'start_time' => '13:00', |
| 358 | + 'end_time' => '15:00', |
| 359 | + ])->save(); |
| 360 | + |
| 361 | + $this->tag->setContext([]) |
| 362 | + ->setParameters([ |
| 363 | + 'collection' => 'events', |
| 364 | + 'offset' => 1, |
| 365 | + ]); |
| 366 | + |
| 367 | + expect($this->tag->today())->toHaveCount(1); |
| 368 | + |
| 369 | + $this->tag->setContext([]) |
| 370 | + ->setParameters([ |
| 371 | + 'collection' => 'events', |
| 372 | + 'ignore_finished' => true, |
| 373 | + 'offset' => 1, |
| 374 | + ]); |
| 375 | + |
| 376 | + expect($this->tag->today())->toHaveCount(0); |
| 377 | +}); |
| 378 | + |
| 379 | +test('can offset single day occurrences', function () { |
| 380 | + Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); |
| 381 | + |
| 382 | + $this->tag->setContext([]) |
| 383 | + ->setParameters([ |
| 384 | + 'collection' => 'events', |
| 385 | + 'offset' => 1, |
| 386 | + ]); |
| 387 | + |
| 388 | + expect($this->tag->today())->toHaveCount(0); |
| 389 | +}); |
0 commit comments