From 9221e6e3f87c784db9f1752a9219697e033ccd8b Mon Sep 17 00:00:00 2001 From: Matheus Gontijo Date: Tue, 7 Jan 2020 11:28:33 -0300 Subject: [PATCH 01/12] bugfix - customer emails are not being sent from admin if customer is assiged to store "0". "0" should be considered a valid store id --- .../Magento/Customer/Model/EmailNotification.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Customer/Model/EmailNotification.php b/app/code/Magento/Customer/Model/EmailNotification.php index 432317444f4b7..068525344d3bb 100644 --- a/app/code/Magento/Customer/Model/EmailNotification.php +++ b/app/code/Magento/Customer/Model/EmailNotification.php @@ -167,7 +167,7 @@ public function credentialsChanged( private function emailAndPasswordChanged(CustomerInterface $customer, $email) { $storeId = $customer->getStoreId(); - if (!$storeId) { + if ($storeId === null) { $storeId = $this->getWebsiteStoreId($customer); } @@ -193,7 +193,7 @@ private function emailAndPasswordChanged(CustomerInterface $customer, $email) private function emailChanged(CustomerInterface $customer, $email) { $storeId = $customer->getStoreId(); - if (!$storeId) { + if ($storeId === null) { $storeId = $this->getWebsiteStoreId($customer); } @@ -218,7 +218,7 @@ private function emailChanged(CustomerInterface $customer, $email) private function passwordReset(CustomerInterface $customer) { $storeId = $customer->getStoreId(); - if (!$storeId) { + if ($storeId === null) { $storeId = $this->getWebsiteStoreId($customer); } @@ -317,7 +317,7 @@ private function getWebsiteStoreId($customer, $defaultStoreId = null) public function passwordReminder(CustomerInterface $customer) { $storeId = $customer->getStoreId(); - if (!$storeId) { + if ($storeId === null) { $storeId = $this->getWebsiteStoreId($customer); } @@ -341,7 +341,7 @@ public function passwordReminder(CustomerInterface $customer) public function passwordResetConfirmation(CustomerInterface $customer) { $storeId = $customer->getStoreId(); - if (!$storeId) { + if ($storeId === null) { $storeId = $this->getWebsiteStoreId($customer); } @@ -382,7 +382,7 @@ public function newAccount( ); } - if (!$storeId) { + if ($storeId === null) { $storeId = $this->getWebsiteStoreId($customer, $sendemailStoreId); } From fda71af352ac2bfd168fd2ce5cd8488c21843b75 Mon Sep 17 00:00:00 2001 From: Matheus Gontijo Date: Tue, 14 Jan 2020 08:25:23 -0300 Subject: [PATCH 02/12] updating storeId to null --- app/code/Magento/Customer/Model/EmailNotification.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/EmailNotification.php b/app/code/Magento/Customer/Model/EmailNotification.php index 068525344d3bb..5a54d92ddfef2 100644 --- a/app/code/Magento/Customer/Model/EmailNotification.php +++ b/app/code/Magento/Customer/Model/EmailNotification.php @@ -362,7 +362,7 @@ public function passwordResetConfirmation(CustomerInterface $customer) * @param CustomerInterface $customer * @param string $type * @param string $backUrl - * @param int $storeId + * @param int|null $storeId * @param string $sendemailStoreId * @return void * @throws LocalizedException @@ -371,7 +371,7 @@ public function newAccount( CustomerInterface $customer, $type = self::NEW_ACCOUNT_EMAIL_REGISTERED, $backUrl = '', - $storeId = 0, + $storeId = null, $sendemailStoreId = null ) { $types = self::TEMPLATE_TYPES; From 1ac923d3487a7ce8f65db2bd1191a9349a77c99d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tylek?= Date: Sat, 4 Apr 2020 19:28:42 +0200 Subject: [PATCH 03/12] Use the same greeting as in other Magento Customer emails --- .../Magento/Customer/view/frontend/email/change_email.html | 7 +++---- .../view/frontend/email/change_email_and_password.html | 7 +++---- .../Customer/view/frontend/email/password_reset.html | 7 +++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/Customer/view/frontend/email/change_email.html b/app/code/Magento/Customer/view/frontend/email/change_email.html index 4853adf638066..bd961ad99ec40 100644 --- a/app/code/Magento/Customer/view/frontend/email/change_email.html +++ b/app/code/Magento/Customer/view/frontend/email/change_email.html @@ -8,13 +8,12 @@ {{template config_path="design/email/header_template"}} -

{{trans "Hello,"}}

-
- +

{{trans "%name," name=$customer.name}}

{{trans "We have received a request to change the following information associated with your account at %store_name: email." store_name=$store.frontend_name}} {{trans 'If you have not authorized this action, please contact us immediately at %store_email' store_email=$store_email |raw}}{{depend store_phone}} {{trans 'or call us at %store_phone' store_phone=$store_phone |raw}}{{/depend}}. diff --git a/app/code/Magento/Customer/view/frontend/email/change_email_and_password.html b/app/code/Magento/Customer/view/frontend/email/change_email_and_password.html index 49867bdedc9e0..4f5c85b2381f3 100644 --- a/app/code/Magento/Customer/view/frontend/email/change_email_and_password.html +++ b/app/code/Magento/Customer/view/frontend/email/change_email_and_password.html @@ -8,13 +8,12 @@ {{template config_path="design/email/header_template"}} -

{{trans "Hello,"}}

-
- +

{{trans "%name," name=$customer.name}}

{{trans "We have received a request to change the following information associated with your account at %store_name: email, password." store_name=$store.frontend_name}} {{trans 'If you have not authorized this action, please contact us immediately at %store_email' store_email=$store_email |raw}}{{depend store_phone}} {{trans 'or call us at %store_phone' store_phone=$store_phone |raw}}{{/depend}}. diff --git a/app/code/Magento/Customer/view/frontend/email/password_reset.html b/app/code/Magento/Customer/view/frontend/email/password_reset.html index 79015117c2280..cab05a89227b6 100644 --- a/app/code/Magento/Customer/view/frontend/email/password_reset.html +++ b/app/code/Magento/Customer/view/frontend/email/password_reset.html @@ -9,13 +9,12 @@ "var customer.name":"Customer Name", "var store.frontend_name":"Store Name", "var store_email":"Store Email", -"var store_phone":"Store Phone" +"var store_phone":"Store Phone", +"var customer.name":"Customer Name" } @--> {{template config_path="design/email/header_template"}} -

{{trans "Hello,"}}

-
- +

{{trans "%name," name=$customer.name}}

{{trans "We have received a request to change the following information associated with your account at %store_name: password." store_name=$store.frontend_name}} {{trans 'If you have not authorized this action, please contact us immediately at %store_email' store_email=$store_email |raw}}{{depend store_phone}} {{trans 'or call us at %store_phone' store_phone=$store_phone |raw}}{{/depend}}. From 16cb18d7edaf504e7de2899f6935d33f8fcc42d9 Mon Sep 17 00:00:00 2001 From: Lukasz Bajsarowicz Date: Sun, 5 Apr 2020 03:35:23 +0200 Subject: [PATCH 04/12] magento/magento2#27589 Cover with Integration Tests the template changes. --- .../Controller/Account/EmailTemplateTest.php | 199 ++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Customer/Controller/Account/EmailTemplateTest.php diff --git a/dev/tests/integration/testsuite/Magento/Customer/Controller/Account/EmailTemplateTest.php b/dev/tests/integration/testsuite/Magento/Customer/Controller/Account/EmailTemplateTest.php new file mode 100644 index 0000000000000..a2edf0f0f40da --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/Account/EmailTemplateTest.php @@ -0,0 +1,199 @@ +transportBuilderMock = $this->_objectManager->get(TransportBuilderMock::class); + $this->session = $this->_objectManager->get(Session::class); + $this->formKey = $this->_objectManager->get(FormKey::class); + } + + /** + * @magentoDataFixture Magento/Customer/_files/customer.php + * @magentoConfigFixture current_store customer/captcha/enable 0 + */ + public function testForgotPasswordEmailTemplateGreeting() + { + $this->getRequest()->setMethod(HttpRequest::METHOD_POST) + ->setPostValue(['email' => self::FIXTURE_CUSTOMER_EMAIL]); + $this->dispatch('customer/account/forgotPasswordPost'); + + $this->assertSameGreeting(self::EXPECTED_GREETING, $this->transportBuilderMock->getSentMessage()); + } + + /** + * @covers Magento_Customer::view/frontend/email/change_email.html + * + * @magentoDataFixture Magento/Customer/_files/customer.php + * @magentoConfigFixture current_store customer/captcha/enable 0 + */ + public function testCustomerEmailChangeNotificationTemplateGreeting() + { + $this->loginByCustomerId(self::FIXTURE_CUSTOMER_ID); + + $this->sendAccountEditRequest([ + 'email' => 'new.email@example.com', + 'change_email' => 1, + ]); + + $this->assertRedirect($this->stringContains('customer/account/')); + $this->assertSessionMessages( + $this->equalTo(['You saved the account information.']), + MessageInterface::TYPE_SUCCESS + ); + + $this->assertSameGreeting(self::EXPECTED_GREETING, $this->transportBuilderMock->getSentMessage()); + } + + /** + * @covers Magento_Customer::view/frontend/email/change_email_and_password.html + * + * @magentoDataFixture Magento/Customer/_files/customer.php + * @magentoConfigFixture current_store customer/captcha/enable 0 + */ + public function testCustomerEmailAndPasswordChangeNotificationTemplateGreeting() + { + $this->loginByCustomerId(self::FIXTURE_CUSTOMER_ID); + + $this->sendAccountEditRequest([ + 'email' => 'new.email@example.com', + 'change_email' => 1, + 'change_password' => 1, + 'password' => 'new-Password1', + 'password_confirmation' => 'new-Password1', + ]); + + $this->assertRedirect($this->stringContains('customer/account/')); + $this->assertSessionMessages( + $this->equalTo(['You saved the account information.']), + MessageInterface::TYPE_SUCCESS + ); + + $this->assertSameGreeting(self::EXPECTED_GREETING, $this->transportBuilderMock->getSentMessage()); + } + + /** + * @covers Magento_Customer::view/frontend/email/change_password.html + * + * @magentoDataFixture Magento/Customer/_files/customer.php + * @magentoConfigFixture current_store customer/captcha/enable 0 + */ + public function testCustomerPasswordChangeNotificationTemplateGreeting() + { + $this->loginByCustomerId(self::FIXTURE_CUSTOMER_ID); + + $this->sendAccountEditRequest([ + 'change_password' => 1, + 'password' => 'new-Password1', + 'password_confirmation' => 'new-Password1', + ]); + + $this->assertRedirect($this->stringContains('customer/account/')); + $this->assertSessionMessages( + $this->equalTo(['You saved the account information.']), + MessageInterface::TYPE_SUCCESS + ); + + $this->assertSameGreeting(self::EXPECTED_GREETING, $this->transportBuilderMock->getSentMessage()); + } + + /** + * Wraps Customer Edit POST request + * + * @param array $customData + */ + private function sendAccountEditRequest(array $customData): void + { + $basicData = [ + 'form_key' => $this->formKey->getFormKey(), + 'firstname' => self::FIXTURE_CUSTOMER_FIRSTNAME, + 'lastname' => self::FIXTURE_CUSTOMER_LASTNAME, + 'current_password' => self::FIXTURE_CUSTOMER_PASSWORD + ]; + + $this->getRequest()->setMethod(HttpRequest::METHOD_POST) + ->setPostValue(array_merge($basicData, $customData)); + + $this->dispatch('customer/account/editPost'); + } + + /** + * Verifies if `

` text contents equals the expected one. + * + * @param string $expectedGreeting + * @param EmailMessage $message + */ + private function assertSameGreeting(string $expectedGreeting, EmailMessage $message) + { + $messageContent = $this->getMessageRawContent($message); + $emailDom = new \DOMDocument(); + $emailDom->loadHTML($messageContent); + + $emailXpath = new \DOMXPath($emailDom); + $greeting = $emailXpath->query('//p[@class="greeting"]')->item(0); + + $this->assertSame($expectedGreeting, $greeting->textContent); + } + + /** + * Returns raw content of provided message + * + * @param EmailMessage $message + * @return string + */ + private function getMessageRawContent(EmailMessage $message): string + { + $emailParts = $message->getBody()->getParts(); + return current($emailParts)->getRawContent(); + } + + /** + * Performs Customer log in + * + * @param int $customerId + */ + private function loginByCustomerId(int $customerId): void + { + $this->session->loginById($customerId); + } +} From f882122a3280f3b60706f87d9428f75b11a80112 Mon Sep 17 00:00:00 2001 From: Lukasz Bajsarowicz Date: Sun, 5 Apr 2020 04:00:49 +0200 Subject: [PATCH 05/12] magento/magento2#27589 Expect exactly one greeting in the Template --- .../Customer/Controller/Account/EmailTemplateTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Controller/Account/EmailTemplateTest.php b/dev/tests/integration/testsuite/Magento/Customer/Controller/Account/EmailTemplateTest.php index a2edf0f0f40da..6aa1e49174313 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Controller/Account/EmailTemplateTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/Account/EmailTemplateTest.php @@ -170,9 +170,10 @@ private function assertSameGreeting(string $expectedGreeting, EmailMessage $mess $emailDom->loadHTML($messageContent); $emailXpath = new \DOMXPath($emailDom); - $greeting = $emailXpath->query('//p[@class="greeting"]')->item(0); + $greeting = $emailXpath->query('//p[@class="greeting"]'); - $this->assertSame($expectedGreeting, $greeting->textContent); + $this->assertSame(1, $greeting->length); + $this->assertSame($expectedGreeting, $greeting->item(0)->textContent); } /** From 82224a62f63955d1c070e2509298e27acc52cdd4 Mon Sep 17 00:00:00 2001 From: Lukasz Bajsarowicz Date: Sun, 5 Apr 2020 04:36:22 +0200 Subject: [PATCH 06/12] magento/magento2#27589 Fix Static Tests --- .../Customer/Controller/Account/EmailTemplateTest.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Controller/Account/EmailTemplateTest.php b/dev/tests/integration/testsuite/Magento/Customer/Controller/Account/EmailTemplateTest.php index 6aa1e49174313..ac12dc4df8d64 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Controller/Account/EmailTemplateTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/Account/EmailTemplateTest.php @@ -1,4 +1,8 @@ Date: Mon, 6 Apr 2020 14:15:12 +0300 Subject: [PATCH 07/12] Coverage unit test --- .../Test/Unit/Model/EmailNotificationTest.php | 266 +++++++++++------- 1 file changed, 162 insertions(+), 104 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/EmailNotificationTest.php b/app/code/Magento/Customer/Test/Unit/Model/EmailNotificationTest.php index ff83ef62c6aa7..c09edcb40a6e3 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/EmailNotificationTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/EmailNotificationTest.php @@ -3,88 +3,99 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Customer\Test\Unit\Model; use Magento\Customer\Api\Data\CustomerInterface; +use Magento\Customer\Helper\View; +use Magento\Customer\Model\CustomerRegistry; +use Magento\Customer\Model\Data\CustomerSecure; use Magento\Customer\Model\EmailNotification; use Magento\Framework\App\Area; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Helper\Context; use Magento\Framework\Mail\Template\SenderResolverInterface; +use Magento\Framework\Mail\Template\TransportBuilder; +use Magento\Framework\Mail\TransportInterface; +use Magento\Framework\Reflection\DataObjectProcessor; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\Store; +use Magento\Store\Model\StoreManagerInterface; +use Magento\Store\Model\Website; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; /** - * Class EmailNotificationTest + * Verify EmailNotificationTest * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class EmailNotificationTest extends \PHPUnit\Framework\TestCase +class EmailNotificationTest extends TestCase { /** - * @var \Magento\Customer\Model\CustomerRegistry|\PHPUnit_Framework_MockObject_MockObject + * @var CustomerRegistry|MockObject */ private $customerRegistryMock; /** - * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var StoreManagerInterface|MockObject */ private $storeManagerMock; /** - * @var \Magento\Framework\Mail\Template\TransportBuilder|\PHPUnit_Framework_MockObject_MockObject + * @var TransportBuilder|MockObject */ private $transportBuilderMock; /** - * @var \Magento\Customer\Helper\View|\PHPUnit_Framework_MockObject_MockObject + * @var View|MockObject */ private $customerViewHelperMock; /** - * @var \Magento\Framework\Reflection\DataObjectProcessor|\PHPUnit_Framework_MockObject_MockObject + * @var DataObjectProcessor|MockObject */ private $dataProcessorMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Customer\Model\Data\CustomerSecure + * @var CustomerSecure|MockObject */ private $customerSecureMock; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject + * @var ScopeConfigInterface|MockObject */ private $scopeConfigMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\Store + * @var Store|MockObject */ private $storeMock; /** - * @var \Magento\Customer\Model\EmailNotification + * @var SenderResolverInterface|MockObject */ - private $model; + private $senderResolverMock; /** - * @var SenderResolverInterface|\PHPUnit_Framework_MockObject_MockObject + * @var EmailNotification */ - private $senderResolverMock; + private $model; public function setUp() { - $this->customerRegistryMock = $this->createMock(\Magento\Customer\Model\CustomerRegistry::class); - - $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class); + $this->customerRegistryMock = $this->createMock(CustomerRegistry::class); + $this->storeManagerMock = $this->createMock(StoreManagerInterface::class); + $this->transportBuilderMock = $this->createMock(TransportBuilder::class); + $this->customerViewHelperMock = $this->createMock(View::class); + $this->dataProcessorMock = $this->createMock(DataObjectProcessor::class); - $this->transportBuilderMock = $this->createMock(\Magento\Framework\Mail\Template\TransportBuilder::class); - - $this->customerViewHelperMock = $this->createMock(\Magento\Customer\Helper\View::class); - - $this->dataProcessorMock = $this->createMock(\Magento\Framework\Reflection\DataObjectProcessor::class); - - $contextMock = $this->createPartialMock(\Magento\Framework\App\Helper\Context::class, ['getScopeConfig']); + $contextMock = $this->createPartialMock(Context::class, ['getScopeConfig']); $this->scopeConfigMock = $this->createPartialMock( - \Magento\Framework\App\Config\ScopeConfigInterface::class, + ScopeConfigInterface::class, ['getValue', 'isSetFlag'] ); @@ -92,16 +103,16 @@ public function setUp() ->method('getScopeConfig') ->willReturn($this->scopeConfigMock); - $this->customerSecureMock = $this->createMock(\Magento\Customer\Model\Data\CustomerSecure::class); + $this->customerSecureMock = $this->createMock(CustomerSecure::class); - $this->storeMock = $this->createMock(\Magento\Store\Model\Store::class); + $this->storeMock = $this->createMock(Store::class); $this->senderResolverMock = $this->getMockBuilder(SenderResolverInterface::class) ->setMethods(['resolve']) ->disableOriginalConstructor() ->getMockForAbstractClass(); - $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $objectManager = new ObjectManager($this); $this->model = $objectManager->getObject( EmailNotification::class, @@ -119,6 +130,7 @@ public function setUp() /** * @param int $testNumber + * @param int $customerStoreId * @param string $oldEmail * @param string $newEmail * @param bool $isPasswordChanged @@ -126,11 +138,9 @@ public function setUp() * @dataProvider sendNotificationEmailsDataProvider * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testCredentialsChanged($testNumber, $oldEmail, $newEmail, $isPasswordChanged) + public function testCredentialsChanged($testNumber, $customerStoreId, $oldEmail, $newEmail, $isPasswordChanged) { $customerId = 1; - $customerStoreId = 2; - $customerWebsiteId = 1; $customerData = ['key' => 'value']; $customerName = 'Customer Name'; $templateIdentifier = 'Template Identifier'; @@ -145,7 +155,7 @@ public function testCredentialsChanged($testNumber, $oldEmail, $newEmail, $isPas $expects = $this->once(); break; case 2: - $xmlPathTemplate = \Magento\Customer\Model\EmailNotification::XML_PATH_CHANGE_EMAIL_TEMPLATE; + $xmlPathTemplate = EmailNotification::XML_PATH_CHANGE_EMAIL_TEMPLATE; $expects = $this->exactly(2); break; case 3: @@ -160,19 +170,18 @@ public function testCredentialsChanged($testNumber, $oldEmail, $newEmail, $isPas ->with($sender, $customerStoreId) ->willReturn($senderValues); - /** @var \PHPUnit_Framework_MockObject_MockObject $origCustomer */ - $origCustomer = $this->createMock(CustomerInterface::class); - $origCustomer->expects($this->any()) + /** @var MockObject $origCustomerMock */ + $origCustomerMock = $this->createMock(CustomerInterface::class); + $origCustomerMock->expects($this->any()) ->method('getStoreId') - ->willReturn(0); - $origCustomer->expects($this->any()) + ->willReturn($customerStoreId); + $origCustomerMock->expects($this->any()) ->method('getId') ->willReturn($customerId); - $origCustomer->expects($this->any()) - ->method('getWebsiteId') - ->willReturn($customerWebsiteId); + $origCustomerMock->expects($this->never()) + ->method('getWebsiteId'); - $storeMock = $this->createMock(\Magento\Store\Model\Store::class); + $storeMock = $this->createMock(Store::class); $storeMock->expects($this->any()) ->method('getId') ->willReturn($customerStoreId); @@ -181,17 +190,12 @@ public function testCredentialsChanged($testNumber, $oldEmail, $newEmail, $isPas ->method('getStore') ->willReturn($storeMock); - $websiteMock = $this->createPartialMock(\Magento\Store\Model\Website::class, ['getStoreIds']); + $websiteMock = $this->createPartialMock(Website::class, ['getStoreIds']); $websiteMock->expects($this->any()) ->method('getStoreIds') ->willReturn([$customerStoreId]); - $this->storeManagerMock->expects(clone $expects) - ->method('getWebsite') - ->with($customerWebsiteId) - ->willReturn($websiteMock); - - $customerSecureMock = $this->createMock(\Magento\Customer\Model\Data\CustomerSecure::class); + $customerSecureMock = $this->createMock(CustomerSecure::class); $this->customerRegistryMock->expects(clone $expects) ->method('retrieveSecureData') ->with($customerId) @@ -199,12 +203,12 @@ public function testCredentialsChanged($testNumber, $oldEmail, $newEmail, $isPas $this->dataProcessorMock->expects(clone $expects) ->method('buildOutputDataArray') - ->with($origCustomer, CustomerInterface::class) + ->with($origCustomerMock, CustomerInterface::class) ->willReturn($customerData); $this->customerViewHelperMock->expects($this->any()) ->method('getCustomerName') - ->with($origCustomer) + ->with($origCustomerMock) ->willReturn($customerName); $customerSecureMock->expects(clone $expects) @@ -216,30 +220,30 @@ public function testCredentialsChanged($testNumber, $oldEmail, $newEmail, $isPas ->with('name', $customerName) ->willReturnSelf(); - /** @var CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $savedCustomer */ - $savedCustomer = clone $origCustomer; + /** @var CustomerInterface|MockObject $savedCustomerMock */ + $savedCustomerMock = clone $origCustomerMock; - $origCustomer->expects($this->any()) + $origCustomerMock->expects($this->any()) ->method('getEmail') ->willReturn($oldEmail); - $savedCustomer->expects($this->any()) + $savedCustomerMock->expects($this->any()) ->method('getEmail') ->willReturn($newEmail); $this->scopeConfigMock->expects($this->any()) ->method('getValue') ->withConsecutive( - [$xmlPathTemplate, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $customerStoreId], + [$xmlPathTemplate, ScopeInterface::SCOPE_STORE, $customerStoreId], [ - \Magento\Customer\Model\EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, + ScopeInterface::SCOPE_STORE, $customerStoreId ], - [$xmlPathTemplate, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $customerStoreId], + [$xmlPathTemplate, ScopeInterface::SCOPE_STORE, $customerStoreId], [ - \Magento\Customer\Model\EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, + ScopeInterface::SCOPE_STORE, $customerStoreId ] ) @@ -251,7 +255,7 @@ public function testCredentialsChanged($testNumber, $oldEmail, $newEmail, $isPas ->willReturnSelf(); $this->transportBuilderMock->expects(clone $expects) ->method('setTemplateOptions') - ->with(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $customerStoreId]) + ->with(['area' => Area::AREA_FRONTEND, 'store' => $customerStoreId]) ->willReturnSelf(); $this->transportBuilderMock->expects(clone $expects) ->method('setTemplateVars') @@ -267,7 +271,7 @@ public function testCredentialsChanged($testNumber, $oldEmail, $newEmail, $isPas ->withConsecutive([$oldEmail, $customerName], [$newEmail, $customerName]) ->willReturnSelf(); - $transport = $this->createMock(\Magento\Framework\Mail\TransportInterface::class); + $transport = $this->createMock(TransportInterface::class); $this->transportBuilderMock->expects(clone $expects) ->method('getTransport') @@ -276,7 +280,7 @@ public function testCredentialsChanged($testNumber, $oldEmail, $newEmail, $isPas $transport->expects(clone $expects) ->method('sendMessage'); - $this->model->credentialsChanged($savedCustomer, $oldEmail, $isPasswordChanged); + $this->model->credentialsChanged($savedCustomerMock, $oldEmail, $isPasswordChanged); } /** @@ -287,18 +291,42 @@ public function sendNotificationEmailsDataProvider() return [ [ 'test_number' => 1, + 'customerStoreId' => 0, + 'old_email' => 'test@example.com', + 'new_email' => 'test@example.com', + 'is_password_changed' => true + ], + [ + 'test_number' => 1, + 'customerStoreId' => 2, 'old_email' => 'test@example.com', 'new_email' => 'test@example.com', 'is_password_changed' => true ], [ 'test_number' => 2, + 'customerStoreId' => 0, + 'old_email' => 'test1@example.com', + 'new_email' => 'test2@example.com', + 'is_password_changed' => false + ], + [ + 'test_number' => 2, + 'customerStoreId' => 2, 'old_email' => 'test1@example.com', 'new_email' => 'test2@example.com', 'is_password_changed' => false ], [ 'test_number' => 3, + 'customerStoreId' => 0, + 'old_email' => 'test1@example.com', + 'new_email' => 'test2@example.com', + 'is_password_changed' => true + ], + [ + 'test_number' => 3, + 'customerStoreId' => 2, 'old_email' => 'test1@example.com', 'new_email' => 'test2@example.com', 'is_password_changed' => true @@ -307,13 +335,15 @@ public function sendNotificationEmailsDataProvider() } /** + * @param int $customerStoreId + * @dataProvider customerStoreIdDataProvider + * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testPasswordReminder() + public function testPasswordReminder($customerStoreId):void { $customerId = 1; $customerWebsiteId = 1; - $customerStoreId = 2; $customerEmail = 'email@email.com'; $customerData = ['key' => 'value']; $customerName = 'Customer Name'; @@ -328,18 +358,17 @@ public function testPasswordReminder() ->with($sender, $customerStoreId) ->willReturn($senderValues); - /** @var CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customer */ - $customer = $this->createMock(CustomerInterface::class); - $customer->expects($this->any()) - ->method('getWebsiteId') - ->willReturn($customerWebsiteId); - $customer->expects($this->any()) + /** @var CustomerInterface|MockObject $customerMock */ + $customerMock = $this->createMock(CustomerInterface::class); + $customerMock->expects($this->never()) + ->method('getWebsiteId'); + $customerMock->expects($this->any()) ->method('getStoreId') ->willReturn($customerStoreId); - $customer->expects($this->any()) + $customerMock->expects($this->any()) ->method('getId') ->willReturn($customerId); - $customer->expects($this->any()) + $customerMock->expects($this->any()) ->method('getEmail') ->willReturn($customerEmail); @@ -351,7 +380,10 @@ public function testPasswordReminder() ->method('getStore') ->willReturn($this->storeMock); - $websiteMock = $this->createPartialMock(\Magento\Store\Model\Website::class, ['getStoreIds']); + $websiteMock = $this->createPartialMock( + Website::class, + ['getStoreIds'] + ); $websiteMock->expects($this->any()) ->method('getStoreIds') ->willReturn($storeIds); @@ -368,12 +400,12 @@ public function testPasswordReminder() $this->dataProcessorMock->expects($this->once()) ->method('buildOutputDataArray') - ->with($customer, CustomerInterface::class) + ->with($customerMock, CustomerInterface::class) ->willReturn($customerData); $this->customerViewHelperMock->expects($this->any()) ->method('getCustomerName') - ->with($customer) + ->with($customerMock) ->willReturn($customerName); $this->customerSecureMock->expects($this->once()) @@ -403,13 +435,14 @@ public function testPasswordReminder() ['customer' => $this->customerSecureMock, 'store' => $this->storeMock] ); - $this->model->passwordReminder($customer); + $this->model->passwordReminder($customerMock); } /** + * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testPasswordReminderCustomerWithoutStoreId() + public function testPasswordReminderCustomerWithoutStoreId():void { $customerId = 1; $customerWebsiteId = 1; @@ -427,18 +460,18 @@ public function testPasswordReminderCustomerWithoutStoreId() ->method('resolve') ->with($sender, $defaultStoreId) ->willReturn($senderValues); - /** @var CustomerInterface | \PHPUnit_Framework_MockObject_MockObject $customer */ - $customer = $this->createMock(CustomerInterface::class); - $customer->expects($this->any()) + /** @var CustomerInterface | MockObject $customerMock */ + $customerMock = $this->createMock(CustomerInterface::class); + $customerMock->expects($this->any()) ->method('getWebsiteId') ->willReturn($customerWebsiteId); - $customer->expects($this->any()) + $customerMock->expects($this->any()) ->method('getStoreId') ->willReturn($customerStoreId); - $customer->expects($this->any()) + $customerMock->expects($this->any()) ->method('getId') ->willReturn($customerId); - $customer->expects($this->any()) + $customerMock->expects($this->any()) ->method('getEmail') ->willReturn($customerEmail); $this->storeMock->expects($this->any()) @@ -451,7 +484,7 @@ public function testPasswordReminderCustomerWithoutStoreId() ->method('getStore') ->with($defaultStoreId) ->willReturn($this->storeMock); - $websiteMock = $this->createPartialMock(\Magento\Store\Model\Website::class, ['getStoreIds']); + $websiteMock = $this->createPartialMock(Website::class, ['getStoreIds']); $websiteMock->expects($this->any()) ->method('getStoreIds') ->willReturn($storeIds); @@ -466,11 +499,11 @@ public function testPasswordReminderCustomerWithoutStoreId() ->willReturn($this->customerSecureMock); $this->dataProcessorMock->expects($this->once()) ->method('buildOutputDataArray') - ->with($customer, CustomerInterface::class) + ->with($customerMock, CustomerInterface::class) ->willReturn($customerData); $this->customerViewHelperMock->expects($this->any()) ->method('getCustomerName') - ->with($customer) + ->with($customerMock) ->willReturn($customerName); $this->customerSecureMock->expects($this->once()) ->method('addData') @@ -496,16 +529,18 @@ public function testPasswordReminderCustomerWithoutStoreId() $customerName, ['customer' => $this->customerSecureMock, 'store' => $this->storeMock] ); - $this->model->passwordReminder($customer); + $this->model->passwordReminder($customerMock); } /** + * @dataProvider customerStoreIdDataProvider + * @param int $customerStoreId + * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testPasswordResetConfirmation() + public function testPasswordResetConfirmation($customerStoreId):void { $customerId = 1; - $customerStoreId = 2; $customerEmail = 'email@email.com'; $customerData = ['key' => 'value']; $customerName = 'Customer Name'; @@ -519,15 +554,19 @@ public function testPasswordResetConfirmation() ->with($sender, $customerStoreId) ->willReturn($senderValues); - /** @var CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customer */ - $customer = $this->createMock(CustomerInterface::class); - $customer->expects($this->once()) + /** @var CustomerInterface|MockObject $customerMock */ + $customerMock = $this->createMock(CustomerInterface::class); + + $customerMock->expects($this->never()) + ->method('getWebsiteId'); + + $customerMock->expects($this->once()) ->method('getStoreId') ->willReturn($customerStoreId); - $customer->expects($this->any()) + $customerMock->expects($this->any()) ->method('getId') ->willReturn($customerId); - $customer->expects($this->any()) + $customerMock->expects($this->any()) ->method('getEmail') ->willReturn($customerEmail); @@ -546,12 +585,12 @@ public function testPasswordResetConfirmation() $this->dataProcessorMock->expects($this->once()) ->method('buildOutputDataArray') - ->with($customer, CustomerInterface::class) + ->with($customerMock, CustomerInterface::class) ->willReturn($customerData); $this->customerViewHelperMock->expects($this->any()) ->method('getCustomerName') - ->with($customer) + ->with($customerMock) ->willReturn($customerName); $this->customerSecureMock->expects($this->once()) @@ -581,16 +620,18 @@ public function testPasswordResetConfirmation() ['customer' => $this->customerSecureMock, 'store' => $this->storeMock] ); - $this->model->passwordResetConfirmation($customer); + $this->model->passwordResetConfirmation($customerMock); } /** + * @dataProvider customerStoreIdDataProvider + * @param int $customerStoreId + * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testNewAccount() + public function testNewAccount($customerStoreId):void { $customerId = 1; - $customerStoreId = 2; $customerEmail = 'email@email.com'; $customerData = ['key' => 'value']; $customerName = 'Customer Name'; @@ -604,8 +645,12 @@ public function testNewAccount() ->with($sender, $customerStoreId) ->willReturn($senderValues); - /** @var CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customer */ + /** @var CustomerInterface|MockObject $customer */ $customer = $this->createMock(CustomerInterface::class); + + $customer->expects($this->never()) + ->method('getWebsiteId'); + $customer->expects($this->any()) ->method('getStoreId') ->willReturn($customerStoreId); @@ -670,6 +715,19 @@ public function testNewAccount() $this->model->newAccount($customer, EmailNotification::NEW_ACCOUNT_EMAIL_REGISTERED, '', $customerStoreId); } + /** + * DataProvider customer store + * + * @return array + */ + public function customerStoreIdDataProvider():array + { + return [ + ['customerStoreId' => 0], + ['customerStoreId' => 2] + ]; + } + /** * Create default mock for $this->transportBuilderMock. * @@ -690,7 +748,7 @@ private function mockDefaultTransportBuilder( string $customerName, array $templateVars = [] ): void { - $transport = $this->createMock(\Magento\Framework\Mail\TransportInterface::class); + $transportMock = $this->createMock(TransportInterface::class); $this->transportBuilderMock->expects($this->once()) ->method('setTemplateIdentifier') @@ -714,9 +772,9 @@ private function mockDefaultTransportBuilder( ->willReturnSelf(); $this->transportBuilderMock->expects($this->once()) ->method('getTransport') - ->willReturn($transport); + ->willReturn($transportMock); - $transport->expects($this->once()) + $transportMock->expects($this->once()) ->method('sendMessage'); } } From 38e2c5ab3c064c1637a5e106fd3f4e9453018d1d Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Fri, 10 Apr 2020 16:59:06 +0300 Subject: [PATCH 08/12] add AssertAdminCategorySaveSuccessMessageActionGroup --- .../AdminSaveCategoryActionGroup.xml | 3 +-- ...nCategorySaveSuccessMessageActionGroup.xml | 19 +++++++++++++++++++ .../AdminCheckPaginationInStorefrontTest.xml | 2 +- ...AdminCreateCategoryWithAnchorFieldTest.xml | 2 +- ...AdminCreateCategoryWithFiveNestingTest.xml | 10 +++++----- ...CreateCategoryWithInactiveCategoryTest.xml | 2 +- ...eCategoryWithInactiveIncludeInMenuTest.xml | 2 +- ...minCreateCategoryWithNoAnchorFieldTest.xml | 2 +- ...eateCategoryWithProductsGridFilterTest.xml | 2 +- ...inCreateCategoryWithRequiredFieldsTest.xml | 2 +- ...inCreateRootCategoryRequiredFieldsTest.xml | 2 +- ...AdminUpdateCategoryAndMakeInactiveTest.xml | 2 +- ...eCategoryWithInactiveIncludeInMenuTest.xml | 2 +- .../AdminUpdateCategoryWithProductsTest.xml | 2 +- ...vailableAfterEnablingSubCategoriesTest.xml | 2 +- ...goryWithRestrictedUrlKeyNotCreatedTest.xml | 8 ++++---- .../CatalogProductListWidgetOperatorsTest.xml | 2 +- ...dCmsBlockEntityAndAssignToCategoryTest.xml | 1 + ...dCmsBlockEntityAndAssignToCategoryTest.xml | 1 + 19 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertAdminCategorySaveSuccessMessageActionGroup.xml diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminSaveCategoryActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminSaveCategoryActionGroup.xml index 535a08382aabb..95f11901c97f0 100644 --- a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminSaveCategoryActionGroup.xml +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminSaveCategoryActionGroup.xml @@ -10,6 +10,5 @@ - - \ No newline at end of file + diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertAdminCategorySaveSuccessMessageActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertAdminCategorySaveSuccessMessageActionGroup.xml new file mode 100644 index 0000000000000..ddc2a5d44acbd --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertAdminCategorySaveSuccessMessageActionGroup.xml @@ -0,0 +1,19 @@ + + + + + + + Checks success message after category was saved. + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCheckPaginationInStorefrontTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCheckPaginationInStorefrontTest.xml index 278a1fdc7ad9c..02610f539d3c0 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCheckPaginationInStorefrontTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCheckPaginationInStorefrontTest.xml @@ -123,7 +123,7 @@ - + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithAnchorFieldTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithAnchorFieldTest.xml index 7deb79c66ff6d..59d634e492200 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithAnchorFieldTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithAnchorFieldTest.xml @@ -60,7 +60,7 @@ - + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithFiveNestingTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithFiveNestingTest.xml index c1df630685949..dc15d28c9f447 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithFiveNestingTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithFiveNestingTest.xml @@ -45,35 +45,35 @@ - + - + - + - + - + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithInactiveCategoryTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithInactiveCategoryTest.xml index 34714db67fbd6..40b0bd74e59c3 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithInactiveCategoryTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithInactiveCategoryTest.xml @@ -33,7 +33,7 @@ - + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithInactiveIncludeInMenuTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithInactiveIncludeInMenuTest.xml index a11717c04ea8c..0745a831796af 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithInactiveIncludeInMenuTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithInactiveIncludeInMenuTest.xml @@ -33,7 +33,7 @@ - + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithNoAnchorFieldTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithNoAnchorFieldTest.xml index ec3c7a26723c2..2ef7f997661f3 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithNoAnchorFieldTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithNoAnchorFieldTest.xml @@ -62,7 +62,7 @@ - + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithProductsGridFilterTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithProductsGridFilterTest.xml index 99d0f88cf0e9a..5c9a28ef4ae05 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithProductsGridFilterTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithProductsGridFilterTest.xml @@ -75,7 +75,7 @@ - + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithRequiredFieldsTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithRequiredFieldsTest.xml index 871dd606c14db..337fe43a39447 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithRequiredFieldsTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryWithRequiredFieldsTest.xml @@ -33,7 +33,7 @@ - + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateRootCategoryRequiredFieldsTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateRootCategoryRequiredFieldsTest.xml index a5556b076fef6..df85d76a2dd25 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateRootCategoryRequiredFieldsTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateRootCategoryRequiredFieldsTest.xml @@ -35,7 +35,7 @@ - + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateCategoryAndMakeInactiveTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateCategoryAndMakeInactiveTest.xml index 2865e9bc87dd3..11541ac837764 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateCategoryAndMakeInactiveTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateCategoryAndMakeInactiveTest.xml @@ -36,7 +36,7 @@ - + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateCategoryWithInactiveIncludeInMenuTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateCategoryWithInactiveIncludeInMenuTest.xml index 9663632e6dc36..0a93556783e17 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateCategoryWithInactiveIncludeInMenuTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateCategoryWithInactiveIncludeInMenuTest.xml @@ -47,7 +47,7 @@ - + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateCategoryWithProductsTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateCategoryWithProductsTest.xml index ccab2f9e96ce7..7f6ddfe3f6138 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateCategoryWithProductsTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateCategoryWithProductsTest.xml @@ -58,7 +58,7 @@ - + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/ProductAvailableAfterEnablingSubCategoriesTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/ProductAvailableAfterEnablingSubCategoriesTest.xml index ea9a4cb08bb08..0783efa0b713d 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/ProductAvailableAfterEnablingSubCategoriesTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/ProductAvailableAfterEnablingSubCategoriesTest.xml @@ -48,7 +48,7 @@ - + diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminCategoryWithRestrictedUrlKeyNotCreatedTest.xml b/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminCategoryWithRestrictedUrlKeyNotCreatedTest.xml index dec157484dfef..213099d3ba974 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminCategoryWithRestrictedUrlKeyNotCreatedTest.xml +++ b/app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminCategoryWithRestrictedUrlKeyNotCreatedTest.xml @@ -57,7 +57,7 @@ - + @@ -78,7 +78,7 @@ - + @@ -99,7 +99,7 @@ - + @@ -120,7 +120,7 @@ - + diff --git a/app/code/Magento/CatalogWidget/Test/Mftf/Test/CatalogProductListWidgetOperatorsTest.xml b/app/code/Magento/CatalogWidget/Test/Mftf/Test/CatalogProductListWidgetOperatorsTest.xml index 288134a889db0..59f0cd7437f44 100644 --- a/app/code/Magento/CatalogWidget/Test/Mftf/Test/CatalogProductListWidgetOperatorsTest.xml +++ b/app/code/Magento/CatalogWidget/Test/Mftf/Test/CatalogProductListWidgetOperatorsTest.xml @@ -73,7 +73,7 @@ - + diff --git a/app/code/Magento/Cms/Test/Mftf/Test/AdminCreateDisabledCmsBlockEntityAndAssignToCategoryTest.xml b/app/code/Magento/Cms/Test/Mftf/Test/AdminCreateDisabledCmsBlockEntityAndAssignToCategoryTest.xml index 51fbbf8020545..e56f2149d0232 100644 --- a/app/code/Magento/Cms/Test/Mftf/Test/AdminCreateDisabledCmsBlockEntityAndAssignToCategoryTest.xml +++ b/app/code/Magento/Cms/Test/Mftf/Test/AdminCreateDisabledCmsBlockEntityAndAssignToCategoryTest.xml @@ -46,6 +46,7 @@ + diff --git a/app/code/Magento/Cms/Test/Mftf/Test/AdminCreateEnabledCmsBlockEntityAndAssignToCategoryTest.xml b/app/code/Magento/Cms/Test/Mftf/Test/AdminCreateEnabledCmsBlockEntityAndAssignToCategoryTest.xml index 5ccd8fa713cc0..312ca950b2604 100644 --- a/app/code/Magento/Cms/Test/Mftf/Test/AdminCreateEnabledCmsBlockEntityAndAssignToCategoryTest.xml +++ b/app/code/Magento/Cms/Test/Mftf/Test/AdminCreateEnabledCmsBlockEntityAndAssignToCategoryTest.xml @@ -40,6 +40,7 @@ + From dd0c6c003b3e1a44f93865fe317153a773523bb5 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Mon, 13 Apr 2020 15:57:20 +0300 Subject: [PATCH 09/12] Remove redundant Index and flush cache action group --- .../AdminReindexAndFlushCacheActionGroup.xml | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 app/code/Magento/Indexer/Test/Mftf/ActionGroup/IndexerActionGroup/AdminReindexAndFlushCacheActionGroup.xml diff --git a/app/code/Magento/Indexer/Test/Mftf/ActionGroup/IndexerActionGroup/AdminReindexAndFlushCacheActionGroup.xml b/app/code/Magento/Indexer/Test/Mftf/ActionGroup/IndexerActionGroup/AdminReindexAndFlushCacheActionGroup.xml deleted file mode 100644 index 42b6b047ae73e..0000000000000 --- a/app/code/Magento/Indexer/Test/Mftf/ActionGroup/IndexerActionGroup/AdminReindexAndFlushCacheActionGroup.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - Run reindex and flush cache. - - - - - - From 9daf3780246e36a3353e6813c40a2bb9073761c3 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Mon, 13 Apr 2020 18:02:25 +0300 Subject: [PATCH 10/12] Added assertion to AssertAdminSuccessLoginActionGroup --- .../Test/Mftf/ActionGroup/AssertAdminSuccessLoginActionGroup.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Backend/Test/Mftf/ActionGroup/AssertAdminSuccessLoginActionGroup.xml b/app/code/Magento/Backend/Test/Mftf/ActionGroup/AssertAdminSuccessLoginActionGroup.xml index 1f0ce1824fead..f669c4b9f3ca4 100644 --- a/app/code/Magento/Backend/Test/Mftf/ActionGroup/AssertAdminSuccessLoginActionGroup.xml +++ b/app/code/Magento/Backend/Test/Mftf/ActionGroup/AssertAdminSuccessLoginActionGroup.xml @@ -14,5 +14,6 @@ + From c0dd36506679daf3fce55c061e6610d92723b1d3 Mon Sep 17 00:00:00 2001 From: engcom-Echo Date: Tue, 14 Apr 2020 13:58:49 +0300 Subject: [PATCH 11/12] Resolve conflict --- .../Test/Unit/Model/EmailNotificationTest.php | 261 +++++++++++------- 1 file changed, 158 insertions(+), 103 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/EmailNotificationTest.php b/app/code/Magento/Customer/Test/Unit/Model/EmailNotificationTest.php index a8bf94247fd6d..ab90eacbb6032 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/EmailNotificationTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/EmailNotificationTest.php @@ -3,22 +3,29 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); namespace Magento\Customer\Test\Unit\Model; use Magento\Customer\Api\Data\CustomerInterface; +use Magento\Customer\Helper\View; +use Magento\Customer\Model\CustomerRegistry; +use Magento\Customer\Model\Data\CustomerSecure; use Magento\Customer\Model\EmailNotification; use Magento\Framework\App\Area; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Helper\Context; use Magento\Framework\Mail\Template\SenderResolverInterface; +use Magento\Framework\Mail\Template\TransportBuilder; +use Magento\Framework\Mail\TransportInterface; +use Magento\Framework\Reflection\DataObjectProcessor; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; use Magento\Store\Model\ScopeInterface; -use PHPUnit\Framework\TestCase; -use PHPUnit\Framework\MockObject\MockObject; use Magento\Store\Model\Store; -use Magento\Customer\Model\Data\CustomerSecure; +use Magento\Store\Model\StoreManagerInterface; use Magento\Store\Model\Website; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; /** * Unit test for \Magento\Customer\Model\EmailNotification @@ -32,11 +39,6 @@ class EmailNotificationTest extends TestCase */ private const STUB_CUSTOMER_ID = 1; - /** - * @var int - */ - private const STUB_CUSTOMER_STORE_ID = 2; - /** * @var int */ @@ -63,27 +65,27 @@ class EmailNotificationTest extends TestCase private const STUB_SENDER = 'Sender'; /** - * @var \Magento\Customer\Model\CustomerRegistry|MockObject + * @var CustomerRegistry|MockObject */ private $customerRegistryMock; /** - * @var \Magento\Store\Model\StoreManagerInterface|MockObject + * @var StoreManagerInterface|MockObject */ private $storeManagerMock; /** - * @var \Magento\Framework\Mail\Template\TransportBuilder|MockObject + * @var TransportBuilder|MockObject */ private $transportBuilderMock; /** - * @var \Magento\Customer\Helper\View|MockObject + * @var View|MockObject */ private $customerViewHelperMock; /** - * @var \Magento\Framework\Reflection\DataObjectProcessor|MockObject + * @var DataObjectProcessor|MockObject */ private $dataProcessorMock; @@ -93,12 +95,12 @@ class EmailNotificationTest extends TestCase private $customerSecureMock; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface|MockObject + * @var ScopeConfigInterface|MockObject */ private $scopeConfigMock; /** - * @var \Magento\Store\Model\Store|MockObject + * @var Store|MockObject */ private $storeMock; @@ -115,22 +117,18 @@ class EmailNotificationTest extends TestCase /** * @inheritdoc */ - public function setUp(): void + public function setUp():void { - $this->customerRegistryMock = $this->createMock(\Magento\Customer\Model\CustomerRegistry::class); - - $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class); - - $this->transportBuilderMock = $this->createMock(\Magento\Framework\Mail\Template\TransportBuilder::class); - - $this->customerViewHelperMock = $this->createMock(\Magento\Customer\Helper\View::class); - - $this->dataProcessorMock = $this->createMock(\Magento\Framework\Reflection\DataObjectProcessor::class); + $this->customerRegistryMock = $this->createMock(CustomerRegistry::class); + $this->storeManagerMock = $this->createMock(StoreManagerInterface::class); + $this->transportBuilderMock = $this->createMock(TransportBuilder::class); + $this->customerViewHelperMock = $this->createMock(View::class); + $this->dataProcessorMock = $this->createMock(DataObjectProcessor::class); - $contextMock = $this->createPartialMock(\Magento\Framework\App\Helper\Context::class, ['getScopeConfig']); + $contextMock = $this->createPartialMock(Context::class, ['getScopeConfig']); $this->scopeConfigMock = $this->createPartialMock( - \Magento\Framework\App\Config\ScopeConfigInterface::class, + ScopeConfigInterface::class, ['getValue', 'isSetFlag'] ); @@ -167,15 +165,22 @@ public function setUp(): void * Test email notify when credentials changed * * @param int $testNumber + * @param int $customerStoreId * @param string $oldEmail * @param string $newEmail * @param bool $isPasswordChanged - * * @dataProvider sendNotificationEmailsDataProvider + * + * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testEmailNotifyWhenCredentialsChanged($testNumber, $oldEmail, $newEmail, $isPasswordChanged): void - { + public function testEmailNotifyWhenCredentialsChanged( + $testNumber, + $customerStoreId, + $oldEmail, + $newEmail, + $isPasswordChanged + ):void { $customerData = ['key' => 'value']; $senderValues = ['name' => self::STUB_SENDER, 'email' => self::STUB_SENDER]; @@ -199,27 +204,26 @@ public function testEmailNotifyWhenCredentialsChanged($testNumber, $oldEmail, $n $this->senderResolverMock ->expects($expects) ->method('resolve') - ->with(self::STUB_SENDER, self::STUB_CUSTOMER_STORE_ID) + ->with(self::STUB_SENDER, $customerStoreId) ->willReturn($senderValues); /** - * @var MockObject $origCustomer + * @var MockObject $origCustomerMock */ - $origCustomer = $this->createMock(CustomerInterface::class); - $origCustomer->expects($this->any()) + $origCustomerMock = $this->createMock(CustomerInterface::class); + $origCustomerMock->expects($this->any()) ->method('getStoreId') - ->willReturn(0); - $origCustomer->expects($this->any()) + ->willReturn($customerStoreId); + $origCustomerMock->expects($this->any()) ->method('getId') ->willReturn(self::STUB_CUSTOMER_ID); - $origCustomer->expects($this->any()) - ->method('getWebsiteId') - ->willReturn(self::STUB_CUSTOMER_WEBSITE_ID); + $origCustomerMock->expects($this->never()) + ->method('getWebsiteId'); $storeMock = $this->createMock(Store::class); $storeMock->expects($this->any()) ->method('getId') - ->willReturn(self::STUB_CUSTOMER_STORE_ID); + ->willReturn($customerStoreId); $this->storeManagerMock->expects(clone $expects) ->method('getStore') @@ -228,12 +232,10 @@ public function testEmailNotifyWhenCredentialsChanged($testNumber, $oldEmail, $n $websiteMock = $this->createPartialMock(Website::class, ['getStoreIds']); $websiteMock->expects($this->any()) ->method('getStoreIds') - ->willReturn([self::STUB_CUSTOMER_STORE_ID]); + ->willReturn([$customerStoreId]); - $this->storeManagerMock->expects(clone $expects) - ->method('getWebsite') - ->with(self::STUB_CUSTOMER_WEBSITE_ID) - ->willReturn($websiteMock); + $this->storeManagerMock->expects($this->never()) + ->method('getWebsite'); $customerSecureMock = $this->createMock(CustomerSecure::class); $this->customerRegistryMock->expects(clone $expects) @@ -243,12 +245,12 @@ public function testEmailNotifyWhenCredentialsChanged($testNumber, $oldEmail, $n $this->dataProcessorMock->expects(clone $expects) ->method('buildOutputDataArray') - ->with($origCustomer, CustomerInterface::class) + ->with($origCustomerMock, CustomerInterface::class) ->willReturn($customerData); $this->customerViewHelperMock->expects($this->any()) ->method('getCustomerName') - ->with($origCustomer) + ->with($origCustomerMock) ->willReturn(self::STUB_CUSTOMER_NAME); $customerSecureMock->expects(clone $expects) @@ -263,9 +265,9 @@ public function testEmailNotifyWhenCredentialsChanged($testNumber, $oldEmail, $n /** * @var CustomerInterface|MockObject $savedCustomer */ - $savedCustomer = clone $origCustomer; + $savedCustomer = clone $origCustomerMock; - $origCustomer->expects($this->any()) + $origCustomerMock->expects($this->any()) ->method('getEmail') ->willReturn($oldEmail); @@ -279,22 +281,22 @@ public function testEmailNotifyWhenCredentialsChanged($testNumber, $oldEmail, $n [ $xmlPathTemplate, ScopeInterface::SCOPE_STORE, - self::STUB_CUSTOMER_STORE_ID + $customerStoreId ], [ EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, - self::STUB_CUSTOMER_STORE_ID + $customerStoreId ], [ $xmlPathTemplate, ScopeInterface::SCOPE_STORE, - self::STUB_CUSTOMER_STORE_ID + $customerStoreId ], [ EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, - self::STUB_CUSTOMER_STORE_ID + $customerStoreId ] )->willReturnOnConsecutiveCalls( self::STUB_EMAIL_IDENTIFIER, @@ -309,7 +311,7 @@ public function testEmailNotifyWhenCredentialsChanged($testNumber, $oldEmail, $n ->willReturnSelf(); $this->transportBuilderMock->expects(clone $expects) ->method('setTemplateOptions') - ->with(['area' => Area::AREA_FRONTEND, 'store' => self::STUB_CUSTOMER_STORE_ID]) + ->with(['area' => Area::AREA_FRONTEND, 'store' => $customerStoreId]) ->willReturnSelf(); $this->transportBuilderMock->expects(clone $expects) ->method('setTemplateVars') @@ -325,7 +327,7 @@ public function testEmailNotifyWhenCredentialsChanged($testNumber, $oldEmail, $n ->withConsecutive([$oldEmail, self::STUB_CUSTOMER_NAME], [$newEmail, self::STUB_CUSTOMER_NAME]) ->willReturnSelf(); - $transport = $this->createMock(\Magento\Framework\Mail\TransportInterface::class); + $transport = $this->createMock(TransportInterface::class); $this->transportBuilderMock->expects(clone $expects) ->method('getTransport') @@ -348,18 +350,42 @@ public function sendNotificationEmailsDataProvider(): array return [ [ 'test_number' => 1, + 'customerStoreId' => 0, + 'old_email' => 'test@example.com', + 'new_email' => 'test@example.com', + 'is_password_changed' => true + ], + [ + 'test_number' => 1, + 'customerStoreId' => 2, 'old_email' => 'test@example.com', 'new_email' => 'test@example.com', 'is_password_changed' => true ], [ 'test_number' => 2, + 'customerStoreId' => 0, 'old_email' => 'test1@example.com', 'new_email' => 'test2@example.com', 'is_password_changed' => false ], + [ + 'test_number' => 2, + 'customerStoreId' => 2, + 'old_email' => 'test1@example.com', + 'new_email' => 'test2@example.com', + 'is_password_changed' => false + ], + [ + 'test_number' => 3, + 'customerStoreId' => 0, + 'old_email' => 'test1@example.com', + 'new_email' => 'test2@example.com', + 'is_password_changed' => true + ], [ 'test_number' => 3, + 'customerStoreId' => 2, 'old_email' => 'test1@example.com', 'new_email' => 'test2@example.com', 'is_password_changed' => true @@ -370,9 +396,12 @@ public function sendNotificationEmailsDataProvider(): array /** * Test Password Reminder Email Notify * + * @param int $customerStoreId + * @dataProvider customerStoreIdDataProvider + * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testPasswordReminder(): void + public function testPasswordReminder($customerStoreId):void { $customerData = ['key' => 'value']; $senderValues = ['name' => self::STUB_SENDER, 'email' => self::STUB_SENDER]; @@ -381,29 +410,31 @@ public function testPasswordReminder(): void $this->senderResolverMock ->expects($this->once()) ->method('resolve') - ->with(self::STUB_SENDER, self::STUB_CUSTOMER_STORE_ID) + ->with(self::STUB_SENDER, $customerStoreId) ->willReturn($senderValues); /** - * @var CustomerInterface|MockObject $customer + * @var CustomerInterface|MockObject $customerMock */ - $customer = $this->createMock(CustomerInterface::class); - $customer->expects($this->any()) + $customerMock = $this->createMock(CustomerInterface::class); + $customerMock->expects($this->never()) + ->method('getWebsiteId'); + $customerMock->expects($this->any()) ->method('getWebsiteId') ->willReturn(self::STUB_CUSTOMER_WEBSITE_ID); - $customer->expects($this->any()) + $customerMock->expects($this->any()) ->method('getStoreId') - ->willReturn(self::STUB_CUSTOMER_STORE_ID); - $customer->expects($this->any()) + ->willReturn($customerStoreId); + $customerMock->expects($this->any()) ->method('getId') ->willReturn(self::STUB_CUSTOMER_ID); - $customer->expects($this->any()) + $customerMock->expects($this->any()) ->method('getEmail') ->willReturn(self::STUB_CUSTOMER_EMAIL); $this->storeMock->expects($this->any()) ->method('getId') - ->willReturn(self::STUB_CUSTOMER_STORE_ID); + ->willReturn($customerStoreId); $this->storeManagerMock->expects($this->at(0)) ->method('getStore') @@ -426,12 +457,12 @@ public function testPasswordReminder(): void $this->dataProcessorMock->expects($this->once()) ->method('buildOutputDataArray') - ->with($customer, CustomerInterface::class) + ->with($customerMock, CustomerInterface::class) ->willReturn($customerData); $this->customerViewHelperMock->expects($this->any()) ->method('getCustomerName') - ->with($customer) + ->with($customerMock) ->willReturn(self::STUB_CUSTOMER_NAME); $this->customerSecureMock->expects($this->once()) @@ -448,26 +479,26 @@ public function testPasswordReminder(): void ->with( EmailNotification::XML_PATH_REMIND_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, - self::STUB_CUSTOMER_STORE_ID + $customerStoreId )->willReturn(self::STUB_EMAIL_IDENTIFIER); $this->scopeConfigMock->expects($this->at(1)) ->method('getValue') ->with( EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, - self::STUB_CUSTOMER_STORE_ID + $customerStoreId )->willReturn(self::STUB_SENDER); $this->mockDefaultTransportBuilder( self::STUB_EMAIL_IDENTIFIER, - self::STUB_CUSTOMER_STORE_ID, + $customerStoreId, $senderValues, self::STUB_CUSTOMER_EMAIL, self::STUB_CUSTOMER_NAME, ['customer' => $this->customerSecureMock, 'store' => $this->storeMock] ); - $this->model->passwordReminder($customer); + $this->model->passwordReminder($customerMock); } /** @@ -475,7 +506,7 @@ public function testPasswordReminder(): void * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testPasswordReminderCustomerWithoutStoreId(): void + public function testPasswordReminderCustomerWithoutStoreId():void { $customerStoreId = null; $customerData = ['key' => 'value']; @@ -570,9 +601,12 @@ public function testPasswordReminderCustomerWithoutStoreId(): void /** * Test email notify for password reset confirm * + * @dataProvider customerStoreIdDataProvider + * @param int $customerStoreId + * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testPasswordResetConfirmation(): void + public function testPasswordResetConfirmation($customerStoreId):void { $customerData = ['key' => 'value']; $senderValues = ['name' => self::STUB_SENDER, 'email' => self::STUB_SENDER]; @@ -580,26 +614,30 @@ public function testPasswordResetConfirmation(): void $this->senderResolverMock ->expects($this->once()) ->method('resolve') - ->with(self::STUB_SENDER, self::STUB_CUSTOMER_STORE_ID) + ->with(self::STUB_SENDER, $customerStoreId) ->willReturn($senderValues); /** - * @var CustomerInterface|MockObject $customer + * @var CustomerInterface|MockObject $customerMock */ - $customer = $this->createMock(CustomerInterface::class); - $customer->expects($this->once()) + $customerMock = $this->createMock(CustomerInterface::class); + + $customerMock->expects($this->never()) + ->method('getWebsiteId'); + + $customerMock->expects($this->once()) ->method('getStoreId') - ->willReturn(self::STUB_CUSTOMER_STORE_ID); - $customer->expects($this->any()) + ->willReturn($customerStoreId); + $customerMock->expects($this->any()) ->method('getId') ->willReturn(self::STUB_CUSTOMER_ID); - $customer->expects($this->any()) + $customerMock->expects($this->any()) ->method('getEmail') ->willReturn(self::STUB_CUSTOMER_EMAIL); $this->storeMock->expects($this->any()) ->method('getId') - ->willReturn(self::STUB_CUSTOMER_STORE_ID); + ->willReturn($customerStoreId); $this->storeManagerMock->expects($this->at(0)) ->method('getStore') @@ -612,12 +650,12 @@ public function testPasswordResetConfirmation(): void $this->dataProcessorMock->expects($this->once()) ->method('buildOutputDataArray') - ->with($customer, CustomerInterface::class) + ->with($customerMock, CustomerInterface::class) ->willReturn($customerData); $this->customerViewHelperMock->expects($this->any()) ->method('getCustomerName') - ->with($customer) + ->with($customerMock) ->willReturn(self::STUB_CUSTOMER_NAME); $this->customerSecureMock->expects($this->once()) @@ -634,35 +672,37 @@ public function testPasswordResetConfirmation(): void ->with( EmailNotification::XML_PATH_FORGOT_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, - self::STUB_CUSTOMER_STORE_ID + $customerStoreId )->willReturn(self::STUB_EMAIL_IDENTIFIER); $this->scopeConfigMock->expects($this->at(1)) ->method('getValue') ->with( EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, - self::STUB_CUSTOMER_STORE_ID + $customerStoreId )->willReturn(self::STUB_SENDER); $this->mockDefaultTransportBuilder( self::STUB_EMAIL_IDENTIFIER, - self::STUB_CUSTOMER_STORE_ID, + $customerStoreId, $senderValues, self::STUB_CUSTOMER_EMAIL, self::STUB_CUSTOMER_NAME, ['customer' => $this->customerSecureMock, 'store' => $this->storeMock] ); - $this->model->passwordResetConfirmation($customer); + $this->model->passwordResetConfirmation($customerMock); } /** * Test email notify with new account * - * @param void + * @dataProvider customerStoreIdDataProvider + * @param int $customerStoreId + * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testNewAccount(): void + public function testNewAccount($customerStoreId):void { $customerData = ['key' => 'value']; $senderValues = ['name' => self::STUB_SENDER, 'email' => self::STUB_SENDER]; @@ -670,16 +710,18 @@ public function testNewAccount(): void $this->senderResolverMock ->expects($this->once()) ->method('resolve') - ->with(self::STUB_SENDER, self::STUB_CUSTOMER_STORE_ID) + ->with(self::STUB_SENDER, $customerStoreId) ->willReturn($senderValues); /** * @var CustomerInterface|MockObject $customer */ $customer = $this->createMock(CustomerInterface::class); + $customer->expects($this->never()) + ->method('getWebsiteId'); $customer->expects($this->any()) ->method('getStoreId') - ->willReturn(self::STUB_CUSTOMER_STORE_ID); + ->willReturn($customerStoreId); $customer->expects($this->any()) ->method('getId') ->willReturn(self::STUB_CUSTOMER_ID); @@ -689,11 +731,11 @@ public function testNewAccount(): void $this->storeMock->expects($this->any()) ->method('getId') - ->willReturn(self::STUB_CUSTOMER_STORE_ID); + ->willReturn($customerStoreId); $this->storeManagerMock->expects($this->once()) ->method('getStore') - ->with(self::STUB_CUSTOMER_STORE_ID) + ->with($customerStoreId) ->willReturn($this->storeMock); $this->customerRegistryMock->expects($this->once()) @@ -725,19 +767,19 @@ public function testNewAccount(): void ->with( EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, - self::STUB_CUSTOMER_STORE_ID + $customerStoreId )->willReturn(self::STUB_EMAIL_IDENTIFIER); $this->scopeConfigMock->expects($this->at(1)) ->method('getValue') ->with( EmailNotification::XML_PATH_REGISTER_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, - self::STUB_CUSTOMER_STORE_ID + $customerStoreId )->willReturn(self::STUB_SENDER); $this->mockDefaultTransportBuilder( self::STUB_EMAIL_IDENTIFIER, - self::STUB_CUSTOMER_STORE_ID, + $customerStoreId, $senderValues, self::STUB_CUSTOMER_EMAIL, self::STUB_CUSTOMER_NAME, @@ -748,10 +790,23 @@ public function testNewAccount(): void $customer, EmailNotification::NEW_ACCOUNT_EMAIL_REGISTERED, '', - self::STUB_CUSTOMER_STORE_ID + $customerStoreId ); } + /** + * DataProvider customer store + * + * @return array + */ + public function customerStoreIdDataProvider():array + { + return [ + ['customerStoreId' => 0], + ['customerStoreId' => 2] + ]; + } + /** * Create default mock for $this->transportBuilderMock. * @@ -771,8 +826,8 @@ private function mockDefaultTransportBuilder( string $customerEmail, string $customerName, array $templateVars = [] - ): void { - $transport = $this->createMock(\Magento\Framework\Mail\TransportInterface::class); + ):void { + $transportMock = $this->createMock(TransportInterface::class); $this->transportBuilderMock->expects($this->once()) ->method('setTemplateIdentifier') @@ -796,9 +851,9 @@ private function mockDefaultTransportBuilder( ->willReturnSelf(); $this->transportBuilderMock->expects($this->once()) ->method('getTransport') - ->willReturn($transport); + ->willReturn($transportMock); - $transport->expects($this->once()) + $transportMock->expects($this->once()) ->method('sendMessage'); } } From 54467d43a6e4254b8ee65cbc28a4548eaedb91d0 Mon Sep 17 00:00:00 2001 From: Slava Mankivski Date: Thu, 16 Apr 2020 12:30:02 -0500 Subject: [PATCH 12/12] ENGCOM-7452: Revert https://github.com/magento/magento2/pull/23234 --- app/code/Magento/Ui/view/base/web/js/modal/alert.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/modal/alert.js b/app/code/Magento/Ui/view/base/web/js/modal/alert.js index f36fe54a37a9e..0c7042952bc18 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/alert.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/alert.js @@ -39,18 +39,11 @@ define([ }] }, - /** - * Create widget. - */ - _create: function () { - this.options.actions.always(); - this._super(); - }, - /** * Close modal window. */ closeModal: function () { + this.options.actions.always(); this.element.bind('alertclosed', _.bind(this._remove, this)); return this._super();