- Patch-/Minor-Updates (guzzle, commonmark, flysystem, excel, phpspreadsheet, phpseclib, laravel/framework 11.x) - barryvdh/laravel-dompdf 3.1 (dompdf 3.1.6), Test fuer den PDF-Weg inkl. eingebettetem PHP und Briefpapier - Rueckport des Laravel-12.60-Fixes gegen CRLF in der email-Regel - Protokoll: Ergebnis composer audit, offene Punkte Laravel 12 und PDF-Seitenzahlen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.1 KiB
PHP
62 lines
2.1 KiB
PHP
<?php
|
|
|
|
use App\Libraries\InvoicePDF;
|
|
use App\Libraries\MyPDFMerger;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\View;
|
|
use setasign\Fpdi\Fpdi;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class);
|
|
|
|
/**
|
|
* Rechnungen, Lieferscheine und Gutschriften laufen über dompdf mit
|
|
* eingebettetem PHP (Seitenzahlen per page_script/page_text) und werden
|
|
* anschließend mit FPDI auf das Briefpapier gelegt. Schützt diesen Weg bei
|
|
* Updates von dompdf oder FPDI.
|
|
*
|
|
* page_script wirkt nur auf Seiten, die beim Aufruf schon gerendert sind —
|
|
* das Skript muss deshalb am Ende des <body> stehen (wie in credit_details).
|
|
*/
|
|
beforeEach(function () {
|
|
$this->pdfDir = storage_path('framework/testing/pdf-pipeline-'.uniqid()).'/';
|
|
File::ensureDirectoryExists($this->pdfDir);
|
|
View::addLocation($this->pdfDir);
|
|
|
|
File::put($this->pdfDir.'pdf-probe.blade.php', <<<'BLADE'
|
|
<html><body>
|
|
<p>Seite eins</p>
|
|
<div style="page-break-before: always;">Seite zwei</div>
|
|
<script type="text/php">
|
|
if (isset($pdf)) {
|
|
$pdf->page_script('$GLOBALS["pdfProbePages"][] = $PAGE_NUM."/".$PAGE_COUNT;');
|
|
}
|
|
</script>
|
|
</body></html>
|
|
BLADE);
|
|
|
|
$GLOBALS['pdfProbePages'] = [];
|
|
});
|
|
|
|
afterEach(function () {
|
|
File::deleteDirectory($this->pdfDir);
|
|
unset($GLOBALS['pdfProbePages']);
|
|
});
|
|
|
|
test('embedded php runs on every page of an invoice pdf', function () {
|
|
$file = (new InvoicePDF('pdf-probe'))->create([], 'probe.pdf', 'save', $this->pdfDir);
|
|
|
|
expect($file)->toBe($this->pdfDir.'probe.pdf')
|
|
->and(file_get_contents($file))->toStartWith('%PDF')
|
|
->and($GLOBALS['pdfProbePages'])->toBe(['1/2', '2/2']);
|
|
});
|
|
|
|
test('the rendered pdf can be laid onto the letterhead template', function () {
|
|
$file = (new InvoicePDF('pdf-probe'))->create([], 'probe.pdf', 'save', $this->pdfDir);
|
|
|
|
$merged = (new MyPDFMerger)->addPDF($file)->myMerge('string', 'probe.pdf', 'template_invoice_de');
|
|
File::put($this->pdfDir.'merged.pdf', $merged);
|
|
|
|
expect($merged)->toStartWith('%PDF')
|
|
->and((new Fpdi)->setSourceFile($this->pdfDir.'merged.pdf'))->toBe(2);
|
|
});
|