58 private $globalConfigMock;
63 private $eventManagerMock;
68 private $paymentInfoMock;
73 private $paymentHelperMock;
78 private $invoiceResourceMock;
83 private $addressRendererMock;
88 private $templateContainerMock;
93 private $identityContainerMock;
98 private $senderBuilderFactoryMock;
105 $this->orderMock = $this->getMockBuilder(\
Magento\Sales\Model\Order::class)
106 ->disableOriginalConstructor()
109 $this->storeMock = $this->getMockBuilder(\
Magento\Store\Model\Store::class)
110 ->setMethods([
'getStoreId'])
111 ->disableOriginalConstructor()
114 $this->storeMock->expects($this->any())
115 ->method(
'getStoreId')
117 $this->orderMock->expects($this->any())
119 ->willReturn($this->storeMock);
121 $this->senderMock = $this->getMockBuilder(\
Magento\Sales\Model\
Order\Email\Sender::class)
122 ->disableOriginalConstructor()
123 ->setMethods([
'send',
'sendCopyTo'])
126 $this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
127 ->disableOriginalConstructor()
128 ->getMockForAbstractClass();
130 $this->invoiceMock = $this->getMockBuilder(\
Magento\Sales\Model\
Order\Invoice::class)
131 ->disableOriginalConstructor()
132 ->setMethods([
'setSendEmail',
'setEmailSent'])
135 $this->commentMock = $this->getMockBuilder(\
Magento\Sales\Api\
Data\InvoiceCommentCreationInterface::class)
136 ->disableOriginalConstructor()
137 ->getMockForAbstractClass();
139 $this->commentMock->expects($this->any())
140 ->method(
'getComment')
141 ->willReturn(
'Comment text');
143 $this->addressMock = $this->getMockBuilder(\
Magento\Sales\Model\
Order\Address::class)
144 ->disableOriginalConstructor()
147 $this->orderMock->expects($this->any())
148 ->method(
'getBillingAddress')
149 ->willReturn($this->addressMock);
150 $this->orderMock->expects($this->any())
151 ->method(
'getShippingAddress')
152 ->willReturn($this->addressMock);
154 $this->globalConfigMock = $this->getMockBuilder(\
Magento\Framework\
App\
Config\ScopeConfigInterface::class)
155 ->disableOriginalConstructor()
156 ->getMockForAbstractClass();
158 $this->eventManagerMock = $this->getMockBuilder(\
Magento\Framework\Event\ManagerInterface::class)
159 ->disableOriginalConstructor()
160 ->getMockForAbstractClass();
162 $this->paymentInfoMock = $this->getMockBuilder(\
Magento\
Payment\Model\Info::class)
163 ->disableOriginalConstructor()
166 $this->orderMock->expects($this->any())
167 ->method(
'getPayment')
168 ->willReturn($this->paymentInfoMock);
170 $this->paymentHelperMock = $this->getMockBuilder(\
Magento\
Payment\Helper\Data::class)
171 ->disableOriginalConstructor()
174 $this->paymentHelperMock->expects($this->any())
175 ->method(
'getInfoBlockHtml')
176 ->with($this->paymentInfoMock, 1)
177 ->willReturn(
'Payment Info Block');
180 ->disableOriginalConstructor()
183 $this->addressRendererMock = $this->getMockBuilder(\
Magento\Sales\Model\
Order\
Address\Renderer::class)
184 ->disableOriginalConstructor()
187 $this->addressRendererMock->expects($this->any())
189 ->with($this->addressMock,
'html')
190 ->willReturn(
'Formatted address');
192 $this->templateContainerMock = $this->getMockBuilder(\
Magento\Sales\Model\
Order\Email\Container\Template::class)
193 ->disableOriginalConstructor()
196 $this->identityContainerMock = $this->getMockBuilder(
197 \
Magento\Sales\Model\
Order\Email\Container\InvoiceIdentity::class
199 ->disableOriginalConstructor()
202 $this->identityContainerMock->expects($this->any())
204 ->willReturn($this->storeMock);
206 $this->senderBuilderFactoryMock = $this->getMockBuilder(
207 \
Magento\Sales\Model\
Order\Email\SenderBuilderFactory::class
209 ->disableOriginalConstructor()
210 ->setMethods([
'create'])
213 $this->subject = new \Magento\Sales\Model\Order\Invoice\Sender\EmailSender(
214 $this->templateContainerMock,
215 $this->identityContainerMock,
216 $this->senderBuilderFactoryMock,
218 $this->addressRendererMock,
219 $this->paymentHelperMock,
220 $this->invoiceResourceMock,
221 $this->globalConfigMock,
222 $this->eventManagerMock
237 public function testSend($configValue, $forceSyncMode, $isComment, $emailSendingResult)
239 $this->globalConfigMock->expects($this->once())
241 ->with(
'sales_email/general/async_sending')
242 ->willReturn($configValue);
245 $this->commentMock =
null;
248 $this->invoiceMock->expects($this->once())
249 ->method(
'setSendEmail')
252 if (!$configValue || $forceSyncMode) {
254 'order' => $this->orderMock,
255 'invoice' => $this->invoiceMock,
256 'comment' => $isComment ?
'Comment text' :
'',
257 'billing' => $this->addressMock,
258 'payment_html' =>
'Payment Info Block',
259 'store' => $this->storeMock,
260 'formattedShippingAddress' =>
'Formatted address',
261 'formattedBillingAddress' =>
'Formatted address',
263 $transport = new \Magento\Framework\DataObject($transport);
265 $this->eventManagerMock->expects($this->once())
268 'email_invoice_set_template_vars_before',
270 'sender' => $this->subject,
271 'transport' => $transport->getData(),
272 'transportObject' => $transport,
276 $this->templateContainerMock->expects($this->once())
277 ->method(
'setTemplateVars')
278 ->with($transport->getData());
280 $this->identityContainerMock->expects($this->once())
281 ->method(
'isEnabled')
282 ->willReturn($emailSendingResult);
284 if ($emailSendingResult) {
285 $this->senderBuilderFactoryMock->expects($this->once())
287 ->willReturn($this->senderMock);
289 $this->senderMock->expects($this->once())
292 $this->senderMock->expects($this->once())
293 ->method(
'sendCopyTo');
295 $this->invoiceMock->expects($this->once())
296 ->method(
'setEmailSent')
299 $this->invoiceResourceMock->expects($this->once())
300 ->method(
'saveAttribute')
301 ->with($this->invoiceMock, [
'send_email',
'email_sent']);
304 $this->subject->send(
312 $this->invoiceResourceMock->expects($this->once())
313 ->method(
'saveAttribute')
314 ->with($this->invoiceMock,
'send_email');
317 $this->subject->send(
326 $this->invoiceMock->expects($this->once())
327 ->method(
'setEmailSent')
330 $this->invoiceResourceMock->expects($this->at(0))
331 ->method(
'saveAttribute')
332 ->with($this->invoiceMock,
'email_sent');
333 $this->invoiceResourceMock->expects($this->at(1))
334 ->method(
'saveAttribute')
335 ->with($this->invoiceMock,
'send_email');
338 $this->subject->send(
354 'Successful sync sending with comment' => [0,
false,
true,
true],
355 'Successful sync sending without comment' => [0,
false,
false,
true],
356 'Failed sync sending with comment' => [0,
false,
true,
false],
357 'Successful forced sync sending with comment' => [1,
true,
true,
true],
358 'Async sending' => [1,
false,
false,
false],
testSend($configValue, $forceSyncMode, $isComment, $emailSendingResult)