Exemple #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\Sales\Model\Observer\Frontend\Quote\Address\CollectTotals::dispatch
  */
 public function testChangeQuoteCustomerGroupIdForCustomerWithEnabledAutomaticGroupChange()
 {
     /** @var \Magento\Framework\ObjectManager $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 $quote \Magento\Sales\Model\Quote */
     $quote = $objectManager->create('Magento\\Sales\\Model\\Quote');
     $quote->load('test01', 'reserved_order_id');
     $quote->setCustomer($customer);
     $quoteAddress = $quote->getBillingAddress();
     $eventObserver = $objectManager->create('Magento\\Framework\\Event\\Observer', array('data' => array('quote_address' => $quoteAddress)));
     $this->model->dispatch($eventObserver);
     $this->assertEquals(1, $quote->getCustomer()->getGroupId());
 }
 public function testDispatchWithCustomerCountryInEU()
 {
     /** @var \Magento\Framework\Service\Data\Eav\AttributeValueBuilder $attributeValueBuilder */
     $attributeValueBuilder = $this->objectManager->getObject('Magento\\Framework\\Service\\Data\\Eav\\AttributeValueBuilder');
     $attributeValueBuilder->setAttributeCode('disable_auto_group_change')->setValue(false);
     /** Preconditions */
     $this->customerDataMock->expects($this->exactly(2))->method('getCustomAttribute')->with('disable_auto_group_change')->will($this->returnValue($attributeValueBuilder->create()));
     $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->customerHelperMock->expects($this->once())->method('isCountryInEU')->with('customerCountryCode')->will($this->returnValue($attributeValueBuilder->create()));
     $this->quoteMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue('customerGroupId'));
     $validationResult = array('some' => 'result');
     $this->vatValidatorMock->expects($this->once())->method('validate')->with($this->quoteAddressMock, $this->storeId)->will($this->returnValue($validationResult));
     $this->customerHelperMock->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->customerBuilderMock->expects($this->once())->method('mergeDataObjectWithArray')->with($this->customerDataMock, array('group_id' => 'customerGroupId'))->will($this->returnValue($this->customerDataMock));
     $this->model->dispatch($this->observerMock);
 }