From cf3c0c4c98126dfb9c08bd5cb741473cee3e8fad Mon Sep 17 00:00:00 2001 From: Nicolas GEHIN Date: Tue, 7 Mar 2023 10:22:52 +0100 Subject: [PATCH] Test unit for PR #36885 --- .../class-wc-abstract-order-test.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-order-test.php b/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-order-test.php index 5a8cdf5e67b..3b2cc7a9c46 100644 --- a/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-order-test.php +++ b/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-order-test.php @@ -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' ) ) ); + } + }