Zeige auf der Shopkachel Titelbild, Saeulen, Materialart mit Symbol und Marker
CI Feature / test (push) Successful in 5m10s
Deploy Test / test (push) Successful in 5m21s
Deploy Test / deploy (push) Successful in 32s

- ShopCatalog als gemeinsame Datenquelle der Kacheln, shop/kachel als Partial
- Titelbild nur mit Website-Freigabe (PresentationMedia::coverPresentation), schmueckend mit leerem alt
- Symbol je Materialart (Stammdaten), Marker Neu, Aktualisiert, Beliebt mit Einstellung am Artikel
- Migration 2026_12_01_100000, rein ergaenzend
- ADR-54, Plan, DEPLOYMENT.md

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-26 07:44:47 +01:00
1 parent db3a6ba779
commit 0ac70884cc
18 files changed
+991 -88

No files matched your search

+366
View File
@@ -0,0 +1,366 @@
<?php
namespace Tests\Feature;
use App\Domain\Catalog\ArticleRelease;
use App\Domain\Catalog\ArticleService;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\EditorialContentKind;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\PillarService;
use App\Domain\Catalog\PresentationAssignment;
use App\Domain\Catalog\PresentationRole;
use App\Domain\Commerce\ShopCatalog;
use App\Domain\Commerce\ShopMarkers;
use App\Filament\Pages\RedaktionelleStammdaten;
use App\Filament\Resources\LicenseArticles\Pages\ViewLicenseArticle;
use App\Models\User;
use App\Support\Brand\SymbolCatalog;
use Filament\Actions\Testing\TestAction;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Tests\Support\BuildsShop;
use Tests\TestCase;
/**
* Shopkachel (ADR-54): Titelbild nur mit Website-Freigabe, Säulen nur veröffentlicht, Materialart mit Symbol, Marker mit
* Wort, eine Datenquelle für die Shopseite.
*/
class ShopTilesTest extends TestCase
{
use BuildsShop;
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
Storage::fake('media_public');
$this->seedShop();
}
private function konflikte(): LicenseArticle
{
return $this->article('shop-konflikte');
}
/** Ein Bildelement, optional für die Website freigegeben (Ableitung liegt im öffentlichen Speicher). */
private function image(string $title, bool $released): ContentElement
{
$element = app(ContentService::class)->createElement('bild', 'bild', $title);
$element->display_title = $title;
$element->save();
if ($released) {
$path = 'website/'.$element->id.'/datei.jpg';
Storage::disk('media_public')->put($path, 'bild');
$element->forceFill(['website_released_at' => now(), 'website_public_path' => $path, 'website_alt' => 'Alt '.$title])->save();
}
return $element->fresh();
}
private function cover(LicenseArticle $article, ContentElement $element, string $role = 'titelbild', int $position = 1): void
{
PresentationAssignment::query()->create([
'subject_type' => $article->getMorphClass(),
'subject_id' => $article->id,
'content_element_id' => $element->id,
'presentation_role_id' => PresentationRole::query()->where('slug', $role)->value('id'),
'position' => $position,
]);
}
private function card(string $key = 'a:'): array
{
$cards = app(ShopCatalog::class)->cards();
$found = array_values(array_filter($cards, fn (array $card): bool => $card['key'] === $key.$this->konflikte()->id));
$this->assertCount(1, $found);
return $found[0];
}
/** Zahl der Bilder in den Kachelflächen (das Logo im Kopf zählt nicht). */
private function tileImages(string $html): int
{
return preg_match_all('#<div class="shop-tile-media[^"]*"[^>]*>\s*<img#', $html);
}
private function editor(): User
{
$editor = User::factory()->redakteur()->create();
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $editor;
}
private function keeper(): User
{
$keeper = User::factory()->katalogverwalter()->create();
$keeper->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $keeper;
}
// ---- Bild ---------------------------------------------------------------------------------------------------------
public function test_without_a_released_cover_the_tile_has_no_image_and_a_placeholder(): void
{
$this->assertNull($this->card()['image']);
$html = $this->get(route('shop'))->assertOk()->getContent();
$this->assertStringContainsString('is-placeholder', $html);
$this->assertSame(0, $this->tileImages($html));
}
public function test_a_cover_without_website_release_is_never_shown_or_linked(): void
{
$private = $this->image('Privates Titelbild', released: false);
$this->cover($this->konflikte(), $private);
$this->assertNull($this->card()['image']);
$html = $this->get(route('shop'))->assertOk()->getContent();
$this->assertSame(0, $this->tileImages($html));
$this->assertStringNotContainsString('website-medien/'.$private->id, $html);
$this->assertStringNotContainsString('originals', $html);
$this->assertStringNotContainsString('Privates Titelbild', $html);
}
public function test_a_released_cover_appears_on_the_tile_as_a_decorative_lazy_image(): void
{
$released = $this->image('Freigegebenes Titelbild', released: true);
$this->cover($this->konflikte(), $released);
$this->assertSame(route('website.media', $released), $this->card()['image']['url']);
$html = $this->get(route('shop'))->assertOk()->getContent();
$this->assertStringContainsString('src="'.route('website.media', $released).'"', $html);
$this->assertMatchesRegularExpression('#<img src="[^"]+website-medien/'.$released->id.'" alt="" loading="lazy"#', $html, 'Das Bild ist schmückend, der Titel ist der Link.');
}
public function test_an_unreleased_first_cover_is_skipped_for_the_next_released_one(): void
{
$this->cover($this->konflikte(), $this->image('Nicht freigegeben', released: false), 'titelbild', 1);
$gallery = $this->image('Galeriebild freigegeben', released: true);
$this->cover($this->konflikte(), $gallery, 'galerie', 2);
$this->assertSame(route('website.media', $gallery), $this->card()['image']['url']);
}
public function test_a_film_is_not_used_as_a_cover(): void
{
$film = app(ContentService::class)->createElement('film', 'film', 'Ein Film');
$path = 'website/'.$film->id.'/datei.mp4';
Storage::disk('media_public')->put($path, 'film');
$film->forceFill(['website_released_at' => now(), 'website_public_path' => $path])->save();
$this->cover($this->konflikte(), $film->fresh());
$this->assertNull($this->card()['image']);
}
// ---- Gruppen, Materialart, Symbol ---------------------------------------------------------------------------------
public function test_only_published_pillars_appear_and_the_search_finds_a_tile_by_pillar_or_kind(): void
{
$service = app(PillarService::class);
$open = $service->create('Wertschätzung im Alltag');
$service->present($open, 'Wertschätzung im Alltag', 'wertschaetzung-im-alltag', 'Kurz', true, 10);
$hidden = $service->create('Interne Säule');
$service->present($hidden, 'Interne Säule', 'interne-saeule', null, false, 20);
$service->assign($this->konflikte(), [$open->id, $hidden->id]);
$card = $this->card();
$this->assertSame(['Wertschätzung im Alltag'], $card['pillars']);
$html = $this->get(route('shop'))->assertOk()->getContent();
$this->assertStringContainsString('Wertschätzung im Alltag', $html);
$this->assertStringNotContainsString('Interne Säule', $html);
$this->get(route('shop', ['suche' => 'Wertschätzung']))->assertOk()->assertSee('Konflikte im Training')->assertDontSee('Grenzen setzen im Verein');
$this->get(route('shop', ['suche' => 'Interne']))->assertOk()->assertSee('Keine Treffer');
}
public function test_the_tile_shows_the_kind_and_its_symbol_when_there_is_no_image(): void
{
$kind = EditorialContentKind::query()->where('slug', 'programm')->firstOrFail();
$article = $this->konflikte();
$article->editorial_content_kind_id = $kind->id;
$article->save();
$key = array_key_first(SymbolCatalog::options());
$kind->forceFill(['symbol' => $key])->save();
$card = $this->card();
$this->assertSame($kind->label, $card['kind_label']);
$this->assertSame($key, $card['symbol']);
$this->get(route('shop'))->assertOk()->assertSee($kind->label)->assertSee('shop-tile-symbol', false);
}
public function test_an_unknown_symbol_key_is_ignored(): void
{
$kind = EditorialContentKind::query()->where('slug', 'programm')->firstOrFail();
$article = $this->konflikte();
$article->editorial_content_kind_id = $kind->id;
$article->save();
$kind->forceFill(['symbol' => '../etc/passwd'])->save();
$this->assertNull($this->card()['symbol']);
$this->get(route('shop'))->assertOk()->assertDontSee('shop-tile-symbol', false)->assertDontSee('passwd');
}
public function test_a_symbol_is_stored_with_the_kind_in_the_master_data_and_an_invalid_one_is_dropped(): void
{
$kind = EditorialContentKind::query()->where('slug', 'programm')->firstOrFail();
$key = array_key_first(SymbolCatalog::options());
Livewire::actingAs($this->editor(), 'staff')
->test(RedaktionelleStammdaten::class)
->call('zeigeGruppe', 'materialart')
->callAction(TestAction::make('bearbeiten')->table($kind), ['label' => $kind->label, 'symbol' => $key, 'contexts' => $kind->contexts])
->assertHasNoActionErrors();
$this->assertSame($key, $kind->fresh()->symbol);
Livewire::actingAs($this->editor(), 'staff')
->test(RedaktionelleStammdaten::class)
->call('zeigeGruppe', 'materialart')
->callAction(TestAction::make('bearbeiten')->table($kind), ['label' => $kind->label, 'symbol' => 'gibt-es-nicht', 'contexts' => $kind->contexts]);
$this->assertNotSame('gibt-es-nicht', $kind->fresh()->symbol);
}
// ---- Marker -------------------------------------------------------------------------------------------------------
private function labels(): array
{
return array_column($this->card()['markers'], 'label');
}
public function test_new_is_automatic_for_a_limited_time_after_the_first_offer(): void
{
$this->assertSame(['Neu'], $this->labels());
$this->travel(29)->days();
$this->assertSame(['Neu'], $this->labels());
$this->travel(2)->days();
$this->assertSame([], $this->labels(), 'Nach 30 Tagen verschwindet „Neu“ von selbst.');
}
public function test_updated_appears_for_a_new_stand_and_never_together_with_new(): void
{
$article = $this->konflikte();
$this->travel(40)->days();
$this->assertSame([], $this->labels());
ArticleRelease::query()->whereKey($article->current_release_id)->update(['number' => 2, 'created_at' => now()->subDay()]);
$this->assertSame(['Aktualisiert'], $this->labels());
$this->travel(31)->days();
$this->assertSame([], $this->labels());
}
public function test_the_editorial_setting_overrides_the_automatic_markers_and_popular_is_manual(): void
{
$article = $this->konflikte();
$markers = app(ShopMarkers::class);
$this->travel(60)->days();
$this->assertSame([], $this->labels());
$markers->save($article, ['neu' => 'an', 'aktualisiert' => 'an', 'beliebt' => 'an']);
$this->assertSame(['Neu', 'Aktualisiert', 'Beliebt'], $this->labels());
$markers->save($article->fresh(), ['neu' => 'aus', 'aktualisiert' => 'aus', 'beliebt' => 'aus']);
$this->assertSame([], $this->labels());
$markers->save($article->fresh(), ['neu' => 'auto', 'aktualisiert' => 'auto', 'beliebt' => 'an']);
$this->assertSame(['Beliebt'], $this->labels());
}
public function test_an_unknown_marker_setting_is_refused_and_defaults_apply(): void
{
$article = $this->konflikte();
try {
app(ShopMarkers::class)->save($article, ['neu' => 'vielleicht', 'aktualisiert' => 'auto', 'beliebt' => 'aus']);
$this->fail('Eine unbekannte Einstellung wird abgelehnt.');
} catch (DomainRuleException $exception) {
$this->assertStringContainsString('Neu', $exception->getMessage());
}
$article->forceFill(['shop_markers' => ['neu' => 'kaputt', 'beliebt' => ['x']]])->save();
$this->assertSame(['neu' => 'auto', 'aktualisiert' => 'auto', 'beliebt' => 'aus'], app(ShopMarkers::class)->settings($article->fresh()));
}
public function test_markers_carry_their_word_on_the_tile_and_for_screen_readers(): void
{
$html = $this->get(route('shop'))->assertOk()->getContent();
$this->assertStringContainsString('shop-marker shop-marker-neu', $html);
$this->assertStringContainsString('>Neu</span>', $html);
$this->assertMatchesRegularExpression('#<p class="sr-only">Neu</p>#', $html);
}
public function test_the_article_page_sets_markers_without_touching_the_editorial(): void
{
$article = $this->konflikte();
$article->forceFill(['teaser' => 'Eigener Kurztext bleibt'])->save();
Livewire::actingAs($this->keeper(), 'staff')
->test(ViewLicenseArticle::class, ['record' => $article->getKey()])
->assertSee('Marker auf der Kachel')
->callAction('markers', ['neu' => 'aus', 'aktualisiert' => 'auto', 'beliebt' => 'an'])
->assertHasNoActionErrors();
$article->refresh();
$this->assertSame(['neu' => 'aus', 'aktualisiert' => 'auto', 'beliebt' => 'an'], $article->shop_markers);
$this->assertSame('Eigener Kurztext bleibt', $article->teaser);
$this->assertSame(['Beliebt'], $this->labels());
}
public function test_only_the_catalog_keeper_can_reach_the_marker_action(): void
{
$article = $this->konflikte();
foreach ([User::factory()->create(), $this->editor()] as $user) {
Livewire::actingAs($user, 'staff')
->test(ViewLicenseArticle::class, ['record' => $article->getKey()])
->assertForbidden();
}
$this->assertNull($article->fresh()->shop_markers);
}
// ---- Eine Datenquelle ---------------------------------------------------------------------------------------------
public function test_the_shop_page_and_the_catalog_list_the_same_products_in_the_same_order(): void
{
$titles = array_column(app(ShopCatalog::class)->cards(), 'title');
$html = $this->get(route('shop'))->assertOk()->getContent();
$this->assertNotSame([], $titles);
$last = -1;
foreach ($titles as $title) {
$position = mb_strpos($html, e($title));
$this->assertNotFalse($position, $title.' fehlt auf der Shopseite.');
$this->assertGreaterThan($last, $position);
$last = $position;
}
$this->assertStringContainsString(count($titles).' Produkte', $html);
}
public function test_an_archived_article_and_an_article_without_an_option_are_not_listed(): void
{
$service = app(ArticleService::class);
$draft = $service->create('ohne-option');
$titles = array_column(app(ShopCatalog::class)->cards(), 'key');
$this->assertNotContains('a:'.$draft->id, $titles);
$article = $this->konflikte();
$article->forceFill(['archived_at' => now()])->save();
$this->assertNotContains('a:'.$article->id, array_column(app(ShopCatalog::class)->cards(), 'key'));
}
}