Skip to content

Commit 7670964

Browse files
author
Anna Bukatar
committed
ACP2E-1196: Minimum order amount error when discount rule is applied for shipping amount
1 parent f749e83 commit 7670964

File tree

1 file changed

+62
-15
lines changed

1 file changed

+62
-15
lines changed

app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -252,30 +252,77 @@ public function testValidateMinimumAmountVirtual(): void
252252
}
253253

254254
/**
255-
* @return void
255+
* Provide data for test different cases
256+
*
257+
* @param void
258+
* @return array
256259
*/
257-
public function testValidateMinimumAmount(): void
260+
public function getDataProvider(): array
258261
{
259-
$storeId = 1;
260-
$scopeConfigValues = [
261-
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
262-
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
263-
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
264-
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true]
262+
return [
263+
'Non-virtual Quote' => [
264+
'scopeConfigValues' => [
265+
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, 1, true],
266+
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, 1, 20],
267+
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, 1, true],
268+
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, 1, true]
269+
],
270+
'address' => [
271+
'setAddressType' => 'billing'
272+
],
273+
'quote' => [
274+
'getStoreId' => 1,
275+
'getIsVirtual' => false
276+
],
277+
'result' => true
278+
],
279+
'With Shipping Discount' => [
280+
'scopeConfigValues' => [
281+
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, 1, true],
282+
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, 1, 2],
283+
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, 1, true],
284+
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, 1, true]
285+
],
286+
'address' => [
287+
'setBaseSubtotal' => 25.00,
288+
'setBaseDiscountAmount' => -27.60,
289+
'setBaseShippingDiscountAmount' => 4.6,
290+
'setAddressType' => 'shipping'
291+
],
292+
'quote' => [
293+
'getStoreId' => 1,
294+
'getIsVirtual' => false
295+
],
296+
'result' => true
297+
]
265298
];
299+
}
266300

267-
$this->quote->expects($this->once())
268-
->method('getStoreId')
269-
->willReturn($storeId);
270-
$this->quote->expects($this->once())
271-
->method('getIsVirtual')
272-
->willReturn(false);
301+
/**
302+
* @dataProvider getDataProvider
303+
* @return void
304+
*/
305+
public function testValidateMinimumAmount(
306+
array $scopeConfigValues,
307+
array $address,
308+
array $quote,
309+
bool $result
310+
): void {
311+
foreach ($quote as $method => $value) {
312+
$this->quote->expects($this->once())
313+
->method($method)
314+
->willReturn($value);
315+
}
316+
317+
foreach ($address as $setter => $value) {
318+
$this->address->$setter($value);
319+
}
273320

274321
$this->scopeConfig->expects($this->once())
275322
->method('isSetFlag')
276323
->willReturnMap($scopeConfigValues);
277324

278-
$this->assertTrue($this->address->validateMinimumAmount());
325+
$this->assertEquals($result, $this->address->validateMinimumAmount());
279326
}
280327

281328
/**

0 commit comments

Comments
 (0)