diff --git a/app/code/Magento/Customer/Model/EmailNotification.php b/app/code/Magento/Customer/Model/EmailNotification.php
index b72929a9de3a5..55d82e0d7ccbe 100644
--- a/app/code/Magento/Customer/Model/EmailNotification.php
+++ b/app/code/Magento/Customer/Model/EmailNotification.php
@@ -170,7 +170,7 @@ public function credentialsChanged(
private function emailAndPasswordChanged(CustomerInterface $customer, $email): void
{
$storeId = $customer->getStoreId();
- if (!$storeId) {
+ if ($storeId === null) {
$storeId = $this->getWebsiteStoreId($customer);
}
@@ -196,7 +196,7 @@ private function emailAndPasswordChanged(CustomerInterface $customer, $email): v
private function emailChanged(CustomerInterface $customer, $email): void
{
$storeId = $customer->getStoreId();
- if (!$storeId) {
+ if ($storeId === null) {
$storeId = $this->getWebsiteStoreId($customer);
}
@@ -221,7 +221,7 @@ private function emailChanged(CustomerInterface $customer, $email): void
private function passwordReset(CustomerInterface $customer): void
{
$storeId = $customer->getStoreId();
- if (!$storeId) {
+ if ($storeId === null) {
$storeId = $this->getWebsiteStoreId($customer);
}
@@ -320,7 +320,7 @@ private function getWebsiteStoreId($customer, $defaultStoreId = null): int
public function passwordReminder(CustomerInterface $customer): void
{
$storeId = $customer->getStoreId();
- if (!$storeId) {
+ if ($storeId === null) {
$storeId = $this->getWebsiteStoreId($customer);
}
@@ -344,7 +344,7 @@ public function passwordReminder(CustomerInterface $customer): void
public function passwordResetConfirmation(CustomerInterface $customer): void
{
$storeId = $customer->getStoreId();
- if (!$storeId) {
+ if ($storeId === null) {
$storeId = $this->getWebsiteStoreId($customer);
}
@@ -365,7 +365,7 @@ public function passwordResetConfirmation(CustomerInterface $customer): void
* @param CustomerInterface $customer
* @param string $type
* @param string $backUrl
- * @param int $storeId
+ * @param int|null $storeId
* @param string $sendemailStoreId
* @return void
* @throws LocalizedException
@@ -374,7 +374,7 @@ public function newAccount(
CustomerInterface $customer,
$type = self::NEW_ACCOUNT_EMAIL_REGISTERED,
$backUrl = '',
- $storeId = 0,
+ $storeId = null,
$sendemailStoreId = null
): void {
$types = self::TEMPLATE_TYPES;
@@ -385,7 +385,7 @@ public function newAccount(
);
}
- if (!$storeId) {
+ if ($storeId === null) {
$storeId = $this->getWebsiteStoreId($customer, $sendemailStoreId);
}
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');
}
}
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}}.
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.
-
-
-
-
-
-
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();
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..ac12dc4df8d64
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/Account/EmailTemplateTest.php
@@ -0,0 +1,204 @@
+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"]');
+
+ $this->assertSame(1, $greeting->length);
+ $this->assertSame($expectedGreeting, $greeting->item(0)->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);
+ }
+}