Die Theme-Sitzung wartete darauf: Seebad ruft schon ortsneutrale Plätze über `partials/motif` auf und behilft sich mit einem eigenen `motifs/`- Ordner. Der Kommentar dort sagt es selbst – „so a later picture-world system can replace the mapping below". Das System gibt es jetzt. **Bildwelten** (A18–A20) sind Pakete wie Themes: `resources/image-worlds/ <key>/` mit `world.json` und `svg/`. Eine Website wählt eine Bildwelt, eine Wohnung darf eine andere tragen – das ist der Platz für die Bergwohnung auf einer Küsten-Website. Vorlagen fragen über `$theme->motif($slot)` nach einem Platz, nie nach einer Datei. Die Render-Logik ist aus Seebads Partial in die Anwendung gewandert, damit jedes Theme sie bekommt: Inline-SVG (nimmt die Textfarbe an, kein zweiter Request), Titel und ARIA entfernt, und die internen Ids je Aufruf eindeutig gemacht – zwei Kopien derselben Grafik auf einer Seite würden sonst auf denselben Verlauf zeigen und eine davon verlöre ihre Farben. Ein leerer Platz ist kein Fehler: die Vorlage bekommt schlicht keine Dekoration. Weil das leicht zu übersehen ist, meldet `php artisan image-worlds:check`, welcher Platz ohne Datei dasteht. **Marke je Website** (A14/A22): Logo, Favicon und ein Logo für E-Mail und Vertrag als Medien der Website. Der Mietvertrag bettet die Datei ein statt eine URL zu holen – er wird auf dem Server gerendert und darf nicht davon abhängen, dass dieser sich selbst erreicht. Ohne Logo bleibt der Vertrag wie bisher. `resources/themes/**` ist unberührt: die Ostsee-Grafiken sind kopiert, nicht verschoben. Was die Theme-Sitzung nun tun kann, steht in ZUSAMMENARBEIT.md §6; ihr Wunsch aus §5 ist als erledigt vermerkt. 272 Feature-Tests grün. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
137 lines
5.0 KiB
PHP
137 lines
5.0 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature;
|
||
|
||
use App\ImageWorlds\ImageWorldRegistry;
|
||
use App\ImageWorlds\MotifRenderer;
|
||
use App\Models\Property;
|
||
use App\Models\Site;
|
||
use App\Models\Tenant;
|
||
use App\Tenancy\TenantContext;
|
||
use App\Themes\Theme;
|
||
use App\Themes\ThemeFactory;
|
||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
use Illuminate\Support\Facades\File;
|
||
use Tests\TestCase;
|
||
|
||
/**
|
||
* Picture worlds (A18–A20): a website is dressed in a set of graphics, an apartment may wear a different
|
||
* one. Templates ask for a slot, never for a file, so the same template works in every world.
|
||
*/
|
||
class ImageWorldTest extends TestCase
|
||
{
|
||
use RefreshDatabase;
|
||
|
||
private string $extra;
|
||
|
||
protected function setUp(): void
|
||
{
|
||
parent::setUp();
|
||
|
||
// A second world, so "the apartment overrules the website" is testable against something.
|
||
$this->extra = resource_path('image-worlds/berge');
|
||
File::ensureDirectoryExists($this->extra.'/svg');
|
||
File::put($this->extra.'/world.json', json_encode([
|
||
'name' => 'Berge',
|
||
'description' => 'Gipfel statt Wellen.',
|
||
'slots' => ['divider' => 'grat', 'crest' => 'gipfel'],
|
||
]));
|
||
File::put($this->extra.'/svg/grat.svg', '<svg viewBox="0 0 10 10"><title>Grat</title><path id="line" fill="url(#verlauf)"/></svg>');
|
||
|
||
app()->forgetInstance(ImageWorldRegistry::class);
|
||
}
|
||
|
||
protected function tearDown(): void
|
||
{
|
||
File::deleteDirectory($this->extra);
|
||
|
||
parent::tearDown();
|
||
}
|
||
|
||
public function test_the_registry_finds_every_world_and_reports_slots_without_a_file(): void
|
||
{
|
||
$registry = app(ImageWorldRegistry::class);
|
||
|
||
$this->assertArrayHasKey('ostsee', $registry->all());
|
||
$this->assertArrayHasKey('berge', $registry->all());
|
||
$this->assertSame('Berge', $registry->options()['berge']);
|
||
|
||
$this->assertSame([], $registry->get('ostsee')->missingFiles());
|
||
$this->assertSame(['crest'], $registry->get('berge')->missingFiles(), 'gipfel.svg fehlt und muss auffallen.');
|
||
$this->assertNull($registry->get('gibtsnicht'));
|
||
}
|
||
|
||
public function test_a_slot_without_a_file_renders_nothing_instead_of_breaking(): void
|
||
{
|
||
$this->useWorld('berge');
|
||
|
||
$this->assertSame('', (string) app(MotifRenderer::class)->render('crest'));
|
||
$this->assertFalse(app(MotifRenderer::class)->has('crest'));
|
||
$this->assertTrue(app(MotifRenderer::class)->has('divider'));
|
||
}
|
||
|
||
public function test_the_apartment_overrules_the_website(): void
|
||
{
|
||
$this->useWorld('ostsee');
|
||
$this->assertSame('ostsee', app(MotifRenderer::class)->world()?->key);
|
||
|
||
$this->useWorld('ostsee', apartmentWorld: 'berge');
|
||
$this->assertSame('berge', app(MotifRenderer::class)->world()?->key, 'Die Bergwohnung trägt ihre eigene Bildwelt.');
|
||
}
|
||
|
||
public function test_without_any_choice_the_installation_decides(): void
|
||
{
|
||
config(['image-worlds.default' => 'berge']);
|
||
$this->useWorld(null);
|
||
|
||
$this->assertSame('berge', app(MotifRenderer::class)->world()?->key);
|
||
}
|
||
|
||
public function test_the_rendered_graphic_is_decorative_unless_it_is_given_a_label(): void
|
||
{
|
||
$this->useWorld('berge');
|
||
|
||
$plain = (string) app(MotifRenderer::class)->render('divider', 'h-8 text-accent');
|
||
|
||
$this->assertStringContainsString('aria-hidden="true"', $plain);
|
||
$this->assertStringContainsString('class="h-8 text-accent"', $plain);
|
||
$this->assertStringNotContainsString('<title>', $plain, 'Der Titel würde sonst doppelt vorgelesen.');
|
||
|
||
$labelled = (string) app(MotifRenderer::class)->render('divider', null, 'Bergkamm');
|
||
|
||
$this->assertStringContainsString('role="img"', $labelled);
|
||
$this->assertStringContainsString('aria-label="Bergkamm"', $labelled);
|
||
}
|
||
|
||
/**
|
||
* Two copies of one graphic on a page must not share their internal ids – the second would otherwise
|
||
* point at the first one's gradient and lose its colours.
|
||
*/
|
||
public function test_the_internal_ids_are_unique_per_rendering(): void
|
||
{
|
||
$this->useWorld('berge');
|
||
|
||
$first = (string) app(MotifRenderer::class)->render('divider');
|
||
$second = (string) app(MotifRenderer::class)->render('divider');
|
||
|
||
$this->assertNotSame($first, $second);
|
||
$this->assertMatchesRegularExpression('/id="line-m\w{6}"/', $first);
|
||
$this->assertStringContainsString('url(#verlauf-m', $first);
|
||
}
|
||
|
||
private function useWorld(?string $key, ?string $apartmentWorld = null): Theme
|
||
{
|
||
$tenant = Tenant::factory()->create();
|
||
|
||
return app(TenantContext::class)->run($tenant, function () use ($key, $apartmentWorld): Theme {
|
||
$site = Site::factory()->create(['image_world' => $key, 'is_default' => true]);
|
||
Property::factory()->create(['site_id' => $site->id, 'image_world' => $apartmentWorld]);
|
||
|
||
$theme = app(ThemeFactory::class)->forSite($site);
|
||
app()->instance(Theme::class, $theme);
|
||
|
||
return $theme;
|
||
});
|
||
}
|
||
}
|