Skip to content

Commit 2448b3a

Browse files
ENGCOM-6001: 2.3.3 Fix multiple copy to email recipients #24855
2 parents bb871c5 + 4c79404 commit 2448b3a

File tree

2 files changed

+58
-47
lines changed

2 files changed

+58
-47
lines changed

app/code/Magento/Sales/Model/Order/Email/SenderBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ public function sendCopyTo()
8585
$copyTo = $this->identityContainer->getEmailCopyTo();
8686

8787
if (!empty($copyTo)) {
88-
$this->configureEmailTemplate();
8988
foreach ($copyTo as $email) {
89+
$this->configureEmailTemplate();
9090
$this->transportBuilder->addTo($email);
9191
$transport = $this->transportBuilder->getTransport();
9292
$transport->sendMessage();

app/code/Magento/Sales/Test/Unit/Model/Order/Email/SenderBuilderTest.php

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ class SenderBuilderTest extends \PHPUnit\Framework\TestCase
3737

3838
protected function setUp()
3939
{
40-
$templateId = 'test_template_id';
41-
$templateOptions = ['option1', 'option2'];
42-
$templateVars = ['var1', 'var2'];
43-
$emailIdentity = 'email_identity_test';
44-
$emailCopyTo = ['example@mail.com'];
4540

4641
$this->templateContainerMock = $this->createPartialMock(
4742
\Magento\Sales\Model\Order\Email\Container\Template::class,
@@ -83,36 +78,6 @@ protected function setUp()
8378
]
8479
);
8580

86-
$this->templateContainerMock->expects($this->once())
87-
->method('getTemplateId')
88-
->will($this->returnValue($templateId));
89-
$this->transportBuilder->expects($this->once())
90-
->method('setTemplateIdentifier')
91-
->with($this->equalTo($templateId));
92-
$this->templateContainerMock->expects($this->once())
93-
->method('getTemplateOptions')
94-
->will($this->returnValue($templateOptions));
95-
$this->transportBuilder->expects($this->once())
96-
->method('setTemplateOptions')
97-
->with($this->equalTo($templateOptions));
98-
$this->templateContainerMock->expects($this->once())
99-
->method('getTemplateVars')
100-
->will($this->returnValue($templateVars));
101-
$this->transportBuilder->expects($this->once())
102-
->method('setTemplateVars')
103-
->with($this->equalTo($templateVars));
104-
105-
$this->identityContainerMock->expects($this->once())
106-
->method('getEmailIdentity')
107-
->will($this->returnValue($emailIdentity));
108-
$this->transportBuilder->expects($this->once())
109-
->method('setFromByScope')
110-
->with($this->equalTo($emailIdentity), 1);
111-
112-
$this->identityContainerMock->expects($this->once())
113-
->method('getEmailCopyTo')
114-
->will($this->returnValue($emailCopyTo));
115-
11681
$this->senderBuilder = new SenderBuilder(
11782
$this->templateContainerMock,
11883
$this->identityContainerMock,
@@ -122,6 +87,7 @@ protected function setUp()
12287

12388
public function testSend()
12489
{
90+
$this->setExpectedCount(1);
12591
$customerName = 'test_name';
12692
$customerEmail = 'test_email';
12793
$identity = 'email_identity_test';
@@ -142,20 +108,20 @@ public function testSend()
142108
$this->identityContainerMock->expects($this->once())
143109
->method('getCustomerName')
144110
->will($this->returnValue($customerName));
145-
$this->identityContainerMock->expects($this->once())
111+
$this->identityContainerMock->expects($this->exactly(1))
146112
->method('getStore')
147113
->willReturn($this->storeMock);
148114
$this->storeMock->expects($this->once())
149115
->method('getId')
150116
->willReturn(1);
151-
$this->transportBuilder->expects($this->once())
117+
$this->transportBuilder->expects($this->exactly(1))
152118
->method('setFromByScope')
153119
->with($identity, 1);
154-
$this->transportBuilder->expects($this->once())
120+
$this->transportBuilder->expects($this->exactly(1))
155121
->method('addTo')
156122
->with($this->equalTo($customerEmail), $this->equalTo($customerName));
157123

158-
$this->transportBuilder->expects($this->once())
124+
$this->transportBuilder->expects($this->exactly(1))
159125
->method('getTransport')
160126
->will($this->returnValue($transportMock));
161127

@@ -164,6 +130,7 @@ public function testSend()
164130

165131
public function testSendCopyTo()
166132
{
133+
$this->setExpectedCount(2);
167134
$identity = 'email_identity_test';
168135
$transportMock = $this->createMock(
169136
\Magento\Sales\Test\Unit\Model\Order\Email\Stub\TransportInterfaceMock::class
@@ -172,22 +139,66 @@ public function testSendCopyTo()
172139
->method('getCustomerEmail');
173140
$this->identityContainerMock->expects($this->never())
174141
->method('getCustomerName');
175-
$this->transportBuilder->expects($this->once())
176-
->method('addTo')
177-
->with($this->equalTo('example@mail.com'));
178-
$this->transportBuilder->expects($this->once())
142+
$this->transportBuilder->expects($this->exactly(2))
143+
->method('addTo');
144+
$this->transportBuilder->expects($this->exactly(2))
179145
->method('setFromByScope')
180146
->with($identity, 1);
181-
$this->identityContainerMock->expects($this->once())
147+
$this->identityContainerMock->expects($this->exactly(2))
182148
->method('getStore')
183149
->willReturn($this->storeMock);
184-
$this->storeMock->expects($this->once())
150+
$this->storeMock->expects($this->exactly(2))
185151
->method('getId')
186152
->willReturn(1);
187-
$this->transportBuilder->expects($this->once())
153+
$this->transportBuilder->expects($this->exactly(2))
188154
->method('getTransport')
189155
->will($this->returnValue($transportMock));
190156

191157
$this->senderBuilder->sendCopyTo();
192158
}
159+
160+
/**
161+
* Sets expected count invocation.
162+
*
163+
* @param int $count
164+
*/
165+
private function setExpectedCount(int $count = 1)
166+
{
167+
168+
$templateId = 'test_template_id';
169+
$templateOptions = ['option1', 'option2'];
170+
$templateVars = ['var1', 'var2'];
171+
$emailIdentity = 'email_identity_test';
172+
$emailCopyTo = ['example@mail.com', 'example2@mail.com'];
173+
174+
$this->templateContainerMock->expects($this->exactly($count))
175+
->method('getTemplateId')
176+
->will($this->returnValue($templateId));
177+
$this->transportBuilder->expects($this->exactly($count))
178+
->method('setTemplateIdentifier')
179+
->with($this->equalTo($templateId));
180+
$this->templateContainerMock->expects($this->exactly($count))
181+
->method('getTemplateOptions')
182+
->will($this->returnValue($templateOptions));
183+
$this->transportBuilder->expects($this->exactly($count))
184+
->method('setTemplateOptions')
185+
->with($this->equalTo($templateOptions));
186+
$this->templateContainerMock->expects($this->exactly($count))
187+
->method('getTemplateVars')
188+
->will($this->returnValue($templateVars));
189+
$this->transportBuilder->expects($this->exactly($count))
190+
->method('setTemplateVars')
191+
->with($this->equalTo($templateVars));
192+
193+
$this->identityContainerMock->expects($this->exactly($count))
194+
->method('getEmailIdentity')
195+
->will($this->returnValue($emailIdentity));
196+
$this->transportBuilder->expects($this->exactly($count))
197+
->method('setFromByScope')
198+
->with($this->equalTo($emailIdentity), 1);
199+
200+
$this->identityContainerMock->expects($this->once())
201+
->method('getEmailCopyTo')
202+
->will($this->returnValue($emailCopyTo));
203+
}
193204
}

0 commit comments

Comments
 (0)