| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- /**
- * CLI test script for mail rendering and PDF generation.
- * Run: php admin/test-mail.php
- *
- * Writes output files to storage/logs/ for inspection.
- * Does NOT send actual emails.
- */
- declare(strict_types=1);
- if (PHP_SAPI !== 'cli') {
- http_response_code(403);
- exit('Forbidden');
- }
- require_once __DIR__ . '/../src/autoload.php';
- use App\App\Bootstrap;
- use App\Form\FormSchema;
- use App\Mail\SubmissionFormatter;
- use App\Mail\PdfGenerator;
- Bootstrap::init(false);
- $submission = [
- 'email' => 'test@example.org',
- 'submitted_at' => date('c'),
- 'application_key' => 'test-' . bin2hex(random_bytes(4)),
- 'form_data' => [
- 'vorname' => 'Max',
- 'nachname' => 'Mustermann',
- 'geburtsdatum' => '1990-05-15',
- 'strasse' => 'Musterstraße 12',
- 'plz' => '85354',
- 'ort' => 'Freising',
- 'telefon' => '01234567890',
- 'job' => 'Ingenieur',
- 'pate' => 'Hans Meier',
- 'mitgliedsart' => 'Aktiv',
- 'qualifikation_vorhanden' => 'ja',
- 'führerschein_vorhanden' => 'b',
- 'führerschein_nachweis' => 'Stapler',
- 'bisherige_dienstzeiten' => [
- ['FF Musterstadt', '2015-01-01', '2020-12-31'],
- ['THW OV Freising', '2021-03-01', ''],
- ],
- 'letzter_dienstgrad' => 'Oberfeuerwehrmann',
- 'basismodul' => '1',
- 'truppführer' => '1',
- 'gruppenführer' => '0',
- 'atemschutzgeräteträger' => '1',
- 'gültige_g26' => '1',
- 'motorsägenführer' => '0',
- 'feuerwehrsanitäter' => '0',
- 'weitere_lehrgaenge' => 'Sprechfunk, ABC-Einsatz',
- 'abzeichen_lösch' => '3',
- 'abzeichen_thl' => '2',
- 'freier_kommentar' => 'Ich freue mich auf die Zusammenarbeit!',
- 'körperliche_eignung' => '1',
- 'schwimmer' => '1',
- 'einwilligung_datenschutz' => '1',
- 'einwilligung_bildrechte' => '1',
- ],
- 'uploads' => [
- 'portraitfoto' => [
- [
- 'original_filename' => 'portrait.jpg',
- 'stored_dir' => 'portraitfoto/abc12345',
- 'stored_filename' => 'portrait.jpg',
- ],
- ],
- 'qualifikationsnachweise' => [
- [
- 'original_filename' => 'zeugnis_truppfuehrer.pdf',
- 'stored_dir' => 'qualifikationsnachweise/def67890',
- 'stored_filename' => 'zeugnis_truppfuehrer.pdf',
- ],
- [
- 'original_filename' => 'lehrgang_foto.jpg',
- 'stored_dir' => 'qualifikationsnachweise/ghi11111',
- 'stored_filename' => 'lehrgang_foto.jpg',
- ],
- ],
- ],
- ];
- echo "=== SubmissionFormatter test ===\n";
- $schema = new FormSchema();
- $formatter = new SubmissionFormatter($schema);
- $steps = $formatter->formatSteps($submission);
- foreach ($steps as $step) {
- echo "\n[" . $step['title'] . "]\n";
- foreach ($step['fields'] as $f) {
- echo " " . $f['label'] . ': ' . $f['value'] . "\n";
- }
- }
- $uploads = $formatter->formatUploads($submission);
- echo "\n[Uploads]\n";
- foreach ($uploads as $group) {
- foreach ($group['files'] as $name) {
- echo " " . $group['label'] . ': ' . $name . "\n";
- }
- }
- echo "\n=== PdfGenerator test ===\n";
- $pdfGen = new PdfGenerator($formatter, $schema);
- $formPdf = $pdfGen->generateFormDataPdf($submission);
- if ($formPdf !== null) {
- $dest = Bootstrap::rootPath() . '/storage/logs/test_antragsdaten.pdf';
- copy($formPdf, $dest);
- unlink($formPdf);
- echo "Form data PDF: $dest (" . filesize($dest) . " bytes)\n";
- } else {
- echo "Form data PDF: FAILED\n";
- }
- $attPdf = $pdfGen->generateAttachmentsPdf($submission);
- if ($attPdf !== null) {
- $dest = Bootstrap::rootPath() . '/storage/logs/test_anlagen.pdf';
- copy($attPdf, $dest);
- unlink($attPdf);
- echo "Attachments PDF: $dest (" . filesize($dest) . " bytes)\n";
- } else {
- echo "Attachments PDF: none (no image uploads to compile)\n";
- }
- $pdfAtts = $pdfGen->collectPdfAttachments($submission);
- echo "PDF attachments for separate email: " . count($pdfAtts) . "\n";
- foreach ($pdfAtts as $att) {
- echo " - " . $att['filename'] . " (" . $att['path'] . ")\n";
- }
- echo "\n=== Admin HTML rendering test ===\n";
- $mailer = new \App\Mail\Mailer();
- $rc = new ReflectionClass($mailer);
- $method = $rc->getMethod('renderAdminHtml');
- $method->setAccessible(true);
- $html = $method->invoke($mailer, $submission);
- $htmlDest = Bootstrap::rootPath() . '/storage/logs/test_admin_mail.html';
- file_put_contents($htmlDest, $html);
- echo "Admin HTML: $htmlDest (" . strlen($html) . " bytes)\n";
- $method2 = $rc->getMethod('renderApplicantHtml');
- $method2->setAccessible(true);
- $html2 = $method2->invoke($mailer, $submission);
- $htmlDest2 = Bootstrap::rootPath() . '/storage/logs/test_applicant_mail.html';
- file_put_contents($htmlDest2, $html2);
- echo "Applicant HTML: $htmlDest2 (" . strlen($html2) . " bytes)\n";
- echo "\nDone.\n";
|