123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Customer\Test\Unit\Model;
- use Magento\Customer\Api\Data\CustomerInterface;
- use Magento\Customer\Model\EmailNotification;
- use Magento\Framework\App\Area;
- use Magento\Framework\Mail\Template\SenderResolverInterface;
- use Magento\Store\Model\ScopeInterface;
- /**
- * Class EmailNotificationTest
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- class EmailNotificationTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Customer\Model\CustomerRegistry|\PHPUnit_Framework_MockObject_MockObject
- */
- private $customerRegistryMock;
- /**
- * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- private $storeManagerMock;
- /**
- * @var \Magento\Framework\Mail\Template\TransportBuilder|\PHPUnit_Framework_MockObject_MockObject
- */
- private $transportBuilderMock;
- /**
- * @var \Magento\Customer\Helper\View|\PHPUnit_Framework_MockObject_MockObject
- */
- private $customerViewHelperMock;
- /**
- * @var \Magento\Framework\Reflection\DataObjectProcessor|\PHPUnit_Framework_MockObject_MockObject
- */
- private $dataProcessorMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Customer\Model\Data\CustomerSecure
- */
- private $customerSecureMock;
- /**
- * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- private $scopeConfigMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\Store
- */
- private $storeMock;
- /**
- * @var \Magento\Customer\Model\EmailNotification
- */
- private $model;
- /**
- * @var SenderResolverInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- private $senderResolverMock;
- public function setUp()
- {
- $this->customerRegistryMock = $this->createMock(\Magento\Customer\Model\CustomerRegistry::class);
- $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
- $this->transportBuilderMock = $this->createMock(\Magento\Framework\Mail\Template\TransportBuilder::class);
- $this->customerViewHelperMock = $this->createMock(\Magento\Customer\Helper\View::class);
- $this->dataProcessorMock = $this->createMock(\Magento\Framework\Reflection\DataObjectProcessor::class);
- $contextMock = $this->createPartialMock(\Magento\Framework\App\Helper\Context::class, ['getScopeConfig']);
- $this->scopeConfigMock = $this->createPartialMock(
- \Magento\Framework\App\Config\ScopeConfigInterface::class,
- ['getValue', 'isSetFlag']
- );
- $contextMock->expects($this->any())
- ->method('getScopeConfig')
- ->willReturn($this->scopeConfigMock);
- $this->customerSecureMock = $this->createMock(\Magento\Customer\Model\Data\CustomerSecure::class);
- $this->storeMock = $this->createMock(\Magento\Store\Model\Store::class);
- $this->senderResolverMock = $this->getMockBuilder(SenderResolverInterface::class)
- ->setMethods(['resolve'])
- ->disableOriginalConstructor()
- ->getMockForAbstractClass();
- $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
- $this->model = $objectManager->getObject(
- EmailNotification::class,
- [
- 'customerRegistry' => $this->customerRegistryMock,
- 'storeManager' => $this->storeManagerMock,
- 'transportBuilder' => $this->transportBuilderMock,
- 'customerViewHelper' => $this->customerViewHelperMock,
- 'dataProcessor' => $this->dataProcessorMock,
- 'scopeConfig' => $this->scopeConfigMock,
- 'senderResolver' => $this->senderResolverMock,
- ]
- );
- }
- /**
- * @param int $testNumber
- * @param string $oldEmail
- * @param string $newEmail
- * @param bool $isPasswordChanged
- *
- * @dataProvider sendNotificationEmailsDataProvider
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function testCredentialsChanged($testNumber, $oldEmail, $newEmail, $isPasswordChanged)
- {
- $customerId = 1;
- $customerStoreId = 2;
- $customerWebsiteId = 1;
- $customerData = ['key' => 'value'];
- $customerName = 'Customer Name';
- $templateIdentifier = 'Template Identifier';
- $sender = 'Sender';
- $senderValues = ['name' => $sender, 'email' => $sender];
- $expects = $this->once();
- $xmlPathTemplate = EmailNotification::XML_PATH_RESET_PASSWORD_TEMPLATE;
- switch ($testNumber) {
- case 1:
- $xmlPathTemplate = EmailNotification::XML_PATH_RESET_PASSWORD_TEMPLATE;
- $expects = $this->once();
- break;
- case 2:
- $xmlPathTemplate = \Magento\Customer\Model\EmailNotification::XML_PATH_CHANGE_EMAIL_TEMPLATE;
- $expects = $this->exactly(2);
- break;
- case 3:
- $xmlPathTemplate = EmailNotification::XML_PATH_CHANGE_EMAIL_AND_PASSWORD_TEMPLATE;
- $expects = $this->exactly(2);
- break;
- }
- $this->senderResolverMock
- ->expects($expects)
- ->method('resolve')
- ->with($sender, $customerStoreId)
- ->willReturn($senderValues);
- /** @var \PHPUnit_Framework_MockObject_MockObject $origCustomer */
- $origCustomer = $this->createMock(CustomerInterface::class);
- $origCustomer->expects($this->any())
- ->method('getStoreId')
- ->willReturn(0);
- $origCustomer->expects($this->any())
- ->method('getId')
- ->willReturn($customerId);
- $origCustomer->expects($this->any())
- ->method('getWebsiteId')
- ->willReturn($customerWebsiteId);
- $storeMock = $this->createMock(\Magento\Store\Model\Store::class);
- $storeMock->expects($this->any())
- ->method('getId')
- ->willReturn($customerStoreId);
- $this->storeManagerMock->expects(clone $expects)
- ->method('getStore')
- ->willReturn($storeMock);
- $websiteMock = $this->createPartialMock(\Magento\Store\Model\Website::class, ['getStoreIds']);
- $websiteMock->expects($this->any())
- ->method('getStoreIds')
- ->willReturn([$customerStoreId]);
- $this->storeManagerMock->expects(clone $expects)
- ->method('getWebsite')
- ->with($customerWebsiteId)
- ->willReturn($websiteMock);
- $customerSecureMock = $this->createMock(\Magento\Customer\Model\Data\CustomerSecure::class);
- $this->customerRegistryMock->expects(clone $expects)
- ->method('retrieveSecureData')
- ->with($customerId)
- ->willReturn($customerSecureMock);
- $this->dataProcessorMock->expects(clone $expects)
- ->method('buildOutputDataArray')
- ->with($origCustomer, CustomerInterface::class)
- ->willReturn($customerData);
- $this->customerViewHelperMock->expects($this->any())
- ->method('getCustomerName')
- ->with($origCustomer)
- ->willReturn($customerName);
- $customerSecureMock->expects(clone $expects)
- ->method('addData')
- ->with($customerData)
- ->willReturnSelf();
- $customerSecureMock->expects(clone $expects)
- ->method('setData')
- ->with('name', $customerName)
- ->willReturnSelf();
- /** @var CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $savedCustomer */
- $savedCustomer = clone $origCustomer;
- $origCustomer->expects($this->any())
- ->method('getEmail')
- ->willReturn($oldEmail);
- $savedCustomer->expects($this->any())
- ->method('getEmail')
- ->willReturn($newEmail);
- $this->scopeConfigMock->expects($this->any())
- ->method('getValue')
- ->withConsecutive(
- [$xmlPathTemplate, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $customerStoreId],
- [
- \Magento\Customer\Model\EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY,
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
- $customerStoreId
- ],
- [$xmlPathTemplate, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $customerStoreId],
- [
- \Magento\Customer\Model\EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY,
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
- $customerStoreId
- ]
- )
- ->willReturnOnConsecutiveCalls($templateIdentifier, $sender, $templateIdentifier, $sender);
- $this->transportBuilderMock->expects(clone $expects)
- ->method('setTemplateIdentifier')
- ->with($templateIdentifier)
- ->willReturnSelf();
- $this->transportBuilderMock->expects(clone $expects)
- ->method('setTemplateOptions')
- ->with(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $customerStoreId])
- ->willReturnSelf();
- $this->transportBuilderMock->expects(clone $expects)
- ->method('setTemplateVars')
- ->with(['customer' => $customerSecureMock, 'store' => $storeMock])
- ->willReturnSelf();
- $this->transportBuilderMock->expects(clone $expects)
- ->method('setFrom')
- ->with($senderValues)
- ->willReturnSelf();
- $this->transportBuilderMock->expects(clone $expects)
- ->method('addTo')
- ->withConsecutive([$oldEmail, $customerName], [$newEmail, $customerName])
- ->willReturnSelf();
- $transport = $this->createMock(\Magento\Framework\Mail\TransportInterface::class);
- $this->transportBuilderMock->expects(clone $expects)
- ->method('getTransport')
- ->willReturn($transport);
- $transport->expects(clone $expects)
- ->method('sendMessage');
- $this->model->credentialsChanged($savedCustomer, $oldEmail, $isPasswordChanged);
- }
- /**
- * @return array
- */
- public function sendNotificationEmailsDataProvider()
- {
- return [
- [
- 'test_number' => 1,
- 'old_email' => 'test@example.com',
- 'new_email' => 'test@example.com',
- 'is_password_changed' => true
- ],
- [
- 'test_number' => 2,
- 'old_email' => 'test1@example.com',
- 'new_email' => 'test2@example.com',
- 'is_password_changed' => false
- ],
- [
- 'test_number' => 3,
- 'old_email' => 'test1@example.com',
- 'new_email' => 'test2@example.com',
- 'is_password_changed' => true
- ]
- ];
- }
- /**
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function testPasswordReminder()
- {
- $customerId = 1;
- $customerWebsiteId = 1;
- $customerStoreId = 2;
- $customerEmail = 'email@email.com';
- $customerData = ['key' => 'value'];
- $customerName = 'Customer Name';
- $templateIdentifier = 'Template Identifier';
- $sender = 'Sender';
- $senderValues = ['name' => $sender, 'email' => $sender];
- $storeIds = [1, 2];
- $this->senderResolverMock
- ->expects($this->once())
- ->method('resolve')
- ->with($sender, $customerStoreId)
- ->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($customerStoreId);
- $this->storeManagerMock->expects($this->at(0))
- ->method('getStore')
- ->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, $customerStoreId)
- ->willReturn($templateIdentifier);
- $this->scopeConfigMock->expects($this->at(1))
- ->method('getValue')
- ->with(EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, $customerStoreId)
- ->willReturn($sender);
- $this->mockDefaultTransportBuilder(
- $templateIdentifier,
- $customerStoreId,
- $senderValues,
- $customerEmail,
- $customerName,
- ['customer' => $this->customerSecureMock, 'store' => $this->storeMock]
- );
- $this->model->passwordReminder($customer);
- }
- /**
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function testPasswordReminderCustomerWithoutStoreId()
- {
- $customerId = 1;
- $customerWebsiteId = 1;
- $customerStoreId = null;
- $customerEmail = 'email@email.com';
- $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)
- */
- public function testPasswordResetConfirmation()
- {
- $customerId = 1;
- $customerStoreId = 2;
- $customerEmail = 'email@email.com';
- $customerData = ['key' => 'value'];
- $customerName = 'Customer Name';
- $templateIdentifier = 'Template Identifier';
- $sender = 'Sender';
- $senderValues = ['name' => $sender, 'email' => $sender];
- $this->senderResolverMock
- ->expects($this->once())
- ->method('resolve')
- ->with($sender, $customerStoreId)
- ->willReturn($senderValues);
- /** @var CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customer */
- $customer = $this->createMock(CustomerInterface::class);
- $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($customerStoreId);
- $this->storeManagerMock->expects($this->at(0))
- ->method('getStore')
- ->willReturn($this->storeMock);
- $this->storeManagerMock->expects($this->at(1))
- ->method('getStore')
- ->with($customerStoreId)
- ->willReturn($this->storeMock);
- $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_FORGOT_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $customerStoreId)
- ->willReturn($templateIdentifier);
- $this->scopeConfigMock->expects($this->at(1))
- ->method('getValue')
- ->with(EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, $customerStoreId)
- ->willReturn($sender);
- $this->mockDefaultTransportBuilder(
- $templateIdentifier,
- $customerStoreId,
- $senderValues,
- $customerEmail,
- $customerName,
- ['customer' => $this->customerSecureMock, 'store' => $this->storeMock]
- );
- $this->model->passwordResetConfirmation($customer);
- }
- /**
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function testNewAccount()
- {
- $customerId = 1;
- $customerStoreId = 2;
- $customerEmail = 'email@email.com';
- $customerData = ['key' => 'value'];
- $customerName = 'Customer Name';
- $templateIdentifier = 'Template Identifier';
- $sender = 'Sender';
- $senderValues = ['name' => $sender, 'email' => $sender];
- $this->senderResolverMock
- ->expects($this->once())
- ->method('resolve')
- ->with($sender, $customerStoreId)
- ->willReturn($senderValues);
- /** @var CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customer */
- $customer = $this->createMock(CustomerInterface::class);
- $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($customerStoreId);
- $this->storeManagerMock->expects($this->once())
- ->method('getStore')
- ->with($customerStoreId)
- ->willReturn($this->storeMock);
- $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_REGISTER_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $customerStoreId)
- ->willReturn($templateIdentifier);
- $this->scopeConfigMock->expects($this->at(1))
- ->method('getValue')
- ->with(EmailNotification::XML_PATH_REGISTER_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, $customerStoreId)
- ->willReturn($sender);
- $this->mockDefaultTransportBuilder(
- $templateIdentifier,
- $customerStoreId,
- $senderValues,
- $customerEmail,
- $customerName,
- ['customer' => $this->customerSecureMock, 'back_url' => '', 'store' => $this->storeMock]
- );
- $this->model->newAccount($customer, EmailNotification::NEW_ACCOUNT_EMAIL_REGISTERED, '', $customerStoreId);
- }
- /**
- * Create default mock for $this->transportBuilderMock.
- *
- * @param string $templateIdentifier
- * @param int $customerStoreId
- * @param array $senderValues
- * @param string $customerEmail
- * @param string $customerName
- * @param array $templateVars
- *
- * @return void
- */
- private function mockDefaultTransportBuilder(
- string $templateIdentifier,
- int $customerStoreId,
- array $senderValues,
- string $customerEmail,
- string $customerName,
- array $templateVars = []
- ): void {
- $transport = $this->createMock(\Magento\Framework\Mail\TransportInterface::class);
- $this->transportBuilderMock->expects($this->once())
- ->method('setTemplateIdentifier')
- ->with($templateIdentifier)
- ->willReturnSelf();
- $this->transportBuilderMock->expects($this->once())
- ->method('setTemplateOptions')
- ->with(['area' => Area::AREA_FRONTEND, 'store' => $customerStoreId])
- ->willReturnSelf();
- $this->transportBuilderMock->expects($this->once())
- ->method('setTemplateVars')
- ->with($templateVars)
- ->willReturnSelf();
- $this->transportBuilderMock->expects($this->once())
- ->method('setFrom')
- ->with($senderValues)
- ->willReturnSelf();
- $this->transportBuilderMock->expects($this->once())
- ->method('addTo')
- ->with($customerEmail, $customerName)
- ->willReturnSelf();
- $this->transportBuilderMock->expects($this->once())
- ->method('getTransport')
- ->willReturn($transport);
- $transport->expects($this->once())
- ->method('sendMessage');
- }
- }
|