- Sites (Domain, Theme, Farben; mehrfähig für weitere Vermieter), Seiten aus Bausteinen mit Menüs, Erscheinungsbilder mit jährlichem Zeitplan, Priorität und signierter Vorschau - Theme-Kern (app/Themes): Manifest, Registry, Vererbung (Child-Themes), Token-Farben als CSS-Variablen, Bausteinkatalog als Registry (config/themes.php) - 15 Bausteine: Titelbereich mit Suche, Eckdaten, Text mit Bildern, Galerie, Ausstattung, Lage, Preise, Angebote, Kalender & Anfrage, Bewertungen, Gastgeber, FAQ, Abschluss, Kontakt, Fließtext - Theme Ostsee-Licht: Layout, Kopf/Fuß, Banner, mobile Buchungsleiste, Lightbox, selbst gehostete Schriften, Reduced Motion - Seiten Start, Wohnung, Kühlungsborn, Preise & Buchung, Kontakt, Impressum, Datenschutz; Sitemap, robots.txt, JSON-LD - Admin: Seiten-Baukasten, Erscheinungsbilder, Websites - Dokumentation docs/THEMES.md inkl. Übergabe für die Design-Sitzung Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
224 lines
9.1 KiB
PHP
224 lines
9.1 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\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\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_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']);
|
||
}
|
||
}
|