Bug34Test.php 2.4KB

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