Test unit for PR #36885

This commit is contained in:
Nicolas GEHIN 2023-03-07 10:22:52 +01:00
parent 072e9a043c
commit cf3c0c4c98
No known key found for this signature in database
GPG Key ID: 18742D816113E29B
1 changed files with 40 additions and 0 deletions

View File

@ -269,4 +269,44 @@ class WC_Abstract_Order_Test extends WC_Unit_Test_Case {
$this->assertEquals( $coupon->get_id(), $coupon_data['id'] );
$this->assertEquals( $coupon_code, $coupon_data['code'] );
}
/**
* Test for get_discount_to_display which must return a value
* with and without tax whatever the setting of the options
*
* Issue :https://github.com/woocommerce/woocommerce/issues/36794
*/
public function test_get_discount_to_display() {
// Set dummy data
$tax_rate = array(
'tax_rate_country' => '',
'tax_rate_state' => '',
'tax_rate' => '20.0000',
'tax_rate_name' => 'tax',
'tax_rate_priority' => '1',
'tax_rate_order' => '1',
);
WC_Tax::_insert_tax_rate( $tax_rate );
$coupon = WC_Helper_Coupon::create_coupon();
$product = WC_Helper_Product::create_simple_product();
$order = new WC_Order();
$order->add_product( $product );
$order->apply_coupon( $coupon );
$order->calculate_totals();
$order->save();
// Test
update_option( 'woocommerce_currency', 'USD' );
update_option( 'woocommerce_currency_pos', 'right' );
update_option( 'woocommerce_price_thousand_sep', '' );
update_option( 'woocommerce_price_decimal_sep', '.' );
update_option( 'woocommerce_price_num_decimals', 2 );
update_option( 'woocommerce_tax_display_cart', 'incl' );
$this->assertEquals( '1.00$', strip_tags( $order->get_discount_to_display( 'excl' ) ) );
$this->assertEquals( '1.20$', strip_tags( $order->get_discount_to_display( 'incl' ) ) );
}
}