- 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>
291 lines
13 KiB
PHP
291 lines
13 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature;
|
||
|
||
use App\Enums\ReviewStatus;
|
||
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;
|
||
use App\Models\Appearance;
|
||
use App\Models\Page;
|
||
use App\Models\Photo;
|
||
use App\Models\Property;
|
||
use App\Models\Review;
|
||
use App\Models\Site;
|
||
use App\Models\User;
|
||
use App\Themes\SectionRegistry;
|
||
use App\Themes\Theme;
|
||
use App\Themes\ThemeFactory;
|
||
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\Http\UploadedFile;
|
||
use Illuminate\Support\Facades\Storage;
|
||
use Illuminate\Support\Facades\URL;
|
||
use Livewire\Livewire;
|
||
use PHPUnit\Framework\Attributes\DataProvider;
|
||
use Tests\TestCase;
|
||
|
||
class ThemeSystemTest extends TestCase
|
||
{
|
||
use RefreshDatabase;
|
||
|
||
private Site $site;
|
||
|
||
protected function setUp(): void
|
||
{
|
||
parent::setUp();
|
||
|
||
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
|
||
$this->seed([PropertySeeder::class, WebsiteContentSeeder::class, SiteSeeder::class]);
|
||
$this->site = Site::sole();
|
||
$this->withoutVite();
|
||
}
|
||
|
||
public function test_base_theme_is_discovered_and_provides_a_view_for_every_section(): void
|
||
{
|
||
$theme = app(ThemeRegistry::class)->get('ostsee-licht');
|
||
$this->assertSame('Ostsee-Licht', $theme->name);
|
||
$this->assertArrayHasKey('accent', $theme->tokens);
|
||
|
||
foreach (array_keys(app(SectionRegistry::class)->all()) as $section) {
|
||
$this->assertFileExists($theme->viewsPath()."/sections/{$section}.blade.php", "Section {$section} needs a view in the base theme");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @return array<string, array{string}>
|
||
*/
|
||
public static function pageProvider(): array
|
||
{
|
||
return array_map(fn (string $slug): array => [$slug], array_combine(
|
||
['Start', 'Wohnung', 'Kühlungsborn', 'Buchen', 'Kontakt', 'Impressum', 'Datenschutz'],
|
||
['/', '/wohnung', '/kuehlungsborn', '/buchen', '/kontakt', '/impressum', '/datenschutz'],
|
||
));
|
||
}
|
||
|
||
#[DataProvider('pageProvider')]
|
||
public function test_every_seeded_page_renders(string $path): void
|
||
{
|
||
$this->get($path)->assertOk()->assertSee('Zum Inhalt springen')->assertSee('Preise & Buchung', false);
|
||
}
|
||
|
||
public function test_home_page_shows_content_from_the_admin(): void
|
||
{
|
||
$photo = Photo::factory()->create(['alt_text' => 'Terrasse im Sommer']);
|
||
Review::factory()->for(Property::sole())->create(['status' => ReviewStatus::Approved, 'display_name' => 'Familie M.', 'body' => 'Wunderbar ruhig!']);
|
||
|
||
$this->get('/')
|
||
->assertOk()
|
||
->assertSee('Ihr Zuhause zwischen <em>Garten</em> und Meer', false)
|
||
->assertSee('53 m²')
|
||
->assertSee('Wunderbar ruhig!')
|
||
->assertSee('"@type":"VacationRental"', false)
|
||
->assertSee('--accent:#2C5F7C', false);
|
||
$this->assertNotNull($photo);
|
||
}
|
||
|
||
public function test_unknown_and_unpublished_pages_are_not_found(): void
|
||
{
|
||
Page::factory()->for($this->site)->create(['slug' => 'entwurf', 'is_published' => false]);
|
||
|
||
$this->get('/gibt-es-nicht')->assertNotFound();
|
||
$this->get('/entwurf')->assertNotFound();
|
||
}
|
||
|
||
/**
|
||
* @return array<string, array{string, string}>
|
||
*/
|
||
public static function seasonProvider(): array
|
||
{
|
||
return [
|
||
'Herbst → Standard' => ['2026-10-22', 'Standard'],
|
||
'Sommer' => ['2026-07-15', 'Sommer'],
|
||
'Winter (über den Jahreswechsel)' => ['2027-02-10', 'Winter'],
|
||
'Weihnachten schlägt Winter' => ['2026-12-20', 'Weihnachten'],
|
||
'Silvester schlägt Winter, vor Neujahr' => ['2026-12-31', 'Silvester'],
|
||
'Silvester, nach Neujahr' => ['2027-01-02', 'Silvester'],
|
||
];
|
||
}
|
||
|
||
#[DataProvider('seasonProvider')]
|
||
public function test_appearance_follows_the_calendar_and_priority(string $date, string $expected): void
|
||
{
|
||
$this->assertSame($expected, $this->site->appearanceOn(CarbonImmutable::parse($date))?->name);
|
||
}
|
||
|
||
public function test_seasonal_appearance_changes_texts_colours_and_banner(): void
|
||
{
|
||
$this->travelTo(CarbonImmutable::parse('2026-12-20 10:00'));
|
||
|
||
$this->get('/')
|
||
->assertOk()
|
||
->assertSee('data-appearance="weihnachten"', false)
|
||
->assertSee('Besinnliche Tage <em>am Meer</em>', false)
|
||
->assertSee('Weihnachten an der Ostsee: 19.–26.12.')
|
||
->assertSee('--accent:#8C2F39', false);
|
||
}
|
||
|
||
public function test_signed_preview_shows_another_appearance_and_is_not_indexed(): void
|
||
{
|
||
$silvester = $this->site->appearances()->where('name', 'Silvester')->sole();
|
||
|
||
$this->get(URL::temporarySignedRoute('home', now()->addHour(), ['vorschau' => $silvester->id]))
|
||
->assertOk()
|
||
->assertSee('Ins neue Jahr <em>mit Meerblick</em>', false)
|
||
->assertSee('<meta name="robots" content="noindex">', false);
|
||
|
||
$this->get('/?vorschau='.$silvester->id)->assertOk()->assertDontSee('Ins neue Jahr');
|
||
}
|
||
|
||
public function test_child_theme_overrides_only_what_it_provides(): void
|
||
{
|
||
$path = storage_path('framework/testing/themes');
|
||
@mkdir($path.'/kind/views/sections', 0777, true);
|
||
file_put_contents($path.'/kind/theme.json', json_encode(['key' => 'kind', 'name' => 'Kind', 'parent' => 'ostsee-licht', 'tokens' => ['accent' => ['label' => 'Akzent', 'default' => '#FF0000']]]));
|
||
file_put_contents($path.'/kind/views/sections/facts.blade.php', '<p>Eckdaten im Kind-Theme</p>');
|
||
config(['themes.paths' => [resource_path('themes'), $path]]);
|
||
app()->forgetInstance(ThemeRegistry::class);
|
||
|
||
$this->site->update(['theme' => 'kind']);
|
||
$theme = app(ThemeFactory::class)->forSite($this->site->fresh())->activate();
|
||
app()->instance(Theme::class, $theme);
|
||
|
||
$this->assertSame(['kind', 'ostsee-licht'], array_map(fn ($manifest) => $manifest->key, $theme->chain()));
|
||
$this->assertSame('#FF0000', $theme->tokens()['accent']);
|
||
$this->assertSame('#F6F2EA', $theme->tokens()['ground']);
|
||
$this->assertStringContainsString('Eckdaten im Kind-Theme', view('theme::sections.facts')->render());
|
||
$this->assertTrue(view()->exists('theme::sections.hero'), 'falls back to the base theme');
|
||
}
|
||
|
||
public function test_sitemap_and_robots(): void
|
||
{
|
||
$this->get('/sitemap.xml')->assertOk()->assertHeader('Content-Type', 'application/xml')->assertSee(url('/wohnung'), false);
|
||
$this->get('/robots.txt')->assertOk()->assertSee('Disallow: /admin')->assertSee('Sitemap: '.url('/sitemap.xml'));
|
||
}
|
||
|
||
public function test_availability_search_prefills_the_booking_page(): void
|
||
{
|
||
$this->get('/buchen?anreise=2026-11-07&abreise=2026-11-10&personen=3')
|
||
->assertOk()
|
||
->assertSee('Gesamtpreis');
|
||
}
|
||
|
||
public function test_content_editor_manages_pages_and_appearances(): void
|
||
{
|
||
$this->actingAs(User::factory()->role(UserRole::Content)->create());
|
||
|
||
$this->get(PageResource::getUrl('index'))->assertOk()->assertSee('Die Wohnung');
|
||
$this->get(AppearanceResource::getUrl('index'))->assertOk()->assertSee('Weihnachten');
|
||
$this->get(SiteResource::getUrl('index'))->assertForbidden();
|
||
|
||
$page = $this->site->pages()->where('slug', 'kontakt')->sole();
|
||
$this->get(PageResource::getUrl('edit', ['record' => $page]))->assertOk();
|
||
|
||
Livewire::test(EditPage::class, ['record' => $page->getRouteKey()])
|
||
->set('data.title', 'Kontakt & Anfahrt')
|
||
->call('save')
|
||
->assertHasNoFormErrors();
|
||
$this->assertSame('Kontakt & Anfahrt', $page->fresh()->title);
|
||
|
||
Livewire::test(CreateAppearance::class)
|
||
->fillForm([
|
||
'name' => 'Ostern',
|
||
'site_id' => $this->site->id,
|
||
'starts_md' => '28.3.',
|
||
'ends_md' => '12.04.',
|
||
'priority' => 15,
|
||
'is_active' => true,
|
||
'overrides' => ['hero' => ['title' => 'Frühling an der Ostsee']],
|
||
'tokens' => ['accent' => '#5A7D3A'],
|
||
])
|
||
->call('create')
|
||
->assertHasNoFormErrors();
|
||
|
||
$easter = Appearance::where('name', 'Ostern')->sole();
|
||
$this->assertSame(['03-28', '04-12', 'Frühling an der Ostsee', '#5A7D3A'], [$easter->starts_md, $easter->ends_md, $easter->override('hero.title'), $easter->tokens['accent']]);
|
||
$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());
|
||
|
||
Livewire::test(CreateAppearance::class)
|
||
->fillForm(['name' => 'Kaputt', 'site_id' => $this->site->id, 'starts_md' => '31.02.', 'ends_md' => '01.03.'])
|
||
->call('create')
|
||
->assertHasFormErrors(['starts_md']);
|
||
}
|
||
}
|