test-mail.php 4.8 KB

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