Skip to content

Commit 1e8ce46

Browse files
committed
Fix reset password link with appropriate customer store
1 parent b2eb795 commit 1e8ce46

File tree

2 files changed

+110
-6
lines changed

2 files changed

+110
-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: 108 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ 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'];
@@ -320,6 +321,8 @@ public function testPasswordReminder()
320321
$sender = 'Sender';
321322
$senderValues = ['name' => $sender, 'email' => $sender];
322323

324+
$storeIds = [1, 2];
325+
323326
$this->senderResolverMock
324327
->expects($this->once())
325328
->method('resolve')
@@ -328,6 +331,9 @@ public function testPasswordReminder()
328331

329332
/** @var CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customer */
330333
$customer = $this->createMock(CustomerInterface::class);
334+
$customer->expects($this->any())
335+
->method('getWebsiteId')
336+
->willReturn($customerWebsiteId);
331337
$customer->expects($this->any())
332338
->method('getStoreId')
333339
->willReturn($customerStoreId);
@@ -346,10 +352,15 @@ public function testPasswordReminder()
346352
->method('getStore')
347353
->willReturn($this->storeMock);
348354

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

354365
$this->customerRegistryMock->expects($this->once())
355366
->method('retrieveSecureData')
@@ -396,6 +407,99 @@ public function testPasswordReminder()
396407
$this->model->passwordReminder($customer);
397408
}
398409

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

0 commit comments

Comments
 (0)