Skip to content

Commit

Permalink
Merge pull request #2828 from magento-borg/MAGETWO-64854
Browse files Browse the repository at this point in the history
[borg] MAGETWO-64854: Incorrect Refund Logic with Enterprise Rewards can allow for double-refunds
  • Loading branch information
cpartica authored Jul 13, 2018
2 parents 5621eee + b187d52 commit ce5eacd
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
<section name="AdminMessagesSection">
<element name="success" type="text" selector="#messages div.message-success"/>
<element name="nthSuccess" type="text" selector=".message.message-success.success:nth-of-type({{n}})>div" parameterized="true"/>
<element name="error" type="text" selector="#messages div.message-error"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,16 @@
<seeElement stepKey="LookingForNameOfProduct" selector="{{BundleStorefrontSection.bundleProductName}}"/>

<!--Testing disabled view-->
<actionGroup ref="FindProductToEdit" stepKey="FindProductEditPage"/>
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="GoToProductCatalog"/>
<waitForPageLoad stepKey="WaitForCatalogProductPageToLoad"/>
<actionGroup ref="filterProductGridBySku" stepKey="FindProductEditPage">
<argument name="product" value="BundleProduct"/>
</actionGroup>
<click selector="{{AdminDataGridTableSection.rowViewAction('1')}}" stepKey="ClickProductInGrid"/>
<click stepKey="ClickOnEnableDisableToggle" selector="{{AdminProductFormBundleSection.enableDisableToggle}}"/>
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="clickSaveButtonAgain"/>
<seeElement selector="{{AdminCategoryMessagesSection.SuccessMessage}}" stepKey="messageYouSavedTheProductIsShown2"/>
<waitForPageLoad stepKey="PauseForSave"/>
<see selector="{{AdminCategoryMessagesSection.SuccessMessage}}" userInput="You saved the product." stepKey="messageYouSavedTheProductIsShownAgain"/>
<amOnPage url="{{BundleProduct.urlKey}}.html" stepKey="GoToProductPageAgain"/>
<waitForPageLoad stepKey="WaitForProductPageToLoadToShowElement"/>
<dontSeeElement stepKey="LookingForNameOfProductTwo" selector="{{BundleStorefrontSection.bundleProductName}}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
<section name="AdminCreditMemoTotalSection">
<element name="subtotalRow" type="text" selector=".order-subtotal-table tbody > tr:nth-of-type({{row}}) td span.price" parameterized="true"/>
<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"/>
<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"/>
<element name="refundShipping" type="input" selector=".order-subtotal-table tbody input[name='creditmemo[shipping_amount]']"/>
<element name="adjustmentRefund" type="input" selector=".order-subtotal-table tbody input[name='creditmemo[adjustment_positive]'"/>
<element name="adjustmentFee" type="input" selector=".order-subtotal-table tbody input[name='creditmemo[adjustment_negative]']"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<element name="spinner" type="text" selector="[data-role='spinner'][data-component*='sales_order_view_creditmemo']"/>
<element name="gridRow" type="text" selector="#sales_order_view_tabs_order_creditmemos_content .data-grid tbody > tr:nth-of-type({{row}})" parameterized="true"/>
<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"/>
<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"/>
</section>
</sections>
59 changes: 59 additions & 0 deletions lib/internal/Magento/Framework/Math/FloatComparator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework\Math;

/**
* Contains methods to compare float digits.
*
* @api
*/
class FloatComparator
{
/**
* Precision for floats comparing.
*
* @var float
*/
private static $epsilon = 0.00001;

/**
* Compares two float digits.
*
* @param float $a
* @param float $b
* @return bool
*/
public function equal(float $a, float $b): bool
{
return abs($a - $b) <= self::$epsilon;
}

/**
* Compares if the first argument greater than the second argument.
*
* @param float $a
* @param float $b
* @return bool
*/
public function greaterThan(float $a, float $b): bool
{
return ($a - $b) > self::$epsilon;
}

/**
* Compares if the first argument greater or equal to the second.
*
* @param float $a
* @param float $b
* @return bool
*/
public function greaterThanOrEqual(float $a, float $b): bool
{
return $this->equal($a, $b) || $this->greaterThan($a, $b);
}
}
115 changes: 115 additions & 0 deletions lib/internal/Magento/Framework/Math/Test/Unit/FloatComparatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework\Math\Test\Unit;

use Magento\Framework\Math\FloatComparator;
use PHPUnit\Framework\TestCase;

class FloatComparatorTest extends TestCase
{
/**
* @var FloatComparator
*/
private $comparator;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->comparator = new FloatComparator();
}

/**
* Checks a case when `a` and `b` are equal.
*
* @param float $a
* @param float $b
* @param bool $expected
* @dataProvider eqDataProvider
*/
public function testEq(float $a, float $b, bool $expected)
{
self::assertEquals($expected, $this->comparator->equal($a, $b));
}

/**
* Gets list of variations to compare equal float.
*
* @return array
*/
public function eqDataProvider(): array
{
return [
[10, 10.00001, true],
[10, 10.000001, true],
[10.0000099, 10.00001, true],
[1, 1.0001, false],
[1, -1.00001, false],
];
}

/**
* Checks a case when `a` > `b`.
*
* @param float $a
* @param float $b
* @param bool $expected
* @dataProvider gtDataProvider
*/
public function testGt(float $a, float $b, bool $expected)
{
self::assertEquals($expected, $this->comparator->greaterThan($a, $b));
}

/**
* Gets list of variations to compare if `a` > `b`.
*
* @return array
*/
public function gtDataProvider(): array
{
return [
[10, 10.00001, false],
[10, 10.000001, false],
[10.0000099, 10.00001, false],
[1.0001, 1, true],
[1, -1.00001, true],
];
}

/**
* Checks a case when `a` >= `b`.
*
* @param float $a
* @param float $b
* @param bool $expected
* @dataProvider gteDataProvider
*/
public function testGte(float $a, float $b, bool $expected)
{
self::assertEquals($expected, $this->comparator->greaterThanOrEqual($a, $b));
}

/**
* Gets list of variations to compare if `a` >= `b`.
*
* @return array
*/
public function gteDataProvider(): array
{
return [
[10, 10.00001, true],
[10, 10.000001, true],
[10.0000099, 10.00001, true],
[1.0001, 1, true],
[1, -1.00001, true],
[1.0001, 1.001, false],
];
}
}

0 comments on commit ce5eacd

Please sign in to comment.