コード例 #1
0
 /**
  * @magentoConfigFixture current_store customer/create_account/auto_group_assign 1
  * @magentoConfigFixture current_store customer/create_account/default_group 1
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Sales/_files/quote.php
  *
  * @covers \Magento\Quote\Model\Observer\Frontend\Quote\Address\CollectTotals::dispatch
  */
 public function testChangeQuoteCustomerGroupIdForCustomerWithEnabledAutomaticGroupChange()
 {
     /** @var \Magento\Framework\ObjectManagerInterface $objectManager */
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     /** @var $customer \Magento\Customer\Model\Customer */
     $customer = $objectManager->create('Magento\\Customer\\Model\\Customer');
     $customer->load(1);
     $customer->setDisableAutoGroupChange(0);
     $customer->setGroupId(2);
     $customer->save();
     /** @var \Magento\Customer\Model\CustomerRegistry $customerRegistry */
     $customerRegistry = $objectManager->get('Magento\\Customer\\Model\\CustomerRegistry');
     $customerRegistry->remove($customer->getId());
     /** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
     $customerRepository = $objectManager->create('Magento\\Customer\\Api\\CustomerRepositoryInterface');
     $customerData = $customerRepository->getById($customer->getId());
     /** @var $quote \Magento\Quote\Model\Quote */
     $quote = $objectManager->create('Magento\\Quote\\Model\\Quote');
     $quote->load('test01', 'reserved_order_id');
     $quote->setCustomer($customerData);
     $quoteAddress = $quote->getBillingAddress();
     $eventObserver = $objectManager->create('Magento\\Framework\\Event\\Observer', ['data' => ['quote_address' => $quoteAddress]]);
     $this->model->dispatch($eventObserver);
     $this->assertEquals(1, $quote->getCustomer()->getGroupId());
 }
コード例 #2
0
ファイル: CollectTotalsTest.php プロジェクト: nja78/magento2
 public function testDispatchWithCustomerCountryInEU()
 {
     $this->vatValidatorMock->expects($this->once())->method('isEnabled')->with($this->quoteAddressMock, $this->storeId)->will($this->returnValue(true));
     $this->quoteAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue('customerCountryCode'));
     $this->quoteAddressMock->expects($this->once())->method('getVatId')->will($this->returnValue('vatID'));
     $this->customerVatMock->expects($this->once())->method('isCountryInEU')->with('customerCountryCode')->willReturn(true);
     $this->quoteMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue('customerGroupId'));
     $validationResult = ['some' => 'result'];
     $this->vatValidatorMock->expects($this->once())->method('validate')->with($this->quoteAddressMock, $this->storeId)->will($this->returnValue($validationResult));
     $this->customerVatMock->expects($this->once())->method('getCustomerGroupIdBasedOnVatNumber')->with('customerCountryCode', $validationResult, $this->storeId)->will($this->returnValue('customerGroupId'));
     /** Assertions */
     $this->quoteAddressMock->expects($this->once())->method('setPrevQuoteCustomerGroupId')->with('customerGroupId');
     $this->quoteMock->expects($this->once())->method('setCustomerGroupId')->with('customerGroupId');
     $this->quoteMock->expects($this->once())->method('setCustomer')->with($this->customerMock);
     $this->dataObjectHelperMock->expects($this->never())->method('populateWithArray')->with($this->customerMock, ['group_id' => 'customerGroupId'])->will($this->returnSelf());
     $this->customerDataFactoryMock->expects($this->any())->method('create')->willReturn($this->customerMock);
     $this->model->dispatch($this->observerMock);
 }