/** * Tests the specific method * * @param string $calculationSequence * @param string $keyExpected * @param string $keyAbsent * @dataProvider dataProviderProcessConfigArray */ public function testProcessConfigArray($calculationSequence, $keyExpected, $keyAbsent) { $taxData = $this->getMock('Magento\\Tax\\Helper\\Data', [], [], '', false); $taxData->expects($this->any())->method('getCalculationSequence')->will($this->returnValue($calculationSequence)); $taxConfig = $this->getMock('\\Magento\\Tax\\Model\\Config', [], [], '', false); $taxCalculationService = $this->getMock('\\Magento\\Tax\\Service\\V1\\TaxCalculationService', [], [], '', false); $quoteDetailsBuilder = $this->getMock('\\Magento\\Tax\\Service\\V1\\Data\\QuoteDetailsBuilder', [], [], '', false); /** @var \Magento\Tax\Model\Sales\Total\Quote\Tax */ $taxTotalsCalcModel = new Tax($taxConfig, $taxCalculationService, $quoteDetailsBuilder, $taxData); $array = $taxTotalsCalcModel->processConfigArray([], null); $this->assertArrayHasKey($keyExpected, $array, 'Did not find the expected array key: ' . $keyExpected); $this->assertArrayNotHasKey($keyAbsent, $array, 'Should not have found the array key; ' . $keyAbsent); }
/** * @param \Magento\Tax\Helper\Data $taxData * @param \Magento\Tax\Model\Config $taxConfig * @param \Magento\Tax\Service\V1\TaxCalculationService $taxCalculationService * @param \Magento\Tax\Service\V1\Data\QuoteDetailsBuilder $quoteDetailsBuilder * @param \Magento\Tax\Model\Calculation $calculation * @param \Magento\Weee\Helper\Data $weeeData */ public function __construct(\Magento\Tax\Helper\Data $taxData, \Magento\Tax\Model\Config $taxConfig, \Magento\Tax\Service\V1\TaxCalculationService $taxCalculationService, \Magento\Tax\Service\V1\Data\QuoteDetailsBuilder $quoteDetailsBuilder, \Magento\Tax\Model\Calculation $calculation, \Magento\Weee\Helper\Data $weeeData) { $this->_weeeData = $weeeData; $this->_calculator = $calculation; parent::__construct($taxData, $taxConfig, $taxCalculationService, $quoteDetailsBuilder); $this->setCode('weee'); }
/** * Tests the specific method * * @param array $itemData * @param array $appliedRatesData * @param array $taxDetailsData * @param array $quoteDetailsData * @param array $addressData * @param array $verifyData * * @dataProvider dataProviderCollectArray * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function testCollect($itemData, $appliedRatesData, $taxDetailsData, $quoteDetailsData, $addressData, $verifyData) { $this->markTestIncomplete('Source code is not testable. Need to be refactored before unit testing'); $shippingAssignmentMock = $this->getMock('Magento\\Quote\\Api\\Data\\ShippingAssignmentInterface'); $totalsMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Address\\Total', [], [], '', false); $objectManager = new ObjectManager($this); $taxData = $this->getMock('Magento\\Tax\\Helper\\Data', [], [], '', false); $taxConfig = $this->getMockBuilder('\\Magento\\Tax\\Model\\Config')->disableOriginalConstructor()->setMethods(['priceIncludesTax', 'getShippingTaxClass', 'shippingPriceIncludesTax', 'discountTax'])->getMock(); $taxConfig->expects($this->any())->method('priceIncludesTax')->will($this->returnValue(false)); $taxConfig->expects($this->any())->method('getShippingTaxClass')->will($this->returnValue(1)); $taxConfig->expects($this->any())->method('shippingPriceIncludesTax')->will($this->returnValue(false)); $taxConfig->expects($this->any())->method('discountTax')->will($this->returnValue(false)); $product = $this->getMock('\\Magento\\Catalog\\Model\\Product', [], [], '', false); $item = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Item')->disableOriginalConstructor()->setMethods(['getParentItem', 'getHasChildren', 'getProduct', 'getQuote', 'getCode', '__wakeup'])->getMock(); $item->expects($this->any())->method('getParentItem')->will($this->returnValue(null)); $item->expects($this->any())->method('getHasChildren')->will($this->returnValue(false)); $item->expects($this->any())->method('getCode')->will($this->returnValue("1")); $item->expects($this->any())->method('getProduct')->will($this->returnValue($product)); foreach ($itemData as $key => $value) { $item->setData($key, $value); } $items = [$item]; $taxDetails = $this->getMock('Magento\\Tax\\Api\\Data\\TaxDetailsInterface'); $taxDetails->expects($this->any())->method('getItems')->will($this->returnValue($items)); $storeManager = $this->getMockBuilder('\\Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->setMethods(['getStore', 'hasSingleStore', 'isSingleStoreMode', 'getStores', 'getWebsite', 'getWebsites', 'reinitStores', 'getDefaultStoreView', 'setIsSingleStoreModeAllowed', 'getGroup', 'getGroups', 'clearWebsiteCache', 'setCurrentStore'])->getMock(); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $storeManager->expects($this->any())->method('getStore')->will($this->returnValue($storeMock)); $calculatorFactory = $this->getMockBuilder('Magento\\Tax\\Model\\Calculation\\CalculatorFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $calculationTool = $this->getMockBuilder('Magento\\Tax\\Model\\Calculation')->disableOriginalConstructor()->setMethods(['getRate', 'getAppliedRates', 'round', 'calcTaxAmount', '__wakeup'])->getMock(); $calculationTool->expects($this->any())->method('round')->will($this->returnArgument(0)); $calculationTool->expects($this->any())->method('getRate')->will($this->returnValue(20)); $calculationTool->expects($this->any())->method('calcTaxAmount')->will($this->returnValue(20)); $calculationTool->expects($this->any())->method('getAppliedRates')->will($this->returnValue($appliedRatesData)); $calculator = $objectManager->getObject('Magento\\Tax\\Model\\Calculation\\TotalBaseCalculator', ['calculationTool' => $calculationTool]); $calculatorFactory->expects($this->any())->method('create')->will($this->returnValue($calculator)); $taxCalculationService = $this->getMock('\\Magento\\Tax\\Api\\TaxCalculationInterface'); $taxClassKeyDataObjectMock = $this->getMock('\\Magento\\Tax\\Api\\Data\\TaxClassKeyInterface'); $taxClassKeyDataObjectFactoryMock = $this->getMockBuilder('\\Magento\\Tax\\Api\\Data\\TaxClassKeyInterfaceFactory')->disableOriginalConstructor()->getMock(); $taxClassKeyDataObjectFactoryMock->expects($this->any())->method('create')->will($this->returnValue($taxClassKeyDataObjectMock)); $taxClassKeyDataObjectMock->expects($this->any())->method('setType')->willReturnSelf(); $taxClassKeyDataObjectMock->expects($this->any())->method('setValue')->willReturnSelf(); $itemDataObjectMock = $this->getMock('\\Magento\\Tax\\Api\\Data\\QuoteDetailsItemInterface'); $itemDataObjectFactoryMock = $this->getMockBuilder('\\Magento\\Tax\\Api\\Data\\QuoteDetailsItemInterfaceFactory')->disableOriginalConstructor()->getMock(); $itemDataObjectFactoryMock->expects($this->any())->method('create')->will($this->returnValue($itemDataObjectMock)); $itemDataObjectMock->expects($this->any())->method('setTaxClassKey')->willReturnSelf(); $itemDataObjectMock->expects($this->any())->method('getAssociatedTaxables')->willReturnSelf(); $regionFactory = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\RegionInterfaceFactory')->disableOriginalConstructor()->setMethods(['setRegionId', 'create'])->getMock(); $addressFactory = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterfaceFactory')->disableOriginalConstructor()->setMethods(['getRegionBuilder', 'create'])->getMock(); $region = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\RegionInterface', [], '', false); $regionFactory->expects($this->any())->method('setRegionId')->will($this->returnValue($regionFactory)); $regionFactory->expects($this->any())->method('create')->will($this->returnValue($region)); $addressFactory->expects($this->any())->method('getRegionBuilder')->will($this->returnValue($regionFactory)); $quoteDetails = $this->getMock('Magento\\Tax\\Api\\Data\\QuoteDetailsInterface'); $quoteDetailsDataObjectFactoryMock = $this->getMock('\\Magento\\Tax\\Api\\Data\\QuoteDetailsInterfaceFactory', ['create'], [], '', false); $quoteDetailsDataObjectFactoryMock->expects($this->any())->method('create')->will($this->returnValue($quoteDetails)); $quoteDetailsItemDataObjectFactoryMock = $this->getMock('Magento\\Tax\\Api\\Data\\QuoteDetailsItemInterfaceFactory', ['create'], [], '', false); $taxTotalsCalcModel = new Tax($taxConfig, $taxCalculationService, $quoteDetailsDataObjectFactoryMock, $quoteDetailsItemDataObjectFactoryMock, $taxClassKeyDataObjectFactoryMock, $addressFactory, $regionFactory, $taxData); $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['convertPrice', '__wakeup', 'getStoreId'])->getMock(); $store->expects($this->any())->method('getStoreId')->will($this->returnValue(1)); $quote = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false); $quote->expects($this->any())->method('getStore')->will($this->returnValue($store)); $address = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Address')->disableOriginalConstructor()->setMethods(['getAssociatedTaxables', 'getQuote', 'getBillingAddress', 'getRegionId', '__wakeup', 'getCustomAttributesCodes'])->getMock(); $item->expects($this->any())->method('getQuote')->will($this->returnValue($quote)); $address->expects($this->any())->method('getQuote')->will($this->returnValue($quote)); $address->expects($this->any())->method('getAssociatedTaxables')->will($this->returnValue([])); $address->expects($this->any())->method('getRegionId')->will($this->returnValue($region)); $address->expects($this->any())->method('getCustomAttributesCodes')->willReturn([]); $quote->expects($this->any())->method('getBillingAddress')->will($this->returnValue($address)); $addressFactory->expects($this->any())->method('create')->will($this->returnValue($address)); $addressData["cached_items_all"] = $items; foreach ($addressData as $key => $value) { $address->setData($key, $value); } $taxTotalsCalcModel->collect($quote, $shippingAssignmentMock, $totalsMock); foreach ($verifyData as $key => $value) { $this->assertSame($verifyData[$key], $address->getData($key)); } }
/** * Map extra taxables associated with quote. Add AvaTax details to extension objects. * * @param QuoteDetailsItemInterfaceFactory $itemDataObjectFactory * @param Address $address * @param bool $useBaseCurrency * @return \Magento\Tax\Api\Data\QuoteDetailsItemInterface[] */ public function mapQuoteExtraTaxables(QuoteDetailsItemInterfaceFactory $itemDataObjectFactory, Address $address, $useBaseCurrency) { $itemDataObjects = parent::mapQuoteExtraTaxables($itemDataObjectFactory, $address, $useBaseCurrency); $storeId = $address->getQuote()->getStore()->getId(); if (!$this->config->isModuleEnabled($storeId) || $this->config->getTaxMode($storeId) == Config::TAX_MODE_NO_ESTIMATE_OR_SUBMIT || !$this->config->isAddressTaxable($address, $storeId)) { return $itemDataObjects; } foreach ($itemDataObjects as $itemDataObject) { switch ($itemDataObject->getType()) { case Giftwrapping::QUOTE_TYPE: $itemCode = $this->config->getSkuGiftWrapOrder($storeId); $taxCode = $this->taxClassHelper->getAvataxTaxCodeForGiftOptions($storeId); $this->addExtensionAttributesToTaxQuoteDetailsItem($itemDataObject, $itemCode, $taxCode, \ClassyLlama\AvaTax\Framework\Interaction\Line::GIFT_WRAP_ORDER_LINE_DESCRIPTION); break; case Giftwrapping::PRINTED_CARD_TYPE: $itemCode = $this->config->getSkuShippingGiftWrapCard($storeId); $taxCode = $this->taxClassHelper->getAvataxTaxCodeForGiftOptions($storeId); $this->addExtensionAttributesToTaxQuoteDetailsItem($itemDataObject, $itemCode, $taxCode, \ClassyLlama\AvaTax\Framework\Interaction\Line::GIFT_WRAP_ORDER_LINE_DESCRIPTION); break; } } return $itemDataObjects; }