test-mail.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * Test script for the mail system. Run from CLI:
  5. * php bin/test-mail.php
  6. *
  7. * Generates PDFs and HTML output to verify formatting without sending emails.
  8. */
  9. require dirname(__DIR__) . '/src/autoload.php';
  10. use App\App\Bootstrap;
  11. use App\Form\FormSchema;
  12. use App\Mail\SubmissionFormatter;
  13. use App\Mail\PdfGenerator;
  14. use App\Mail\Mailer;
  15. Bootstrap::init(false);
  16. $submission = [
  17. 'email' => 'max.mustermann@example.org',
  18. 'application_key' => 'test_' . bin2hex(random_bytes(8)),
  19. 'status' => 'submitted',
  20. 'submitted_at' => date('c'),
  21. 'form_data' => [
  22. 'vorname' => 'Max',
  23. 'nachname' => 'Mustermann',
  24. 'geburtsdatum' => '1990-05-15',
  25. 'strasse' => 'Musterstraße 42',
  26. 'plz' => '85354',
  27. 'ort' => 'Freising',
  28. 'telefon' => '01701234567',
  29. 'job' => 'Softwareentwickler',
  30. 'pate' => 'Hans Meier',
  31. 'mitgliedsart' => 'Aktiv',
  32. 'qualifikation_vorhanden' => 'ja',
  33. 'führerschein_vorhanden' => 'b',
  34. 'führerschein_nachweis' => 'Staplerführerschein',
  35. 'bisherige_dienstzeiten' => "Feuerwehr/Hilfsorganisation,von,bis\nFF Moosburg,2015-03-01,2020-12-31\nTHW OV Freising,2021-01-15,2023-06-30",
  36. 'letzter_dienstgrad' => 'Oberfeuerwehrmann',
  37. 'basismodul' => '1',
  38. 'truppführer' => '1',
  39. 'gruppenführer' => '',
  40. 'atemschutzgeräteträger' => '1',
  41. 'gültige_g26' => '1',
  42. 'motorsägenführer' => '',
  43. 'feuerwehrsanitäter' => '1',
  44. 'weitere_lehrgaenge' => 'Erste Hilfe Ausbilder',
  45. 'abzeichen_lösch' => '3',
  46. 'abzeichen_thl' => '2',
  47. 'freier_kommentar' => 'Ich freue mich auf die Zusammenarbeit.',
  48. 'körperliche_eignung' => '1',
  49. 'schwimmer' => '1',
  50. 'einwilligung_datenschutz' => '1',
  51. 'einwilligung_bildrechte' => '1',
  52. ],
  53. 'uploads' => [
  54. 'portraitfoto' => [
  55. [
  56. 'original_filename' => 'bewerbungsfoto.jpg',
  57. 'stored_dir' => 'test/portraitfoto/abc12345',
  58. 'stored_filename' => 'bewerbungsfoto.jpg',
  59. 'relative_path' => 'test/portraitfoto/abc12345/bewerbungsfoto.jpg',
  60. 'mime' => 'image/jpeg',
  61. 'size' => 150000,
  62. ],
  63. ],
  64. 'qualifikationsnachweise' => [
  65. [
  66. 'original_filename' => 'nachweis_truppfuehrer.pdf',
  67. 'stored_dir' => 'test/qualifikationsnachweise/def67890',
  68. 'stored_filename' => 'nachweis_truppfuehrer.pdf',
  69. 'relative_path' => 'test/qualifikationsnachweise/def67890/nachweis_truppfuehrer.pdf',
  70. 'mime' => 'application/pdf',
  71. 'size' => 250000,
  72. ],
  73. ],
  74. ],
  75. ];
  76. echo "=== Testing SubmissionFormatter ===\n\n";
  77. $schema = new FormSchema();
  78. $formatter = new SubmissionFormatter($schema);
  79. $steps = $formatter->getFormattedSteps($submission['form_data']);
  80. foreach ($steps as $step) {
  81. echo "--- " . $step['title'] . " ---\n";
  82. foreach ($step['fields'] as $field) {
  83. echo " " . $field['label'] . ": " . $field['value'] . "\n";
  84. }
  85. echo "\n";
  86. }
  87. $uploads = $formatter->getUploadSummary($submission['uploads']);
  88. echo "--- Uploads ---\n";
  89. foreach ($uploads as $u) {
  90. echo " " . $u['label'] . ": " . $u['filename'] . "\n";
  91. }
  92. echo "\n=== Testing PdfGenerator (Form Data PDF) ===\n\n";
  93. $pdfGen = new PdfGenerator($formatter, $schema);
  94. $formPdf = $pdfGen->generateFormDataPdf($submission);
  95. if ($formPdf !== null) {
  96. echo "Form data PDF generated: " . $formPdf . " (" . filesize($formPdf) . " bytes)\n";
  97. $outputDir = dirname(__DIR__) . '/storage/logs';
  98. $copyPath = $outputDir . '/test_antragsdaten.pdf';
  99. copy($formPdf, $copyPath);
  100. echo "Copied to: " . $copyPath . "\n";
  101. unlink($formPdf);
  102. } else {
  103. echo "ERROR: Form data PDF generation failed.\n";
  104. }
  105. echo "\n=== Testing PdfGenerator (Attachments PDF) ===\n";
  106. echo "(Expected: null or partial - test files don't exist on disk)\n\n";
  107. $attPdf = $pdfGen->generateAttachmentsPdf($submission);
  108. if ($attPdf !== null) {
  109. echo "Attachments PDF generated: " . $attPdf . " (" . filesize($attPdf) . " bytes)\n";
  110. unlink($attPdf);
  111. } else {
  112. echo "No attachments PDF (expected: test upload files don't exist on disk).\n";
  113. }
  114. echo "\n=== Testing Mailer HTML Rendering ===\n\n";
  115. $mailer = new Mailer();
  116. $ref = new \ReflectionClass($mailer);
  117. $adminMethod = $ref->getMethod('renderAdminHtml');
  118. $adminMethod->setAccessible(true);
  119. $adminHtml = $adminMethod->invoke($mailer, $submission, true, true);
  120. $outputDir = dirname(__DIR__) . '/storage/logs';
  121. file_put_contents($outputDir . '/test_admin_email.html', $adminHtml);
  122. echo "Admin HTML saved to: " . $outputDir . "/test_admin_email.html\n";
  123. $applicantMethod = $ref->getMethod('renderApplicantHtml');
  124. $applicantMethod->setAccessible(true);
  125. $applicantHtml = $applicantMethod->invoke($mailer, $submission);
  126. file_put_contents($outputDir . '/test_applicant_email.html', $applicantHtml);
  127. echo "Applicant HTML saved to: " . $outputDir . "/test_applicant_email.html\n";
  128. echo "\nDone. Check the generated files in storage/logs/.\n";