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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/code/Magento/Customer/Model/EmailNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,9 @@ private function getWebsiteStoreId($customer, $defaultStoreId = null)
*/
public function passwordReminder(CustomerInterface $customer)
{
$storeId = $this->getWebsiteStoreId($customer);
$storeId = $customer->getStoreId();
if (!$storeId) {
$storeId = $this->storeManager->getStore()->getId();
$storeId = $this->getWebsiteStoreId($customer);
}

$customerEmailData = $this->getFullCustomerObject($customer);
Expand Down
111 changes: 107 additions & 4 deletions app/code/Magento/Customer/Test/Unit/Model/EmailNotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,15 @@ public function sendNotificationEmailsDataProvider()
public function testPasswordReminder()
{
$customerId = 1;
$customerWebsiteId = 1;
$customerStoreId = 2;
$customerEmail = '[email protected]';
$customerData = ['key' => 'value'];
$customerName = 'Customer Name';
$templateIdentifier = 'Template Identifier';
$sender = 'Sender';
$senderValues = ['name' => $sender, 'email' => $sender];
$storeIds = [1, 2];

$this->senderResolverMock
->expects($this->once())
Expand All @@ -328,6 +330,9 @@ public function testPasswordReminder()

/** @var CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customer */
$customer = $this->createMock(CustomerInterface::class);
$customer->expects($this->any())
->method('getWebsiteId')
->willReturn($customerWebsiteId);
$customer->expects($this->any())
->method('getStoreId')
->willReturn($customerStoreId);
Expand All @@ -346,10 +351,15 @@ public function testPasswordReminder()
->method('getStore')
->willReturn($this->storeMock);

$this->storeManagerMock->expects($this->at(1))
->method('getStore')
->with($customerStoreId)
->willReturn($this->storeMock);
$websiteMock = $this->createPartialMock(\Magento\Store\Model\Website::class, ['getStoreIds']);
$websiteMock->expects($this->any())
->method('getStoreIds')
->willReturn($storeIds);

$this->storeManagerMock->expects($this->any())
->method('getWebsite')
->with($customerWebsiteId)
->willReturn($websiteMock);

$this->customerRegistryMock->expects($this->once())
->method('retrieveSecureData')
Expand Down Expand Up @@ -396,6 +406,99 @@ public function testPasswordReminder()
$this->model->passwordReminder($customer);
}

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testPasswordReminderCustomerWithoutStoreId()
{
$customerId = 1;
$customerWebsiteId = 1;
$customerStoreId = null;
$customerEmail = '[email protected]';
$customerData = ['key' => 'value'];
$customerName = 'Customer Name';
$templateIdentifier = 'Template Identifier';
$sender = 'Sender';
$senderValues = ['name' => $sender, 'email' => $sender];
$storeIds = [1, 2];
$defaultStoreId = reset($storeIds);
$this->senderResolverMock
->expects($this->once())
->method('resolve')
->with($sender, $defaultStoreId)
->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())
->method('getStoreId')
->willReturn($customerStoreId);
$customer->expects($this->any())
->method('getId')
->willReturn($customerId);
$customer->expects($this->any())
->method('getEmail')
->willReturn($customerEmail);
$this->storeMock->expects($this->any())
->method('getId')
->willReturn($defaultStoreId);
$this->storeManagerMock->expects($this->at(0))
->method('getStore')
->willReturn($this->storeMock);
$this->storeManagerMock->expects($this->at(1))
->method('getStore')
->with($defaultStoreId)
->willReturn($this->storeMock);
$websiteMock = $this->createPartialMock(\Magento\Store\Model\Website::class, ['getStoreIds']);
$websiteMock->expects($this->any())
->method('getStoreIds')
->willReturn($storeIds);
$this->storeManagerMock->expects($this->any())
->method('getWebsite')
->with($customerWebsiteId)
->willReturn($websiteMock);

$this->customerRegistryMock->expects($this->once())
->method('retrieveSecureData')
->with($customerId)
->willReturn($this->customerSecureMock);
$this->dataProcessorMock->expects($this->once())
->method('buildOutputDataArray')
->with($customer, CustomerInterface::class)
->willReturn($customerData);
$this->customerViewHelperMock->expects($this->any())
->method('getCustomerName')
->with($customer)
->willReturn($customerName);
$this->customerSecureMock->expects($this->once())
->method('addData')
->with($customerData)
->willReturnSelf();
$this->customerSecureMock->expects($this->once())
->method('setData')
->with('name', $customerName)
->willReturnSelf();
$this->scopeConfigMock->expects($this->at(0))
->method('getValue')
->with(EmailNotification::XML_PATH_REMIND_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $defaultStoreId)
->willReturn($templateIdentifier);
$this->scopeConfigMock->expects($this->at(1))
->method('getValue')
->with(EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, $defaultStoreId)
->willReturn($sender);
$this->mockDefaultTransportBuilder(
$templateIdentifier,
$defaultStoreId,
$senderValues,
$customerEmail,
$customerName,
['customer' => $this->customerSecureMock, 'store' => $this->storeMock]
);
$this->model->passwordReminder($customer);
}

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
Expand Down