Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit ce5eacd

Browse files
authored
Merge pull request #2828 from magento-borg/MAGETWO-64854
[borg] MAGETWO-64854: Incorrect Refund Logic with Enterprise Rewards can allow for double-refunds
2 parents 5621eee + b187d52 commit ce5eacd

File tree

6 files changed

+184
-3
lines changed

6 files changed

+184
-3
lines changed

app/code/Magento/Backend/Test/Mftf/Section/AdminMessagesSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
<section name="AdminMessagesSection">
1212
<element name="success" type="text" selector="#messages div.message-success"/>
1313
<element name="nthSuccess" type="text" selector=".message.message-success.success:nth-of-type({{n}})>div" parameterized="true"/>
14+
<element name="error" type="text" selector="#messages div.message-error"/>
1415
</section>
1516
</sections>

app/code/Magento/Bundle/Test/Mftf/Test/EnableDisableBundleProductStatusTest.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,16 @@
7575
<seeElement stepKey="LookingForNameOfProduct" selector="{{BundleStorefrontSection.bundleProductName}}"/>
7676

7777
<!--Testing disabled view-->
78-
<actionGroup ref="FindProductToEdit" stepKey="FindProductEditPage"/>
78+
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="GoToProductCatalog"/>
79+
<waitForPageLoad stepKey="WaitForCatalogProductPageToLoad"/>
80+
<actionGroup ref="filterProductGridBySku" stepKey="FindProductEditPage">
81+
<argument name="product" value="BundleProduct"/>
82+
</actionGroup>
83+
<click selector="{{AdminDataGridTableSection.rowViewAction('1')}}" stepKey="ClickProductInGrid"/>
7984
<click stepKey="ClickOnEnableDisableToggle" selector="{{AdminProductFormBundleSection.enableDisableToggle}}"/>
8085
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="clickSaveButtonAgain"/>
81-
<seeElement selector="{{AdminCategoryMessagesSection.SuccessMessage}}" stepKey="messageYouSavedTheProductIsShown2"/>
8286
<waitForPageLoad stepKey="PauseForSave"/>
87+
<see selector="{{AdminCategoryMessagesSection.SuccessMessage}}" userInput="You saved the product." stepKey="messageYouSavedTheProductIsShownAgain"/>
8388
<amOnPage url="{{BundleProduct.urlKey}}.html" stepKey="GoToProductPageAgain"/>
8489
<waitForPageLoad stepKey="WaitForProductPageToLoadToShowElement"/>
8590
<dontSeeElement stepKey="LookingForNameOfProductTwo" selector="{{BundleStorefrontSection.bundleProductName}}"/>

app/code/Magento/Sales/Test/Mftf/Section/AdminCreditMemoTotalSection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
1111
<section name="AdminCreditMemoTotalSection">
1212
<element name="subtotalRow" type="text" selector=".order-subtotal-table tbody > tr:nth-of-type({{row}}) td span.price" parameterized="true"/>
13-
<element name="total" type="text" selector="//table[contains(@class,'order-subtotal-table')]/tbody/tr/td[contains(text(), '{{total}}')]/following-sibling::td/span/span[contains(@class, 'price')]" parameterized="true"/>
13+
<element name="total" type="text" selector="//table[contains(@class,'order-subtotal-table')]/tbody/tr/td[contains(text(), '{{total}}')]/following-sibling::td//span[contains(@class, 'price')]" parameterized="true"/>
1414
<element name="refundShipping" type="input" selector=".order-subtotal-table tbody input[name='creditmemo[shipping_amount]']"/>
1515
<element name="adjustmentRefund" type="input" selector=".order-subtotal-table tbody input[name='creditmemo[adjustment_positive]'"/>
1616
<element name="adjustmentFee" type="input" selector=".order-subtotal-table tbody input[name='creditmemo[adjustment_negative]']"/>

