Neue Einstellung "fullscreen" (Vorgabe: nicht anbieten) an den Kartenwidgets und an Bild und Text. Die Schaltfläche erscheint nur mit freigegebenem Clip und wenn das Gerät Vollbild kann. Im Vollbild gibt es Ton und native Bedienung, Scrollen und Zeiger stoppen den Clip nicht; beim Verlassen kehrt die Karte zum Kartenbild zurück. Gemeinsames Modul resources/js/player/fullscreen.js. iPhone-Weg bisher nur als Logik, Gerätetest steht aus. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
387 lines
19 KiB
PHP
387 lines
19 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Domain\Catalog\ContentElement;
|
|
use App\Domain\Catalog\ContentService;
|
|
use App\Domain\Catalog\EditorialContentKind;
|
|
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\Types\ImageTextWidget;
|
|
use App\Domain\Cms\Widgets\WidgetRegistry;
|
|
use App\Domain\Media\PresentationFile;
|
|
use App\Domain\Media\WebsiteMedia;
|
|
use App\Domain\Media\WebsiteRelease;
|
|
use App\Filament\Resources\Pages\Pages\EditPage;
|
|
use App\Models\User;
|
|
use Filament\Actions\Testing\TestAction;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Bild und Text: Bildanteil, Bild ohne Text und ein Video, das auf dem Bild beim Überfahren und per Klick spielt
|
|
* (CardClip, wie auf der Medienkarte). Öffentlich spielt nur ein für die Website freigegebener Clip.
|
|
*/
|
|
class CmsImageTextMediaTest 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_without_a_share_the_layout_is_unchanged_and_each_share_sets_its_own_class(): void
|
|
{
|
|
$image = $this->image('Foto Pause');
|
|
$this->release($image);
|
|
|
|
$default = $this->publish('/anteil-vorgabe', $this->widget(['body' => '<p>Text</p>'], ['image' => $image->id]));
|
|
$this->assertStringContainsString('class="lf-bt lf-bt--cream lf-bt--image-left lf-bt--height-normal"', $default, 'Ohne Einstellung ändert sich die Darstellung gespeicherter Seiten nicht.');
|
|
$this->assertStringNotContainsString('lf-bt--share', $default);
|
|
|
|
foreach (array_keys(ImageTextWidget::IMAGE_SHARE) as $share) {
|
|
$html = $this->publish('/anteil-'.str_replace('_', '-', $share), $this->widget(['body' => '<p>Text</p>'], ['image' => $image->id], ['image_share' => $share]));
|
|
$this->assertStringContainsString('lf-bt--shared lf-bt--share-'.$share, $html, $share);
|
|
}
|
|
}
|
|
|
|
public function test_the_share_is_ignored_without_image_or_without_text_and_unknown_values_are_rejected(): void
|
|
{
|
|
$image = $this->image('Foto Pause');
|
|
$this->release($image);
|
|
|
|
$noImage = $this->publish('/anteil-ohne-bild', $this->widget(['body' => '<p>Text</p>'], [], ['image_share' => 'half']));
|
|
$this->assertStringNotContainsString('lf-bt--share', $noImage);
|
|
|
|
$noText = $this->publish('/anteil-ohne-text', $this->widget([], ['image' => $image->id], ['image_share' => 'half']));
|
|
$this->assertStringNotContainsString('lf-bt--share', $noText);
|
|
|
|
try {
|
|
app(WidgetRegistry::class)->normalize($this->widget(['body' => '<p>Text</p>'], [], ['image_share' => 'dreiviertel'])[0]['slots']);
|
|
$this->fail('Angenommen: unbekannter Bildanteil');
|
|
} catch (ValidationException $exception) {
|
|
$this->assertStringContainsString('nicht freigegeben', implode(' ', array_merge(...array_values($exception->errors()))));
|
|
}
|
|
|
|
$this->assertNull(ImageTextWidget::imageShare(['image_share' => ['half']]));
|
|
$this->assertSame('third', ImageTextWidget::imageShare(['image_share' => 'third']));
|
|
}
|
|
|
|
public function test_an_image_can_stand_alone_without_any_text(): void
|
|
{
|
|
$image = $this->image('Foto Pause');
|
|
$this->release($image);
|
|
|
|
$html = $this->publish('/nur-bild', $this->widget([], ['image' => $image->id], [], ['alt' => 'Gruppe im Park']));
|
|
|
|
$this->assertStringContainsString('lf-bt--without-text', $html);
|
|
$this->assertStringNotContainsString('lf-bt__copy', $html, 'Ohne Text gibt es keine leere Textspalte.');
|
|
$this->assertStringContainsString('<img class="lf-bt__image" src="'.app(WebsiteMedia::class)->present($image->id)->url.'"', $html);
|
|
$this->assertStringContainsString('alt="Gruppe im Park"', $html);
|
|
$this->assertStringContainsString('srcset="', $html);
|
|
|
|
$normalized = app(WidgetRegistry::class)->normalize($this->widget([], ['image' => $image->id])[0]['slots']);
|
|
$this->assertSame($image->id, $normalized[0]['refs']['image']);
|
|
}
|
|
|
|
public function test_a_widget_with_neither_text_nor_image_is_rejected_but_any_text_part_is_enough_without_image(): void
|
|
{
|
|
try {
|
|
app(WidgetRegistry::class)->normalize($this->widget([])[0]['slots']);
|
|
$this->fail('Angenommen: leeres Widget');
|
|
} catch (ValidationException $exception) {
|
|
$this->assertArrayHasKey('blocks.0.data.body', $exception->errors());
|
|
$this->assertStringContainsString('Text eingeben oder ein Bild wählen', $exception->errors()['blocks.0.data.body'][0]);
|
|
}
|
|
|
|
foreach ([['title' => 'Nur Überschrift'], ['eyebrow' => 'Nur Label'], ['cta_label' => 'Los', 'cta_url' => '/los'], ['body' => '<p>Nur Text</p>']] as $data) {
|
|
$normalized = app(WidgetRegistry::class)->normalize($this->widget($data)[0]['slots']);
|
|
$this->assertNotEmpty($normalized, json_encode($data));
|
|
}
|
|
}
|
|
|
|
public function test_the_released_trailer_plays_on_the_image_on_hover_and_click(): void
|
|
{
|
|
$film = $this->clip('Teaser Pause');
|
|
$image = $this->image('Foto Pause');
|
|
$this->release($film);
|
|
$this->release($image);
|
|
|
|
$html = $this->publish('/bild-video', $this->widget(['body' => '<p>Text</p>'], ['image' => $image->id, 'video' => $film->id]));
|
|
|
|
$this->assertMatchesRegularExpression('~<div class="lf-bt__media"\s+data-card-clip data-clip-src="'.preg_quote(route('website.media', $film), '~').'" data-clip-title="[^"]+"\s*>~', $html);
|
|
$this->assertStringContainsString('<video class="lf-pc__clip" muted loop playsinline preload="none"', $html, 'Stumm, in Schleife, nichts wird vorab geladen.');
|
|
$this->assertDoesNotMatchRegularExpression('/<video[^>]* src=/', $html, 'Die Quelle wird erst beim ersten Start gesetzt.');
|
|
$this->assertStringNotContainsString('autoplay', $html);
|
|
$this->assertStringContainsString('data-clip-toggle', $html, 'Die Schaltfläche steht für Tastatur und Handy bereit.');
|
|
$this->assertStringContainsString('lf-bt__image', $html, 'Das Bild bleibt stehen, bis das Video startet.');
|
|
$this->assertStringNotContainsString('originals/', $html);
|
|
}
|
|
|
|
public function test_fullscreen_for_the_video_is_off_by_default_and_a_per_widget_choice(): void
|
|
{
|
|
$film = $this->clip('Teaser Pause');
|
|
$image = $this->image('Foto Pause');
|
|
$this->release($film);
|
|
$this->release($image);
|
|
$refs = ['image' => $image->id, 'video' => $film->id];
|
|
|
|
$default = $this->publish('/bild-video-vollbild-aus', $this->widget(['body' => '<p>Text</p>'], $refs));
|
|
$on = $this->publish('/bild-video-vollbild', $this->widget(['body' => '<p>Text</p>'], $refs, ['fullscreen' => 'yes']));
|
|
$withoutVideo = $this->publish('/bild-ohne-video-vollbild', $this->widget(['body' => '<p>Text</p>'], ['image' => $image->id], ['fullscreen' => 'yes']));
|
|
|
|
$this->assertStringContainsString('data-card-clip', $default);
|
|
$this->assertStringNotContainsString('data-clip-fullscreen', $default, 'Vorgabe: kein Vollbild, auch für gespeicherte Widgets ohne Wahl.');
|
|
$this->assertStringContainsString('data-clip-fullscreen', $on);
|
|
$this->assertStringContainsString('aria-label="Vollbild: Teaser Pause"', $on);
|
|
$this->assertStringNotContainsString('data-clip-fullscreen', $withoutVideo, 'Ohne freigegebenes Video gibt es kein Vollbild.');
|
|
|
|
$registry = app(WidgetRegistry::class);
|
|
$this->assertSame(['no', 'yes'], array_keys($registry->get('image_text')->settingOptions()['fullscreen']));
|
|
$this->assertContains('fullscreen', $registry->get('image_text')->settingGroups()['Bild und Video']);
|
|
|
|
try {
|
|
$registry->normalize($this->widget(['body' => '<p>Text</p>'], $refs, ['fullscreen' => 'immer'])[0]['slots']);
|
|
$this->fail('Eine unbekannte Vollbild-Wahl wurde angenommen.');
|
|
} catch (ValidationException $exception) {
|
|
$this->assertArrayHasKey('blocks.0.settings.fullscreen', $exception->errors());
|
|
}
|
|
}
|
|
|
|
public function test_an_image_with_a_video_can_also_stand_without_text(): void
|
|
{
|
|
$film = $this->clip('Teaser Pause');
|
|
$image = $this->image('Foto Pause');
|
|
$this->release($film);
|
|
$this->release($image);
|
|
|
|
$html = $this->publish('/bild-video-allein', $this->widget([], ['image' => $image->id, 'video' => $film->id], [], ['alt' => 'Pause']));
|
|
|
|
$this->assertStringContainsString('lf-bt--without-text', $html);
|
|
$this->assertStringContainsString('data-card-clip', $html);
|
|
}
|
|
|
|
public function test_an_unreleased_video_is_not_played_publicly_and_explained_in_the_preview(): void
|
|
{
|
|
$film = $this->clip('Teaser Pause');
|
|
$image = $this->image('Foto Pause');
|
|
$this->release($image);
|
|
|
|
$revision = $this->publishRevision('/bild-video-offen', $this->widget(['body' => '<p>Text</p>'], ['image' => $image->id, 'video' => $film->id]));
|
|
|
|
$public = $this->get('/bild-video-offen')->assertOk()->getContent();
|
|
$this->assertStringNotContainsString('data-card-clip', $public);
|
|
$this->assertStringNotContainsString('<video', $public);
|
|
$this->assertStringNotContainsString('freigegebenes Video', $public, 'Hinweise für die Redaktion erscheinen öffentlich nie.');
|
|
|
|
$preview = $this->actingAs(User::factory()->redakteur()->create(), 'staff')->get(route('pages.preview', $revision))->assertOk()->getContent();
|
|
$this->assertStringNotContainsString('<video', $preview);
|
|
$this->assertStringContainsString('kein für die Website freigegebenes Video', $preview);
|
|
}
|
|
|
|
public function test_withdrawing_the_release_takes_the_video_off_the_page(): void
|
|
{
|
|
$film = $this->clip('Teaser Pause');
|
|
$image = $this->image('Foto Pause');
|
|
$this->release($film);
|
|
$this->release($image);
|
|
$this->publish('/bild-video-zurueck', $this->widget(['body' => '<p>Text</p>'], ['image' => $image->id, 'video' => $film->id]));
|
|
$this->assertStringContainsString('data-card-clip', $this->get('/bild-video-zurueck')->getContent());
|
|
|
|
app(WebsiteRelease::class)->withdraw($film->fresh());
|
|
$this->flushScoped();
|
|
|
|
$this->assertStringNotContainsString('data-card-clip', $this->get('/bild-video-zurueck')->assertOk()->getContent());
|
|
}
|
|
|
|
public function test_a_video_needs_an_image_to_stand_on(): void
|
|
{
|
|
$film = $this->clip('Teaser Pause');
|
|
$this->release($film);
|
|
|
|
try {
|
|
app(WidgetRegistry::class)->normalize($this->widget(['body' => '<p>Text</p>'], ['video' => $film->id])[0]['slots']);
|
|
$this->fail('Angenommen: Video ohne Bild');
|
|
} catch (ValidationException $exception) {
|
|
$this->assertArrayHasKey('blocks.0.refs.image', $exception->errors());
|
|
$this->assertStringContainsString('Bitte auch ein Bild wählen', $exception->errors()['blocks.0.refs.image'][0]);
|
|
}
|
|
}
|
|
|
|
public function test_the_video_choice_is_validated_and_dropped_when_empty(): void
|
|
{
|
|
$film = $this->clip('Teaser Pause');
|
|
$image = $this->image('Foto Pause');
|
|
$archived = $this->clip('Archiv Pause');
|
|
$archived->forceFill(['archived_at' => now()])->save();
|
|
$confidential = $this->publicFilm('traineranleitung');
|
|
$registry = app(WidgetRegistry::class);
|
|
|
|
$normalized = $registry->normalize($this->widget(['body' => '<p>Text</p>'], ['image' => $image->id, 'video' => $film->id])[0]['slots']);
|
|
$this->assertSame($film->id, $normalized[0]['refs']['video']);
|
|
|
|
$without = $registry->normalize($this->widget(['body' => '<p>Text</p>'], ['image' => $image->id, 'video' => null])[0]['slots']);
|
|
$this->assertArrayNotHasKey('video', $without[0]['refs'], 'Ohne Wahl bleibt die gespeicherte Form wie bisher.');
|
|
|
|
foreach (['kein Film' => $image->id, 'archiviert' => $archived->id, 'Traineranleitung' => $confidential->id, 'unbekannt' => 999999] as $case => $id) {
|
|
try {
|
|
$registry->normalize($this->widget(['body' => '<p>Text</p>'], ['image' => $image->id, 'video' => $id])[0]['slots']);
|
|
$this->fail('Angenommen: '.$case);
|
|
} catch (ValidationException $exception) {
|
|
$this->assertArrayHasKey('blocks.0.refs.video', $exception->errors(), $case);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function test_a_video_is_chosen_through_the_shared_picker_which_offers_only_films(): void
|
|
{
|
|
$film = $this->clip('Teaser Pause');
|
|
$image = $this->image('Foto Pause');
|
|
$confidential = $this->publicFilm('traineranleitung');
|
|
$page = Page::query()->firstOrCreate(['path' => '/video-picker']);
|
|
app(PageService::class)->saveRevision($page, $this->widget(['body' => '<p>Text</p>']), null, null, null);
|
|
$editor = User::factory()->redakteur()->create();
|
|
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
|
|
|
$component = Livewire::actingAs($editor, 'staff')->test(EditPage::class, ['record' => $page->id]);
|
|
$sectionKey = array_key_first($component->get('data.sections'));
|
|
$slotKey = array_key_first($component->get("data.sections.$sectionKey.slots"));
|
|
$widgetKey = array_key_first($component->get("data.sections.$sectionKey.slots.$slotKey.widget"));
|
|
$component->mountAction(TestAction::make('edit')->schemaComponent("sections.$sectionKey.slots.$slotKey.widget")->arguments(['item' => $widgetKey]))
|
|
->call('openWebsiteVideoPicker', 'mountedActions.0.data.refs.image')
|
|
->assertSet('pickerOpen', false)
|
|
->call('openWebsiteVideoPicker', 'mountedActions.0.data.refs.video')
|
|
->assertSet('pickerOpen', true)
|
|
->assertSet('pickerPurpose', 'website-video')
|
|
->assertSet('pickerKind', 'film')
|
|
->assertSee('Video aus dem Medienmanager')
|
|
->assertSee('Teaser Pause');
|
|
|
|
$items = collect($component->instance()->pickerResult()['items']);
|
|
$this->assertNotNull($items->firstWhere('element_id', $film->id), 'Der Film erscheint im gemeinsamen Picker.');
|
|
$this->assertNull($items->firstWhere('element_id', $image->id), 'Bilder erscheinen im Videowähler nicht.');
|
|
$this->assertNull($items->firstWhere('element_id', $confidential->id), 'Traineranleitungen sind nicht wählbar.');
|
|
|
|
$component->call('markPicker', $items->firstWhere('element_id', $film->id)['target'], true)
|
|
->call('confirmPicker')
|
|
->assertSet('pickerOpen', false)
|
|
->assertSet('mountedActions.0.data.refs.video', $film->id);
|
|
|
|
// Der Bildwähler bleibt beim Bild.
|
|
$component->call('openWebsiteImagePicker', 'mountedActions.0.data.refs.image')
|
|
->assertSet('pickerPurpose', 'website-bild')
|
|
->assertSet('pickerKind', 'bild');
|
|
}
|
|
|
|
public function test_an_older_saved_widget_without_the_new_fields_renders_as_before(): void
|
|
{
|
|
$html = $this->publish('/bild-text-alt', [['layout' => 'u4', 'style' => [], 'slots' => [
|
|
['type' => 'image_text', 'v' => 3, 'variant' => 'image_right', 'settings' => ['surface' => 'cream'], 'data' => ['title' => 'Alt', 'body' => '<p>Bestand</p>'], 'refs' => ['image' => 'cms/park.jpg']],
|
|
]]]);
|
|
|
|
$this->assertStringContainsString('class="lf-bt lf-bt--cream lf-bt--image-right lf-bt--height-normal"', $html);
|
|
$this->assertStringNotContainsString('data-card-clip', $html);
|
|
$this->assertStringContainsString('<p>Bestand</p>', $html);
|
|
}
|
|
|
|
public function test_the_widget_summary_names_an_image_only_widget(): void
|
|
{
|
|
$widget = app(WidgetRegistry::class)->get('image_text');
|
|
|
|
$this->assertSame('Bild: Gruppe im Park', $widget->summary(['data' => ['alt' => 'Gruppe im Park']]));
|
|
$this->assertSame('Bild', $widget->summary(['data' => []]));
|
|
$this->assertSame('Titel', $widget->summary(['data' => ['title' => 'Titel']]));
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
* @param array<string, mixed> $refs
|
|
* @param array<string, mixed> $settings
|
|
* @return list<array<string, mixed>>
|
|
*/
|
|
private function widget(array $data, array $refs = [], array $settings = [], array $more = []): array
|
|
{
|
|
return [['layout' => 'u4', 'style' => [], 'slots' => [
|
|
['type' => 'image_text', 'v' => 3, 'variant' => 'image_left', 'settings' => $settings, 'data' => $data + $more, 'refs' => $refs],
|
|
]]];
|
|
}
|
|
|
|
/**
|
|
* @param list<array<string, mixed>> $sections
|
|
*/
|
|
private function publishRevision(string $path, array $sections): PageRevision
|
|
{
|
|
$page = Page::query()->create(['path' => $path]);
|
|
$service = app(PageService::class);
|
|
$revision = $service->saveRevision($page, $sections, null, null, null);
|
|
$service->publish($page, $revision);
|
|
|
|
return $revision;
|
|
}
|
|
|
|
/**
|
|
* @param list<array<string, mixed>> $sections
|
|
*/
|
|
private function publish(string $path, array $sections): string
|
|
{
|
|
$this->publishRevision($path, $sections);
|
|
|
|
return $this->get($path)->assertOk()->getContent();
|
|
}
|
|
|
|
private function publicFilm(string $kind = 'unterrichtsfilm'): ContentElement
|
|
{
|
|
$film = app(ContentService::class)->createElement('film', 'film', 'Denkpause Rohschnitt');
|
|
$film->forceFill(['editorial_content_kind_id' => EditorialContentKind::query()->where('slug', $kind)->value('id')])->save();
|
|
|
|
return $film->refresh();
|
|
}
|
|
|
|
private function clip(string $title): ContentElement
|
|
{
|
|
return $this->presentation('film', $title, '0123456789abcdefghij', 'mp4');
|
|
}
|
|
|
|
private function image(string $title): ContentElement
|
|
{
|
|
return $this->presentation('bild', $title, 'bild-bytes', 'jpg');
|
|
}
|
|
|
|
private function presentation(string $output, string $title, string $bytes, string $extension): ContentElement
|
|
{
|
|
$path = 'inhalte/'.md5($title).'.'.$extension;
|
|
Storage::disk('cms_incoming')->put($path, $bytes);
|
|
$element = app(ContentService::class)->createElement($output, $output, $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] as $class) {
|
|
$this->app->forgetInstance($class);
|
|
}
|
|
}
|
|
}
|