|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace TransformStudios\Events\Tests; |
| 4 | + |
| 5 | +use Carbon\CarbonImmutable; |
| 6 | +use Illuminate\Support\Carbon; |
| 7 | +use Statamic\Facades\Entry; |
| 8 | +use Statamic\Facades\Site; |
| 9 | +use TransformStudios\Events\Events; |
| 10 | + |
| 11 | +beforeEach(function () { |
| 12 | + Site::setSites([ |
| 13 | + 'default' => ['name' => 'English', 'locale' => 'en_US', 'url' => '/'], |
| 14 | + 'ar' => ['name' => 'Arabic', 'locale' => 'ar', 'url' => '/ar/'], |
| 15 | + ]); |
| 16 | + |
| 17 | + $this->collection->sites(['default', 'ar'])->save(); |
| 18 | + |
| 19 | + Carbon::setTestNow('2026-08-15 10:00:00'); |
| 20 | +}); |
| 21 | + |
| 22 | +test('includes localized events that inherit start_date from the origin', function () { |
| 23 | + $origin = Entry::make() |
| 24 | + ->collection('events') |
| 25 | + ->locale('default') |
| 26 | + ->slug('art-collective') |
| 27 | + ->data([ |
| 28 | + 'title' => 'Collective Art Activities', |
| 29 | + 'start_date' => '2026-08-31', |
| 30 | + 'start_time' => '14:00', |
| 31 | + 'end_time' => '16:00', |
| 32 | + 'timezone' => 'America/Los_Angeles', |
| 33 | + ]); |
| 34 | + $origin->save(); |
| 35 | + |
| 36 | + $localized = $origin->makeLocalization('ar'); |
| 37 | + $localized->set('title', 'أنشطة فنية جماعية'); |
| 38 | + $localized->save(); |
| 39 | + |
| 40 | + expect($localized->has('start_date'))->toBeFalse() |
| 41 | + ->and($localized->get('start_date'))->toBeNull() |
| 42 | + ->and($localized->value('start_date'))->toBe('2026-08-31'); |
| 43 | + |
| 44 | + Site::setCurrent('ar'); |
| 45 | + |
| 46 | + $occurrences = Events::fromCollection('events') |
| 47 | + ->site('ar') |
| 48 | + ->between( |
| 49 | + CarbonImmutable::parse('2026-08-01')->startOfDay(), |
| 50 | + CarbonImmutable::parse('2026-08-31')->endOfDay() |
| 51 | + ); |
| 52 | + |
| 53 | + expect($occurrences)->toHaveCount(1) |
| 54 | + ->and($occurrences->first()->title)->toBe('أنشطة فنية جماعية') |
| 55 | + ->and($occurrences->first()->start->toDateString())->toBe('2026-08-31'); |
| 56 | +}); |
| 57 | + |
| 58 | +test('still drops localized events whose origin start date is in the past', function () { |
| 59 | + $origin = Entry::make() |
| 60 | + ->collection('events') |
| 61 | + ->locale('default') |
| 62 | + ->slug('past-event') |
| 63 | + ->data([ |
| 64 | + 'title' => 'Past Event', |
| 65 | + 'start_date' => '2026-07-01', |
| 66 | + 'start_time' => '14:00', |
| 67 | + ]); |
| 68 | + $origin->save(); |
| 69 | + |
| 70 | + $localized = $origin->makeLocalization('ar'); |
| 71 | + $localized->set('title', 'حدث سابق'); |
| 72 | + $localized->save(); |
| 73 | + |
| 74 | + Site::setCurrent('ar'); |
| 75 | + |
| 76 | + expect( |
| 77 | + Events::fromCollection('events')->site('ar')->upcoming(1) |
| 78 | + )->toBeEmpty(); |
| 79 | +}); |
0 commit comments