/** * @param array $result * @param bool $expectedValue * @dataProvider getButtonDataProvider */ public function testGetButtonData($result, $expectedValue) { $this->registryMock->expects($this->any())->method('registry')->willReturn(1); $this->customerRegistryMock->expects($this->once())->method('retrieve')->willReturn($this->customerModelMock); $this->customerModelMock->expects($this->once())->method('isCustomerLocked')->willReturn($expectedValue); $this->urlBuilderMock->expects($this->any())->method('getUrl')->willReturn('http://website.com/'); $this->assertEquals($result, $this->block->getButtonData()); }
/** * test SaveAuth */ public function testSaveAuth() { $customerId = 1; $customerSecureMock = $this->getMock(\Magento\Customer\Model\Data\CustomerSecure::class, [], [], '', false); $dbAdapter = $this->getMock(\Magento\Framework\DB\Adapter\AdapterInterface::class, [], [], '', false); $this->customerRegistry->expects($this->once())->method('retrieveSecureData')->willReturn($customerSecureMock); $customerSecureMock->expects($this->exactly(3))->method('getData')->willReturn(1); $this->customerResourceModel->expects($this->any())->method('getConnection')->willReturn($dbAdapter); $this->customerResourceModel->expects($this->any())->method('getTable')->willReturn('customer_entity'); $dbAdapter->expects($this->any())->method('update')->with('customer_entity', ['failures_num' => 1, 'first_failure' => 1, 'lock_expires' => 1]); $dbAdapter->expects($this->any())->method('quoteInto')->with('entity_id = ?', $customerId); $this->model->saveAuth($customerId); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testNewAccount() { $customerId = 1; $customerStoreId = 2; $customerEmail = '*****@*****.**'; $customerData = ['key' => 'value']; $customerName = 'Customer Name'; $templateIdentifier = 'Template Identifier'; $sender = 'Sender'; $customer = $this->getMock(\Magento\Customer\Api\Data\CustomerInterface::class, [], [], '', false); $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, \Magento\Customer\Api\Data\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); $transport = $this->getMock(\Magento\Framework\Mail\TransportInterface::class, [], [], '', false); $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(['customer' => $this->customerSecureMock, 'back_url' => '', 'store' => $this->storeMock])->willReturnSelf(); $this->transportBuilderMock->expects($this->once())->method('setFrom')->with($sender)->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'); $this->model->newAccount($customer, EmailNotification::NEW_ACCOUNT_EMAIL_REGISTERED, '', $customerStoreId); }
/** * @param string $expectedResult * @param bool $value * @dataProvider getAccountLockDataProvider * @return void */ public function testGetAccountLock($expectedResult, $value) { $this->customerRegistry->expects($this->once())->method('retrieve')->willReturn($this->customerModel); $this->customerModel->expects($this->once())->method('isCustomerLocked')->willReturn($value); $expectedResult = new \Magento\Framework\Phrase($expectedResult); $this->assertEquals($expectedResult, $this->block->getAccountLock()); }
/** * @param string $email * @param string $templateIdentifier * @param string $sender * @param int $storeId * @param int $customerId * @param string $hash */ protected function prepareInitiatePasswordReset($email, $templateIdentifier, $sender, $storeId, $customerId, $hash) { $websiteId = 1; $dateTime = date(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT); $customerData = ['key' => 'value']; $customerName = 'Customer Name'; $this->store->expects($this->once())->method('getWebsiteId')->willReturn($websiteId); $this->store->expects($this->any())->method('getId')->willReturn($storeId); $this->storeManager->expects($this->any())->method('getStore')->willReturn($this->store); $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $customer->expects($this->any())->method('getEmail')->willReturn($email); $customer->expects($this->any())->method('getId')->willReturn($customerId); $customer->expects($this->any())->method('getStoreId')->willReturn($storeId); $this->customerRepository->expects($this->once())->method('get')->with($email, $websiteId)->willReturn($customer); $this->customerRepository->expects($this->once())->method('save')->with($customer)->willReturnSelf(); $this->random->expects($this->once())->method('getUniqueHash')->willReturn($hash); $this->customerViewHelper->expects($this->any())->method('getCustomerName')->with($customer)->willReturn($customerName); $this->customerSecure->expects($this->any())->method('setRpToken')->with($hash)->willReturnSelf(); $this->customerSecure->expects($this->any())->method('setRpTokenCreatedAt')->with($dateTime)->willReturnSelf(); $this->customerSecure->expects($this->any())->method('addData')->with($customerData)->willReturnSelf(); $this->customerSecure->expects($this->any())->method('setData')->with('name', $customerName)->willReturnSelf(); $this->customerRegistry->expects($this->any())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecure); $this->dataObjectProcessor->expects($this->any())->method('buildOutputDataArray')->with($customer, '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn($customerData); $this->prepareEmailSend($email, $templateIdentifier, $sender, $storeId, $customerName); }
/** * return bool */ public function testValidateResetPasswordToken() { $this->reInitModel(); $this->customer->expects($this->once())->method('getResetPasswordLinkExpirationPeriod')->willReturn(100000); $this->customerRegistry->expects($this->atLeastOnce())->method('retrieveSecureData')->willReturn($this->customerSecure); $this->assertTrue($this->accountManagement->validateResetPasswordLinkToken(22, 'newStringToken')); }
public function testCreateAccountWithPasswordHashWithCustomerAddresses() { $websiteId = 1; $addressId = 2; $customerId = null; $storeId = 1; $hash = '4nj54lkj5jfi03j49f8bgujfgsd'; //Handle store $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $store->expects($this->any())->method('getWebsiteId')->willReturn($websiteId); //Handle address - existing and non-existing. Non-Existing should return null when call getId method $existingAddress = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock(); $nonExistingAddress = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock(); //Ensure that existing address is not in use $this->addressRepository->expects($this->atLeastOnce())->method("save")->withConsecutive(array($this->logicalNot($this->identicalTo($existingAddress))), array($this->identicalTo($nonExistingAddress))); $existingAddress->expects($this->any())->method("getId")->willReturn($addressId); //Expects that id for existing address should be unset $existingAddress->expects($this->once())->method("setId")->with(null); //Handle Customer calls $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $customer->expects($this->atLeastOnce())->method('getWebsiteId')->willReturn($websiteId); $customer->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId); $customer->expects($this->any())->method("getId")->willReturn($customerId); //Return Customer from customer repositoryå $this->customerRepository->expects($this->atLeastOnce())->method('save')->willReturn($customer); $this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($customer); $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->setMethods(['setRpToken', 'setRpTokenCreatedAt', 'getPasswordHash'])->disableOriginalConstructor()->getMock(); $customerSecure->expects($this->once())->method('setRpToken')->with($hash); $customerSecure->expects($this->any())->method('getPasswordHash')->willReturn($hash); $this->customerRegistry->expects($this->any())->method('retrieveSecureData')->with($customerId)->willReturn($customerSecure); $this->random->expects($this->once())->method('getUniqueHash')->willReturn($hash); $customer->expects($this->atLeastOnce())->method('getAddresses')->willReturn([$existingAddress, $nonExistingAddress]); $this->storeManager->expects($this->atLeastOnce())->method('getStore')->willReturn($store); $this->assertSame($customer, $this->accountManagement->createAccountWithPasswordHash($customer, $hash)); }
public function testDelete() { $customerId = 14; $customerModel = $this->getMock('Magento\\Customer\\Model\\Customer', ['delete'], [], '', false); $this->customer->expects($this->once())->method('getId')->willReturn($customerId); $this->customerRegistry->expects($this->once())->method('retrieve')->with($customerId)->willReturn($customerModel); $customerModel->expects($this->once())->method('delete'); $this->customerRegistry->expects($this->once())->method('remove')->with($customerId); $this->assertTrue($this->model->delete($this->customer)); }
/** * @return void */ public function testCheckIfLocked() { $customerId = 7; $email = '*****@*****.**'; $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false); $customerMock->expects($this->once())->method('getId')->willReturn($customerId); $this->customerSecure->expects($this->once())->method('isCustomerLocked')->willReturn(true); $this->scopeConfigMock->expects($this->once())->method('getValue')->with('contact/email/recipient_email')->willReturn($email); $this->customerRegistryMock->expects($this->once())->method('retrieve')->with($customerId)->willReturn($this->customerSecure); $this->setExpectedException('\\Magento\\Framework\\Exception\\State\\UserLockedException', __('The account is locked. Please wait and try again or contact %1.', $email)); $this->helper->checkIfLocked($customerMock); }
/** * @param int $testNumber * @param string $oldEmail * @param string $newEmail * @param bool $isPasswordChanged * * @dataProvider sendNotificationEmailsDataProvider * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testSendNotificationEmailsIfRequired($testNumber, $oldEmail, $newEmail, $isPasswordChanged) { $customerId = 1; $customerStoreId = 2; $customerWebsiteId = 1; $customerData = ['key' => 'value']; $customerName = 'Customer Name'; $templateIdentifier = 'Template Identifier'; $sender = 'Sender'; switch ($testNumber) { case 1: $xmlPathTemplate = EmailNotification::XML_PATH_RESET_PASSWORD_TEMPLATE; $expects = $this->once(); break; case 2: $xmlPathTemplate = 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; } $origCustomer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $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->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $storeMock->expects($this->any())->method('getId')->willReturn($customerStoreId); $this->storeManagerMock->expects(clone $expects)->method('getStore')->willReturn($storeMock); $websiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->setMethods(['getStoreIds'])->getMock(); $websiteMock->expects($this->any())->method('getStoreIds')->willReturn([$customerStoreId]); $this->storeManagerMock->expects(clone $expects)->method('getWebsite')->with($customerWebsiteId)->willReturn($websiteMock); $customerSecureMock = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->disableOriginalConstructor()->getMock(); $this->customerRegistryMock->expects(clone $expects)->method('retrieveSecureData')->with($customerId)->willReturn($customerSecureMock); $this->dataProcessorMock->expects(clone $expects)->method('buildOutputDataArray')->with($origCustomer, '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->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(); $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\Helper\EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $customerStoreId], [$xmlPathTemplate, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $customerStoreId], [\Magento\Customer\Helper\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($sender)->willReturnSelf(); $this->transportBuilderMock->expects(clone $expects)->method('addTo')->withConsecutive([$oldEmail, $customerName], [$newEmail, $customerName])->willReturnSelf(); $transport = $this->getMockBuilder('Magento\\Framework\\Mail\\TransportInterface')->getMock(); $this->transportBuilderMock->expects(clone $expects)->method('getTransport')->willReturn($transport); $transport->expects(clone $expects)->method('sendMessage'); $this->assertEquals($this->helper, $this->helper->sendNotificationEmailsIfRequired($origCustomer, $savedCustomer, $isPasswordChanged)); }
public function testUpgradeCustomerPassword() { $customerId = '1'; $password = '******'; $passwordHash = 'hash:salt:999'; $model = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->setMethods(['getId'])->getMock(); $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMockForAbstractClass(); $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->disableOriginalConstructor()->setMethods(['getPasswordHash', 'setPasswordHash'])->getMock(); $model->expects($this->exactly(2))->method('getId')->willReturn($customerId); $this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($customer); $this->customerRegistry->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($customerSecure); $customerSecure->expects($this->once())->method('getPasswordHash')->willReturn($passwordHash); $this->encryptorMock->expects($this->once())->method('validateHashVersion')->with($passwordHash)->willReturn(false); $this->encryptorMock->expects($this->once())->method('getHash')->with($password, true)->willReturn($passwordHash); $customerSecure->expects($this->once())->method('setPasswordHash')->with($passwordHash); $this->customerRepository->expects($this->once())->method('save')->with($customer); $event = new \Magento\Framework\DataObject(); $event->setData(['password' => 'password', 'model' => $model]); $observerMock = new \Magento\Framework\Event\Observer(); $observerMock->setEvent($event); $this->model->execute($observerMock); }
public function testDeleteById() { $addressId = 12; $customerId = 43; $this->address->expects($this->once())->method('getCustomerId')->willReturn($customerId); $addressCollection = $this->getMock('Magento\\Customer\\Model\\ResourceModel\\Address\\Collection', [], [], '', false); $this->addressRegistry->expects($this->once())->method('retrieve')->with($addressId)->willReturn($this->address); $this->customerRegistry->expects($this->once())->method('retrieve')->with($customerId)->willReturn($this->customer); $this->customer->expects($this->once())->method('getAddressesCollection')->willReturn($addressCollection); $addressCollection->expects($this->once())->method('clear'); $this->addressResourceModel->expects($this->once())->method('delete')->with($this->address); $this->addressRegistry->expects($this->once())->method('remove')->with($addressId); $this->assertTrue($this->repository->deleteById($addressId)); }
/** * @return void */ public function testAuthenticate() { $username = '******'; $password = '******'; $passwordHash = '1a2b3f4c'; $customerData = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $customerModel = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->getMock(); $customerModel->expects($this->once())->method('updateData')->willReturn($customerModel); $this->customerRepository->expects($this->once())->method('get')->with($username)->willReturn($customerData); $this->authenticationMock->expects($this->once())->method('authenticate'); $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->setMethods(['getPasswordHash'])->disableOriginalConstructor()->getMock(); $customerSecure->expects($this->any())->method('getPasswordHash')->willReturn($passwordHash); $this->customerRegistry->expects($this->any())->method('retrieveSecureData')->willReturn($customerSecure); $this->customerFactory->expects($this->once())->method('create')->willReturn($customerModel); $this->manager->expects($this->exactly(2))->method('dispatch')->withConsecutive(['customer_customer_authenticated', ['model' => $customerModel, 'password' => $password]], ['customer_data_object_login', ['customer' => $customerData]]); $this->assertEquals($customerData, $this->accountManagement->authenticate($username, $password)); }
/** * @param bool $result * @dataProvider validateCustomerPassword */ public function testValidateCustomerPassword($result) { $customerId = 7; $password = '******'; $hash = '1b2af329dd0'; $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false); $this->customerRepositoryMock->expects($this->any())->method('getById')->willReturn($customerMock); $this->customerSecure->expects($this->any())->method('getId')->willReturn($customerId); $this->customerSecure->expects($this->once())->method('getPasswordHash')->willReturn($hash); $this->customerRegistryMock->expects($this->any())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecure); $this->encryptorMock->expects($this->once())->method('validateHash')->with($password, $hash)->willReturn($result); if ($result) { $this->assertTrue($this->authentication->authenticate($customerId, $password)); } else { $this->backendConfigMock->expects($this->exactly(2))->method('getValue')->withConsecutive([\Magento\Customer\Model\Authentication::LOCKOUT_THRESHOLD_PATH], [\Magento\Customer\Model\Authentication::MAX_FAILURES_PATH])->willReturnOnConsecutiveCalls(1, 1); $this->customerSecure->expects($this->once())->method('isCustomerLocked')->willReturn(false); $this->customerRegistryMock->expects($this->once())->method('retrieve')->with($customerId)->willReturn($this->customerSecure); $this->customerRepositoryMock->expects($this->once())->method('save')->willReturn($customerMock); $this->setExpectedException('\\Magento\\Framework\\Exception\\InvalidEmailOrPasswordException'); $this->authentication->authenticate($customerId, $password); } }
/** * @return void */ public function testChangePassword() { $customerId = 7; $email = '*****@*****.**'; $currentPassword = '******'; $newPassword = '******'; $passwordHash = '1a2b3f4c'; $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $customer->expects($this->any())->method('getId')->willReturn($customerId); $this->customerRepository->expects($this->once())->method('get')->with($email)->willReturn($customer); $this->accountManagementHelper->expects($this->once())->method('validatePasswordAndLockStatus')->with($customer, $currentPassword); $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->setMethods(['setRpToken', 'setRpTokenCreatedAt', 'setPasswordHash'])->disableOriginalConstructor()->getMock(); $customerSecure->expects($this->once())->method('setRpToken')->with(null); $customerSecure->expects($this->once())->method('setRpTokenCreatedAt')->with(null); $customerSecure->expects($this->once())->method('setPasswordHash')->with($passwordHash); $this->customerRegistry->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($customerSecure); $this->encryptor->expects($this->once())->method('getHash')->with($newPassword, true)->willReturn($passwordHash); $this->scopeConfig->expects($this->any())->method('getValue')->willReturnMap([[AccountManagement::XML_PATH_MINIMUM_PASSWORD_LENGTH, 'default', null, 7], [AccountManagement::XML_PATH_REQUIRED_CHARACTER_CLASSES_NUMBER, 'default', null, 1]]); $this->string->expects($this->any())->method('strlen')->with($newPassword)->willReturn(7); $this->customerRepository->expects($this->once())->method('save')->with($customer); $this->assertTrue($this->accountManagement->changePassword($email, $currentPassword, $newPassword)); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testSendPasswordReminderEmail() { $customerId = 1; $customerStoreId = 2; $customerEmail = '*****@*****.**'; $passwordToken = 'token'; $isFrontendSecure = true; $resetUrl = 'reset url'; $customerData = ['key' => 'value']; $customerName = 'Customer Name'; $templateIdentifier = 'Template Identifier'; $sender = 'Sender'; $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $customer->expects($this->any())->method('getStoreId')->willReturn($customerStoreId); $customer->expects($this->any())->method('getId')->willReturn($customerId); $customer->expects($this->any())->method('getEmail')->willReturn($customerEmail); $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->storeManager->expects($this->any())->method('getStore')->with($customerStoreId)->willReturn($store); $store->expects($this->any())->method('isFrontUrlSecure')->willReturn($isFrontendSecure); $this->url->expects($this->once())->method('getUrl')->with('customer/account/createPassword', ['_query' => ['id' => $customerId, 'token' => $passwordToken], '_store' => $customerStoreId, '_secure' => $isFrontendSecure])->willReturn($resetUrl); $customerSecure = $this->getMockBuilder('\\Magento\\Customer\\Model\\Data\\CustomerSecure')->disableOriginalConstructor()->setMethods(['addData', 'setData', 'setResetPasswordUrl'])->getMock(); $this->customerRegistry->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($customerSecure); $this->dataObjectProcessor->expects($this->once())->method('buildOutputDataArray')->with($customer, '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn($customerData); $this->customerViewHelper->expects($this->any())->method('getCustomerName')->with($customer)->willReturn($customerName); $customerSecure->expects($this->once())->method('addData')->with($customerData)->willReturnSelf(); $customerSecure->expects($this->once())->method('setData')->with('name', $customerName)->willReturnSelf(); $customerSecure->expects($this->once())->method('setResetPasswordUrl')->with($resetUrl); $this->scopeConfig->expects($this->at(0))->method('getValue')->with(AccountManagement::XML_PATH_REMIND_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $customerStoreId)->willReturn($templateIdentifier); $this->scopeConfig->expects($this->at(1))->method('getValue')->with(AccountManagement::XML_PATH_FORGOT_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, $customerStoreId)->willReturn($sender); $transport = $this->getMockBuilder('Magento\\Framework\\Mail\\TransportInterface')->getMock(); $this->transportBuilder->expects($this->once())->method('setTemplateIdentifier')->with($templateIdentifier)->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('setTemplateOptions')->with(['area' => Area::AREA_FRONTEND, 'store' => $customerStoreId])->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('setTemplateVars')->with(['customer' => $customerSecure, 'store' => $store])->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('setFrom')->with($sender)->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('addTo')->with($customerEmail, $customerName)->willReturnSelf(); $this->transportBuilder->expects($this->once())->method('getTransport')->willReturn($transport); $transport->expects($this->once())->method('sendMessage'); $this->assertEquals($this->accountManagement, $this->accountManagement->sendPasswordReminderEmail($customer, $passwordToken)); }