app/code/Magento/Sales/Test/Mftf/Section/AdminOrderCreditMemosTabSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
<element name="spinner" type="text" selector="[data-role='spinner'][data-component*='sales_order_view_creditmemo']"/>
1313
<element name="gridRow" type="text" selector="#sales_order_view_tabs_order_creditmemos_content .data-grid tbody > tr:nth-of-type({{row}})" parameterized="true"/>
1414
<element name="viewGridRow" type="button" selector="#sales_order_view_tabs_order_creditmemos_content .data-grid tbody > tr:nth-of-type({{row}}) a[href*='order_creditmemo/view']" parameterized="true"/>
15+
<element name="gridRowCell" type="text" selector="//div[@id='sales_order_view_tabs_order_creditmemos_content']//tr[{{row}}]//td[count(//div[@id='sales_order_view_tabs_order_creditmemos_content']//tr//th[contains(., '{{column}}')][1]/preceding-sibling::th) +1 ]" parameterized="true"/>
1516
</section>
1617
</sections>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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\Framework\Math;
9+
10+
/**
11+
* Contains methods to compare float digits.
12+
*
13+
* @api
14+
*/
15+
class FloatComparator
16+
{
17+
/**
18+
* Precision for floats comparing.
19+
*
20+
* @var float
21+
*/
22+
private static $epsilon = 0.00001;
23+
24+
/**
25+
* Compares two float digits.
26+
*
27+
* @param float $a
28+
* @param float $b
29+
* @return bool
30+
*/
31+
public function equal(float $a, float $b): bool
32+
{
33+
return abs($a - $b) <= self::$epsilon;
34+
}
35+
36+
/**
37+
* Compares if the first argument greater than the second argument.
38+
*
39+
* @param float $a
40+
* @param float $b
41+
* @return bool
42+
*/
43+
public function greaterThan(float $a, float $b): bool
44+
{
45+
return ($a - $b) > self::$epsilon;
46+
}
47+
48+
/**
49+
* Compares if the first argument greater or equal to the second.
50+
*
51+
* @param float $a
52+
* @param float $b
53+
* @return bool
54+
*/
55+
public function greaterThanOrEqual(float $a, float $b): bool
56+
{
57+
return $this->equal($a, $b) || $this->greaterThan($a, $b);
58+
}
59+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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\Framework\Math\Test\Unit;
9+
10+
use Magento\Framework\Math\FloatComparator;
11+
use PHPUnit\Framework\TestCase;
12+
13+
class FloatComparatorTest extends TestCase
14+
{
15+
/**
16+
* @var FloatComparator
17+
*/
18+
private $comparator;
19+
20+
/**
21+
* @inheritdoc
22+
*/
23+
protected function setUp()
24+
{
25+
$this->comparator = new FloatComparator();
26+
}
27+
28+
/**
29+
* Checks a case when `a` and `b` are equal.
30+
*
31+
* @param float $a
32+
* @param float $b
33+
* @param bool $expected
34+
* @dataProvider eqDataProvider
35+
*/
36+
public function testEq(float $a, float $b, bool $expected)
37+
{
38+
self::assertEquals($expected, $this->comparator->equal($a, $b));
39+
}
40+
41+
/**
42+
* Gets list of variations to compare equal float.
43+
*
44+
* @return array
45+
*/
46+
public function eqDataProvider(): array
47+
{
48+
return [
49+
[10, 10.00001, true],
50+
[10, 10.000001, true],
51+
[10.0000099, 10.00001, true],
52+
[1, 1.0001, false],
53+
[1, -1.00001, false],
54+
];
55+
}
56+
57+
/**
58+
* Checks a case when `a` > `b`.
59+
*
60+
* @param float $a
61+
* @param float $b
62+
* @param bool $expected
63+
* @dataProvider gtDataProvider
64+
*/
65+
public function testGt(float $a, float $b, bool $expected)
66+
{
67+
self::assertEquals($expected, $this->comparator->greaterThan($a, $b));
68+
}
69+
70+
/**
71+
* Gets list of variations to compare if `a` > `b`.
72+
*
73+
* @return array
74+
*/
75+
public function gtDataProvider(): array
76+
{
77+
return [
78+
[10, 10.00001, false],
79+
[10, 10.000001, false],
80+
[10.0000099, 10.00001, false],
81+
[1.0001, 1, true],
82+
[1, -1.00001, true],
83+
];
84+
}
85+
86+
/**
87+
* Checks a case when `a` >= `b`.
88+
*
89+
* @param float $a
90+
* @param float $b
91+
* @param bool $expected
92+
* @dataProvider gteDataProvider
93+
*/
94+
public function testGte(float $a, float $b, bool $expected)
95+
{
96+
self::assertEquals($expected, $this->comparator->greaterThanOrEqual($a, $b));
97+
}
98+
99+
/**
100+
* Gets list of variations to compare if `a` >= `b`.
101+
*
102+
* @return array
103+
*/
104+
public function gteDataProvider(): array
105+
{
106+
return [
107+
[10, 10.00001, true],
108+
[10, 10.000001, true],
109+
[10.0000099, 10.00001, true],
110+
[1.0001, 1, true],
111+
[1, -1.00001, true],
112+
[1.0001, 1.001, false],
113+
];
114+
}
115+
}

0 commit comments

Comments
 (0)