/**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testCreateAccountWithPassword()
 {
     $websiteId = 1;
     $storeId = null;
     $defaultStoreId = 1;
     $customerId = 1;
     $customerEmail = '*****@*****.**';
     $password = '******';
     $hash = '4nj54lkj5jfi03j49f8bgujfgsd';
     $newLinkToken = '2jh43j5h2345jh23lh452h345hfuzasd96ofu';
     $templateIdentifier = 'Template Identifier';
     $sender = 'Sender';
     $this->string->expects($this->any())->method('strlen')->willReturnCallback(function ($string) {
         return strlen($string);
     });
     $this->encryptor->expects($this->once())->method('getHash')->with($password, true)->willReturn($hash);
     $address = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock();
     $address->expects($this->once())->method('setCustomerId')->with($customerId);
     $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $store->expects($this->once())->method('getId')->willReturn($defaultStoreId);
     $website = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->getMock();
     $website->expects($this->atLeastOnce())->method('getStoreIds')->willReturn([1, 2, 3]);
     $website->expects($this->once())->method('getDefaultStore')->willReturn($store);
     $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $customer->expects($this->atLeastOnce())->method('getId')->willReturn($customerId);
     $customer->expects($this->atLeastOnce())->method('getEmail')->willReturn($customerEmail);
     $customer->expects($this->atLeastOnce())->method('getWebsiteId')->willReturn($websiteId);
     $customer->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId);
     $customer->expects($this->once())->method('setStoreId')->with($defaultStoreId);
     $customer->expects($this->once())->method('getAddresses')->willReturn([$address]);
     $customer->expects($this->once())->method('setAddresses')->with(null);
     $this->customerRepository->expects($this->once())->method('get')->with($customerEmail)->willReturn($customer);
     $this->share->expects($this->once())->method('isWebsiteScope')->willReturn(true);
     $this->storeManager->expects($this->atLeastOnce())->method('getWebsite')->with($websiteId)->willReturn($website);
     $this->customerRepository->expects($this->atLeastOnce())->method('save')->willReturn($customer);
     $this->addressRepository->expects($this->atLeastOnce())->method('save')->with($address);
     $this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($customer);
     $this->random->expects($this->once())->method('getUniqueHash')->willReturn($newLinkToken);
     $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->setMethods(['setRpToken', 'setRpTokenCreatedAt', 'getPasswordHash'])->disableOriginalConstructor()->getMock();
     $customerSecure->expects($this->any())->method('setRpToken')->with($newLinkToken);
     $customerSecure->expects($this->any())->method('setRpTokenCreatedAt');
     $customerSecure->expects($this->any())->method('getPasswordHash')->willReturn($hash);
     $this->customerRegistry->expects($this->atLeastOnce())->method('retrieveSecureData')->willReturn($customerSecure);
     $this->dataObjectProcessor->expects($this->once())->method('buildOutputDataArray')->willReturn([]);
     $this->scopeConfig->expects($this->at(1))->method('getValue')->with(AccountManagement::XML_PATH_REGISTER_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $defaultStoreId)->willReturn($templateIdentifier);
     $this->scopeConfig->expects($this->at(2))->method('getValue')->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')->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('setTemplateVars')->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('setFrom')->with($sender)->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('addTo')->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('getTransport')->willReturn($transport);
     $transport->expects($this->once())->method('sendMessage');
     $this->accountManagement->createAccount($customer, $password);
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testCreateAccountWithPassword()
 {
     $websiteId = 1;
     $storeId = null;
     $defaultStoreId = 1;
     $customerId = 1;
     $customerEmail = '*****@*****.**';
     $hash = '4nj54lkj5jfi03j49f8bgujfgsd';
     $newLinkToken = '2jh43j5h2345jh23lh452h345hfuzasd96ofu';
     $templateIdentifier = 'Template Identifier';
     $sender = 'Sender';
     $password = '******';
     $minPasswordLength = 5;
     $minCharacterSetsNum = 2;
     $this->scopeConfig->expects($this->any())->method('getValue')->willReturnMap([[AccountManagement::XML_PATH_MINIMUM_PASSWORD_LENGTH, 'default', null, $minPasswordLength], [AccountManagement::XML_PATH_REQUIRED_CHARACTER_CLASSES_NUMBER, 'default', null, $minCharacterSetsNum], [AccountManagement::XML_PATH_REGISTER_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $defaultStoreId, $templateIdentifier], [AccountManagement::XML_PATH_REGISTER_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, 1, $sender]]);
     $this->string->expects($this->any())->method('strlen')->with($password)->willReturn(iconv_strlen($password, 'UTF-8'));
     $this->encryptor->expects($this->once())->method('getHash')->with($password, true)->willReturn($hash);
     $address = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock();
     $address->expects($this->once())->method('setCustomerId')->with($customerId);
     $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $store->expects($this->once())->method('getId')->willReturn($defaultStoreId);
     $website = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->getMock();
     $website->expects($this->atLeastOnce())->method('getStoreIds')->willReturn([1, 2, 3]);
     $website->expects($this->once())->method('getDefaultStore')->willReturn($store);
     $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $customer->expects($this->atLeastOnce())->method('getId')->willReturn($customerId);
     $customer->expects($this->atLeastOnce())->method('getEmail')->willReturn($customerEmail);
     $customer->expects($this->atLeastOnce())->method('getWebsiteId')->willReturn($websiteId);
     $customer->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId);
     $customer->expects($this->once())->method('setStoreId')->with($defaultStoreId);
     $customer->expects($this->once())->method('getAddresses')->willReturn([$address]);
     $customer->expects($this->once())->method('setAddresses')->with(null);
     $this->customerRepository->expects($this->once())->method('get')->with($customerEmail)->willReturn($customer);
     $this->share->expects($this->once())->method('isWebsiteScope')->willReturn(true);
     $this->storeManager->expects($this->atLeastOnce())->method('getWebsite')->with($websiteId)->willReturn($website);
     $this->customerRepository->expects($this->atLeastOnce())->method('save')->willReturn($customer);
     $this->addressRepository->expects($this->atLeastOnce())->method('save')->with($address);
     $this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($customer);
     $this->random->expects($this->once())->method('getUniqueHash')->willReturn($newLinkToken);
     $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->setMethods(['setRpToken', 'setRpTokenCreatedAt', 'getPasswordHash'])->disableOriginalConstructor()->getMock();
     $customerSecure->expects($this->any())->method('setRpToken')->with($newLinkToken);
     $customerSecure->expects($this->any())->method('setRpTokenCreatedAt');
     $customerSecure->expects($this->any())->method('getPasswordHash')->willReturn($hash);
     $this->customerRegistry->expects($this->atLeastOnce())->method('retrieveSecureData')->willReturn($customerSecure);
     $this->emailNotificationMock->expects($this->once())->method('newAccount')->willReturnSelf();
     $this->accountManagement->createAccount($customer, $password);
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function createAccount(\Magento\Customer\Api\Data\CustomerInterface $customer, $password = null, $redirectUrl = '')
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'createAccount');
     if (!$pluginInfo) {
         return parent::createAccount($customer, $password, $redirectUrl);
     } else {
         return $this->___callPlugins('createAccount', func_get_args(), $pluginInfo);
     }
 }