예제 #1
0
 public function testGetUserName()
 {
     $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(true);
     $customerDataObject = $this->getMockBuilder('\\Magento\\Customer\\Model\\Data\\Customer')->disableOriginalConstructor()->getMock();
     $this->customerSessionMock->expects($this->once())->method('getCustomerDataObject')->willReturn($customerDataObject);
     $this->customerViewHelperMock->expects($this->once())->method('getCustomerName')->willReturn(' customer name ');
     $this->assertEquals('customer name', $this->helper->getUserName());
 }
예제 #2
0
 public function testGetUserName()
 {
     $this->_customerSession->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true));
     $objectBuilder = $this->getMockForAbstractClass('\\Magento\\Framework\\Service\\Data\\AbstractSimpleObjectBuilder', ['getData'], '', false);
     $customerDataObject = new \Magento\Customer\Service\V1\Data\Customer($objectBuilder);
     $this->_customerSession->expects($this->once())->method('getCustomerDataObject')->will($this->returnValue($customerDataObject));
     $this->_customerViewHelper->expects($this->once())->method('getCustomerName')->will($this->returnValue(' customer name '));
     $this->assertEquals('customer name', $this->_helper->getUserName());
 }
예제 #3
0
 public function testConstruct()
 {
     $this->customerRepository = $this->getMockForAbstractClass('Magento\\Customer\\Api\\CustomerRepositoryInterface');
     $this->customerViewHelper = $this->getMock('Magento\\Customer\\Helper\\View', [], [], '', false);
     $dummyCustomer = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->customerRepository->expects($this->once())->method('getById')->with('customer id')->will($this->returnValue($dummyCustomer));
     $this->customerViewHelper->expects($this->once())->method('getCustomerName')->with($dummyCustomer)->will($this->returnValue(new \Magento\Framework\Object()));
     $this->request = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface');
     $this->request->expects($this->at(0))->method('getParam')->with('customerId', false)->will($this->returnValue('customer id'));
     $this->request->expects($this->at(1))->method('getParam')->with('productId', false)->will($this->returnValue(false));
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->model = $objectManagerHelper->getObject('Magento\\Review\\Block\\Adminhtml\\Main', ['request' => $this->request, 'customerRepository' => $this->customerRepository, 'customerViewHelper' => $this->customerViewHelper]);
 }
 /**
  * @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);
 }
예제 #5
0
 /**
  * @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);
 }
 /**
  * @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));
 }
 /**
  * @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));
 }