コード例 #1
0
 /**
  * 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'));
 }
コード例 #2
0
 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));
 }
コード例 #3
0
 /**
  * @param \Magento\Customer\Api\Data\CustomerInterface $customer
  * @param string                                       $redirectUrl
  *
  * @return $this
  */
 public function sendEmailConfirmation(\Magento\Customer\Api\Data\CustomerInterface $customer, $redirectUrl)
 {
     $storeId = $this->getWebsiteStoreId($customer);
     if ($this->scopeConfig->isSetFlag(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_DISABLE_CUSTOMER_SUCCESS, 'store', $storeId)) {
         return $this;
     } else {
         parent::sendEmailConfirmation($customer, $redirectUrl);
     }
 }
コード例 #4
0
 /**
  * @param string $currentPassword
  * @param string $newPassword
  * @param [] $errors
  * @param string $customerEmail
  * @return void
  */
 protected function mockChangePasswordErrors($currentPassword, $newPassword, $errors, $customerEmail)
 {
     if (!empty($errors['exception'])) {
         $exception = new $errors['exception'](__($errors['message']));
         $this->customerAccountManagement->expects($this->once())->method('changePassword')->with($customerEmail, $currentPassword, $newPassword)->willThrowException($exception);
         $this->messageManager->expects($this->any())->method('addException')->with($exception, __('We can\'t save the customer.'))->willReturnSelf();
     }
     $this->customerSession->expects($this->once())->method('setCustomerFormData')->with(true)->willReturnSelf();
     $this->messageManager->expects($this->any())->method('addError')->with($errors['message'])->willReturnSelf();
     $this->resultRedirect->expects($this->any())->method('setPath')->with('*/*/edit')->willReturnSelf();
 }
コード例 #5
0
 /**
  * @expectedException \Magento\Framework\Exception\InputException
  * @expectedExceptionMessage Invalid value of "" provided for the email type field
  */
 public function testInitiatePasswordResetNoTemplate()
 {
     $storeId = 1;
     $customerId = 1;
     $email = '*****@*****.**';
     $template = null;
     $templateIdentifier = 'Template Identifier';
     $sender = 'Sender';
     mt_srand(mt_rand() + 100000000 * microtime() % PHP_INT_MAX);
     $hash = md5(uniqid(microtime() . mt_rand(0, mt_getrandmax()), true));
     $this->prepareInitiatePasswordReset($email, $templateIdentifier, $sender, $storeId, $customerId, $hash);
     $this->accountManagement->initiatePasswordReset($email, $template);
 }
コード例 #6
0
 /**
  * @return void
  */
 public function testAuthenticate()
 {
     $username = '******';
     $password = '******';
     $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->accountManagementHelper->expects($this->once())->method('checkIfLocked')->with($customerData);
     $this->accountManagementHelper->expects($this->once())->method('validatePasswordAndLockStatus')->with($customerData, $password);
     $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));
 }
コード例 #7
0
 /**
  * @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));
 }
コード例 #8
0
 /**
  * @expectedException \Magento\Framework\Exception\LocalizedException
  */
 public function testCreateAccountWithPasswordHashForGuest()
 {
     $storeId = 1;
     $storeName = 'store_name';
     $websiteId = 1;
     $hash = '4nj54lkj5jfi03j49f8bgujfgsd';
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $storeMock->expects($this->once())->method('getId')->willReturn($storeId);
     $storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
     $storeMock->expects($this->once())->method('getName')->willReturn($storeName);
     $this->storeManager->expects($this->exactly(3))->method('getStore')->willReturn($storeMock);
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMockForAbstractClass();
     $customerMock->expects($this->exactly(2))->method('getId')->willReturn(null);
     $customerMock->expects($this->exactly(3))->method('getStoreId')->willReturn(null);
     $customerMock->expects($this->exactly(2))->method('getWebsiteId')->willReturn(null);
     $customerMock->expects($this->once())->method('setStoreId')->with($storeId)->willReturnSelf();
     $customerMock->expects($this->once())->method('setWebsiteId')->with($websiteId)->willReturnSelf();
     $customerMock->expects($this->once())->method('setCreatedIn')->with($storeName)->willReturnSelf();
     $customerMock->expects($this->once())->method('getAddresses')->willReturn(null);
     $customerMock->expects($this->once())->method('setAddresses')->with(null)->willReturnSelf();
     $this->customerRepository->expects($this->once())->method('save')->with($customerMock, $hash)->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('Exception message')));
     $this->accountManagement->createAccountWithPasswordHash($customerMock, $hash);
 }
