public function testGetDefaultCalculatedRate() { $productTaxClassId = 1; $customerId = 2; $storeId = 3; $rate = 0.5; $storeMock = $this->getMock('\\Magento\\Store\\Model\\Store', ['getStoreId'], [], '', false); $this->storeManager->expects($this->once())->method('getStore')->willReturn($storeMock); $storeMock->expects($this->once())->method('getStoreId')->willReturn($storeId); $rateRequestMock = $this->getMock('\\Magento\\Framework\\Object', ['setProductClassId'], [], '', false); $this->calculationTool->expects($this->once())->method('getDefaultRateRequest')->with($storeId, $customerId)->willReturn($rateRequestMock); $rateRequestMock->expects($this->once())->method('setProductClassId')->with($productTaxClassId)->willReturnSelf(); $this->calculationTool->expects($this->once())->method('getRate')->with($rateRequestMock)->willReturn($rate); $this->assertEquals($rate, $this->taxCalculationService->getDefaultCalculatedRate($productTaxClassId, $customerId, null)); }
/** * Get all tax rates JSON for all product tax classes. * * @return string */ public function getAllRatesByProductClassJson() { $result = []; foreach ($this->productTaxClassSource->getAllOptions() as $productTaxClass) { $taxClassId = $productTaxClass['value']; $taxRate = $this->calculationService->getDefaultCalculatedRate($taxClassId, $this->currentCustomer->getCustomerId(), $this->getStore()->getId()); $result["value_{$taxClassId}"] = $taxRate; } return $this->jsonHelper->jsonEncode($result); }