/**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testCreateCustomerAccessToken()
 {
     $customerUserName = '******';
     $password = '******';
     $accessToken = $this->tokenService->createCustomerAccessToken($customerUserName, $password);
     $customerData = $this->customerAccountService->authenticate($customerUserName, $password);
     /** @var $token TokenModel */
     $token = $this->tokenModel->loadByCustomerId($customerData->getId())->getToken();
     $this->assertEquals($accessToken, $token);
 }
Ejemplo n.º 2
0
 public function testGetDefaultRateRequest()
 {
     $customerDataSet = $this->_customerAccountService->getCustomer(self::FIXTURE_CUSTOMER_ID);
     $address = $this->_addressService->getAddress(self::FIXTURE_ADDRESS_ID);
     $rateRequest = $this->_model->getRateRequest(null, null, null, null, $customerDataSet->getId());
     $this->assertNotNull($rateRequest);
     $this->assertEquals($address->getCountryId(), $rateRequest->getCountryId());
     $this->assertEquals($address->getRegion()->getRegionId(), $rateRequest->getRegionId());
     $this->assertEquals($address->getPostcode(), $rateRequest->getPostcode());
     $customerTaxClassId = $this->_groupService->getGroup($customerDataSet->getGroupId())->getTaxClassId();
     $this->assertEquals($customerTaxClassId, $rateRequest->getCustomerClassId());
 }
Ejemplo n.º 3
0
 /**
  * Load search results
  *
  * @return $this
  */
 public function load()
 {
     $result = [];
     if (!$this->hasStart() || !$this->hasLimit() || !$this->hasQuery()) {
         $this->setResults($result);
         return $this;
     }
     $this->_searchCriteriaBuilder->setCurrentPage($this->getStart());
     $this->_searchCriteriaBuilder->setPageSize($this->getLimit());
     $searchFields = ['firstname', 'lastname', 'company'];
     $filters = [];
     foreach ($searchFields as $field) {
         $filters[] = $this->_filterBuilder->setField($field)->setConditionType('like')->setValue($this->getQuery() . '%')->create();
     }
     $this->_searchCriteriaBuilder->addFilter($filters);
     $searchCriteria = $this->_searchCriteriaBuilder->create();
     $searchResults = $this->_customerService->searchCustomers($searchCriteria);
     /** @var \Magento\Customer\Service\V1\Data\CustomerDetails $customerDetails */
     foreach ($searchResults->getItems() as $customerDetails) {
         $customerData = $customerDetails->getCustomer();
         $customerAddresses = $customerDetails->getAddresses();
         /** Look for a company name defined in default billing address */
         $company = null;
         foreach ($customerAddresses as $customerAddress) {
             if ($customerAddress->isDefaultBilling()) {
                 $company = $customerAddress->getCompany();
                 break;
             }
         }
         $result[] = array('id' => 'customer/1/' . $customerData->getId(), 'type' => __('Customer'), 'name' => $this->_customerViewHelper->getCustomerName($customerData), 'description' => $company, 'url' => $this->_adminhtmlData->getUrl('customer/index/edit', array('id' => $customerData->getId())));
     }
     $this->setResults($result);
     return $this;
 }
Ejemplo n.º 4
0
 public function testLogin()
 {
     $customerId = 1;
     $username = '******';
     $password = '******';
     $customerDataMock = $this->prepareLoginDataMock($customerId);
     $this->customerAccountServiceMock->expects($this->once())->method('authenticate')->with($this->equalTo($username), $this->equalTo($password))->will($this->returnValue($customerDataMock));
     $this->assertTrue($this->_model->login($username, $password));
 }
Ejemplo n.º 5
0
 /**
  * @param bool $expectedResult
  * @param bool $isCustomerIdValid
  * @param bool $isCustomerEmulated
  * @dataProvider getIsLoggedInDataProvider
  */
 public function testIsLoggedIn($expectedResult, $isCustomerIdValid, $isCustomerEmulated)
 {
     $customerId = 1;
     $this->_storageMock->expects($this->any())->method('getData')->with('customer_id')->will($this->returnValue($customerId));
     if ($isCustomerIdValid) {
         $this->customerAccountServiceMock->expects($this->once())->method('getCustomer')->with($customerId);
     } else {
         $this->customerAccountServiceMock->expects($this->once())->method('getCustomer')->with($customerId)->will($this->throwException(new \Exception('Customer ID is invalid.')));
     }
     $this->_storageMock->expects($this->any())->method('getIsCustomerEmulated')->will($this->returnValue($isCustomerEmulated));
     $this->assertEquals($expectedResult, $this->_model->isLoggedIn());
 }
Ejemplo n.º 6
0
 /**
  * Update Customer name in Quote
  */
 protected function _updateQuoteCustomerName()
 {
     /** @var $emptyAddress \Magento\Sales\Model\Quote\Address */
     $emptyAddress = $this->_quoteAddressFactory->create();
     $emptyAddress->setFirstname(null);
     $emptyAddress->setLastname(null);
     $this->_block->getQuote()->setBillingAddress($emptyAddress);
     $customerData = $this->_customerService->getCustomer(self::FIXTURE_CUSTOMER_ID);
     $customerData = $this->_customerBuilder->populate($customerData)->setFirstname(self::SAMPLE_FIRST_NAME)->setLastname(self::SAMPLE_LAST_NAME)->create();
     $this->_block->getQuote()->setCustomerData($customerData);
     $this->_block->getQuote()->save();
     $this->assertEquals(self::SAMPLE_FIRST_NAME, $this->_block->getFirstname());
     $this->assertEquals(self::SAMPLE_LAST_NAME, $this->_block->getLastname());
 }