Offers by their own rules, seasonal photos per section, theme authoring tooling

- Special offers: kinds (rule, fixed dates, gap filler), package price, priority, highlight;
  GapFinder detects calendar gaps (optionally waiving the minimum stay); OfferShowcase decides
  what the website advertises and prices fixed dates/gaps with PriceCalculator; offers section
  shows them side by side, as a list or rotating; hero can show the top offer. Appearances no
  longer carry a featured offer.
- Sections get stable ids; appearances set photos per section ("Bilder je Baustein") and
  sections can be limited to appearances. Photo pickers show thumbnails everywhere.
- Themes: themes:make (scaffold, never overwrites), themes:check (contract, build, markup,
  colours, external resources, WCAG contrast), themes:preview (signed links per page and
  appearance), signed ?theme= preview and preview action in the site form, inherited colour
  tokens in the admin. Base CSS split into theme.css + reusable theme-base.css.
- docs/THEME-ERSTELLUNG.md: binding guide for building additional themes elsewhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lars StommerandClaude Opus 5.5 committed 2026-10-22 18:51:38 +02:00
1 parent bc77b64ea7
commit 7d0bc93abc
50 files changed
+2805 -259

No files matched your search

+31
View File
@@ -3,6 +3,7 @@
namespace Tests\Feature;
use App\Enums\BookingStatus;
use App\Enums\OfferKind;
use App\Filament\Resources\Bookings\BookingResource;
use App\Filament\Resources\Bookings\Pages\CreateBooking;
use App\Filament\Resources\Bookings\Pages\ListBookings;
@@ -143,6 +144,36 @@ public function test_special_offer_with_euro_value_is_stored_in_cents(): void
$this->assertSame([5950, ['5'], ['Winter']], [$offer->discount_value, array_map('strval', $offer->arrival_weekdays), $offer->season_names]);
}
public function test_fixed_dates_package_and_gap_filler_are_created(): void
{
$manager = Livewire::test(SpecialOffersRelationManager::class, ['ownerRecord' => $this->property, 'pageClass' => EditProperty::class]);
$manager->callAction(TestAction::make(CreateAction::class)->table(), [
'kind' => 'fixed_dates',
'name' => 'Ostsee-Woche',
'discount_type' => 'fixed_stay_price',
'discount_value' => '499.00',
'stay_from' => '2026-11-07',
'stay_until' => '2026-11-14',
'is_featured' => true,
'priority' => 5,
])->assertHasNoFormErrors();
$manager->callAction(TestAction::make(CreateAction::class)->table(), [
'kind' => 'gap_filler',
'name' => 'Kurzfristige Lücke',
'discount_type' => 'percent',
'discount_value' => 20,
'max_gap_nights' => 4,
'waives_min_stay' => true,
])->assertHasNoFormErrors();
$package = $this->property->specialOffers()->where('name', 'Ostsee-Woche')->sole();
$gap = $this->property->specialOffers()->where('name', 'Kurzfristige Lücke')->sole();
$this->assertSame([OfferKind::FixedDates, 49900, '2026-11-07', '2026-11-14', true, 5], [$package->kind, $package->discount_value, $package->stay_from->toDateString(), $package->stay_until->toDateString(), $package->is_featured, $package->priority]);
$this->assertSame([OfferKind::GapFiller, 4, true], [$gap->kind, $gap->max_gap_nights, $gap->waives_min_stay]);
}
public function test_blocked_period_is_created(): void
{
Livewire::test(BlockedPeriodsRelationManager::class, ['ownerRecord' => $this->property, 'pageClass' => EditProperty::class])
+138
View File
@@ -0,0 +1,138 @@
<?php
namespace Tests\Feature;
use App\Enums\DiscountType;
use App\Enums\OfferKind;
use App\Models\BlockedPeriod;
use App\Models\Property;
use App\Models\Season;
use App\Models\SpecialOffer;
use App\Pricing\AdvertisedOffer;
use App\Pricing\OfferShowcase;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Database\Seeders\SiteSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class OfferShowcaseTest extends TestCase
{
use RefreshDatabase;
private Property $property;
private CarbonImmutable $now;
protected function setUp(): void
{
parent::setUp();
$this->now = CarbonImmutable::parse('2026-02-01 10:00');
$this->property = Property::factory()->create(['cleaning_fee' => 10000, 'included_guests' => 2]);
Season::factory()->for($this->property)->create(['name' => 'Winter', 'starts_on' => '2026-01-03', 'ends_on' => '2026-06-01', 'nightly_rate' => 5000, 'min_nights' => 3]);
}
public function test_only_public_offers_without_code_in_their_booking_window_are_shown(): void
{
$this->offer(['name' => 'Ab 3 Nächten', 'min_nights' => 3]);
$this->offer(['name' => 'Intern', 'is_public' => false]);
$this->offer(['name' => 'Stammgast', 'code' => 'OSTSEE']);
$this->offer(['name' => 'Abgelaufen', 'bookable_until' => '2026-01-31 23:59']);
$this->offer(['name' => 'Vorbei', 'stay_until' => '2026-01-20']);
$this->offer(['name' => 'Inaktiv', 'is_active' => false]);
$this->assertSame(['Ab 3 Nächten'], $this->titles());
}
public function test_highlighted_offers_come_first_then_priority(): void
{
$this->offer(['name' => 'Normal', 'priority' => 0]);
$this->offer(['name' => 'Wichtig', 'priority' => 5]);
$this->offer(['name' => 'Hervorgehoben', 'is_featured' => true]);
$this->assertSame(['Hervorgehoben', 'Wichtig', 'Normal'], $this->titles());
$this->assertSame(['Hervorgehoben'], $this->showcase()->current($this->property, $this->now, featuredOnly: true)->map(fn (AdvertisedOffer $offer): string => $offer->title)->all());
}
public function test_fixed_dates_are_advertised_with_their_price_only_while_free(): void
{
$this->offer([
'name' => 'Ostsee-Woche',
'kind' => OfferKind::FixedDates,
'stay_from' => '2026-03-07',
'stay_until' => '2026-03-14',
'discount_type' => DiscountType::FixedStayPrice,
'discount_value' => 29900,
]);
$advertised = $this->showcase()->current($this->property, $this->now)->sole();
$this->assertSame('2026-03-07', $advertised->arrival->toDateString());
$this->assertSame(29900 + 10000, $advertised->quote->total());
$this->assertSame(7 * 5000 + 10000, $advertised->regularTotal());
$this->assertStringContainsString('anreise=2026-03-07', $advertised->bookingUrl());
BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-03-10', 'ends_on' => '2026-03-12']);
$this->assertSame([], $this->titles());
}
public function test_gap_filler_advertises_each_gap_found_in_the_calendar(): void
{
BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-02-05', 'ends_on' => '2026-02-10']);
BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-02-12', 'ends_on' => '2026-02-20']);
BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-02-23', 'ends_on' => '2026-03-01']);
$this->offer(['name' => 'Lückenfüller', 'kind' => OfferKind::GapFiller, 'max_gap_nights' => 4, 'waives_min_stay' => true, 'discount_value' => 20]);
$gaps = $this->showcase()->current($this->property, $this->now)
->map(fn (AdvertisedOffer $offer): string => $offer->arrival->format('d.m.').'–'.$offer->departure->format('d.m.'))
->all();
$this->assertSame(['10.02.–12.02.', '20.02.–23.02.'], $gaps);
}
public function test_gap_below_minimum_stay_is_not_advertised_unless_the_offer_waives_it(): void
{
BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-02-05', 'ends_on' => '2026-02-10']);
BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-02-12', 'ends_on' => '2026-02-20']);
$this->offer(['name' => 'Lückenfüller', 'kind' => OfferKind::GapFiller, 'max_gap_nights' => 4, 'discount_value' => 20]);
$this->assertSame([], $this->titles());
}
public function test_offers_section_shows_the_advertised_offers_on_the_website(): void
{
$this->travelTo($this->now);
$this->property->delete();
$this->seed([PropertySeeder::class, SiteSeeder::class]);
SpecialOffer::factory()->for(Property::query()->sole())->create(['name' => 'Ab 3 Nächten −10 %', 'min_nights' => 3, 'discount_value' => 10]);
$this->withoutVite()
->get(route('booking.create'))
->assertOk()
->assertSee('Ab 3 Nächten −10 %')
->assertSee('ab 3 Nächten');
}
/**
* @return list<string>
*/
private function titles(): array
{
return $this->showcase()->current($this->property, $this->now)->map(fn (AdvertisedOffer $offer): string => $offer->title)->all();
}
private function showcase(): OfferShowcase
{
return app(OfferShowcase::class);
}
/**
* @param array<string, mixed> $attributes
*/
private function offer(array $attributes): SpecialOffer
{
return SpecialOffer::factory()->for($this->property)->create($attributes);
}
}
+56
View File
@@ -3,10 +3,13 @@
namespace Tests\Feature;
use App\Enums\DiscountType;
use App\Enums\OfferKind;
use App\Models\BlockedPeriod;
use App\Models\Property;
use App\Models\Season;
use App\Models\SpecialOffer;
use App\Pricing\PriceCalculator;
use App\Pricing\QuoteException;
use App\Pricing\StayRequest;
use Carbon\CarbonImmutable;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -118,6 +121,59 @@ public function test_deposit_is_calculated_on_the_discounted_rent(): void
$this->assertSame(20000 - 2000 + 10000, $quote->total());
}
public function test_from_three_nights_ten_percent(): void
{
$this->offer(['name' => 'Ab 3 Nächten', 'min_nights' => 3, 'discount_value' => 10]);
$this->assertSame(0, $this->calculator->calculate($this->property, $this->stay('2026-02-10', '2026-02-12'))->discount());
$this->assertSame(1500, $this->calculator->calculate($this->property, $this->stay('2026-02-10', '2026-02-13'))->discount());
}
public function test_fixed_dates_package_applies_only_to_exactly_these_dates(): void
{
$this->offer([
'name' => 'Ostsee-Woche',
'kind' => OfferKind::FixedDates,
'stay_from' => '2026-02-07',
'stay_until' => '2026-02-14',
'discount_type' => DiscountType::FixedStayPrice,
'discount_value' => 29900,
]);
$exact = $this->calculator->calculate($this->property, $this->stay('2026-02-07', '2026-02-14'));
$shifted = $this->calculator->calculate($this->property, $this->stay('2026-02-08', '2026-02-14'));
$this->assertSame(7 * 5000 - 29900, $exact->discount());
$this->assertSame(29900 + 10000, $exact->total());
$this->assertSame(0, $shifted->discount());
}
public function test_gap_filler_applies_inside_a_short_gap_and_may_waive_the_minimum_stay(): void
{
$this->property->seasons()->update(['min_nights' => 5]);
BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-02-01', 'ends_on' => '2026-02-10']);
BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-02-13', 'ends_on' => '2026-02-20']);
$this->offer(['name' => 'Lückenfüller', 'kind' => OfferKind::GapFiller, 'max_gap_nights' => 4, 'waives_min_stay' => true, 'discount_value' => 20]);
$inGap = $this->calculator->calculate($this->property, $this->stay('2026-02-10', '2026-02-13'));
$this->assertSame(3000, $inGap->discount());
$this->expectException(QuoteException::class);
$this->calculator->calculate($this->property, $this->stay('2026-02-21', '2026-02-24'));
}
public function test_gap_filler_ignores_gaps_longer_than_allowed_and_open_ended_free_periods(): void
{
BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-02-01', 'ends_on' => '2026-02-10']);
BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-02-20', 'ends_on' => '2026-02-25']);
$this->offer(['name' => 'Lückenfüller', 'kind' => OfferKind::GapFiller, 'max_gap_nights' => 4, 'discount_value' => 20]);
$longGap = $this->calculator->calculate($this->property, $this->stay('2026-02-10', '2026-02-13'));
$openEnded = $this->calculator->calculate($this->property, $this->stay('2026-02-25', '2026-02-28'));
$this->assertSame([0, 0], [$longGap->discount(), $openEnded->discount()]);
}
public function test_inactive_offers_are_ignored(): void
{
$this->offer(['is_active' => false]);
+67
View File
@@ -6,6 +6,7 @@
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\Sites\SiteResource;
@@ -25,6 +26,8 @@
use Database\Seeders\SiteSeeder;
use Database\Seeders\WebsiteContentSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\URL;
use Livewire\Livewire;
use PHPUnit\Framework\Attributes\DataProvider;
@@ -211,6 +214,70 @@ public function test_content_editor_manages_pages_and_appearances(): void
$this->assertSame('Ostern', $this->site->appearanceOn(CarbonImmutable::parse('2027-04-01'))->name);
}
public function test_placed_sections_get_stable_ids_and_copies_get_new_ones(): void
{
$page = $this->site->pages()->where('slug', 'start')->sole();
$ids = array_map(fn (array $section): string => $section['data']['id'], $page->sections);
$this->assertCount(count($page->sections), array_unique($ids));
$page->update(['sections' => [...$page->sections, $page->sections[0]]]);
$this->assertSame($ids, array_slice(array_map(fn (array $section): string => $section['data']['id'], $page->fresh()->sections), 0, count($ids)));
$this->assertNotSame($ids[0], last($page->fresh()->sections)['data']['id']);
}
public function test_section_can_be_limited_to_an_appearance(): void
{
$christmas = $this->site->appearances()->where('name', 'Weihnachten')->sole();
$page = $this->site->pages()->where('slug', 'start')->sole();
$page->update(['sections' => [...$page->sections, ['type' => 'text_image', 'data' => ['heading' => 'Adventsmarkt am Hafen', 'appearances' => [(string) $christmas->id]]]]]);
$this->get('/')->assertOk()->assertDontSee('Adventsmarkt am Hafen');
$this->travelTo(CarbonImmutable::parse('2026-12-20 10:00'));
$this->get('/')->assertOk()->assertSee('Adventsmarkt am Hafen');
}
public function test_appearance_sets_seasonal_photos_per_section(): 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]]]);
$this->get('/')->assertOk()->assertDontSee('Raue See im Winter');
$this->travelTo(CarbonImmutable::parse('2026-11-15 10:00'));
$this->get('/')->assertOk()->assertSee('Raue See im Winter');
}
public function test_appearance_form_lists_the_sections_with_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');
$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)
->call('save')
->assertHasNoFormErrors();
$this->assertSame($photo->id, (int) $winter->fresh()->section_photos[$cta['data']['id']]['photo_id']);
}
public function test_invalid_day_is_rejected(): void
{
$this->actingAs(User::factory()->create());
+118
View File
@@ -0,0 +1,118 @@
<?php
namespace Tests\Feature;
use App\Models\Site;
use App\Themes\ThemeChecker;
use App\Themes\ThemeRegistry;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Database\Seeders\SiteSeeder;
use Database\Seeders\WebsiteContentSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\URL;
use Tests\TestCase;
class ThemeToolingTest extends TestCase
{
use RefreshDatabase;
private string $themesPath;
protected function setUp(): void
{
parent::setUp();
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
$this->seed([PropertySeeder::class, WebsiteContentSeeder::class, SiteSeeder::class]);
$this->themesPath = storage_path('framework/testing/theme-tooling');
File::deleteDirectory($this->themesPath);
File::ensureDirectoryExists($this->themesPath);
config(['themes.paths' => [$this->themesPath, resource_path('themes')]]);
app()->forgetInstance(ThemeRegistry::class);
}
protected function tearDown(): void
{
File::deleteDirectory($this->themesPath);
parent::tearDown();
}
public function test_installed_themes_fulfil_the_theme_contract(): void
{
config(['themes.paths' => [resource_path('themes')]]);
app()->forgetInstance(ThemeRegistry::class);
$this->artisan('themes:check')->assertSuccessful();
}
public function test_new_theme_is_created_next_to_the_existing_ones_and_passes_the_check(): void
{
$this->artisan('themes:make', ['key' => 'ostsee-nacht', '--name' => 'Ostsee-Nacht'])->assertSuccessful();
app()->forgetInstance(ThemeRegistry::class);
$registry = app(ThemeRegistry::class);
$theme = $registry->get('ostsee-nacht');
$this->assertSame(['ostsee-nacht', 'ostsee-licht'], array_map(fn ($manifest) => $manifest->key, $registry->chain('ostsee-nacht')));
$this->assertArrayHasKey('ostsee-nacht', $registry->options());
$this->assertSame(array_keys($registry->tokens('ostsee-licht')), array_keys($theme->tokens));
$this->assertSame([], app(ThemeChecker::class)->check($theme)['errors']);
$this->assertFileExists(resource_path('themes/ostsee-licht/theme.json'), 'the base theme stays untouched');
$this->artisan('themes:make', ['key' => 'ostsee-nacht'])->assertFailed();
}
public function test_checker_reports_contract_violations(): void
{
$this->artisan('themes:make', ['key' => 'kaputt'])->assertSuccessful();
$path = $this->themesPath.'/kaputt';
$manifest = json_decode(File::get($path.'/theme.json'), true);
$manifest['tokens']['muted']['default'] = '#CCCCCC';
File::put($path.'/theme.json', json_encode($manifest));
File::put($path.'/views/sections/booking.blade.php', '<section class="bg-blue-700">{{ $heading }}</section>');
File::put($path.'/views/sections/text-image.blade.php', '<section></section>');
File::put($path.'/theme.css', File::get($path.'/theme.css')."\n@import url('https://fonts.googleapis.com/css2?family=Inter');\n");
app()->forgetInstance(ThemeRegistry::class);
$errors = implode("\n", app(ThemeChecker::class)->check(app(ThemeRegistry::class)->get('kaputt'))['errors']);
$this->assertStringContainsString('Kalender/Anfrage fehlt', $errors);
$this->assertStringContainsString('feste Farbe „bg-blue-700“', $errors);
$this->assertStringContainsString('unbekannter Baustein', $errors);
$this->assertStringContainsString('fonts.googleapis', $errors);
$this->assertStringContainsString('Kontrast muted auf ground', $errors);
$this->artisan('themes:check', ['theme' => 'kaputt'])->assertFailed();
}
public function test_contrast_follows_wcag(): void
{
$this->assertSame(21.0, ThemeChecker::contrast('#000000', '#FFFFFF'));
$this->assertGreaterThan(4.5, ThemeChecker::contrast('#4E5C66', '#F6F2EA'));
$this->assertLessThan(4.5, ThemeChecker::contrast('#999', '#FFF'));
}
public function test_signed_preview_shows_the_site_with_another_theme_without_switching(): void
{
$this->artisan('themes:make', ['key' => 'ostsee-nacht', '--name' => 'Ostsee-Nacht'])->assertSuccessful();
File::put($this->themesPath.'/ostsee-nacht/views/sections/facts.blade.php', '<section aria-label="{{ $sectionId }}">Eckdaten im neuen Theme</section>');
app()->forgetInstance(ThemeRegistry::class);
$this->withoutVite();
$this->get(URL::temporarySignedRoute('home', now()->addHour(), ['theme' => 'ostsee-nacht']))
->assertOk()
->assertSee('Eckdaten im neuen Theme')
->assertSee('Theme „Ostsee-Nacht“')
->assertSee('<meta name="robots" content="noindex">', false);
$this->get('/?theme=ostsee-nacht')->assertOk()->assertDontSee('Eckdaten im neuen Theme');
$this->assertSame('ostsee-licht', Site::sole()->theme);
$this->artisan('themes:preview', ['theme' => 'ostsee-nacht'])
->expectsOutputToContain('Die Wohnung')
->expectsOutputToContain('Weihnachten:')
->assertSuccessful();
}
}