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 1/4] 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 2/4] 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 3/4] 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 4/4] 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 @@