billing: Veröffentlichungsnachweis mit Titelbild, Bildrechten und Rich-Text
Der Nachweis-PDF bindet nun das Titelbild der PM kompakt oben ein – links das Bild mit den beim Upload erfassten Bildrechten (Copyright, Urheber, Lizenz, Quelle, KI-Kennzeichnung), rechts daneben die Angaben zur Veröffentlichung als Tabelle. Der Volltext übernimmt Fett-/Kursiv- Formatierung (F2/F3/F4), und Fortsetzungsseiten beginnen den Inhalt mit Abstand unterhalb des Seitenrands statt direkt am Seitenanfang. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
b8e273577d
commit
50d9208ca9
2 changed files with 851 additions and 46 deletions
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\ImageLicenseType;
|
||||
use App\Enums\Portal;
|
||||
use App\Enums\PressReleaseStatus;
|
||||
use App\Enums\SinglePurchaseStatus;
|
||||
|
|
@ -16,6 +17,7 @@ use App\Services\Billing\ExtraPmPurchaseService;
|
|||
use App\Services\Billing\ProofPdfService;
|
||||
use App\Services\PressRelease\ProofPdfRenderer;
|
||||
use Database\Seeders\RolesAndPermissionsSeeder;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
beforeEach(function (): void {
|
||||
$this->seed(RolesAndPermissionsSeeder::class);
|
||||
|
|
@ -145,6 +147,94 @@ test('a long release flows over multiple numbered pages', function () {
|
|||
expect($pdf)->toContain('Fortsetzung');
|
||||
});
|
||||
|
||||
test('continuation pages start their content below the page top', function () {
|
||||
$pr = PressRelease::factory()->published()->create([
|
||||
'title' => 'Lange Meldung',
|
||||
'text' => implode('', array_map(
|
||||
static fn (int $i): string => '<p>Absatz '.$i.': '.str_repeat('Dies ist ein ausfuehrlicher Beispielsatz. ', 12).'</p>',
|
||||
range(1, 12),
|
||||
)),
|
||||
]);
|
||||
|
||||
$pdf = app(ProofPdfRenderer::class)->render($pr);
|
||||
|
||||
// Content-Streams in Dokumentreihenfolge extrahieren (Seite 1, 2, …).
|
||||
preg_match_all('/stream\n(.*?)endstream/s', $pdf, $matches);
|
||||
expect(count($matches[1]))->toBeGreaterThanOrEqual(2);
|
||||
|
||||
// Jede Fortsetzungsseite (ab Seite 2) darf ihren Inhalt nicht direkt am
|
||||
// Seitenrand beginnen — die erste Textposition liegt spürbar tiefer.
|
||||
foreach (array_slice($matches[1], 1) as $continuationStream) {
|
||||
preg_match('/(-?\d+\.\d+) (-?\d+\.\d+) Td/', $continuationStream, $firstTd);
|
||||
|
||||
expect((float) $firstTd[2])->toBeLessThanOrEqual(760.0);
|
||||
}
|
||||
});
|
||||
|
||||
test('a release with a title image embeds it as an image xobject', function () {
|
||||
Storage::fake('local');
|
||||
|
||||
$canvas = imagecreatetruecolor(600, 400);
|
||||
imagefilledrectangle($canvas, 0, 0, 600, 400, imagecolorallocate($canvas, 30, 60, 120));
|
||||
ob_start();
|
||||
imagejpeg($canvas);
|
||||
$jpeg = (string) ob_get_clean();
|
||||
imagedestroy($canvas);
|
||||
|
||||
$pr = PressRelease::factory()->published()->create(['title' => 'Meldung mit Bild']);
|
||||
|
||||
$path = 'press-releases/'.$pr->id.'/images/foto.jpg';
|
||||
Storage::disk('local')->put($path, $jpeg);
|
||||
|
||||
$pr->images()->create([
|
||||
'disk' => 'local',
|
||||
'path' => $path,
|
||||
'copyright' => 'Foto: Jane Doe',
|
||||
'author' => 'Jane Doe',
|
||||
'license_type' => ImageLicenseType::Own->value,
|
||||
'source_url' => 'https://example.com/bildquelle',
|
||||
'is_preview' => true,
|
||||
'sort_order' => 1,
|
||||
]);
|
||||
|
||||
$pdf = app(ProofPdfRenderer::class)->render($pr);
|
||||
|
||||
expect($pdf)
|
||||
->toContain('/Subtype /Image')
|
||||
->toContain('/Filter /DCTDecode')
|
||||
->toContain('/XObject <<')
|
||||
->toContain(' Do Q')
|
||||
// Rechtliche Bildangaben aus dem Upload unter dem Bild.
|
||||
->toContain('Bildnachweis: Foto: Jane Doe')
|
||||
->toContain('Lizenz: Eigene Aufnahme')
|
||||
->toContain('Quelle: https://example.com/bildquelle');
|
||||
});
|
||||
|
||||
test('a release without a title image embeds no image xobject', function () {
|
||||
$pr = PressRelease::factory()->published()->create(['title' => 'Meldung ohne Bild']);
|
||||
|
||||
$pdf = app(ProofPdfRenderer::class)->render($pr);
|
||||
|
||||
expect($pdf)->not->toContain('/Subtype /Image');
|
||||
});
|
||||
|
||||
test('rich text keeps bold and italic formatting', function () {
|
||||
$pr = PressRelease::factory()->published()->create([
|
||||
'title' => 'Formatierte Meldung',
|
||||
'text' => '<p>Ein <strong>fetterText</strong> und <em>kursiverText</em> sowie <strong><em>beidesText</em></strong> hier.</p>',
|
||||
]);
|
||||
|
||||
$pdf = app(ProofPdfRenderer::class)->render($pr);
|
||||
|
||||
// Fett → Helvetica-Bold (F2), kursiv → Helvetica-Oblique (F3),
|
||||
// fett+kursiv → Helvetica-BoldOblique (F4).
|
||||
expect($pdf)
|
||||
->toMatch('#/F2 [0-9.]+ Tf[^)]*\(fetterText\)#')
|
||||
->toMatch('#/F3 [0-9.]+ Tf[^)]*\(kursiverText\)#')
|
||||
->toMatch('#/F4 [0-9.]+ Tf[^)]*\(beidesText\)#')
|
||||
->toContain('/BaseFont /Helvetica-BoldOblique');
|
||||
});
|
||||
|
||||
test('the rendered proof documents the real public url of the release', function () {
|
||||
$pr = PressRelease::factory()->published()->create([
|
||||
'portal' => Portal::Presseecho,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue