From 78dd01ad38fdd662f954c933c9b8ea77d63e1a10 Mon Sep 17 00:00:00 2001 From: Jeroen Date: Fri, 4 Sep 2020 16:34:59 +0200 Subject: [PATCH 1/2] Check if copy method is copy before sending comment email --- app/code/Magento/Sales/Model/Order/Email/NotifySender.php | 2 +- .../Unit/Model/Order/Email/Sender/AbstractSenderTest.php | 2 +- .../Order/Email/Sender/CreditmemoCommentSenderTest.php | 7 +++++-- .../Model/Order/Email/Sender/InvoiceCommentSenderTest.php | 7 +++++-- .../Model/Order/Email/Sender/ShipmentCommentSenderTest.php | 7 +++++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Sales/Model/Order/Email/NotifySender.php b/app/code/Magento/Sales/Model/Order/Email/NotifySender.php index 9e40ab769b0a6..1bb3053bf751f 100644 --- a/app/code/Magento/Sales/Model/Order/Email/NotifySender.php +++ b/app/code/Magento/Sales/Model/Order/Email/NotifySender.php @@ -35,7 +35,7 @@ protected function checkAndSend(Order $order, $notify = true) if ($notify) { $sender->send(); - } else { + } elseif ($this->identityContainer->getCopyMethod() === 'copy') { // Email copies are sent as separated emails if their copy method // is 'copy' or a customer should not be notified $sender->sendCopyTo(); diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/AbstractSenderTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/AbstractSenderTest.php index b826e058b679e..0494616b8cefd 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/AbstractSenderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/AbstractSenderTest.php @@ -192,7 +192,7 @@ public function stepIdentityContainerInit($identityMockClassName) { $this->identityContainerMock = $this->getMockBuilder($identityMockClassName) ->disableOriginalConstructor() - ->onlyMethods(['getStore', 'isEnabled', 'getConfigValue', 'getTemplateId', 'getGuestTemplateId']) + ->onlyMethods(['getStore', 'isEnabled', 'getConfigValue', 'getTemplateId', 'getGuestTemplateId', 'getCopyMethod']) ->getMock(); $this->identityContainerMock->expects($this->any()) ->method('getStore') diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/CreditmemoCommentSenderTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/CreditmemoCommentSenderTest.php index 0ed2a379f5b73..d191ae9356236 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/CreditmemoCommentSenderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/CreditmemoCommentSenderTest.php @@ -97,7 +97,7 @@ public function testSendVirtualOrder() $this->assertFalse($result); } - public function testSendTrueWithCustomerCopy() + public function testSendTrueWithoutCustomerCopy() { $billingAddress = $this->addressMock; $comment = 'comment_test'; @@ -140,7 +140,7 @@ public function testSendTrueWithCustomerCopy() $this->assertTrue($result); } - public function testSendTrueWithoutCustomerCopy() + public function testSendTrueWithCustomerCopy() { $billingAddress = $this->addressMock; $comment = 'comment_test'; @@ -161,6 +161,9 @@ public function testSendTrueWithoutCustomerCopy() $this->identityContainerMock->expects($this->once()) ->method('isEnabled') ->willReturn(true); + $this->identityContainerMock->expects($this->once()) + ->method('getCopyMethod') + ->willReturn('copy'); $this->templateContainerMock->expects($this->once()) ->method('setTemplateVars') ->with( diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/InvoiceCommentSenderTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/InvoiceCommentSenderTest.php index 68f2bd7b1a628..9e4e89766dfe1 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/InvoiceCommentSenderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/InvoiceCommentSenderTest.php @@ -65,7 +65,7 @@ public function testSendFalse() $this->assertFalse($result); } - public function testSendTrueWithCustomerCopy() + public function testSendTrueWithoutCustomerCopy() { $billingAddress = $this->addressMock; $this->stepAddressFormat($billingAddress); @@ -110,7 +110,7 @@ public function testSendTrueWithCustomerCopy() $this->assertTrue($result); } - public function testSendTrueWithoutCustomerCopy() + public function testSendTrueWithCustomerCopy() { $billingAddress = $this->addressMock; $customerName = 'Test Customer'; @@ -132,6 +132,9 @@ public function testSendTrueWithoutCustomerCopy() $this->identityContainerMock->expects($this->once()) ->method('isEnabled') ->willReturn(true); + $this->identityContainerMock->expects($this->once()) + ->method('getCopyMethod') + ->willReturn('copy'); $this->templateContainerMock->expects($this->once()) ->method('setTemplateVars') ->with( diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/ShipmentCommentSenderTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/ShipmentCommentSenderTest.php index 5421991fae848..91e7ae18d3550 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/ShipmentCommentSenderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/ShipmentCommentSenderTest.php @@ -58,7 +58,7 @@ public function testSendFalse() $this->assertFalse($result); } - public function testSendTrueWithCustomerCopy() + public function testSendTrueWithoutCustomerCopy() { $billingAddress = $this->addressMock; $comment = 'comment_test'; @@ -101,7 +101,7 @@ public function testSendTrueWithCustomerCopy() $this->assertTrue($result); } - public function testSendTrueWithoutCustomerCopy() + public function testSendTrueWithCustomerCopy() { $billingAddress = $this->addressMock; $comment = 'comment_test'; @@ -116,6 +116,9 @@ public function testSendTrueWithoutCustomerCopy() $this->identityContainerMock->expects($this->once()) ->method('isEnabled') ->willReturn(true); + $this->identityContainerMock->expects($this->once()) + ->method('getCopyMethod') + ->willReturn('copy'); $this->orderMock->expects($this->any()) ->method('getCustomerName') ->willReturn($customerName); From c7c4ad60ecf20c04104891d7c0bdaa84bacb8903 Mon Sep 17 00:00:00 2001 From: "vadim.malesh" Date: Mon, 12 Oct 2020 11:36:47 +0300 Subject: [PATCH 2/2] fix static --- app/code/Magento/Sales/Model/Order/Email/NotifySender.php | 1 + .../Test/Unit/Model/Order/Email/Sender/AbstractSenderTest.php | 4 +++- .../Model/Order/Email/Sender/InvoiceCommentSenderTest.php | 2 -- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Sales/Model/Order/Email/NotifySender.php b/app/code/Magento/Sales/Model/Order/Email/NotifySender.php index 1bb3053bf751f..468842d7b2ce4 100644 --- a/app/code/Magento/Sales/Model/Order/Email/NotifySender.php +++ b/app/code/Magento/Sales/Model/Order/Email/NotifySender.php @@ -10,6 +10,7 @@ /** * Class NotifySender + * phpcs:disable Magento2.Classes.AbstractApi * @api * @since 100.0.2 */ diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/AbstractSenderTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/AbstractSenderTest.php index 0494616b8cefd..be7788783adc7 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/AbstractSenderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/AbstractSenderTest.php @@ -192,7 +192,9 @@ public function stepIdentityContainerInit($identityMockClassName) { $this->identityContainerMock = $this->getMockBuilder($identityMockClassName) ->disableOriginalConstructor() - ->onlyMethods(['getStore', 'isEnabled', 'getConfigValue', 'getTemplateId', 'getGuestTemplateId', 'getCopyMethod']) + ->onlyMethods( + ['getStore', 'isEnabled', 'getConfigValue', 'getTemplateId', 'getGuestTemplateId', 'getCopyMethod'] + ) ->getMock(); $this->identityContainerMock->expects($this->any()) ->method('getStore') diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/InvoiceCommentSenderTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/InvoiceCommentSenderTest.php index 9e4e89766dfe1..56d78789d7dda 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/InvoiceCommentSenderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/InvoiceCommentSenderTest.php @@ -31,8 +31,6 @@ protected function setUp(): void $this->stepMockSetup(); $this->paymentHelper = $this->createPartialMock(Data::class, ['getInfoBlockHtml']); - $this->invoiceResource = $this->createMock(Invoice::class); - $this->stepIdentityContainerInit(InvoiceCommentIdentity::class); $this->addressRenderer->expects($this->any())->method('format')->willReturn(1);