Bug35Test.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. require_once 'Swift/Tests/SwiftUnitTestCase.php';
  3. class Swift_Bug35Test extends Swift_Tests_SwiftUnitTestCase
  4. {
  5. public function setUp()
  6. {
  7. Swift_Preferences::getInstance()->setCharset('utf-8');
  8. }
  9. public function testHTMLPartAppearsLastEvenWhenAttachmentsAdded()
  10. {
  11. $message = Swift_Message::newInstance();
  12. $message->setCharset('utf-8');
  13. $message->setSubject('test subject');
  14. $message->addPart('plain part', 'text/plain');
  15. $attachment = Swift_Attachment::newInstance('<data>', 'image.gif', 'image/gif');
  16. $message->attach($attachment);
  17. $message->setBody('HTML part', 'text/html');
  18. $message->setTo(array('user@domain.tld' => 'User'));
  19. $message->setFrom(array('other@domain.tld' => 'Other'));
  20. $message->setSender(array('other@domain.tld' => 'Other'));
  21. $id = $message->getId();
  22. $date = preg_quote(date('r', $message->getDate()), '~');
  23. $boundary = $message->getBoundary();
  24. $this->assertPattern(
  25. '~^' .
  26. 'Sender: Other <other@domain.tld>' . "\r\n" .
  27. 'Message-ID: <' . $id . '>' . "\r\n" .
  28. 'Date: ' . $date . "\r\n" .
  29. 'Subject: test subject' . "\r\n" .
  30. 'From: Other <other@domain.tld>' . "\r\n" .
  31. 'To: User <user@domain.tld>' . "\r\n" .
  32. 'MIME-Version: 1.0' . "\r\n" .
  33. 'Content-Type: multipart/mixed;' . "\r\n" .
  34. ' boundary="' . $boundary . '"' . "\r\n" .
  35. "\r\n\r\n" .
  36. '--' . $boundary . "\r\n" .
  37. 'Content-Type: multipart/alternative;' . "\r\n" .
  38. ' boundary="(.*?)"' . "\r\n" .
  39. "\r\n\r\n" .
  40. '--\\1' . "\r\n" .
  41. 'Content-Type: text/plain; charset=utf-8' . "\r\n" .
  42. 'Content-Transfer-Encoding: quoted-printable' . "\r\n" .
  43. "\r\n" .
  44. 'plain part' .
  45. "\r\n\r\n" .
  46. '--\\1' . "\r\n" .
  47. 'Content-Type: text/html; charset=utf-8' . "\r\n" .
  48. 'Content-Transfer-Encoding: quoted-printable' . "\r\n" .
  49. "\r\n" .
  50. 'HTML part' .
  51. "\r\n\r\n" .
  52. '--\\1--' . "\r\n" .
  53. "\r\n\r\n" .
  54. '--' . $boundary . "\r\n" .
  55. 'Content-Type: image/gif; name=image.gif' . "\r\n" .
  56. 'Content-Transfer-Encoding: base64' . "\r\n" .
  57. 'Content-Disposition: attachment; filename=image.gif' . "\r\n" .
  58. "\r\n" .
  59. preg_quote(base64_encode('<data>'), '~') .
  60. "\r\n\r\n" .
  61. '--' . $boundary . '--' . "\r\n" .
  62. '$~D',
  63. $message->toString()
  64. );
  65. }
  66. }