Files
fewo-stommer/tests/Feature/BookingAdminTest.php
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

190 lines
7.6 KiB
PHP

<?php
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;
use App\Filament\Resources\Bookings\Pages\ViewBooking;
use App\Filament\Resources\Guests\GuestResource;
use App\Filament\Resources\Properties\Pages\EditProperty;
use App\Filament\Resources\Properties\RelationManagers\BlockedPeriodsRelationManager;
use App\Filament\Resources\Properties\RelationManagers\SpecialOffersRelationManager;
use App\Mail\BookingConfirmed;
use App\Mail\BookingDeclined;
use App\Models\Booking;
use App\Models\Property;
use App\Models\User;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Filament\Actions\CreateAction;
use Filament\Actions\Testing\TestAction;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Mail;
use Livewire\Livewire;
use Tests\TestCase;
class BookingAdminTest extends TestCase
{
use RefreshDatabase;
private Property $property;
protected function setUp(): void
{
parent::setUp();
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
$this->seed(PropertySeeder::class);
$this->property = Property::sole();
$this->actingAs(User::factory()->create());
Mail::fake();
}
public function test_booking_pages_render(): void
{
$booking = Booking::factory()->for($this->property)->reserved()->create();
$this->get(BookingResource::getUrl('index'))->assertOk()->assertSee($booking->reference);
$this->get(BookingResource::getUrl('view', ['record' => $booking]))->assertOk()->assertSee($booking->guest->email);
$this->get(GuestResource::getUrl('index'))->assertOk()->assertSee($booking->guest->email);
Livewire::test(ListBookings::class)->assertCanSeeTableRecords([$booking]);
}
public function test_landlord_confirms_a_reservation(): void
{
$booking = Booking::factory()->for($this->property)->reserved()->create();
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])
->callAction('confirm', ['notify' => true])
->assertNotified('Buchung bestätigt');
$this->assertSame(BookingStatus::Confirmed, $booking->fresh()->status);
Mail::assertSent(BookingConfirmed::class);
}
public function test_landlord_declines_without_notifying_the_guest(): void
{
$booking = Booking::factory()->for($this->property)->reserved()->create();
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])
->callAction('decline', ['notify' => false]);
$this->assertSame(BookingStatus::Declined, $booking->fresh()->status);
Mail::assertNotSent(BookingDeclined::class);
}
public function test_hold_can_be_extended(): void
{
$booking = Booking::factory()->for($this->property)->reserved(now()->addHours(2))->create();
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])
->callAction('extendHold', ['hours' => 24]);
$this->assertSame('2026-10-23 12:00', $booking->fresh()->hold_expires_at->format('Y-m-d H:i'));
}
public function test_phone_booking_is_entered_and_confirmed_with_calculated_price(): void
{
Livewire::test(CreateBooking::class)
->fillForm([
'property_id' => $this->property->id,
'guests' => 2,
'arrival' => '2026-11-07',
'departure' => '2026-11-10',
'first_name' => 'Peter',
'last_name' => 'Telefon',
'email' => 'peter@example.com',
'confirm_immediately' => true,
'send_mails' => false,
])
->call('create')
->assertHasNoFormErrors();
$booking = Booking::sole();
$this->assertSame([BookingStatus::Confirmed, 'manual', 3 * 6500 + 10800], [$booking->status, $booking->source, $booking->total]);
Mail::assertNothingSent();
}
public function test_phone_booking_for_occupied_dates_is_refused(): void
{
Booking::factory()->for($this->property)->create(['arrival' => '2026-11-08', 'departure' => '2026-11-12']);
Livewire::test(CreateBooking::class)
->fillForm([
'property_id' => $this->property->id,
'guests' => 2,
'arrival' => '2026-11-07',
'departure' => '2026-11-10',
'first_name' => 'Peter',
'last_name' => 'Telefon',
'email' => 'peter@example.com',
])
->call('create')
->assertNotified('Buchung nicht möglich');
$this->assertSame(1, Booking::count());
}
public function test_special_offer_with_euro_value_is_stored_in_cents(): void
{
Livewire::test(SpecialOffersRelationManager::class, ['ownerRecord' => $this->property, 'pageClass' => EditProperty::class])
->callAction(TestAction::make(CreateAction::class)->table(), [
'name' => 'Special Weekend',
'discount_type' => 'nightly_rate',
'discount_value' => '59.50',
'arrival_weekdays' => [5],
'season_names' => ['Winter'],
])
->assertHasNoFormErrors();
$offer = $this->property->specialOffers()->sole();
$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])
->callAction(TestAction::make(CreateAction::class)->table(), [
'starts_on' => '2026-12-01',
'ends_on' => '2026-12-05',
'reason' => 'Eigennutzung',
])
->assertHasNoFormErrors();
$this->assertSame(1, $this->property->blockedPeriods()->count());
}
}