25 private $customerRegistryMock;
30 private $storeManagerMock;
35 private $transportBuilderMock;
40 private $customerViewHelperMock;
45 private $dataProcessorMock;
50 private $customerSecureMock;
55 private $scopeConfigMock;
70 private $senderResolverMock;
74 $this->customerRegistryMock = $this->createMock(\
Magento\
Customer\Model\CustomerRegistry::class);
76 $this->storeManagerMock = $this->createMock(\
Magento\Store\Model\StoreManagerInterface::class);
78 $this->transportBuilderMock = $this->createMock(\
Magento\Framework\Mail\Template\TransportBuilder::class);
80 $this->customerViewHelperMock = $this->createMock(\
Magento\
Customer\Helper\View::class);
82 $this->dataProcessorMock = $this->createMock(\
Magento\Framework\Reflection\DataObjectProcessor::class);
84 $contextMock = $this->createPartialMock(\
Magento\Framework\
App\Helper\Context::class, [
'getScopeConfig']);
86 $this->scopeConfigMock = $this->createPartialMock(
88 [
'getValue',
'isSetFlag']
91 $contextMock->expects($this->any())
92 ->method(
'getScopeConfig')
93 ->willReturn($this->scopeConfigMock);
95 $this->customerSecureMock = $this->createMock(\
Magento\
Customer\Model\Data\CustomerSecure::class);
97 $this->storeMock = $this->createMock(\
Magento\Store\Model\Store::class);
99 $this->senderResolverMock = $this->getMockBuilder(SenderResolverInterface::class)
100 ->setMethods([
'resolve'])
101 ->disableOriginalConstructor()
102 ->getMockForAbstractClass();
104 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
107 EmailNotification::class,
109 'customerRegistry' => $this->customerRegistryMock,
110 'storeManager' => $this->storeManagerMock,
111 'transportBuilder' => $this->transportBuilderMock,
112 'customerViewHelper' => $this->customerViewHelperMock,
113 'dataProcessor' => $this->dataProcessorMock,
114 'scopeConfig' => $this->scopeConfigMock,
115 'senderResolver' => $this->senderResolverMock,
129 public function testCredentialsChanged($testNumber, $oldEmail, $newEmail, $isPasswordChanged)
132 $customerStoreId = 2;
133 $customerWebsiteId = 1;
135 $customerName =
'Customer Name';
136 $templateIdentifier =
'Template Identifier';
138 $senderValues = [
'name' => $sender,
'email' => $sender];
140 $expects = $this->once();
142 switch ($testNumber) {
145 $expects = $this->once();
149 $expects = $this->exactly(2);
153 $expects = $this->exactly(2);
157 $this->senderResolverMock
160 ->with($sender, $customerStoreId)
161 ->willReturn($senderValues);
164 $origCustomer = $this->createMock(CustomerInterface::class);
165 $origCustomer->expects($this->any())
166 ->method(
'getStoreId')
168 $origCustomer->expects($this->any())
171 $origCustomer->expects($this->any())
172 ->method(
'getWebsiteId')
173 ->willReturn($customerWebsiteId);
175 $storeMock = $this->createMock(\
Magento\Store\Model\Store::class);
176 $storeMock->expects($this->any())
178 ->willReturn($customerStoreId);
180 $this->storeManagerMock->expects(clone $expects)
182 ->willReturn($storeMock);
184 $websiteMock = $this->createPartialMock(\
Magento\Store\Model\Website::class, [
'getStoreIds']);
185 $websiteMock->expects($this->any())
186 ->method(
'getStoreIds')
187 ->willReturn([$customerStoreId]);
189 $this->storeManagerMock->expects(clone $expects)
190 ->method(
'getWebsite')
191 ->with($customerWebsiteId)
192 ->willReturn($websiteMock);
194 $customerSecureMock = $this->createMock(\
Magento\Customer\Model\Data\CustomerSecure::class);
195 $this->customerRegistryMock->expects(clone $expects)
196 ->method(
'retrieveSecureData')
198 ->willReturn($customerSecureMock);
200 $this->dataProcessorMock->expects(clone $expects)
201 ->method(
'buildOutputDataArray')
202 ->with($origCustomer, CustomerInterface::class)
205 $this->customerViewHelperMock->expects($this->any())
206 ->method(
'getCustomerName')
207 ->with($origCustomer)
208 ->willReturn($customerName);
210 $customerSecureMock->expects(clone $expects)
214 $customerSecureMock->expects(clone $expects)
216 ->with(
'name', $customerName)
220 $savedCustomer = clone $origCustomer;
222 $origCustomer->expects($this->any())
224 ->willReturn($oldEmail);
226 $savedCustomer->expects($this->any())
228 ->willReturn($newEmail);
230 $this->scopeConfigMock->expects($this->any())
233 [$xmlPathTemplate, \
Magento\Store\Model\ScopeInterface::SCOPE_STORE, $customerStoreId],
236 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE,
239 [$xmlPathTemplate, \
Magento\Store\Model\ScopeInterface::SCOPE_STORE, $customerStoreId],
242 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE,
246 ->willReturnOnConsecutiveCalls($templateIdentifier, $sender, $templateIdentifier, $sender);
248 $this->transportBuilderMock->expects(clone $expects)
249 ->method(
'setTemplateIdentifier')
250 ->with($templateIdentifier)
252 $this->transportBuilderMock->expects(clone $expects)
253 ->method(
'setTemplateOptions')
256 $this->transportBuilderMock->expects(clone $expects)
257 ->method(
'setTemplateVars')
258 ->with([
'customer' => $customerSecureMock,
'store' => $storeMock])
260 $this->transportBuilderMock->expects(clone $expects)
262 ->with($senderValues)
265 $this->transportBuilderMock->expects(clone $expects)
267 ->withConsecutive([$oldEmail, $customerName], [$newEmail, $customerName])
270 $transport = $this->createMock(\
Magento\Framework\Mail\TransportInterface::class);
272 $this->transportBuilderMock->expects(clone $expects)
273 ->method(
'getTransport')
274 ->willReturn($transport);
276 $transport->expects(clone $expects)
277 ->method(
'sendMessage');
279 $this->model->credentialsChanged($savedCustomer, $oldEmail, $isPasswordChanged);
292 'is_password_changed' => true
298 'is_password_changed' =>
false 304 'is_password_changed' => true
312 public function testPasswordReminder()
315 $customerWebsiteId = 1;
316 $customerStoreId = 2;
319 $customerName =
'Customer Name';
320 $templateIdentifier =
'Template Identifier';
322 $senderValues = [
'name' => $sender,
'email' => $sender];
325 $this->senderResolverMock
326 ->expects($this->once())
328 ->with($sender, $customerStoreId)
329 ->willReturn($senderValues);
332 $customer = $this->createMock(CustomerInterface::class);
334 ->method(
'getWebsiteId')
335 ->willReturn($customerWebsiteId);
337 ->method(
'getStoreId')
338 ->willReturn($customerStoreId);
346 $this->storeMock->expects($this->any())
348 ->willReturn($customerStoreId);
350 $this->storeManagerMock->expects($this->at(0))
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);
359 $this->storeManagerMock->expects($this->any())
360 ->method(
'getWebsite')
361 ->with($customerWebsiteId)
362 ->willReturn($websiteMock);
364 $this->customerRegistryMock->expects($this->once())
365 ->method(
'retrieveSecureData')
367 ->willReturn($this->customerSecureMock);
369 $this->dataProcessorMock->expects($this->once())
370 ->method(
'buildOutputDataArray')
371 ->with(
$customer, CustomerInterface::class)
374 $this->customerViewHelperMock->expects($this->any())
375 ->method(
'getCustomerName')
377 ->willReturn($customerName);
379 $this->customerSecureMock->expects($this->once())
383 $this->customerSecureMock->expects($this->once())
385 ->with(
'name', $customerName)
388 $this->scopeConfigMock->expects($this->at(0))
391 ->willReturn($templateIdentifier);
392 $this->scopeConfigMock->expects($this->at(1))
395 ->willReturn($sender);
397 $this->mockDefaultTransportBuilder(
403 [
'customer' => $this->customerSecureMock,
'store' => $this->storeMock]
406 $this->model->passwordReminder(
$customer);
412 public function testPasswordReminderCustomerWithoutStoreId()
415 $customerWebsiteId = 1;
416 $customerStoreId =
null;
419 $customerName =
'Customer Name';
420 $templateIdentifier =
'Template Identifier';
422 $senderValues = [
'name' => $sender,
'email' => $sender];
424 $defaultStoreId = reset($storeIds);
425 $this->senderResolverMock
426 ->expects($this->once())
428 ->with($sender, $defaultStoreId)
429 ->willReturn($senderValues);
431 $customer = $this->createMock(CustomerInterface::class);
433 ->method(
'getWebsiteId')
434 ->willReturn($customerWebsiteId);
436 ->method(
'getStoreId')
437 ->willReturn($customerStoreId);
444 $this->storeMock->expects($this->any())
446 ->willReturn($defaultStoreId);
447 $this->storeManagerMock->expects($this->at(0))
449 ->willReturn($this->storeMock);
450 $this->storeManagerMock->expects($this->at(1))
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);
463 $this->customerRegistryMock->expects($this->once())
464 ->method(
'retrieveSecureData')
466 ->willReturn($this->customerSecureMock);
467 $this->dataProcessorMock->expects($this->once())
468 ->method(
'buildOutputDataArray')
469 ->with(
$customer, CustomerInterface::class)
471 $this->customerViewHelperMock->expects($this->any())
472 ->method(
'getCustomerName')
474 ->willReturn($customerName);
475 $this->customerSecureMock->expects($this->once())
479 $this->customerSecureMock->expects($this->once())
481 ->with(
'name', $customerName)
483 $this->scopeConfigMock->expects($this->at(0))
486 ->willReturn($templateIdentifier);
487 $this->scopeConfigMock->expects($this->at(1))
490 ->willReturn($sender);
491 $this->mockDefaultTransportBuilder(
497 [
'customer' => $this->customerSecureMock,
'store' => $this->storeMock]
499 $this->model->passwordReminder(
$customer);
505 public function testPasswordResetConfirmation()
508 $customerStoreId = 2;
511 $customerName =
'Customer Name';
512 $templateIdentifier =
'Template Identifier';
514 $senderValues = [
'name' => $sender,
'email' => $sender];
516 $this->senderResolverMock
517 ->expects($this->once())
519 ->with($sender, $customerStoreId)
520 ->willReturn($senderValues);
523 $customer = $this->createMock(CustomerInterface::class);
525 ->method(
'getStoreId')
526 ->willReturn($customerStoreId);
534 $this->storeMock->expects($this->any())
536 ->willReturn($customerStoreId);
538 $this->storeManagerMock->expects($this->at(0))
540 ->willReturn($this->storeMock);
542 $this->storeManagerMock->expects($this->at(1))
544 ->with($customerStoreId)
545 ->willReturn($this->storeMock);
547 $this->customerRegistryMock->expects($this->once())
548 ->method(
'retrieveSecureData')
550 ->willReturn($this->customerSecureMock);
552 $this->dataProcessorMock->expects($this->once())
553 ->method(
'buildOutputDataArray')
554 ->with(
$customer, CustomerInterface::class)
557 $this->customerViewHelperMock->expects($this->any())
558 ->method(
'getCustomerName')
560 ->willReturn($customerName);
562 $this->customerSecureMock->expects($this->once())
566 $this->customerSecureMock->expects($this->once())
568 ->with(
'name', $customerName)
571 $this->scopeConfigMock->expects($this->at(0))
574 ->willReturn($templateIdentifier);
575 $this->scopeConfigMock->expects($this->at(1))
578 ->willReturn($sender);
580 $this->mockDefaultTransportBuilder(
586 [
'customer' => $this->customerSecureMock,
'store' => $this->storeMock]
589 $this->model->passwordResetConfirmation(
$customer);
595 public function testNewAccount()
598 $customerStoreId = 2;
601 $customerName =
'Customer Name';
602 $templateIdentifier =
'Template Identifier';
604 $senderValues = [
'name' => $sender,
'email' => $sender];
606 $this->senderResolverMock
607 ->expects($this->once())
609 ->with($sender, $customerStoreId)
610 ->willReturn($senderValues);
613 $customer = $this->createMock(CustomerInterface::class);
615 ->method(
'getStoreId')
616 ->willReturn($customerStoreId);
624 $this->storeMock->expects($this->any())
626 ->willReturn($customerStoreId);
628 $this->storeManagerMock->expects($this->once())
630 ->with($customerStoreId)
631 ->willReturn($this->storeMock);
633 $this->customerRegistryMock->expects($this->once())
634 ->method(
'retrieveSecureData')
636 ->willReturn($this->customerSecureMock);
638 $this->dataProcessorMock->expects($this->once())
639 ->method(
'buildOutputDataArray')
640 ->with(
$customer, CustomerInterface::class)
643 $this->customerViewHelperMock->expects($this->any())
644 ->method(
'getCustomerName')
646 ->willReturn($customerName);
648 $this->customerSecureMock->expects($this->once())
652 $this->customerSecureMock->expects($this->once())
654 ->with(
'name', $customerName)
657 $this->scopeConfigMock->expects($this->at(0))
660 ->willReturn($templateIdentifier);
661 $this->scopeConfigMock->expects($this->at(1))
664 ->willReturn($sender);
666 $this->mockDefaultTransportBuilder(
672 [
'customer' => $this->customerSecureMock,
'back_url' =>
'',
'store' => $this->storeMock]
690 private function mockDefaultTransportBuilder(
691 string $templateIdentifier,
692 int $customerStoreId,
695 string $customerName,
696 array $templateVars = []
698 $transport = $this->createMock(\
Magento\Framework\Mail\TransportInterface::class);
700 $this->transportBuilderMock->expects($this->once())
701 ->method(
'setTemplateIdentifier')
702 ->with($templateIdentifier)
704 $this->transportBuilderMock->expects($this->once())
705 ->method(
'setTemplateOptions')
708 $this->transportBuilderMock->expects($this->once())
709 ->method(
'setTemplateVars')
710 ->with($templateVars)
712 $this->transportBuilderMock->expects($this->once())
714 ->with($senderValues)
716 $this->transportBuilderMock->expects($this->once())
720 $this->transportBuilderMock->expects($this->once())
721 ->method(
'getTransport')
722 ->willReturn($transport);
724 $transport->expects($this->once())
725 ->method(
'sendMessage');
const XML_PATH_CHANGE_EMAIL_AND_PASSWORD_TEMPLATE
const XML_PATH_FORGOT_EMAIL_IDENTITY
sendNotificationEmailsDataProvider()
const NEW_ACCOUNT_EMAIL_REGISTERED
const XML_PATH_REMIND_EMAIL_TEMPLATE
const XML_PATH_CHANGE_EMAIL_TEMPLATE
const XML_PATH_RESET_PASSWORD_TEMPLATE
const XML_PATH_REGISTER_EMAIL_TEMPLATE
const XML_PATH_REGISTER_EMAIL_IDENTITY
const XML_PATH_FORGOT_EMAIL_TEMPLATE