Skip to content

Commit 1e1a0eb

Browse files
committed
MC-41588: Send email setting not working at store-view level
- fixed - modified test
1 parent 8010e79 commit 1e1a0eb

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\App\Config\ScopeConfigInterface;
1111
use Magento\Framework\App\ObjectManager;
1212
use Magento\Framework\Mail\Template\SenderResolverInterface;
13+
use Magento\Store\Model\App\Emulation;
1314
use Magento\Store\Model\StoreManagerInterface;
1415
use Magento\Framework\Mail\Template\TransportBuilder;
1516
use Magento\Customer\Helper\View as CustomerViewHelper;
@@ -103,6 +104,11 @@ class EmailNotification implements EmailNotificationInterface
103104
*/
104105
private $senderResolver;
105106

107+
/**
108+
* @var Emulation
109+
*/
110+
private $emulation;
111+
106112
/**
107113
* @param CustomerRegistry $customerRegistry
108114
* @param StoreManagerInterface $storeManager
@@ -111,6 +117,7 @@ class EmailNotification implements EmailNotificationInterface
111117
* @param DataObjectProcessor $dataProcessor
112118
* @param ScopeConfigInterface $scopeConfig
113119
* @param SenderResolverInterface|null $senderResolver
120+
* @param Emulation|null $emulation
114121
*/
115122
public function __construct(
116123
CustomerRegistry $customerRegistry,
@@ -119,7 +126,8 @@ public function __construct(
119126
CustomerViewHelper $customerViewHelper,
120127
DataObjectProcessor $dataProcessor,
121128
ScopeConfigInterface $scopeConfig,
122-
SenderResolverInterface $senderResolver = null
129+
SenderResolverInterface $senderResolver = null,
130+
Emulation $emulation =null
123131
) {
124132
$this->customerRegistry = $customerRegistry;
125133
$this->storeManager = $storeManager;
@@ -128,6 +136,7 @@ public function __construct(
128136
$this->dataProcessor = $dataProcessor;
129137
$this->scopeConfig = $scopeConfig;
130138
$this->senderResolver = $senderResolver ?? ObjectManager::getInstance()->get(SenderResolverInterface::class);
139+
$this->emulation = $emulation ?? ObjectManager::getInstance()->get(Emulation::class);
131140
}
132141

133142
/**
@@ -274,7 +283,9 @@ private function sendEmailTemplate(
274283
->addTo($email, $this->customerViewHelper->getCustomerName($customer))
275284
->getTransport();
276285

286+
$this->emulation->startEnvironmentEmulation($storeId, \Magento\Framework\App\Area::AREA_FRONTEND);
277287
$transport->sendMessage();
288+
$this->emulation->stopEnvironmentEmulation();
278289
}
279290

280291
/**

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\Framework\Mail\TransportInterface;
2121
use Magento\Framework\Reflection\DataObjectProcessor;
2222
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
23+
use Magento\Store\Model\App\Emulation;
2324
use Magento\Store\Model\ScopeInterface;
2425
use Magento\Store\Model\Store;
2526
use Magento\Store\Model\StoreManagerInterface;
@@ -113,6 +114,10 @@ class EmailNotificationTest extends TestCase
113114
* @var SenderResolverInterface|MockObject
114115
*/
115116
private $senderResolverMock;
117+
/**
118+
* @var Emulation|MockObject
119+
*/
120+
private $emulation;
116121

117122
/**
118123
* @inheritdoc
@@ -144,6 +149,7 @@ protected function setUp(): void
144149
->setMethods(['resolve'])
145150
->disableOriginalConstructor()
146151
->getMockForAbstractClass();
152+
$this->emulation = $this->createMock(Emulation::class);
147153

148154
$objectManager = new ObjectManagerHelper($this);
149155

@@ -157,6 +163,7 @@ protected function setUp(): void
157163
'dataProcessor' => $this->dataProcessorMock,
158164
'scopeConfig' => $this->scopeConfigMock,
159165
'senderResolver' => $this->senderResolverMock,
166+
'emulation' => $this->emulation,
160167
]
161168
);
162169
}
@@ -336,6 +343,14 @@ public function testEmailNotifyWhenCredentialsChanged(
336343
$transport->expects(clone $expects)
337344
->method('sendMessage');
338345

346+
$this->emulation->expects(clone $expects)
347+
->method('startEnvironmentEmulation')
348+
->willReturnSelf();
349+
350+
$this->emulation->expects(clone $expects)
351+
->method('stopEnvironmentEmulation')
352+
->willReturnSelf();
353+
339354
$this->model->credentialsChanged($savedCustomer, $oldEmail, $isPasswordChanged);
340355
}
341356

@@ -498,6 +513,14 @@ public function testPasswordReminder($customerStoreId):void
498513
['customer' => $this->customerSecureMock, 'store' => $this->storeMock]
499514
);
500515

516+
$this->emulation->expects($this->once())
517+
->method('startEnvironmentEmulation')
518+
->willReturnSelf();
519+
520+
$this->emulation->expects($this->once())
521+
->method('stopEnvironmentEmulation')
522+
->willReturnSelf();
523+
501524
$this->model->passwordReminder($customerMock);
502525
}
503526

@@ -595,6 +618,14 @@ public function testPasswordReminderCustomerWithoutStoreId():void
595618
self::STUB_CUSTOMER_NAME,
596619
['customer' => $this->customerSecureMock, 'store' => $this->storeMock]
597620
);
621+
$this->emulation->expects($this->once())
622+
->method('startEnvironmentEmulation')
623+
->willReturnSelf();
624+
625+
$this->emulation->expects($this->once())
626+
->method('stopEnvironmentEmulation')
627+
->willReturnSelf();
628+
598629
$this->model->passwordReminder($customer);
599630
}
600631

@@ -690,6 +721,13 @@ public function testPasswordResetConfirmation($customerStoreId):void
690721
self::STUB_CUSTOMER_NAME,
691722
['customer' => $this->customerSecureMock, 'store' => $this->storeMock]
692723
);
724+
$this->emulation->expects($this->once())
725+
->method('startEnvironmentEmulation')
726+
->willReturnSelf();
727+
728+
$this->emulation->expects($this->once())
729+
->method('stopEnvironmentEmulation')
730+
->willReturnSelf();
693731

694732
$this->model->passwordResetConfirmation($customerMock);
695733
}
@@ -785,6 +823,13 @@ public function testNewAccount($customerStoreId):void
785823
self::STUB_CUSTOMER_NAME,
786824
['customer' => $this->customerSecureMock, 'back_url' => '', 'store' => $this->storeMock]
787825
);
826+
$this->emulation->expects($this->once())
827+
->method('startEnvironmentEmulation')
828+
->willReturnSelf();
829+
830+
$this->emulation->expects($this->once())
831+
->method('stopEnvironmentEmulation')
832+
->willReturnSelf();
788833

789834
$this->model->newAccount(
790835
$customer,

0 commit comments

Comments
 (0)