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

119 lines
5.2 KiB
PHP

<?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();
}
}