Skip to content

Commit 73c2619

Browse files
author
Anna Bukatar
committed
ACP2E-1155: Refunding Issue Rest API
1 parent ad9f337 commit 73c2619

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

app/code/Magento/Sales/Model/Order/Validation/CanRefundTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Sales\Model\Order\Validation;
79

810
use Magento\Framework\App\Config\ScopeConfigInterface;

app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Validation/QuantityValidatorTest.php

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
namespace Magento\Sales\Test\Unit\Model\Order\Creditmemo\Validation;
99

1010
use Magento\Framework\Pricing\PriceCurrencyInterface;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Sales\Model\Order\Creditmemo;
1113
use Magento\Sales\Api\Data\CreditmemoInterface;
1214
use Magento\Sales\Api\Data\CreditmemoItemInterface;
1315
use Magento\Sales\Api\Data\OrderInterface;
1416
use Magento\Sales\Api\InvoiceRepositoryInterface;
1517
use Magento\Sales\Api\OrderRepositoryInterface;
1618
use Magento\Sales\Model\Order\Creditmemo\Validation\QuantityValidator;
1719
use Magento\Sales\Model\Order\Item;
20+
use Magento\Store\Api\Data\StoreConfigInterface;
1821
use PHPUnit\Framework\MockObject\MockObject;
1922
use PHPUnit\Framework\TestCase;
2023

@@ -154,6 +157,30 @@ public function testValidateWithWrongItemId()
154157
);
155158
}
156159

160+
private function getCreditMemoMockParams()
161+
{
162+
return [
163+
$this->createMock(\Magento\Framework\Model\Context::class),
164+
$this->createMock(\Magento\Framework\Registry::class),
165+
$this->createMock(\Magento\Framework\Api\ExtensionAttributesFactory::class),
166+
$this->createMock(\Magento\Framework\Api\AttributeValueFactory::class),
167+
$this->createMock(\Magento\Sales\Model\Order\Creditmemo\Config::class),
168+
$this->createMock(\Magento\Sales\Model\OrderFactory::class),
169+
$this->createMock(\Magento\Sales\Model\ResourceModel\Order\Creditmemo\Item\CollectionFactory::class),
170+
$this->createMock(\Magento\Framework\Math\CalculatorFactory::class),
171+
$this->createMock(\Magento\Store\Model\StoreManagerInterface::class),
172+
$this->createMock( \Magento\Sales\Model\Order\Creditmemo\CommentFactory::class),
173+
$this->createMock(\Magento\Sales\Model\ResourceModel\Order\Creditmemo\Comment\CollectionFactory::class),
174+
$this->createMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class),
175+
$this->createMock(\Magento\Framework\Model\ResourceModel\AbstractResource::class),
176+
$this->createMock(\Magento\Framework\Data\Collection\AbstractDb::class),
177+
[],
178+
$this->createMock(\Magento\Sales\Model\Order\InvoiceFactory::class),
179+
$this->createMock(ScopeConfigInterface::class),
180+
$this->createMock(\Magento\Sales\Api\OrderRepositoryInterface::class)
181+
];
182+
}
183+
157184
/**
158185
* @param int $orderId
159186
* @param int $orderItemId
@@ -163,6 +190,7 @@ public function testValidateWithWrongItemId()
163190
* @param int $total
164191
* @param array $expected
165192
* @param bool $isQtyDecimalAllowed
193+
* @param bool $isAllowZeroGrandTotal
166194
* @dataProvider dataProviderForValidateQty
167195
*/
168196
public function testValidate(
@@ -174,16 +202,23 @@ public function testValidate(
174202
$total,
175203
array $expected,
176204
bool $isQtyDecimalAllowed,
177-
bool $isValidGrandTotal
205+
bool $isAllowZeroGrandTotal
178206
) {
179-
$creditmemoMock = $this->getMockBuilder(CreditmemoInterface::class)
180-
->disableOriginalConstructor()
181-
->addMethods(['isValidGrandTotal'])
207+
$scopeConfig = $this->getMockForAbstractClass(ScopeConfigInterface::class);
208+
$scopeConfig->expects($this->any())->method('getValue')->willReturn($isAllowZeroGrandTotal);
209+
$creditMemoConstructorParams = $this->getCreditMemoMockParams();
210+
$creditMemoConstructorParams[16] = $scopeConfig;
211+
212+
$creditmemoMock = $this->getMockBuilder(Creditmemo::class)
213+
->setConstructorArgs($creditMemoConstructorParams)
214+
->onlyMethods(['getOrderId', 'getItems', 'getGrandTotal', '_construct'])
182215
->getMockForAbstractClass();
216+
183217
$creditmemoMock->expects($this->exactly(2))->method('getOrderId')
184218
->willReturn($orderId);
185-
$creditmemoMock->expects($this->once())->method('isValidGrandTotal')
186-
->willReturn($isValidGrandTotal);
219+
$creditmemoMock->expects($this->once())->method('getGrandTotal')
220+
->willReturn($total);
221+
187222
$creditmemoItemMock = $this->getMockBuilder(
188223
CreditmemoItemInterface::class
189224
)->disableOriginalConstructor()
@@ -244,7 +279,7 @@ public function dataProviderForValidateQty()
244279
'total' => 15,
245280
'expected' => [],
246281
'isQtyDecimalAllowed' => false,
247-
'isValidGrandTotal' => true
282+
'isAllowZeroGrandTotal' => true
248283
],
249284
[
250285
'orderId' => 1,
@@ -255,7 +290,7 @@ public function dataProviderForValidateQty()
255290
'total' => 15,
256291
'expected' => [],
257292
'isQtyDecimalAllowed' => false,
258-
'isValidGrandTotal' => true
293+
'isAllowZeroGrandTotal' => true
259294
],
260295
[
261296
'orderId' => 1,
@@ -271,7 +306,7 @@ public function dataProviderForValidateQty()
271306
)
272307
],
273308
'isQtyDecimalAllowed' => false,
274-
'isValidGrandTotal' => true
309+
'isAllowZeroGrandTotal' => true
275310
],
276311
[
277312
'orderId' => 1,
@@ -300,7 +335,7 @@ public function dataProviderForValidateQty()
300335
'total' => 0,
301336
'expected' => [],
302337
'isQtyDecimalAllowed' => false,
303-
'isValidGrandTotal' => true
338+
'isAllowZeroGrandTotal' => true
304339
]
305340
];
306341
}

0 commit comments

Comments
 (0)