コード例 #9
0
ファイル: Checkout.php プロジェクト: whoople/magento2-testing
 /**
  * Involve new customer to system
  *
  * @return $this
  */
 protected function _involveNewCustomer()
 {
     $customer = $this->_quote->getCustomer();
     $confirmationStatus = $this->_accountManagement->getConfirmationStatus($customer->getId());
     if ($confirmationStatus === AccountManagement::ACCOUNT_CONFIRMATION_REQUIRED) {
         $this->_messageManager->addSuccess(__('Thank you for registering with Main Website Store.'));
     } else {
         $this->getCustomerSession()->regenerateId();
         $this->getCustomerSession()->loginById($customer->getId());
     }
     return $this;
 }
コード例 #10
0
 /**
  * {@inheritdoc}
  */
 public function getPasswordHash($password)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getPasswordHash');
     if (!$pluginInfo) {
         return parent::getPasswordHash($password);
     } else {
         return $this->___callPlugins('getPasswordHash', func_get_args(), $pluginInfo);
     }
 }
コード例 #11
0
ファイル: Checkout.php プロジェクト: nja78/magento2
 /**
  * Involve new customer to system
  *
  * @return $this
  */
 protected function _involveNewCustomer()
 {
     $customer = $this->_quote->getCustomer();
     $confirmationStatus = $this->_accountManagement->getConfirmationStatus($customer->getId());
     if ($confirmationStatus === AccountManagement::ACCOUNT_CONFIRMATION_REQUIRED) {
         $url = $this->_customerUrl->getEmailConfirmationUrl($customer->getEmail());
         $this->_messageManager->addSuccess(__('Account confirmation is required. Please check your email for confirmation link. To resend confirmation email please <a href="%1">click here</a>.', $url));
     } else {
         $this->getCustomerSession()->regenerateId();
         $this->getCustomerSession()->loginById($customer->getId());
     }
     return $this;
 }
コード例 #12
0
 /**
  * @covers \Magento\Customer\Controller\Adminhtml\Index\Index::execute
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteWithNewCustomerAndException()
 {
     $subscription = 'false';
     $postValue = ['customer' => ['coolness' => false, 'disable_auto_group_change' => 'false'], 'subscription' => $subscription];
     $filteredData = ['coolness' => false, 'disable_auto_group_change' => 'false'];
     /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $formMock */
     $attributeMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->disableOriginalConstructor()->getMock();
     $attributeMock->expects($this->once())->method('getAttributeCode')->willReturn('coolness');
     $attributeMock->expects($this->once())->method('getFrontendInput')->willReturn('int');
     $attributes = [$attributeMock];
     $this->requestMock->expects($this->exactly(2))->method('getPostValue')->willReturn($postValue);
     $this->requestMock->expects($this->exactly(2))->method('getPost')->willReturnMap([['customer', null, $postValue['customer']], ['address', null, null]]);
     /** @var \Magento\Customer\Model\Metadata\Form|\PHPUnit_Framework_MockObject_MockObject $formMock */
     $formMock = $this->getMockBuilder('Magento\\Customer\\Model\\Metadata\\Form')->disableOriginalConstructor()->getMock();
     $this->formFactoryMock->expects($this->once())->method('create')->with(\Magento\Customer\Api\CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, 'adminhtml_customer', [], false, \Magento\Customer\Model\Metadata\Form::DONT_IGNORE_INVISIBLE)->willReturn($formMock);
     $formMock->expects($this->once())->method('extractData')->with($this->requestMock, 'customer')->willReturn($filteredData);
     /** @var \Magento\Framework\DataObject|\PHPUnit_Framework_MockObject_MockObject $objectMock */
     $objectMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock();
     $this->objectFactoryMock->expects($this->once())->method('create')->with(['data' => $postValue])->willReturn($objectMock);
     $objectMock->expects($this->once())->method('getData')->with('customer')->willReturn($postValue['customer']);
     $formMock->expects($this->once())->method('getAttributes')->willReturn($attributes);
     /** @var \Magento\Customer\Api\Data\CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customerMock */
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $this->customerDataFactoryMock->expects($this->once())->method('create')->willReturn($customerMock);
     $exception = new \Exception(__('Exception'));
     $this->managementMock->expects($this->once())->method('createAccount')->with($customerMock, null, '')->willThrowException($exception);
     $customerMock->expects($this->never())->method('getId');
     $this->authorizationMock->expects($this->never())->method('isAllowed');
     $this->subscriberFactoryMock->expects($this->never())->method('create');
     $this->sessionMock->expects($this->never())->method('unsCustomerData');
     $this->registryMock->expects($this->never())->method('register');
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->messageManagerMock->expects($this->once())->method('addException')->with($exception, __('Something went wrong while saving the customer.'));
     $this->sessionMock->expects($this->once())->method('setCustomerData')->with($postValue);
     /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
     $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $this->redirectFactoryMock->expects($this->once())->method('create')->with([])->willReturn($redirectMock);
     $redirectMock->expects($this->once())->method('setPath')->with('customer/*/new', ['_current' => true])->willReturn(true);
     $this->assertEquals($redirectMock, $this->model->execute());
 }
