Skip to content

Commit 049285e

Browse files
author
Stanislav Idolov
authored
ENGCOM-1493: [Forwardport] Fix reset password link with appropriate customer store #15095
2 parents 9ff5ba8 + 565cd37 commit 049285e

File tree

2 files changed

+109
-6
lines changed

2 files changed

+109
-6
lines changed

app/code/Magento/Customer/Model/EmailNotification.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ private function getWebsiteStoreId($customer, $defaultStoreId = null)
314314
*/
315315
public function passwordReminder(CustomerInterface $customer)
316316
{
317-
$storeId = $this->getWebsiteStoreId($customer);
317+
$storeId = $customer->getStoreId();
318318
if (!$storeId) {
319-
$storeId = $this->storeManager->getStore()->getId();
319+
$storeId = $this->getWebsiteStoreId($customer);
320320
}
321321

322322
$customerEmailData = $this->getFullCustomerObject($customer);

app/code/Magento/Customer/Test/Unit/Model/EmailNotificationTest.php

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,15 @@ public function sendNotificationEmailsDataProvider()
312312
public function testPasswordReminder()
313313
{
314314
$customerId = 1;
315+
$customerWebsiteId = 1;
315316
$customerStoreId = 2;
316317
$customerEmail = 'email@email.com';
317318
$customerData = ['key' => 'value'];
318319
$customerName = 'Customer Name';
319320
$templateIdentifier = 'Template Identifier';
320321
$sender = 'Sender';
321322
$senderValues = ['name' => $sender, 'email' => $sender];
323+
$storeIds = [1, 2];
322324

323325
$this->senderResolverMock
324326
->expects($this->once())
@@ -328,6 +330,9 @@ public function testPasswordReminder()
328330

329331
/** @var CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customer */
330332
$customer = $this->createMock(CustomerInterface::class);
333+
$customer->expects($this->any())
334+
->method('getWebsiteId')
335+
->willReturn($customerWebsiteId);
331336
$customer->expects($this->any())
332337
->method('getStoreId')
333338
->willReturn($customerStoreId);
@@ -346,10 +351,15 @@ public function testPasswordReminder()
346351
->method('getStore')
347352
->willReturn($this->storeMock);
348353

349-
$this->storeManagerMock->expects($this->at(1))
350-
->method('getStore')
351-
->with($customerStoreId)
352-
->willReturn($this->storeMock);
354+
$websiteMock = $this->createPartialMock(\Magento\Store\Model\Website::class, ['getStoreIds']);
355+
$websiteMock->expects($this->any())
356+
->method('getStoreIds')
357+
->willReturn($storeIds);
358+
359+
$this->storeManagerMock->expects($this->any())
360+
->method('getWebsite')
361+
->with($customerWebsiteId)
362+
->willReturn($websiteMock);
353363

354364
$this->customerRegistryMock->expects($this->once())
355365
->method('retrieveSecureData')
@@ -396,6 +406,99 @@ public function testPasswordReminder()
396406
$this->model->passwordReminder($customer);
397407
}
398408

409+
/**
410+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
411+
*/
412+
public function testPasswordReminderCustomerWithoutStoreId()
413+
{
414+
$customerId = 1;
415+
$customerWebsiteId = 1;
416+
$customerStoreId = null;
417+
$customerEmail = 'email@email.com';
418+
$customerData = ['key' => 'value'];
419+
$customerName = 'Customer Name';
420+
$templateIdentifier = 'Template Identifier';
421+
$sender = 'Sender';
422+
$senderValues = ['name' => $sender, 'email' => $sender];
423+
$storeIds = [1, 2];
424+
$defaultStoreId = reset($storeIds);
425+
$this->senderResolverMock
426+
->expects($this->once())
427+
->method('resolve')
428+
->with($sender, $defaultStoreId)
429+
->willReturn($senderValues);
430+
/** @var CustomerInterface | \PHPUnit_Framework_MockObject_MockObject $customer */
431+
$customer = $this->createMock(CustomerInterface::class);
432+
$customer->expects($this->any())
433+
->method('getWebsiteId')
434+
->willReturn($customerWebsiteId);
435+
$customer->expects($this->any())
436+
->method('getStoreId')
437+
->willReturn($customerStoreId);
438+
$customer->expects($this->any())
439+
->method('getId')
440+
->willReturn($customerId);
441+
$customer->expects($this->any())
442+
->method('getEmail')
443+
->willReturn($customerEmail);
444+
$this->storeMock->expects($this->any())
445+
->method('getId')
446+
->willReturn($defaultStoreId);
447+
$this->storeManagerMock->expects($this->at(0))
448+
->method('getStore')
449+
->willReturn($this->storeMock);
450+
$this->storeManagerMock->expects($this->at(1))
451+
->method('getStore')
452+
->with($defaultStoreId)
453+
->willReturn($this->storeMock);
454+
$websiteMock = $this->createPartialMock(\Magento\Store\Model\Website::class, ['getStoreIds']);
455+
$websiteMock->expects($this->any())
456+
->method('getStoreIds')
457+
->willReturn($storeIds);
458+
$this->storeManagerMock->expects($this->any())
459+
->method('getWebsite')
460+
->with($customerWebsiteId)
461+
->willReturn($websiteMock);
462+
463+
$this->customerRegistryMock->expects($this->once())
464+
->method('retrieveSecureData')
465+
->with($customerId)
466+
->willReturn($this->customerSecureMock);
467+
$this->dataProcessorMock->expects($this->once())
468+
->method('buildOutputDataArray')
469+
->with($customer, CustomerInterface::class)
470+
->willReturn($customerData);
471+
$this->customerViewHelperMock->expects($this->any())
472+
->method('getCustomerName')
473+
->with($customer)
474+
->willReturn($customerName);
475+
$this->customerSecureMock->expects($this->once())
476+
->method('addData')
477+
->with($customerData)
478+
->willReturnSelf();
479+
$this->customerSecureMock->expects($this->once())
480+
->method('setData')
481+
->with('name', $customerName)
482+
->willReturnSelf();
483+
$this->scopeConfigMock->expects($this->at(0))
484+
->method('getValue')
485+
->with(EmailNotification::XML_PATH_REMIND_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $defaultStoreId)
486+
->willReturn($templateIdentifier);
487+
$this->scopeConfigMock->expects($this->at(1))
488+
->method('getValue')
489+
->with(EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, $defaultStoreId)
490+
->willReturn($sender);
491+
$this->mockDefaultTransportBuilder(
492+
$templateIdentifier,
493+
$defaultStoreId,
494+
$senderValues,
495+
$customerEmail,
496+
$customerName,
497+
['customer' => $this->customerSecureMock, 'store' => $this->storeMock]
498+
);
499+
$this->model->passwordReminder($customer);
500+
}
501+
399502
/**
400503
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
401504
*/

0 commit comments

Comments
 (0)