Files
fewo-stommer/tests/Feature/OfferShowcaseTest.php
T
Lars StommerandClaude Opus 5.5 7d0bc93abc 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>
2026-10-22 18:51:38 +02:00

139 lines
5.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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);
}
}