Add test to make sure that negative fees never make order total negative

For some reason unknown to me, the following commit added logic to make
sure that negative fees never make the order total negative: 804feb9333

Probably by accident, commit 4326e39250 changed this logic when `$fees_total += $item->get_total()` was replaced by `$fees_total += $fee_total`:

4326e39250 (diff-9b4164165828b26c4b7aec01c7b17884R1594)

This commit adds a failing test that ensures that the old behavior is
tested. This test needs to be fixed before we merge the changes proposed
in PR #25504.
This commit is contained in:
Rodrigo Primo 2020-02-04 15:33:21 -03:00
parent 08e0936aa6
commit fb3b977a16
1 changed files with 20 additions and 0 deletions

View File

@ -791,6 +791,26 @@ class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
$this->assertEquals( 66, $object->get_total() );
}
/**
* Test: calculate_totals negative fees should not make order total negative.
*
* See: https://github.com/woocommerce/woocommerce/commit/804feb93333a8f00d0f93a163c6de58204f31f14
*/
public function test_calculate_totals_negative_fees_should_not_make_order_total_negative() {
$order = WC_Helper_Order::create_order();
$fee = new WC_Order_Item_Fee();
$fee->set_props(
array(
'total' => -60,
)
);
$order->add_item( $fee );
$order->calculate_totals();
$this->assertEquals( 0, $order->get_total() );
}
/**
* Test: has_status
*/