|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Eventum (Issue Tracking System) package. |
| 5 | + * |
| 6 | + * @copyright (c) Eventum Team |
| 7 | + * @license GNU General Public License, version 2 or later (GPL-2+) |
| 8 | + * |
| 9 | + * For the full copyright and license information, |
| 10 | + * please see the COPYING and AUTHORS files |
| 11 | + * that were distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Eventum\Test\Mail; |
| 15 | + |
| 16 | +use Eventum\Mail\Helper\MimePart; |
| 17 | +use Eventum\Mail\MailMessage; |
| 18 | +use Eventum\Test\TestCase; |
| 19 | +use Zend\Mail\Header\MessageId; |
| 20 | +use Zend\Mime; |
| 21 | + |
| 22 | +class MimeMessageTest extends TestCase |
| 23 | +{ |
| 24 | + /** @var MailMessage */ |
| 25 | + private $mail; |
| 26 | + |
| 27 | + public function setUp() |
| 28 | + { |
| 29 | + $from = '"Admin User " <[email protected]>'; |
| 30 | + $to = '"Admin User" <[email protected]>'; |
| 31 | + $subject = '[#3] Note: Re: pläh'; |
| 32 | + $message_id = '[email protected]'; |
| 33 | + $date = 'Wed, 19 Jul 2017 18:15:33 GMT'; |
| 34 | + |
| 35 | + $mail = MailMessage::createNew() |
| 36 | + ->setFrom($from) |
| 37 | + ->setSubject($subject) |
| 38 | + ->setTo($to) |
| 39 | + ->setDate($date); |
| 40 | + |
| 41 | + /** @var MessageId $header */ |
| 42 | + $header = $mail->getHeaderByName('Message-Id'); |
| 43 | + $header->setId($message_id); |
| 44 | + |
| 45 | + $this->mail = $mail; |
| 46 | + } |
| 47 | + |
| 48 | + public function testMimeMessageText() |
| 49 | + { |
| 50 | + $body = "Hello, bödi tekst\n\nBye\n"; |
| 51 | + |
| 52 | + $mime = new Mime\Message(); |
| 53 | + $mime->addPart(MimePart::createTextPart($body)); |
| 54 | + $this->mail->setContent($mime); |
| 55 | + |
| 56 | + $exp = []; |
| 57 | + $exp[] = 'Message-ID: <[email protected]>'; |
| 58 | + $exp[] = 'From: "Admin User " <[email protected]>'; |
| 59 | + $exp[] = 'Subject: =?UTF-8?Q?[#3]=20Note:=20Re:=20pl=C3=A4h?='; |
| 60 | + $exp[] = 'To: "Admin User" <[email protected]>'; |
| 61 | + $exp[] = 'Date: Wed, 19 Jul 2017 18:15:33 GMT'; |
| 62 | + $exp[] = 'MIME-Version: 1.0'; |
| 63 | + $exp[] = 'Content-Type: text/plain;'; |
| 64 | + $exp[] = ' charset="UTF-8"'; |
| 65 | + $exp[] = 'Content-Transfer-Encoding: 8bit'; |
| 66 | + $exp[] = ''; |
| 67 | + $exp[] = "Hello, bödi tekst\n\nBye"; |
| 68 | + $this->assertSame($exp, explode("\r\n", $this->mail->getRawContent())); |
| 69 | + } |
| 70 | + |
| 71 | + public function testMimeMessageAttachment() |
| 72 | + { |
| 73 | + $body = "Hello, bödi tekst\n\nBye\n"; |
| 74 | + |
| 75 | + $mime = new Mime\Message(); |
| 76 | + |
| 77 | + $part = MimePart::createTextPart($body); |
| 78 | + $mime->addPart($part); |
| 79 | + |
| 80 | + $part = MimePart::createAttachmentPart('testing123', 'text/plain', 'filename.txt'); |
| 81 | + $mime->addPart($part); |
| 82 | + |
| 83 | + $this->mail->setContent($mime); |
| 84 | + |
| 85 | + $exp = []; |
| 86 | + $exp[] = 'Message-ID: <[email protected]>'; |
| 87 | + $exp[] = 'From: "Admin User " <[email protected]>'; |
| 88 | + $exp[] = 'Subject: =?UTF-8?Q?[#3]=20Note:=20Re:=20pl=C3=A4h?='; |
| 89 | + $exp[] = 'To: "Admin User" <[email protected]>'; |
| 90 | + $exp[] = 'Date: Wed, 19 Jul 2017 18:15:33 GMT'; |
| 91 | + $exp[] = 'MIME-Version: 1.0'; |
| 92 | + $exp[] = 'Content-Type: text/plain;'; |
| 93 | + $exp[] = ' charset="UTF-8"'; |
| 94 | + $exp[] = 'Content-Transfer-Encoding: 8bit'; |
| 95 | + $exp[] = ''; |
| 96 | + $exp[] = "Hello, bödi tekst\n\nBye"; |
| 97 | + $this->assertSame($exp, explode("\r\n", $this->mail->getRawContent())); |
| 98 | + } |
| 99 | +} |
0 commit comments