Skip to content

Issues 13769. Fix wrong info about sent email in order sender. #13878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/code/Magento/Sales/Model/Order/Email/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ protected function checkAndSend(Order $order)
$sender->sendCopyTo();
} catch (\Exception $e) {
$this->logger->error($e->getMessage());

return false;
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ protected function setUp()
* @param int $configValue
* @param bool|null $forceSyncMode
* @param bool|null $emailSendingResult
* @dataProvider sendDataProvider
* @param $senderSendException
* @return void
* @dataProvider sendDataProvider
*/
public function testSend($configValue, $forceSyncMode, $emailSendingResult)
public function testSend($configValue, $forceSyncMode, $emailSendingResult, $senderSendException)
{
$address = 'address_test';
$configPath = 'sales_email/general/async_sending';
Expand Down Expand Up @@ -110,19 +111,23 @@ public function testSend($configValue, $forceSyncMode, $emailSendingResult)

$this->senderMock->expects($this->once())->method('send');

$this->senderMock->expects($this->once())->method('sendCopyTo');
if ($senderSendException) {
$this->checkSenderSendExceptionCase();
} else {
$this->senderMock->expects($this->once())->method('sendCopyTo');

$this->orderMock->expects($this->once())
->method('setEmailSent')
->with(true);
$this->orderMock->expects($this->once())
->method('setEmailSent')
->with(true);

$this->orderResourceMock->expects($this->once())
->method('saveAttribute')
->with($this->orderMock, ['send_email', 'email_sent']);
$this->orderResourceMock->expects($this->once())
->method('saveAttribute')
->with($this->orderMock, ['send_email', 'email_sent']);

$this->assertTrue(
$this->sender->send($this->orderMock)
);
$this->assertTrue(
$this->sender->send($this->orderMock)
);
}
} else {
$this->orderResourceMock->expects($this->once())
->method('saveAttribute')
Expand All @@ -146,19 +151,42 @@ public function testSend($configValue, $forceSyncMode, $emailSendingResult)
}
}

/**
* Methods check case when method "send" in "senderMock" throw exception.
*
* @return void
*/
protected function checkSenderSendExceptionCase()
{
$this->senderMock->expects($this->once())
->method('send')
->willThrowException(new \Exception('exception'));

$this->orderResourceMock->expects($this->once())
->method('saveAttribute')
->with($this->orderMock, 'send_email');

$this->assertFalse(
$this->sender->send($this->orderMock)
);
}

/**
* @return array
*/
public function sendDataProvider()
{
return [
[0, 0, true],
[0, 0, true],
[0, 0, false],
[0, 0, false],
[0, 1, true],
[0, 1, true],
[1, null, null, null]
[0, 0, true, false],
[0, 0, true, false],
[0, 0, true, true],
[0, 0, false, false],
[0, 0, false, false],
[0, 0, false, true],
[0, 1, true, false],
[0, 1, true, false],
[0, 1, true, false],
[1, null, null, false]
];
}

Expand Down