From 30e10678641fec305dbcae66eac2b3c626ee9cf8 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Tue, 5 Oct 2021 12:21:38 -0400 Subject: [PATCH] Add test coverage. --- ...c-product-variable-data-store-cpt-test.php | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/php/includes/data-stores/class-wc-product-variable-data-store-cpt-test.php diff --git a/tests/php/includes/data-stores/class-wc-product-variable-data-store-cpt-test.php b/tests/php/includes/data-stores/class-wc-product-variable-data-store-cpt-test.php new file mode 100644 index 00000000000..81a77c109e7 --- /dev/null +++ b/tests/php/includes/data-stores/class-wc-product-variable-data-store-cpt-test.php @@ -0,0 +1,68 @@ + '', + 'tax_rate_state' => '', + 'tax_rate' => '10.0000', + 'tax_rate_name' => 'VAT', + 'tax_rate_priority' => '1', + 'tax_rate_compound' => '0', + 'tax_rate_shipping' => '1', + 'tax_rate_order' => '1', + 'tax_rate_class' => '', + ) + ); + + // Create our variable product. + $product = WC_Helper_Product::create_variation_product(); + + // Verify that a VAT exempt customer gets prices with tax removed. + WC()->customer->set_is_vat_exempt( true ); + + $prices_no_tax = array( '9.09', '13.64', '14.55', '15.45', '16.36', '17.27' ); + $variation_prices = $product->get_variation_prices( true ); + + $this->assertEquals( $prices_no_tax, array_values( $variation_prices['price'] ) ); + + // Verify that a normal customer gets prices with tax included. + // This indirectly proves that the customer's VAT exemption influences the cache key. + WC()->customer->set_is_vat_exempt( false ); + + $prices_with_tax = array( '10.00', '15.00', '16.00', '17.00', '18.00', '19.00' ); + $variation_prices = $product->get_variation_prices( true ); + + $this->assertEquals( $prices_with_tax, array_values( $variation_prices['price'] ) ); + + // Clean up. + WC_Tax::_delete_tax_rate( $tax_id ); + + remove_filter( 'wc_tax_enabled', '__return_true' ); + remove_filter( 'woocommerce_prices_include_tax', '__return_true' ); + remove_filter( 'pre_option_woocommerce_tax_display_shop', array( $this, '__return_incl' ) ); + remove_filter( 'pre_option_woocommerce_tax_display_cart', array( $this, '__return_incl' ) ); + } +}