test-mail.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * CLI test script for mail rendering and PDF generation.
  4. * Run: php bin/test-mail.php
  5. *
  6. * Writes output files to storage/logs/ for inspection.
  7. * Does NOT send actual emails.
  8. */
  9. declare(strict_types=1);
  10. require_once __DIR__ . '/../src/autoload.php';
  11. use App\App\Bootstrap;
  12. use App\Form\FormSchema;
  13. use App\Mail\SubmissionFormatter;
  14. use App\Mail\PdfGenerator;
  15. Bootstrap::init(false);
  16. $submission = [
  17. 'email' => 'test@example.org',
  18. 'submitted_at' => date('c'),
  19. 'application_key' => 'test-' . bin2hex(random_bytes(4)),
  20. 'form_data' => [
  21. 'vorname' => 'Max',
  22. 'nachname' => 'Mustermann',
  23. 'geburtsdatum' => '1990-05-15',
  24. 'strasse' => 'Musterstraße 12',
  25. 'plz' => '85354',
  26. 'ort' => 'Freising',
  27. 'telefon' => '01234567890',
  28. 'job' => 'Ingenieur',
  29. 'pate' => 'Hans Meier',
  30. 'mitgliedsart' => 'Aktiv',
  31. 'qualifikation_vorhanden' => 'ja',
  32. 'führerschein_vorhanden' => 'b',
  33. 'führerschein_nachweis' => 'Stapler',
  34. 'bisherige_dienstzeiten' => [
  35. ['FF Musterstadt', '2015-01-01', '2020-12-31'],
  36. ['THW OV Freising', '2021-03-01', ''],
  37. ],
  38. 'letzter_dienstgrad' => 'Oberfeuerwehrmann',
  39. 'basismodul' => '1',
  40. 'truppführer' => '1',
  41. 'gruppenführer' => '0',
  42. 'atemschutzgeräteträger' => '1',
  43. 'gültige_g26' => '1',
  44. 'motorsägenführer' => '0',
  45. 'feuerwehrsanitäter' => '0',
  46. 'weitere_lehrgaenge' => 'Sprechfunk, ABC-Einsatz',
  47. 'abzeichen_lösch' => '3',
  48. 'abzeichen_thl' => '2',
  49. 'freier_kommentar' => 'Ich freue mich auf die Zusammenarbeit!',
  50. 'körperliche_eignung' => '1',
  51. 'schwimmer' => '1',
  52. 'einwilligung_datenschutz' => '1',
  53. 'einwilligung_bildrechte' => '1',
  54. ],
  55. 'uploads' => [
  56. 'portraitfoto' => [
  57. [
  58. 'original_filename' => 'portrait.jpg',
  59. 'stored_dir' => 'portraitfoto/abc12345',
  60. 'stored_filename' => 'portrait.jpg',
  61. ],
  62. ],
  63. 'qualifikationsnachweise' => [
  64. [
  65. 'original_filename' => 'zeugnis_truppfuehrer.pdf',
  66. 'stored_dir' => 'qualifikationsnachweise/def67890',
  67. 'stored_filename' => 'zeugnis_truppfuehrer.pdf',
  68. ],
  69. [
  70. 'original_filename' => 'lehrgang_foto.jpg',
  71. 'stored_dir' => 'qualifikationsnachweise/ghi11111',
  72. 'stored_filename' => 'lehrgang_foto.jpg',
  73. ],
  74. ],
  75. ],
  76. ];
  77. echo "=== SubmissionFormatter test ===\n";
  78. $schema = new FormSchema();
  79. $formatter = new SubmissionFormatter($schema);
  80. $steps = $formatter->formatSteps($submission);
  81. foreach ($steps as $step) {
  82. echo "\n[" . $step['title'] . "]\n";
  83. foreach ($step['fields'] as $f) {
  84. echo " " . $f['label'] . ': ' . $f['value'] . "\n";
  85. }
  86. }
  87. $uploads = $formatter->formatUploads($submission);
  88. echo "\n[Uploads]\n";
  89. foreach ($uploads as $group) {
  90. foreach ($group['files'] as $name) {
  91. echo " " . $group['label'] . ': ' . $name . "\n";
  92. }
  93. }
  94. echo "\n=== PdfGenerator test ===\n";
  95. $pdfGen = new PdfGenerator($formatter, $schema);
  96. $formPdf = $pdfGen->generateFormDataPdf($submission);
  97. if ($formPdf !== null) {
  98. $dest = Bootstrap::rootPath() . '/storage/logs/test_antragsdaten.pdf';
  99. copy($formPdf, $dest);
  100. unlink($formPdf);
  101. echo "Form data PDF: $dest (" . filesize($dest) . " bytes)\n";
  102. } else {
  103. echo "Form data PDF: FAILED\n";
  104. }
  105. $attPdf = $pdfGen->generateAttachmentsPdf($submission);
  106. if ($attPdf !== null) {
  107. $dest = Bootstrap::rootPath() . '/storage/logs/test_anlagen.pdf';
  108. copy($attPdf, $dest);
  109. unlink($attPdf);
  110. echo "Attachments PDF: $dest (" . filesize($dest) . " bytes)\n";
  111. } else {
  112. echo "Attachments PDF: none (no image uploads to compile)\n";
  113. }
  114. $pdfAtts = $pdfGen->collectPdfAttachments($submission);
  115. echo "PDF attachments for separate email: " . count($pdfAtts) . "\n";
  116. foreach ($pdfAtts as $att) {
  117. echo " - " . $att['filename'] . " (" . $att['path'] . ")\n";
  118. }
  119. echo "\n=== Admin HTML rendering test ===\n";
  120. $mailer = new \App\Mail\Mailer();
  121. $rc = new ReflectionClass($mailer);
  122. $method = $rc->getMethod('renderAdminHtml');
  123. $method->setAccessible(true);
  124. $html = $method->invoke($mailer, $submission);
  125. $htmlDest = Bootstrap::rootPath() . '/storage/logs/test_admin_mail.html';
  126. file_put_contents($htmlDest, $html);
  127. echo "Admin HTML: $htmlDest (" . strlen($html) . " bytes)\n";
  128. $method2 = $rc->getMethod('renderApplicantHtml');
  129. $method2->setAccessible(true);
  130. $html2 = $method2->invoke($mailer, $submission);
  131. $htmlDest2 = Bootstrap::rootPath() . '/storage/logs/test_applicant_mail.html';
  132. file_put_contents($htmlDest2, $html2);
  133. echo "Applicant HTML: $htmlDest2 (" . strlen($html2) . " bytes)\n";
  134. echo "\nDone.\n";