コード例 #13
0
 /**
  * AccountManagement constructor.
  *
  * @param \Magento\Customer\Model\CustomerFactory                      $customerFactory
  * @param \Magento\Framework\Event\ManagerInterface                    $eventManager
  * @param \Magento\Store\Model\StoreManagerInterface                   $storeManager
  * @param \Magento\Framework\Math\Random                               $mathRandom
  * @param \Magento\Customer\Model\Metadata\Validator                   $validator
  * @param \Magento\Customer\Api\Data\ValidationResultsInterfaceFactory $validationResultsDataFactory
  * @param \Magento\Customer\Api\AddressRepositoryInterface             $addressRepository
  * @param \Magento\Customer\Api\CustomerMetadataInterface              $customerMetadataService
  * @param \Magento\Customer\Model\CustomerRegistry                     $customerRegistry
  * @param \Psr\Log\LoggerInterface                                     $logger
  * @param \Magento\Framework\Encryption\EncryptorInterface             $encryptor
  * @param \Magento\Customer\Model\Config\Share                         $configShare
  * @param \Magento\Framework\Stdlib\StringUtils                        $stringHelper
  * @param \Magento\Customer\Api\CustomerRepositoryInterface            $customerRepository
  * @param \Magento\Framework\App\Config\ScopeConfigInterface           $scopeConfig
  * @param \Magento\Framework\Mail\Template\TransportBuilder            $transportBuilder
  * @param \Magento\Framework\Reflection\DataObjectProcessor            $dataProcessor
  * @param \Magento\Framework\Registry                                  $registry
  * @param \Magento\Customer\Helper\View                                $customerViewHelper
  * @param \Magento\Framework\Stdlib\DateTime                           $dateTime
  * @param \Magento\Customer\Model\Customer                             $customerModel
  * @param \Magento\Framework\DataObjectFactory                         $objectFactory
  * @param \Magento\Framework\Api\ExtensibleDataObjectConverter         $extensibleDataObjectConverter
  * @param SearchCriteriaBuilder                                        $searchCriteriaBuilder
  * @param FilterBuilder                                                $filterBuilder
  * @param ConfigProvider                                               $advancedLoginConfigProvider
  */
 public function __construct(\Magento\Customer\Model\CustomerFactory $customerFactory, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Math\Random $mathRandom, \Magento\Customer\Model\Metadata\Validator $validator, \Magento\Customer\Api\Data\ValidationResultsInterfaceFactory $validationResultsDataFactory, \Magento\Customer\Api\AddressRepositoryInterface $addressRepository, \Magento\Customer\Api\CustomerMetadataInterface $customerMetadataService, \Magento\Customer\Model\CustomerRegistry $customerRegistry, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\Customer\Model\Config\Share $configShare, \Magento\Framework\Stdlib\StringUtils $stringHelper, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor, \Magento\Framework\Registry $registry, \Magento\Customer\Helper\View $customerViewHelper, \Magento\Framework\Stdlib\DateTime $dateTime, \Magento\Customer\Model\Customer $customerModel, \Magento\Framework\DataObjectFactory $objectFactory, \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter, SearchCriteriaBuilder $searchCriteriaBuilder, FilterBuilder $filterBuilder, AdvancedLoginConfigProvider $advancedLoginConfigProvider)
 {
     parent::__construct($customerFactory, $eventManager, $storeManager, $mathRandom, $validator, $validationResultsDataFactory, $addressRepository, $customerMetadataService, $customerRegistry, $logger, $encryptor, $configShare, $stringHelper, $customerRepository, $scopeConfig, $transportBuilder, $dataProcessor, $registry, $customerViewHelper, $dateTime, $customerModel, $objectFactory, $extensibleDataObjectConverter);
     $this->customerRepository = $customerRepository;
     $this->customerRegistry = $customerRegistry;
     $this->encryptor = $encryptor;
     $this->customerFactory = $customerFactory;
     $this->eventManager = $eventManager;
     $this->searchCriteriaBuilder = $searchCriteriaBuilder;
     $this->filterBuilder = $filterBuilder;
     $this->storeManager = $storeManager;
     $this->advancedLoginConfigProvider = $advancedLoginConfigProvider;
 }