Skip to content

Commit cc069c0

Browse files
author
Anna Bukatar
committed
ACP2E-651: Orders Api zero row total issue for order items with discounts
1 parent 7145168 commit cc069c0

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Test\Unit\Model\Order\Webapi;
9+
10+
use Magento\Sales\Api\Data\OrderItemInterface;
11+
use Magento\Sales\Block\Adminhtml\Items\Column\DefaultColumn;
12+
use Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
use Magento\Sales\Model\Order\Webapi\ChangeOutputArray;
16+
17+
/**
18+
* Test for \Magento\Sales\Model\Order\Webapi\ChangeOutputArray class
19+
*/
20+
class ChangeOutputArrayTest extends TestCase
21+
{
22+
/**
23+
* @var ChangeOutputArray
24+
*/
25+
private $changeOutputArray;
26+
27+
/**
28+
* @var DefaultColumn|MockObject
29+
*/
30+
private $priceRendererMock;
31+
32+
/**
33+
* @var DefaultRenderer|MockObject
34+
*/
35+
private $defaultRendererMock;
36+
37+
protected function setUp(): void
38+
{
39+
$this->priceRendererMock = $this->createMock(DefaultColumn::class);
40+
$this->defaultRendererMock = $this->createMock(DefaultRenderer::class);
41+
$this->changeOutputArray = new ChangeOutputArray($this->priceRendererMock, $this->defaultRendererMock);
42+
}
43+
44+
/**
45+
* @dataProvider negativeTotals
46+
*/
47+
public function testNoNegativeValue($totals, $expected)
48+
{
49+
$this->priceRendererMock->expects($this->once())
50+
->method('getTotalAmount')
51+
->willReturn($totals['totalAmount']);
52+
$this->priceRendererMock->expects($this->once())
53+
->method('getBaseTotalAmount')
54+
->willReturn($totals['baseTotalAmount']);
55+
$this->defaultRendererMock->expects($this->once())
56+
->method('getTotalAmount')
57+
->willReturn($totals['totalAmountIncTax']);
58+
$dataObjectMock = $this->getMockForAbstractClass(OrderItemInterface::class);
59+
$dataObjectMock->expects($this->once())
60+
->method('getBaseRowTotal')
61+
->willReturn($totals['baseRowTotal']);
62+
$dataObjectMock->expects($this->once())
63+
->method('getBaseTaxAmount')
64+
->willReturn($totals['baseTaxAmount']);
65+
$dataObjectMock->expects($this->once())
66+
->method('getBaseDiscountTaxCompensationAmount')
67+
->willReturn($totals['baseDiscountTaxCompensationAmount']);
68+
$dataObjectMock->expects($this->once())
69+
->method('getBaseWeeeTaxAppliedAmount')
70+
->willReturn($totals['baseWeeeTaxAppliedAmount']);
71+
$dataObjectMock->expects($this->once())
72+
->method('getBaseDiscountAmount')
73+
->willReturn($totals['baseDiscountAmount']);
74+
$this->assertEquals($expected, $this->changeOutputArray->execute($dataObjectMock, []));
75+
}
76+
77+
/**
78+
* Data provider for testNoNegativeValue
79+
* @return array
80+
*/
81+
public function negativeTotals()
82+
{
83+
return [
84+
[
85+
'totals' => [
86+
'totalAmount' => -1.14,
87+
'baseTotalAmount' => -1.14,
88+
'totalAmountIncTax' => -8.8817841970013E-16,
89+
'baseRowTotal' => 4.7600,
90+
'baseTaxAmount' => 0.0000,
91+
'baseDiscountTaxCompensationAmount' => 1.1400,
92+
'baseWeeeTaxAppliedAmount' => null,
93+
'baseDiscountAmount' => 5.9000
94+
],
95+
'expected' => [
96+
OrderItemInterface::ROW_TOTAL => 0,
97+
OrderItemInterface::BASE_ROW_TOTAL => 0,
98+
OrderItemInterface::ROW_TOTAL_INCL_TAX => 0,
99+
OrderItemInterface::BASE_ROW_TOTAL_INCL_TAX => 0
100+
]
101+
]
102+
];
103+
}
104+
}

0 commit comments

Comments
 (0)