Wähle den Kartentext auch an der Programm- und Modulkarte und führe den Filmbild-Regler nach.
- Programm- und Modulkarte: „Text der Karte“ (Automatisch wie bisher: Teaser, sonst Kurzbeschreibung, sonst Lernziel; Teaser, Kurzbeschreibung, Ausführliche Beschreibung, Lernziel der Fassung). Eine ausdrückliche Wahl ersetzt nicht still; die Vorschau nennt, wo der Text zu pflegen ist. Das Vorschaubild des Programms oder Moduls lässt sich als Bild-Medium übernehmen (CompositionStill, additive Tabelle composition_still_sources). - Filmbild im Dialog wie im Medienmanager: Regler und Zahlenfeld zeigen dieselbe Stelle, das Bild folgt dem Regler nach kurzer Pause, „Diese Stelle übernehmen“; das Vorschaubild des Films mit kleiner Ansicht daneben. - Gemeinsame Meldung nach dem tatsächlichen Stand für Film- und Programmbilder. - Test bewusst angepasst: Die Programmkarte hat jetzt eine Textwahl (vorher nur die Medienkarte). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
604e1791c5
commit
3825f53a9b
16 files changed
+641
-47
No files matched your search
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionDisplayRelease;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
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\WidgetRegistry;
|
||||
use App\Domain\Media\CompositionStill;
|
||||
use App\Domain\Media\CompositionStillSource;
|
||||
use App\Domain\Media\WebsiteRelease;
|
||||
use App\Filament\Resources\Pages\Pages\EditPage;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Programm- und Modulkarte: Die Redaktion wählt den Kartentext (Teaser, Kurzbeschreibung, ausführliche Beschreibung,
|
||||
* Lernziel) und kann das Vorschaubild des Programms oder Moduls als Website-Bild übernehmen.
|
||||
*/
|
||||
class CmsProgramCardTextAndImageTest 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');
|
||||
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
||||
}
|
||||
|
||||
public function test_the_card_shows_the_chosen_text_and_the_default_keeps_its_order(): void
|
||||
{
|
||||
$program = $this->program('Programm Selbstvertrauen', [
|
||||
'teaser' => 'TEASER-TEXT',
|
||||
'summary' => 'KURZ-TEXT',
|
||||
'description' => "LANG-TEXT erster Absatz\n\nzweiter Absatz",
|
||||
], goal: 'LERNZIEL-TEXT');
|
||||
|
||||
$this->publish('/programmtext', [
|
||||
$this->card($program, []),
|
||||
$this->card($program, ['text_source' => 'auto']),
|
||||
$this->card($program, ['text_source' => 'teaser']),
|
||||
$this->card($program, ['text_source' => 'summary']),
|
||||
$this->card($program, ['text_source' => 'description']),
|
||||
$this->card($program, ['text_source' => 'goal']),
|
||||
]);
|
||||
|
||||
$cards = $this->cards($this->get('/programmtext')->assertOk()->getContent());
|
||||
$this->assertCount(6, $cards);
|
||||
$this->assertStringContainsString('TEASER-TEXT', $cards[0], 'Automatisch: Teaser vor Kurzbeschreibung, wie bisher.');
|
||||
$this->assertStringContainsString('TEASER-TEXT', $cards[1]);
|
||||
$this->assertStringContainsString('TEASER-TEXT', $cards[2]);
|
||||
$this->assertStringContainsString('KURZ-TEXT', $cards[3]);
|
||||
$this->assertStringNotContainsString('TEASER-TEXT', $cards[3]);
|
||||
$this->assertStringContainsString('LANG-TEXT', $cards[4]);
|
||||
$this->assertStringContainsString('zweiter Absatz', $cards[4]);
|
||||
$this->assertStringContainsString('LERNZIEL-TEXT', $cards[5]);
|
||||
$this->assertStringNotContainsString('LANG-TEXT', $cards[0], 'Die ausführliche Beschreibung erscheint nur auf ausdrückliche Wahl.');
|
||||
$this->assertStringNotContainsString('LANG-TEXT', $cards[3]);
|
||||
}
|
||||
|
||||
public function test_automatic_falls_back_to_summary_then_goal_but_an_explicit_choice_does_not(): void
|
||||
{
|
||||
$withSummary = $this->program('Programm Nur Kurz', ['summary' => 'KURZ-TEXT'], goal: 'LERNZIEL-TEXT');
|
||||
$onlyGoal = $this->program('Programm Nur Lernziel', [], goal: 'LERNZIEL-TEXT');
|
||||
|
||||
$revision = $this->publish('/programmtext-ersatz', [
|
||||
$this->card($withSummary, []),
|
||||
$this->card($onlyGoal, []),
|
||||
$this->card($onlyGoal, ['text_source' => 'teaser']),
|
||||
$this->card($onlyGoal, ['text_source' => 'description']),
|
||||
]);
|
||||
|
||||
$cards = $this->cards($this->get('/programmtext-ersatz')->assertOk()->getContent());
|
||||
$this->assertStringContainsString('KURZ-TEXT', $cards[0]);
|
||||
$this->assertStringContainsString('LERNZIEL-TEXT', $cards[1], 'Automatisch: ohne Teaser und Kurzbeschreibung das Lernziel, wie bisher.');
|
||||
$this->assertStringNotContainsString('lf-pc__summary', $cards[2], 'Gewählter, nicht gepflegter Teaser: kein stiller Ersatz.');
|
||||
$this->assertStringNotContainsString('lf-pc__summary', $cards[3]);
|
||||
|
||||
$public = $this->get('/programmtext-ersatz')->getContent();
|
||||
$this->assertStringNotContainsString('Kein Teaser gepflegt', $public, 'Hinweise erscheinen öffentlich nie.');
|
||||
|
||||
$preview = $this->actingAs(User::factory()->redakteur()->create(), 'staff')->get(route('pages.preview', $revision))->assertOk()->getContent();
|
||||
$this->assertStringContainsString('Kein Teaser gepflegt (Programm oder Modul bearbeiten → Teaser).', $preview);
|
||||
$this->assertStringContainsString('Keine ausführliche Beschreibung gepflegt (Programm oder Modul bearbeiten → Beschreibung).', $preview);
|
||||
}
|
||||
|
||||
public function test_the_text_choice_is_offered_on_the_program_card_only_with_its_own_choices(): void
|
||||
{
|
||||
$registry = app(WidgetRegistry::class);
|
||||
|
||||
$this->assertSame(['auto', 'teaser', 'summary', 'description', 'goal'], array_keys($registry->get('program_card')->settingOptions()['text_source']));
|
||||
$this->assertArrayNotHasKey('text_source', $registry->get('topic_card')->settingOptions(), 'Ein Thema hat nur einen Text.');
|
||||
}
|
||||
|
||||
public function test_the_thumbnail_of_a_program_becomes_one_image_medium_for_the_website(): void
|
||||
{
|
||||
$program = $this->program('Programm Mut', ['summary' => 'x'], thumbnail: true);
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
|
||||
$still = app(CompositionStill::class)->fromThumbnail($program, $editor)->refresh();
|
||||
|
||||
$this->assertSame('bild', $still->output_class);
|
||||
$this->assertSame('Titelbild: Programm Mut', $still->display_title);
|
||||
$this->assertSame('Titelbild zu „Programm Mut“', $still->website_alt);
|
||||
$this->assertSame(0, $still->versions()->count());
|
||||
$this->assertNotNull($still->website_released_at, 'Die Warteschlange gibt das abgeleitete Bild für die Website frei.');
|
||||
$this->assertSame($still->id, CompositionStillSource::query()->where('composition_id', $program->id)->value('still_element_id'));
|
||||
|
||||
$stills = app(CompositionStill::class);
|
||||
$this->assertSame($still->id, $stills->fromThumbnail($program)->id, 'Dasselbe Vorschaubild ergibt dasselbe Medium.');
|
||||
$this->assertTrue($stills->reused);
|
||||
$this->assertSame(1, ContentElement::query()->where('output_class', 'bild')->count());
|
||||
|
||||
$still->forceFill(['thumbnail_error' => 'Die Bilddatei ließ sich nicht lesen.'])->save();
|
||||
$this->assertNotSame($still->id, $stills->fromThumbnail($program)->id, 'Ein gescheitertes Bild wird nicht wiederverwendet.');
|
||||
|
||||
$this->get(route('website.media', $still))->assertOk();
|
||||
$still->delete();
|
||||
$this->assertSame(1, CompositionStillSource::query()->count(), 'Nur die Herkunft des gelöschten Bildes entfällt.');
|
||||
}
|
||||
|
||||
public function test_programs_without_thumbnail_or_archived_yield_no_image(): void
|
||||
{
|
||||
$without = $this->program('Programm Ohne Bild', ['summary' => 'x']);
|
||||
$archived = $this->program('Programm Archiv', ['summary' => 'x'], thumbnail: true);
|
||||
$archived->update(['archived_at' => now()]);
|
||||
|
||||
foreach ([[$without, 'noch kein Vorschaubild'], [$archived, 'archiviert']] as [$composition, $message]) {
|
||||
try {
|
||||
app(CompositionStill::class)->fromThumbnail($composition);
|
||||
$this->fail("Erwartete Ablehnung: $message");
|
||||
} catch (DomainRuleException $exception) {
|
||||
$this->assertStringContainsString($message, $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertSame(0, ContentElement::query()->where('output_class', 'bild')->count());
|
||||
}
|
||||
|
||||
public function test_the_editor_adopts_the_thumbnail_into_the_image_field_and_says_when_the_release_was_withdrawn(): void
|
||||
{
|
||||
$program = $this->program('Programm Park', ['summary' => 'x'], thumbnail: true);
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
$page = Page::query()->create(['path' => '/programmbild-editor']);
|
||||
app(PageService::class)->saveRevision($page, [
|
||||
['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'program_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => [], 'data' => [], 'refs' => ['composition' => $program->id]]]],
|
||||
], null, null, null);
|
||||
$component = Livewire::actingAs($editor, 'staff')->test(EditPage::class, ['record' => $page->id]);
|
||||
|
||||
$component->call('adoptCompositionThumbnail', 'data.ziel.image', $program->id);
|
||||
$still = ContentElement::query()->where('output_class', 'bild')->latest('id')->firstOrFail();
|
||||
$component->assertNotified('Im Medienmanager angelegt: „Titelbild: Programm Park“');
|
||||
$this->assertSame($still->id, $component->get('data.ziel.image'));
|
||||
|
||||
$component->call('adoptCompositionThumbnail', 'data.ziel2.image', $program->id);
|
||||
$component->assertNotified('Bereits im Medienmanager: „Titelbild: Programm Park“');
|
||||
|
||||
app(WebsiteRelease::class)->withdraw($still);
|
||||
$component->call('adoptCompositionThumbnail', 'data.ziel3.image', $program->id);
|
||||
$component->assertNotified('Bild ausgewählt, aber nicht für die Website freigegeben: „Titelbild: Programm Park“');
|
||||
|
||||
$before = ContentElement::query()->count();
|
||||
$component->call('adoptCompositionThumbnail', 'umgebung.geheim', $program->id);
|
||||
$component->call('adoptCompositionThumbnail', 'data.ziel4.bild', $program->id);
|
||||
$component->call('adoptCompositionThumbnail', 'data.ziel5.image', 999999);
|
||||
$this->assertSame($before, ContentElement::query()->count(), 'Fremde Ziele und fehlende Programme legen nichts an.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $texts
|
||||
*/
|
||||
private function program(string $designation, array $texts, ?string $goal = null, bool $thumbnail = false): Composition
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$composition = $content->createComposition($designation);
|
||||
$composition->forceFill(['editorial_content_kind_id' => EditorialContentKind::query()->where('slug', 'programm')->value('id')] + $texts)->save();
|
||||
|
||||
if ($thumbnail) {
|
||||
$composition->forceFill(['thumbnail_path' => 'vorschau/komposition-'.$composition->id.'.jpg', 'thumbnail_source' => 'eigen'])->save();
|
||||
Storage::disk('media_derived')->put($composition->thumbnail_path, $this->jpeg());
|
||||
}
|
||||
|
||||
$version = $content->publishComposition(
|
||||
$composition,
|
||||
[['role' => 'Text', 'target' => $content->publishElementVersion($content->createElement('text', 'text', $designation.' Blatt'), 'Inhalt')]],
|
||||
didactic: $goal !== null ? ['learning_goal' => $goal] : [],
|
||||
);
|
||||
app(CompositionDisplayRelease::class)->release($version, User::factory()->create());
|
||||
|
||||
return $composition->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $settings
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function card(Composition $program, array $settings): array
|
||||
{
|
||||
return ['layout' => 'u4', 'style' => [], 'slots' => [
|
||||
['type' => 'program_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => $settings, 'data' => [], 'refs' => ['composition' => $program->id]],
|
||||
]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $sections
|
||||
*/
|
||||
private function publish(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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function cards(string $html): array
|
||||
{
|
||||
preg_match_all('#<article class="lf-pc .*?</article>#s', $html, $matches);
|
||||
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
private function jpeg(): string
|
||||
{
|
||||
$image = imagecreatetruecolor(800, 450);
|
||||
imagefill($image, 0, 0, imagecolorallocate($image, 20, 80, 150));
|
||||
ob_start();
|
||||
imagejpeg($image);
|
||||
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user