Files
laraundfelix/tests/Feature/DokumentVorlageTest.php
T
LarsandClaude Sonnet 5.5 9f9370dbf8
Deploy Test / test (push) Successful in 3m8s
Deploy Test / deploy (push) Successful in 26s
Erlaube in Kopf und Fuß einer PDF-Vorlage ein Logo links oder rechts
Kopf und Fuß haben je eine Anordnung: Band in voller Seitenbreite (Vorgabe, wie
bisher), Logo links oder Logo rechts am Textrand. Die Logohöhe ist einstellbar
(16 bis 100 Punkt, Vorgabe 40); das Logo ist höchstens halb so breit wie der Text,
der Text beginnt darunter beziehungsweise endet darüber. Die Titelseite bleibt
unberührt. Additive Migration mit Vorgaben; der vorherige Programmstand zeigt jede
Grafik weiter als Band.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-24 16:34:17 +01:00

452 lines
25 KiB
PHP

<?php
namespace Tests\Feature;
use App\Domain\Catalog\ArticleRelease;
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\CompositionVersion;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\DocumentMeta;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\PdfTemplate;
use App\Filament\Pages\PdfVorlagen;
use App\Filament\Resources\Documents\Pages\EditDocument;
use App\Filament\Support\EditorialCatalog;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Tests\Support\BuildsDocuments;
use Tests\TestCase;
/**
* PDF-Vorlagen für Dokumente (ADR-51, Nachtrag): Titelseite mit Ausgabe, Datum und Copyright-Vermerk, grafischer Kopf und Fuß,
* Angaben als Teil der Dokumentfassung und eine Verwaltungsseite für die Vorlagen.
*/
class DokumentVorlageTest extends TestCase
{
use BuildsDocuments;
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Storage::fake('media_derived');
Storage::fake('media_public');
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
}
public function test_a_template_gives_the_title_its_own_cover_page_and_the_other_pages_header_and_footer_graphics(): void
{
$template = $this->template();
[$article, $release, $member, $document] = $this->sold($template, [
'subtitle' => 'Handbuch für Trainerinnen und Trainer',
'edition' => 'Ausgabe 2.1 · Stand Dezember 2026',
'published_on' => '2026-12-01',
'copyright' => 'Alle Rechte beim Herausgeber. Weitergabe nur mit Lizenz.',
]);
$pdf = $this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->assertOk()->getContent();
$pages = $this->pdfPages($pdf);
$images = $this->pdfPageImages($pdf);
// Titelseite: der Titel allein, dann die Angaben der Fassung und der Vorlage, unten der Vermerk.
$this->assertStringContainsString('Trainerhandbuch', $pages[0]);
$this->assertStringContainsString('Handbuch für Trainerinnen und Trainer', $pages[0]);
$this->assertStringContainsString('Ausgabe 2.1 · Stand Dezember 2026', $pages[0]);
$this->assertStringContainsString('Veröffentlicht am 01.12.2026', $pages[0]);
$this->assertStringContainsString('Herausgeber: Lara & Felix', $pages[0]);
$this->assertStringContainsString('Alle Rechte beim Herausgeber.', $pages[0]);
$this->assertStringNotContainsString('Inhaltsverzeichnis', $pages[0]);
$this->assertStringNotContainsString('Grundlagen', $pages[0], 'Kein Kapitel auf der Titelseite.');
$this->assertStringContainsString('Lizenziert für '.$member->name.' · Lizenzkopie LK-', $pages[0], 'Die Kennzeichnung steht auch auf der Titelseite.');
// Inhaltsverzeichnis folgt auf Seite 2; Kapitel beginnen dahinter und das Verzeichnis nennt ihre Seiten.
$this->assertStringContainsString('Inhaltsverzeichnis', $pages[1]);
$this->assertStringContainsString('Seite 2 von '.count($pages), $pages[1]);
$start = collect($pages)->search(fn (string $page, int $index): bool => $index > 1 && str_contains($page, '1 Grundlagen'));
$this->assertMatchesRegularExpression('/1 Grundlagen\\s+\\.{3,}\\s+'.($start + 1).'\\s/', $pages[1]);
// Bilder: Titelseite nur mit ihrem Bild, alle anderen Seiten mit Kopf und Fuß.
$this->assertSame(1, $images[0], 'Die Titelseite trägt nur das Titelbild.');
$this->assertSame(array_fill(0, count($pages) - 1, 2), array_slice($images, 1), 'Jede weitere Seite trägt Kopf und Fuß.');
$this->assertSame(3, substr_count($pdf, '/Subtype /Image'), 'Drei verschiedene Grafiken, jede einmal im Dokument.');
$this->assertStringContainsString($document->composition->display_title ?? 'Trainerhandbuch', $pages[0]);
}
public function test_without_a_template_the_pdf_keeps_its_simple_layout_and_a_cover_can_be_switched_off(): void
{
[$article, $release, $member] = $this->sold(null, ['subtitle' => 'Wird ohne Vorlage nicht gedruckt']);
$plain = $this->pdfPages($this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->getContent());
$this->assertStringContainsString('Trainerhandbuch', $plain[0]);
$this->assertStringContainsString('Inhaltsverzeichnis', $plain[0], 'Ohne Vorlage steht das Verzeichnis wie bisher auf der ersten Seite.');
$this->assertStringNotContainsString('Wird ohne Vorlage nicht gedruckt', implode("\n", $plain));
$template = $this->template(cover: false);
[$article, $release, $member] = $this->sold($template, null);
$pdf = $this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->getContent();
$pages = $this->pdfPages($pdf);
$this->assertStringContainsString('Inhaltsverzeichnis', $pages[0], 'Ohne Titelseite beginnt das Verzeichnis auf Seite 1.');
$this->assertSame(array_fill(0, count($pages), 2), $this->pdfPageImages($pdf), 'Kopf und Fuß stehen auf jeder Seite.');
}
public function test_the_fallback_copyright_of_the_template_is_used_when_the_version_has_none(): void
{
$template = $this->template(copyright: 'Standardvermerk der Vorlage.');
[$article, $release, $member] = $this->sold($template, ['edition' => 'Ausgabe 1']);
$first = $this->pdfPages($this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->getContent())[0];
$this->assertStringContainsString('Standardvermerk der Vorlage.', $first);
}
public function test_the_details_belong_to_the_version_and_a_later_edit_changes_only_the_next_version(): void
{
$document = $this->documentComposition();
$one = $this->document(['Grundlagen' => '<p>Text</p>'], composition: $document, meta: ['edition' => 'Ausgabe 1', 'unbekannt' => 'wird verworfen', 'published_on' => 'kein Datum']);
$two = $this->document(['Grundlagen' => '<p>Text</p>'], composition: $document, meta: ['edition' => 'Ausgabe 2']);
$this->assertSame(['edition' => 'Ausgabe 1'], $one->fresh()->document_meta);
$this->assertSame(['edition' => 'Ausgabe 2'], $two->fresh()->document_meta);
$this->assertNotSame(app(ContentService::class)->structureHash($one->fresh()), app(ContentService::class)->structureHash($two->fresh()), 'Die Angaben ändern den Änderungsnachweis.');
$plain = $this->document(['Grundlagen' => '<p>Text</p>']);
$this->assertNull($plain->fresh()->document_meta);
$this->assertSame($plain->structure_hash, app(ContentService::class)->structureHash($plain->fresh()), 'Ohne Angaben bleibt der Nachweis wie vor den Vorlagen.');
$this->assertNull(DocumentMeta::normalize(['subtitle' => ' ']));
}
public function test_the_editor_saves_the_details_in_the_draft_and_binds_them_with_the_document_version(): void
{
$template = $this->template();
$document = app(EditorialCatalog::class)->create('Trainerhandbuch', CompositionKind::Document);
$component = Livewire::actingAs($this->editor(), 'staff')->test(EditDocument::class, ['record' => $document->getKey()])
->call('addChapter', 1)->call('selectChapter', 0)->set('partTitle', 'Grundlagen')->set('rich.partBody', ['type' => 'doc', 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => 'Text']]]]])
->set('docSubtitle', 'Für Trainer')->set('docEdition', 'Ausgabe 1')->set('docPublished', '2026-12-01')->set('docCopyright', 'Vermerk')
->call('saveDraft');
$this->assertSame(['subtitle' => 'Für Trainer', 'edition' => 'Ausgabe 1', 'published_on' => '2026-12-01', 'copyright' => 'Vermerk'], $document->fresh()->working_draft['document_meta']);
$component->call('armRelease')->set('releaseConsent', true)->call('publishRevision');
$version = $document->versions()->firstOrFail();
$this->assertSame('Ausgabe 1', $version->document_meta['edition']);
// Eine Änderung der Ausgabe allein verlangt eine neue Fassung.
$component->set('docEdition', 'Ausgabe 2')->call('armRelease')->assertSet('releaseArmed', true);
$component->set('releaseConsent', true)->call('publishRevision');
$this->assertSame(['Ausgabe 1', 'Ausgabe 2'], $document->versions()->orderBy('number')->get()->map(fn ($v) => $v->document_meta['edition'])->all());
// Die Vorlage wird sofort zugeordnet und zeigt sich beim erneuten Öffnen.
$component->set('pdfTemplateId', (string) $template->id)->call('savePdfTemplate');
$this->assertSame($template->id, $document->fresh()->pdf_template_id);
$reopened = Livewire::actingAs($this->editor(), 'staff')->test(EditDocument::class, ['record' => $document->getKey()]);
$this->assertSame((string) $template->id, $reopened->get('pdfTemplateId'));
$this->assertSame('Ausgabe 2', $reopened->get('docEdition'));
$component->set('pdfTemplateId', '')->call('savePdfTemplate');
$this->assertNull($document->fresh()->pdf_template_id);
}
public function test_the_template_page_creates_changes_and_deletes_templates_with_images_from_the_picker(): void
{
$header = $this->picture('Kopf', 2480, 300, [20, 80, 60]);
$draftImage = app(ContentService::class)->draftElementVersion(app(ContentService::class)->createElement('bild', 'bild', 'Entwurf'), null, ['file' => $this->store('inhalte/entwurf.png', 1200, 200, [90, 40, 40])]);
$component = Livewire::actingAs($this->editor(), 'staff')->test(PdfVorlagen::class)->assertOk();
$this->assertSame([], $component->instance()->templates());
$component->set('name', 'Handbuch')->set('publisher', 'Lara & Felix')->set('copyright', '© Lara & Felix')
->call('openImagePicker', 'header')->assertSet('pickerPurpose', 'vorlagenbild');
$this->assertSame(['bild' => 'Bilder'], $component->instance()->pickerKinds());
$this->assertContains('Kopf', array_column($component->instance()->pickerResult()['items'], 'title'));
// Gestaltung braucht keine freigegebene Fassung: auch ein Bild im Entwurf lässt sich wählen.
$component->call('markPicker', 'element:'.$draftImage->id, true)->call('confirmPicker')->assertSet('bilder.header', 'element:'.$draftImage->id);
$component->call('openImagePicker', 'header')->call('markPicker', 'element:'.$header->id, true)->call('confirmPicker')->assertSet('bilder.header', 'element:'.$header->id)->assertSet('pickerOpen', false);
$this->assertTrue($component->instance()->changed());
$component->call('save');
$template = PdfTemplate::query()->firstOrFail();
$this->assertSame(['Handbuch', $header->id, true], [$template->name, $template->header_version_id, $template->show_cover]);
$this->assertFalse($component->instance()->changed());
$component->set('showCover', false)->call('clearImage', 'header')->call('save');
$this->assertNull($template->fresh()->header_version_id);
$this->assertFalse($template->fresh()->show_cover);
$this->actingAs($this->editor(), 'staff')->get(route('editorial.pdf-template-preview', $template))->assertOk()->assertHeader('Content-Type', 'application/pdf');
$component->call('askConfirmation', 'delete')->call('confirmConfirmation');
$this->assertSame(0, PdfTemplate::query()->count());
}
public function test_images_without_a_content_version_work_too_presentation_media_and_images_released_for_the_website(): void
{
$presentation = $this->mediumWithoutVersion('Präsentationsbild', [200, 60, 60], released: false);
$web = $this->mediumWithoutVersion('Website-Bild', [60, 60, 200], released: true);
$component = Livewire::actingAs($this->editor(), 'staff')->test(PdfVorlagen::class)->set('name', 'Ohne Fassungen')->call('openImagePicker', 'header');
$titles = array_column($component->instance()->pickerResult()['items'], 'title');
$this->assertContains('Präsentationsbild', $titles, 'Der Picker bietet Bilder ohne Inhaltsfassung an.');
$this->assertContains('Website-Bild', $titles);
$component->call('markPicker', 'medium:'.$presentation->id, true)->call('confirmPicker')->assertSet('bilder.header', 'medium:'.$presentation->id);
$component->call('openImagePicker', 'footer')->call('markPicker', 'medium:'.$web->id, true)->call('confirmPicker')->assertSet('bilder.footer', 'medium:'.$web->id);
$component->call('save');
$template = PdfTemplate::query()->firstOrFail();
$this->assertSame([null, $presentation->id, null, $web->id], [$template->header_version_id, $template->header_element_id, $template->footer_version_id, $template->footer_element_id]);
$this->assertSame(['medium:'.$presentation->id, 'medium:'.$web->id], [$template->target('header'), $template->target('footer')]);
// Beide Bilder stehen im PDF.
[$article, $release, $member] = $this->sold($template, null);
$pdf = $this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->getContent();
$this->assertSame(2, substr_count($pdf, '/Subtype /Image'));
$this->assertNotNull($component->instance()->imageUrl('medium:'.$presentation->id));
$this->assertNotNull($component->instance()->imageUrl('medium:'.$web->id));
}
public function test_a_blocked_image_a_missing_file_and_something_that_is_no_image_are_refused(): void
{
$blocked = $this->picture('Gesperrt', 800, 200);
app(ContentService::class)->block($blocked, 'Rechte');
$noFile = $this->mediumWithoutVersion('Ohne Datei', [1, 1, 1], released: false, file: false);
$film = $this->film('Ein Film');
$component = Livewire::actingAs($this->editor(), 'staff')->test(PdfVorlagen::class)->call('openImagePicker', 'cover');
foreach (['element:'.$blocked->id, 'medium:'.$noFile->id, 'element:'.$film->id] as $target) {
$component->call('markPicker', $target, true)->call('confirmPicker')->assertSet('bilder.cover', null);
$component->call('openImagePicker', 'cover');
}
}
public function test_deleting_a_template_returns_its_documents_to_the_simple_layout(): void
{
$template = $this->template();
$document = $this->documentComposition();
$document->forceFill(['pdf_template_id' => $template->id])->save();
$template->delete();
$this->assertNull($document->fresh()->pdf_template_id);
}
public function test_the_staff_preview_of_a_document_uses_its_template_and_the_draft_details(): void
{
$template = $this->template();
$document = $this->documentComposition();
$document->forceFill(['pdf_template_id' => $template->id, 'working_draft' => ['members' => [], 'document_meta' => ['edition' => 'Entwurfsausgabe 7']]])->save();
$this->document(['Grundlagen' => '<p>Text</p>'], composition: $document);
$document->forceFill(['working_draft' => ['members' => [['role' => 'Kapitel', 'target' => 'element:'.ContentElementVersion::query()->firstOrFail()->id, 'note' => '']], 'document_meta' => ['edition' => 'Entwurfsausgabe 7']]])->save();
$pdf = $this->actingAs($this->editor(), 'staff')->get(route('editorial.document-preview.pdf', $document))->assertOk()->getContent();
$this->assertStringContainsString('Entwurfsausgabe 7', $this->pdfPages($pdf)[0]);
}
public function test_a_logo_stands_left_or_right_at_the_text_margin_with_its_own_height_while_the_default_stays_a_full_width_band(): void
{
$template = PdfTemplate::query()->create([
'name' => 'Mit Logos',
'kind' => PdfTemplate::KIND_DOCUMENT,
'show_cover' => true,
'header_version_id' => $this->picture('Logo oben '.uniqid(), 400, 200, [20, 80, 60])->id,
'header_align' => 'left',
'header_logo_height' => 30,
'footer_version_id' => $this->picture('Logo unten '.uniqid(), 400, 200, [200, 160, 40])->id,
'footer_align' => 'right',
'footer_logo_height' => 50,
]);
[$article, $release, $member] = $this->sold($template, null);
$pdf = $this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->assertOk()->getContent();
$pages = $this->pdfPages($pdf);
$placed = $this->placedImages($pdf);
$this->assertSame([], $placed[0], 'Die Titelseite trägt kein Logo.');
foreach (array_slice($placed, 1) as $page) {
$this->assertCount(2, $page);
[$header, $footer] = $page[0]['y'] > 400 ? [$page[0], $page[1]] : [$page[1], $page[0]];
// Kopf: Logo links am Textrand (56), 30 hoch, 24 unter dem oberen Rand.
$this->assertEqualsWithDelta([60.0, 30.0, 56.0, 842.0 - 24.0 - 30.0], [$header['w'], $header['h'], $header['x'], $header['y']], 0.01);
// Fuß: Logo rechts am Textrand (539), 50 hoch, 14 über dem unteren Rand.
$this->assertEqualsWithDelta([100.0, 50.0, 539.0 - 100.0, 14.0], [$footer['w'], $footer['h'], $footer['x'], $footer['y']], 0.01);
}
$this->assertGreaterThan(1, count($pages));
$this->assertStringContainsString('Inhaltsverzeichnis', $pages[1]);
// Das Band in voller Seitenbreite bleibt die Vorgabe und liegt bündig am Rand.
[$article, $release, $member] = $this->sold($this->template(), null);
$band = $this->placedImages($this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->getContent());
$header = collect($band[1])->firstWhere(fn (array $image): bool => $image['y'] > 400);
$this->assertEqualsWithDelta([595.0, 0.0], [$header['w'], $header['x']], 0.5);
}
public function test_a_wide_logo_never_takes_more_than_half_the_text_width_and_the_text_starts_below_it(): void
{
$template = PdfTemplate::query()->create([
'name' => 'Breites Logo',
'kind' => PdfTemplate::KIND_DOCUMENT,
'show_cover' => false,
'header_version_id' => $this->picture('Breit '.uniqid(), 2480, 300, [20, 80, 60])->id,
'header_align' => 'right',
'header_logo_height' => 100,
]);
[$article, $release, $member] = $this->sold($template, null);
$pdf = $this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->assertOk()->getContent();
$logo = $this->placedImages($pdf)[0][0];
$this->assertEqualsWithDelta((539.0 - 56.0) / 2, $logo['w'], 0.01, 'Höchstens die halbe Textbreite.');
$this->assertEqualsWithDelta(539.0, $logo['x'] + $logo['w'], 0.01, 'Bündig am rechten Textrand.');
$this->assertSame(1, substr_count($pdf, '/Subtype /Image'));
}
public function test_the_layout_values_are_kept_within_their_limits(): void
{
$this->assertSame(['align' => 'full', 'height' => 40], PdfTemplate::normalizeLayout(null, null));
$this->assertSame(['align' => 'full', 'height' => 40], PdfTemplate::normalizeLayout('diagonal', 0));
$this->assertSame(['align' => 'left', 'height' => 16], PdfTemplate::normalizeLayout('left', 3));
$this->assertSame(['align' => 'right', 'height' => 100], PdfTemplate::normalizeLayout('right', '500'));
$template = PdfTemplate::query()->create(['name' => 'Ohne Angaben', 'kind' => PdfTemplate::KIND_DOCUMENT]);
$this->assertSame(['align' => 'full', 'height' => 40], $template->fresh()->layout('header'), 'Die Vorgabe ist das Band in voller Seitenbreite.');
}
public function test_the_template_page_saves_the_arrangement_and_the_logo_height_for_header_and_footer(): void
{
$logo = $this->picture('Logo', 400, 200);
$component = Livewire::actingAs($this->editor(), 'staff')->test(PdfVorlagen::class)
->set('name', 'Logos')
->call('openImagePicker', 'header')->call('markPicker', 'element:'.$logo->id, true)->call('confirmPicker')
->set('anordnung.header', 'left')->set('logohoehe.header', '500')
->set('anordnung.footer', 'right')->set('logohoehe.footer', '24');
$this->assertTrue($component->instance()->changed());
$component->call('save');
$template = PdfTemplate::query()->firstOrFail();
$this->assertSame(['left', 100, 'right', 24], [$template->header_align, $template->header_logo_height, $template->footer_align, $template->footer_logo_height], 'Die Höhe bleibt in den Grenzen.');
$this->assertFalse($component->instance()->changed());
$component->assertSet('anordnung.header', 'left')->assertSet('logohoehe.header', 100);
$component->set('anordnung.header', 'full');
$this->assertTrue($component->instance()->changed());
$component->call('save');
$this->assertSame('full', $template->fresh()->header_align);
// Die Seite zeigt die Auswahl und blendet die Logohöhe nur bei einem Logo ein.
$component->assertSee('Logo links')->assertSee('Logo rechts')->assertSee('Band in voller Seitenbreite')->assertSee('Höhe des Logos');
}
/**
* Die gesetzten Bilder je Seite aus den Inhaltsströmen: Breite, Höhe, linke und untere Kante in Punkt.
*
* @return list<list<array{w: float, h: float, x: float, y: float}>>
*/
private function placedImages(string $pdf): array
{
preg_match_all('/\/Type \/Page \/Parent 2 0 R.*?\/Contents (\d+) 0 R/s', $pdf, $contents);
$pages = [];
foreach ($contents[1] as $object) {
preg_match('/\n'.$object.' 0 obj\n<< \/Length \d+ >>\nstream\n(.*?)endstream/s', $pdf, $stream);
preg_match_all('/q (\S+) 0 0 (\S+) (\S+) (\S+) cm \/Im\d+ Do Q/', $stream[1] ?? '', $matches, PREG_SET_ORDER);
$pages[] = array_map(fn (array $m): array => ['w' => (float) $m[1], 'h' => (float) $m[2], 'x' => (float) $m[3], 'y' => (float) $m[4]], $matches);
}
return $pages;
}
/** Legt eine Bilddatei im abgeleiteten Bestand ab und liefert ihren Pfad. */
private function store(string $path, int $width, int $height, array $rgb): string
{
$image = imagecreatetruecolor($width, $height);
imagefill($image, 0, 0, (int) imagecolorallocate($image, ...$rgb));
ob_start();
imagepng($image);
Storage::disk('media_derived')->put($path, (string) ob_get_clean());
return $path;
}
/**
* Ein Bild ohne Inhaltsfassung: ein Präsentationsmedium (Datei unter `vorschau/`) oder ein für die Website freigegebenes Bild.
*/
private function mediumWithoutVersion(string $title, array $rgb, bool $released, bool $file = true): ContentElement
{
$element = app(ContentService::class)->createElement('bild', 'bild', $title);
if ($file) {
$path = $this->store('vorschau/'.$element->id.'/datei.png', 2480, 240, $rgb);
$element->thumbnail_path = $path;
if ($released) {
Storage::disk('media_public')->put('website/'.$element->id.'/datei.png', (string) Storage::disk('media_derived')->get($path));
$element->website_public_path = 'website/'.$element->id.'/datei.png';
$element->website_released_at = now();
}
}
$element->save();
return $element;
}
/**
* Eine Vorlage mit Kopf-, Fuß- und Titelbild (drei verschiedene Grafiken).
*/
private function template(bool $cover = true, ?string $copyright = null): PdfTemplate
{
return PdfTemplate::query()->create([
'name' => 'Handbuch',
'kind' => PdfTemplate::KIND_DOCUMENT,
'show_cover' => $cover,
'header_version_id' => $this->picture('Kopf '.uniqid(), 2480, 300, [20, 80, 60])->id,
'footer_version_id' => $this->picture('Fuß '.uniqid(), 2480, 200, [200, 160, 40])->id,
'cover_version_id' => $this->picture('Titel '.uniqid(), 1600, 900, [60, 60, 160])->id,
'publisher' => 'Lara & Felix',
'copyright' => $copyright,
]);
}
/**
* Ein Handbuch in einem verkauften Modul, optional mit Vorlage und Angaben.
*
* @param array<string, string>|null $meta
* @return array{0: LicenseArticle, 1: ArticleRelease, 2: User, 3: CompositionVersion}
*/
private function sold(?PdfTemplate $template, ?array $meta): array
{
$composition = $this->documentComposition();
$composition->forceFill(['pdf_template_id' => $template?->id])->save();
$document = $this->document([
'Grundlagen' => '<p>'.str_repeat('Haltung zeigen und Abstand halten. ', 40).'</p>',
'Haltung' => '<p>'.str_repeat('Klar sprechen. ', 50).'</p>',
], composition: $composition, meta: $meta);
$module = $this->moduleWith('Modul Handbuch', $document);
[$article, $release] = $this->publishFor('handbuch-'.uniqid(), $module);
return [$article, $release, $this->memberWith($this->fullRights(), [$article]), $document];
}
private function editor(): User
{
$editor = User::factory()->redakteur()->create();
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $editor;
}
}