Saisonfotos am Foto statt am Erscheinungsbild

Ein Foto gehoert zu keinem (ganzjaehrig) oder mehreren Erscheinungsbildern und
erscheint nur dort, vor den ganzjaehrigen Fotos. Bausteine waehlen "automatisch"
oder eine eigene Auswahl; Titelbereich und Abschluss zeigen das erste passende
Foto ihrer Liste. Titelbild und "Bilder je Baustein" des Erscheinungsbilds werden
in die Bausteine uebernommen und entfallen dort.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-10-29 18:53:56 +01:00
1 parent d02f3e05c7
commit 791786ed3e
21 files changed
+449 -235

No files matched your search

+73 -22
View File
@@ -6,9 +6,10 @@
use App\Enums\UserRole;
use App\Filament\Resources\Appearances\AppearanceResource;
use App\Filament\Resources\Appearances\Pages\CreateAppearance;
use App\Filament\Resources\Appearances\Pages\EditAppearance;
use App\Filament\Resources\Pages\PageResource;
use App\Filament\Resources\Pages\Pages\EditPage;
use App\Filament\Resources\Photos\Pages\EditPhoto;
use App\Filament\Resources\Photos\Pages\ListPhotos;
use App\Filament\Resources\Sites\SiteResource;
use App\Models\Appearance;
use App\Models\Page;
@@ -27,6 +28,7 @@
use Database\Seeders\WebsiteContentSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\URL;
use Livewire\Livewire;
@@ -239,43 +241,92 @@ public function test_section_can_be_limited_to_an_appearance(): void
$this->get('/')->assertOk()->assertSee('Adventsmarkt am Hafen');
}
public function test_appearance_sets_seasonal_photos_per_section(): void
public function test_seasonal_photos_appear_only_in_their_appearances_and_come_first(): void
{
Storage::fake('public');
$summerPhoto = Photo::factory()->create(['alt_text' => 'Strand im Sommer', 'sort_order' => 1]);
$summerPhoto->addMedia(UploadedFile::fake()->image('sommer.jpg', 1600, 1000))->toMediaCollection(Photo::COLLECTION);
$winterPhoto = Photo::factory()->create(['alt_text' => 'Raue See im Winter', 'sort_order' => 99]);
$winterPhoto->addMedia(UploadedFile::fake()->image('winter.jpg', 1600, 1000))->toMediaCollection(Photo::COLLECTION);
$page = $this->site->pages()->where('slug', 'start')->sole();
$cta = collect($page->sections)->firstWhere('type', 'cta');
$winter = $this->site->appearances()->where('name', 'Winter')->sole();
$winter->update(['section_photos' => [$cta['data']['id'] => ['photo_id' => $winterPhoto->id]]]);
$christmas = $this->site->appearances()->where('name', 'Weihnachten')->sole();
$allYear = $this->photoWithFile(['alt_text' => 'Garten im Licht', 'sort_order' => 1]);
$snow = $this->photoWithFile(['alt_text' => 'Raue See im Winter', 'sort_order' => 99, 'appearance_ids' => [$winter->id, $christmas->id]]);
$page = $this->site->pages()->where('slug', 'start')->sole();
$page->update(['sections' => collect($page->sections)->map(fn (array $section): array => $section['type'] === 'cta'
? [...$section, 'data' => [...$section['data'], 'photo_ids' => [$snow->id, $allYear->id]]]
: $section)->all()]);
$apartmentGallery = fn () => $this->get('/wohnung')->assertOk();
$this->get('/')->assertOk()->assertDontSee('Raue See im Winter');
$this->get('/')->assertOk()->assertSee('Garten im Licht')->assertDontSee('Raue See im Winter');
$apartmentGallery()->assertDontSee('Raue See im Winter');
$this->travelTo(CarbonImmutable::parse('2026-11-15 10:00'));
$this->get('/')->assertOk()->assertSee('Raue See im Winter')->assertDontSee('Garten im Licht');
$apartmentGallery()->assertSeeInOrder(['Raue See im Winter', 'Garten im Licht']);
$this->travelTo(CarbonImmutable::parse('2026-12-20 10:00'));
$this->get('/')->assertOk()->assertSee('Raue See im Winter');
}
public function test_appearance_form_lists_the_sections_with_photos(): void
public function test_photo_belongs_to_several_appearances_and_the_appearance_counts_its_photos(): void
{
$this->actingAs(User::factory()->role(UserRole::Content)->create());
$winter = $this->site->appearances()->where('name', 'Winter')->sole();
$photo = Photo::factory()->create(['alt_text' => 'Strand im Schnee']);
$cta = collect($this->site->pages()->where('slug', 'start')->sole()->sections)->firstWhere('type', 'cta');
$christmas = $this->site->appearances()->where('name', 'Weihnachten')->sole();
Storage::fake('public');
$photo = $this->photoWithFile(['alt_text' => 'Strand im Schnee']);
$this->get(AppearanceResource::getUrl('edit', ['record' => $winter]))
->assertOk()
->assertSee('Bilder je Baustein')
->assertSee('Abschluss');
Livewire::test(EditAppearance::class, ['record' => $winter->getRouteKey()])
->set("data.section_photos.{$cta['data']['id']}.photo_id", $photo->id)
Livewire::test(EditPhoto::class, ['record' => $photo->getRouteKey()])
->fillForm(['appearance_ids' => [(string) $winter->id, (string) $christmas->id]])
->call('save')
->assertHasNoFormErrors();
$this->assertSame($photo->id, (int) $winter->fresh()->section_photos[$cta['data']['id']]['photo_id']);
$this->assertSame([$winter->id, $christmas->id], $photo->fresh()->appearance_ids);
$this->assertSame(['Winter', 'Weihnachten'], $photo->fresh()->appearanceNames());
$this->get(AppearanceResource::getUrl('edit', ['record' => $winter]))
->assertOk()
->assertSee('1 Foto ist diesem Erscheinungsbild zugeordnet.')
->assertDontSee('Bilder je Baustein');
Livewire::test(ListPhotos::class)
->callTableBulkAction('seasons', [$photo], ['appearance_ids' => []])
->assertHasNoTableBulkActionErrors();
$this->assertNull($photo->fresh()->appearance_ids);
}
public function test_appearance_photos_move_to_the_photos_and_sections(): void
{
$migration = require database_path('migrations/2026_10_29_184538_give_photos_their_seasons.php');
$migration->down();
$standard = $this->site->appearances()->where('is_default', true)->sole();
$winter = $this->site->appearances()->where('name', 'Winter')->sole();
$title = Photo::factory()->create();
$snow = Photo::factory()->create();
$closing = Photo::factory()->create();
$page = $this->site->pages()->where('slug', 'start')->sole();
$cta = collect($page->sections)->firstWhere('type', 'cta');
$page->update(['sections' => collect($page->sections)->map(fn (array $section): array => $section['type'] === 'cta'
? [...$section, 'data' => [...$section['data'], 'photo_id' => $closing->id]]
: $section)->all()]);
DB::table('appearances')->where('id', $standard->id)->update(['hero_photo_id' => $title->id]);
DB::table('appearances')->where('id', $winter->id)->update(['section_photos' => json_encode([$cta['data']['id'] => ['photo_id' => $snow->id]])]);
$migration->up();
$sections = collect($page->fresh()->sections);
$this->assertSame([$title->id], $sections->firstWhere('type', 'hero')['data']['photo_ids']);
$this->assertSame([$snow->id, $closing->id], $sections->firstWhere('type', 'cta')['data']['photo_ids']);
$this->assertArrayNotHasKey('photo_id', $sections->firstWhere('type', 'cta')['data']);
$this->assertNull($title->fresh()->appearance_ids);
$this->assertSame([$winter->id], $snow->fresh()->appearance_ids);
}
/**
* @param array<string, mixed> $attributes
*/
private function photoWithFile(array $attributes): Photo
{
$photo = Photo::factory()->create($attributes);
$photo->addMedia(UploadedFile::fake()->image('foto.jpg', 1600, 1000))->toMediaCollection(Photo::COLLECTION);
return $photo;
}
public function test_invalid_day_is_rejected(): void