forked from Hevelop/magento2-patches
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPatch-Magento-Framework-no-sender-in-email-header.patch
136 lines (126 loc) · 4.39 KB
/
Patch-Magento-Framework-no-sender-in-email-header.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
diff --git a/Mail/Message.php b/Mail/Message.php
index 71da6e673bf2..a9996c0a4f12 100644
--- a/Mail/Message.php
+++ b/Mail/Message.php
@@ -23,7 +23,7 @@ class Message implements MailMessageInterface
*
* @var string
*/
- private $messageType = self::TYPE_TEXT;
+ private $messageType = Mime::TYPE_TEXT;
/**
* Initialize dependencies.
@@ -58,8 +58,8 @@ public function setMessageType($type)
*/
public function setBody($body)
{
- if (is_string($body) && $this->messageType === MailMessageInterface::TYPE_HTML) {
- $body = self::createHtmlMimeFromString($body);
+ if (is_string($body)) {
+ $body = self::createMimeFromString($body, $this->messageType);
}
$this->zendMessage->setBody($body);
return $this;
@@ -157,18 +157,19 @@ public function getRawMessage()
}
/**
- * Create HTML mime message from the string.
+ * Create mime message from the string.
*
- * @param string $htmlBody
+ * @param string $body
+ * @param string $messageType
* @return \Zend\Mime\Message
*/
- private function createHtmlMimeFromString($htmlBody)
+ private function createMimeFromString($body, $messageType)
{
- $htmlPart = new Part($htmlBody);
- $htmlPart->setCharset($this->zendMessage->getEncoding());
- $htmlPart->setType(Mime::TYPE_HTML);
+ $part = new Part($body);
+ $part->setCharset($this->zendMessage->getEncoding());
+ $part->setType($messageType);
$mimeMessage = new \Zend\Mime\Message();
- $mimeMessage->addPart($htmlPart);
+ $mimeMessage->addPart($part);
return $mimeMessage;
}
@@ -177,7 +178,7 @@ private function createHtmlMimeFromString($htmlBody)
*/
public function setBodyHtml($html)
{
- $this->setMessageType(self::TYPE_HTML);
+ $this->setMessageType(Mime::TYPE_HTML);
return $this->setBody($html);
}
@@ -186,7 +187,7 @@ public function setBodyHtml($html)
*/
public function setBodyText($text)
{
- $this->setMessageType(self::TYPE_TEXT);
+ $this->setMessageType(Mime::TYPE_TEXT);
return $this->setBody($text);
}
}
diff --git a/Mail/Test/Unit/MessageTest.php b/Mail/Test/Unit/MessageTest.php
index 0c33e25e0d9d..bea2a9ea91d3 100644
--- a/Mail/Test/Unit/MessageTest.php
+++ b/Mail/Test/Unit/MessageTest.php
@@ -5,44 +5,40 @@
*/
namespace Magento\Framework\Mail\Test\Unit;
+/**
+ * test Magento\Framework\Mail\Message
+ */
class MessageTest extends \PHPUnit\Framework\TestCase
{
/**
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Mail\Message
+ * @var \Magento\Framework\Mail\Message
*/
- protected $_messageMock;
+ protected $message;
protected function setUp()
{
- $this->_messageMock = $this->createPartialMock(
- \Magento\Framework\Mail\Message::class,
- ['setBody', 'setMessageType']
- );
+ $this->message = new \Magento\Framework\Mail\Message();
}
public function testSetBodyHtml()
{
- $this->_messageMock->expects($this->once())
- ->method('setMessageType')
- ->with('text/html');
+ $this->message->setBodyHtml('body');
- $this->_messageMock->expects($this->once())
- ->method('setBody')
- ->with('body');
-
- $this->_messageMock->setBodyHtml('body');
+ $part = $this->message->getBody()->getParts()[0];
+ $this->assertEquals('text/html', $part->getType());
+ $this->assertEquals('8bit', $part->getEncoding());
+ $this->assertEquals('utf-8', $part->getCharset());
+ $this->assertEquals('body', $part->getContent());
}
public function testSetBodyText()
{
- $this->_messageMock->expects($this->once())
- ->method('setMessageType')
- ->with('text/plain');
-
- $this->_messageMock->expects($this->once())
- ->method('setBody')
- ->with('body');
+ $this->message->setBodyText('body');
- $this->_messageMock->setBodyText('body');
+ $part = $this->message->getBody()->getParts()[0];
+ $this->assertEquals('text/plain', $part->getType());
+ $this->assertEquals('8bit', $part->getEncoding());
+ $this->assertEquals('utf-8', $part->getCharset());
+ $this->assertEquals('body', $part->getContent());
}
}