56 protected function setUp()
59 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
61 $this->taxDetailsItemDataObjectFactoryMock =
62 $this->getMockBuilder(\
Magento\Tax\Api\Data\TaxDetailsItemInterfaceFactory::class)
63 ->setMethods([
'create'])
64 ->disableOriginalConstructor()
66 $this->taxDetailsItemDataObjectFactoryMock->expects($this->any())
68 ->willReturn($this->taxDetailsItem);
70 $this->mockCalculationTool = $this->getMockBuilder(\
Magento\Tax\Model\Calculation::class)
71 ->disableOriginalConstructor()
72 ->setMethods([
'__wakeup',
'round',
'getRate',
'getStoreRate',
'getRateRequest',
'getAppliedRates'])
74 $this->mockCalculationTool->expects($this->any())
82 $this->mockConfig = $this->getMockBuilder(\
Magento\Tax\Model\Config::class)
83 ->disableOriginalConstructor()
85 $this->addressRateRequest = new \Magento\Framework\DataObject();
87 $this->appliedTaxRate =
$objectManager->getObject(\
Magento\Tax\Model\TaxDetails\AppliedTaxRate::class);
88 $this->appliedTaxRateDataObjectFactoryMock = $this->createPartialMock(
89 \
Magento\Tax\Api\Data\AppliedTaxRateInterfaceFactory::class,
92 $this->appliedTaxRateDataObjectFactoryMock->expects($this->any())
94 ->willReturn($this->appliedTaxRate);
97 $appliedTaxDataObjectFactoryMock = $this->createPartialMock(
98 \
Magento\Tax\Api\Data\AppliedTaxInterfaceFactory::class,
101 $appliedTaxDataObjectFactoryMock->expects($this->any())
103 ->willReturn($appliedTaxDataObject);
112 'appliedTaxDataObjectFactory' => $appliedTaxDataObjectFactoryMock,
119 $mockItem = $this->getMockItem();
120 $mockItem->expects($this->atLeastOnce())
121 ->method(
'getIsTaxIncluded')
122 ->will($this->returnValue(
true));
124 $this->mockConfig->expects($this->atLeastOnce())
125 ->method(
'crossBorderTradeEnabled')
126 ->will($this->returnValue(
false));
127 $this->mockConfig->expects($this->atLeastOnce())
128 ->method(
'applyTaxAfterDiscount')
129 ->will($this->returnValue(
true));
131 $this->mockCalculationTool->expects($this->atLeastOnce())
133 ->with($this->addressRateRequest)
134 ->will($this->returnValue(self::RATE));
135 $this->mockCalculationTool->expects($this->atLeastOnce())
136 ->method(
'getStoreRate')
137 ->with($this->addressRateRequest, self::STORE_ID)
138 ->will($this->returnValue(self::STORE_RATE));
139 $this->mockCalculationTool->expects($this->atLeastOnce())
140 ->method(
'getAppliedRates')
141 ->withAnyParameters()
142 ->will($this->returnValue([]));
144 $this->assertSame($this->taxDetailsItem, $this->model->calculate($mockItem, self::QUANTITY));
145 $this->assertSame(self::CODE, $this->taxDetailsItem->getCode());
146 $this->assertSame(self::TYPE, $this->taxDetailsItem->getType());
147 $this->assertSame(self::ROW_TAX_ROUNDED, $this->taxDetailsItem->getRowTax());
148 $this->assertEquals(self::PRICE_INCL_TAX_ROUNDED, $this->taxDetailsItem->getPriceInclTax());
150 $this->assertSame($this->taxDetailsItem, $this->model->calculate($mockItem, self::QUANTITY,
false));
151 $this->assertSame(self::CODE, $this->taxDetailsItem->getCode());
152 $this->assertSame(self::TYPE, $this->taxDetailsItem->getType());
153 $this->assertSame(self::ROW_TAX, $this->taxDetailsItem->getRowTax());
154 $this->assertEquals(self::PRICE_INCL_TAX, $this->taxDetailsItem->getPriceInclTax());
159 $mockItem = $this->getMockItem();
160 $mockItem->expects($this->once())
161 ->method(
'getIsTaxIncluded')
162 ->will($this->returnValue(
false));
164 $this->mockConfig->expects($this->once())
165 ->method(
'applyTaxAfterDiscount')
166 ->will($this->returnValue(
true));
168 $this->mockCalculationTool->expects($this->once())
170 ->with($this->addressRateRequest)
171 ->will($this->returnValue(self::RATE));
172 $this->mockCalculationTool->expects($this->once())
173 ->method(
'getAppliedRates')
174 ->withAnyParameters()
175 ->will($this->returnValue([[
'id' => 0,
'percent' => 0,
'rates' => []]]));
177 $this->assertSame($this->taxDetailsItem, $this->model->calculate($mockItem, self::QUANTITY));
178 $this->assertEquals(self::CODE, $this->taxDetailsItem->getCode());
179 $this->assertEquals(self::TYPE, $this->taxDetailsItem->getType());
180 $this->assertEquals(0.0, $this->taxDetailsItem->getRowTax());
186 protected function getMockItem()
189 $mockItem = $this->getMockBuilder(\
Magento\Tax\Api\Data\QuoteDetailsItemInterface::class)
190 ->disableOriginalConstructor()
192 $mockItem->expects($this->atLeastOnce())
193 ->method(
'getDiscountAmount')
194 ->will($this->returnValue(1));
195 $mockItem->expects($this->atLeastOnce())
197 ->will($this->returnValue(self::CODE));
198 $mockItem->expects($this->atLeastOnce())
200 ->will($this->returnValue(self::TYPE));
201 $mockItem->expects($this->atLeastOnce())
202 ->method(
'getUnitPrice')
203 ->will($this->returnValue(self::UNIT_PRICE));
testCalculateWithTaxNotInPrice()
$taxDetailsItemDataObjectFactoryMock
const PRICE_INCL_TAX_ROUNDED
testCalculateWithTaxInPrice()
$appliedTaxRateDataObjectFactoryMock