Files
laraundfelix/tests/Feature/CmsWebsiteOnlyFilmCardTest.php
T
LarsandClaude Sonnet 5.5 0022fd50cb
CI Feature / test (push) Successful in 3m52s
Füge Markensymbole und Material-Tags des Brand-Kits hinzu
Stufe 1 und 2 des Vorschlags in KIT_ERGAENZUNG_v2.1_kleingrafiken.md.
- 16 Symbole inline (x-brand.symbol): Titel, ID und feste Größe werden beim
  Einbetten entfernt, aria-hidden, unbekannte Namen sind ein Fehler
- Material-Tags als HTML/CSS (x-brand.tag) mit Zeichen und echtem Text,
  neue Tokens --lf-tag-*, Kontraste gemessen
- MaterialTag ordnet nach Ausgabeklasse und Kennung der redaktionellen Art
  zu, nicht nach Beschriftung; unklare Fälle bleiben Text
- Eingebaut in die öffentliche Premium-Karte für Medien
- brand-rays/-underline und der Mitgliederbereich bleiben unverändert
  (siehe Dokument, Abschnitt 1a)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-23 11:52:21 +01:00

181 lines
7.2 KiB
PHP

<?php
namespace Tests\Feature;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentService;
use App\Domain\Cms\Catalog\PublicMaterialReader;
use App\Domain\Cms\Page;
use App\Domain\Cms\PageRevision;
use App\Domain\Cms\PageService;
use App\Domain\Cms\Widgets\Support\CardClip;
use App\Domain\Cms\Widgets\Support\WebsiteImage;
use App\Domain\Cms\Widgets\WidgetRegistry;
use App\Domain\Media\PresentationFile;
use App\Domain\Media\WebsiteMedia;
use App\Domain\Media\WebsiteRelease;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
/**
* Ein Film, der nur aus einer Website-Datei besteht (Medium ohne Inhaltsfassung, z. B. ein Teaser), ist auf der
* Medienkarte wählbar. Öffentlich erscheint die Karte erst, wenn die Datei für die Website freigegeben ist; ein
* Programm ist dafür nicht nötig, die Karte hat dann keine Aktion.
*/
class CmsWebsiteOnlyFilmCardTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Storage::fake('cms_incoming');
Storage::fake('media_derived');
Storage::fake('media_public');
Storage::fake('media_originals');
}
public function test_a_film_with_only_a_website_file_is_offered_in_the_card_dropdown(): void
{
$teaser = $this->websiteFilm('Teaser Denkpause');
$options = app(PublicMaterialReader::class)->search('Teaser Denk');
$this->assertArrayHasKey($teaser->id, $options);
$this->assertStringContainsString('Website-Datei nicht freigegeben', $options[$teaser->id]);
$this->assertArrayHasKey($teaser->id, app(PublicMaterialReader::class)->search(null), 'Auch ohne Suchbegriff.');
$this->assertTrue(app(PublicMaterialReader::class)->isSelectable($teaser));
}
public function test_the_dropdown_label_says_when_the_file_is_released(): void
{
$teaser = $this->websiteFilm('Teaser Denkpause');
$this->release($teaser);
$options = app(PublicMaterialReader::class)->search('Teaser Denk');
$this->assertStringContainsString('öffentlich mit Website-Datei', $options[$teaser->id]);
}
public function test_the_card_endpoint_accepts_such_a_film_as_its_medium(): void
{
$teaser = $this->websiteFilm('Teaser Denkpause');
$widget = app(WidgetRegistry::class)->get('media_card');
$options = (new \ReflectionMethod($widget, 'rejectSubject'))->invoke($widget, $teaser->id);
$this->assertNull($options, 'Die Auswahl wird nicht mit „archiviert oder gesperrt“ abgelehnt.');
}
public function test_a_released_website_film_shows_publicly_with_its_clip_and_without_an_action(): void
{
$teaser = $this->websiteFilm('Teaser Denkpause');
$this->release($teaser);
$this->publish('/teaser-karte', $teaser);
$html = $this->get('/teaser-karte')->assertOk()->getContent();
$this->assertStringContainsString('Teaser Denkpause', $html);
$this->assertStringContainsString('data-clip-src="'.route('website.media', $teaser).'"', $html, 'Das freigegebene Video ist der Clip der Karte.');
$this->assertStringNotContainsString('lf-pc__cta', $html, 'Ohne Programmseite gibt es keine Aktion.');
$this->assertStringNotContainsString('teaser/', $html);
$this->assertStringNotContainsString('originals/', $html);
}
public function test_a_film_card_shows_its_kind_as_a_film_tag_with_text(): void
{
$teaser = $this->websiteFilm('Teaser Denkpause');
$this->release($teaser);
$this->publish('/teaser-tag', $teaser);
$html = $this->get('/teaser-tag')->assertOk()->getContent();
$this->assertStringContainsString('brand-tag brand-tag--film', $html);
$this->assertMatchesRegularExpression('#<span class="brand-tag__text">\s*Film\s*</span>#', $html, 'Das Tag trägt echten Text.');
$this->assertSame(1, substr_count($html, 'lf-pc__kind--tag'));
}
public function test_an_unreleased_website_film_stays_out_of_the_public_page_but_shows_in_the_preview(): void
{
$teaser = $this->websiteFilm('Teaser Denkpause');
$this->publish('/teaser-nicht-frei', $teaser);
$this->get('/teaser-nicht-frei')->assertOk()->assertDontSee('Teaser Denkpause');
$subject = app(PublicMaterialReader::class)->subject($teaser->id, includeNonPublic: true);
$this->assertNotNull($subject);
$this->assertFalse($subject->public);
$this->assertStringContainsString('nicht für die Website freigegeben', (string) $subject->notice);
}
public function test_withdrawing_the_release_takes_the_card_off_the_public_page(): void
{
$teaser = $this->websiteFilm('Teaser Denkpause');
$this->release($teaser);
$this->publish('/teaser-zurueck', $teaser);
$this->get('/teaser-zurueck')->assertSee('Teaser Denkpause');
app(WebsiteRelease::class)->withdraw($teaser->fresh());
$this->flushScoped();
$this->get('/teaser-zurueck')->assertOk()->assertDontSee('Teaser Denkpause');
}
public function test_an_archived_website_film_is_never_offered(): void
{
$archived = $this->websiteFilm('Archiv Denkpause');
$archived->forceFill(['archived_at' => now()])->save();
$this->assertArrayNotHasKey($archived->id, app(PublicMaterialReader::class)->search('Archiv'));
}
public function test_an_image_without_a_version_is_not_offered_as_medium(): void
{
$path = 'inhalte/bild.jpg';
Storage::disk('cms_incoming')->put($path, 'bild-bytes');
$image = app(ContentService::class)->createElement('bild', 'bild', 'Bild Denkpause');
app(PresentationFile::class)->store($image, $path);
$this->assertArrayNotHasKey($image->id, app(PublicMaterialReader::class)->search('Bild Denk'), 'Nur Filme ohne Fassung zählen als Medium der Karte.');
}
private function websiteFilm(string $title): ContentElement
{
$path = 'inhalte/'.md5($title).'.mp4';
Storage::disk('cms_incoming')->put($path, '0123456789abcdefghij');
$element = app(ContentService::class)->createElement('film', 'film', $title);
$element->display_title = $title;
$element->save();
app(PresentationFile::class)->store($element, $path);
return $element->fresh();
}
private function release(ContentElement $element): void
{
app(WebsiteRelease::class)->release($element->fresh());
$this->flushScoped();
}
private function flushScoped(): void
{
foreach ([WebsiteImage::class, CardClip::class, WebsiteMedia::class, PublicMaterialReader::class] as $class) {
$this->app->forgetInstance($class);
}
}
private function publish(string $path, ContentElement $film): PageRevision
{
$page = Page::query()->create(['path' => $path]);
$service = app(PageService::class);
$revision = $service->saveRevision($page, [['layout' => 'u4', 'style' => [], 'slots' => [
['type' => 'media_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => [], 'data' => [], 'refs' => ['element' => $film->id]],
]]], null, null, null);
$service->publish($page, $revision);
return $revision;
}
}