From d6b970a61d1ee6e7489fae0eba39a8b6d7ba28e8 Mon Sep 17 00:00:00 2001 From: Barry Kooij Date: Fri, 6 Mar 2015 16:32:40 +0100 Subject: [PATCH] Namespace the Unit Tests --- tests/unit-tests/api/webhooks.php | 12 +- tests/unit-tests/{ => cart}/cart.php | 62 +++++---- .../functions.php} | 14 +- tests/unit-tests/{ => coupon}/coupon.php | 72 +++++----- .../functions.php} | 13 +- tests/unit-tests/customer.php | 114 --------------- tests/unit-tests/customer/customer.php | 121 ++++++++++++++++ .../functions.php} | 11 +- .../functions.php} | 11 +- .../functions.php} | 21 +-- .../{ => product}/product-simple.php | 13 +- tests/unit-tests/{ => tax}/tax.php | 131 +++++++++--------- .../{ => util}/conditional-functions.php | 8 +- .../unit-tests/{ => util}/core-functions.php | 8 +- tests/unit-tests/{ => util}/install.php | 30 ++-- .../{woocommerce.php => util/main-class.php} | 14 +- .../{ => util}/notice-functions.php | 13 +- 17 files changed, 365 insertions(+), 303 deletions(-) rename tests/unit-tests/{ => cart}/cart.php (88%) rename tests/unit-tests/{cart-functions.php => cart/functions.php} (62%) rename tests/unit-tests/{ => coupon}/coupon.php (78%) rename tests/unit-tests/{coupon-functions.php => coupon/functions.php} (82%) delete mode 100644 tests/unit-tests/customer.php create mode 100644 tests/unit-tests/customer/customer.php rename tests/unit-tests/{formatting-functions.php => formatting/functions.php} (98%) rename tests/unit-tests/{order-functions.php => order/functions.php} (92%) rename tests/unit-tests/{product-functions.php => product/functions.php} (82%) rename tests/unit-tests/{ => product}/product-simple.php (96%) rename tests/unit-tests/{ => tax}/tax.php (79%) rename tests/unit-tests/{ => util}/conditional-functions.php (89%) rename tests/unit-tests/{ => util}/core-functions.php (96%) rename tests/unit-tests/{ => util}/install.php (80%) rename tests/unit-tests/{woocommerce.php => util/main-class.php} (79%) rename tests/unit-tests/{ => util}/notice-functions.php (95%) diff --git a/tests/unit-tests/api/webhooks.php b/tests/unit-tests/api/webhooks.php index 4926cb0741b..8e98da7499e 100644 --- a/tests/unit-tests/api/webhooks.php +++ b/tests/unit-tests/api/webhooks.php @@ -1,11 +1,13 @@ assertNotWPError( $response ); $this->assertArrayHasKey( 'webhook', $response ); - $this->check_get_webhook_response( $response['webhook'], new WC_Webhook( $response['webhook']['id'] ) ); + $this->check_get_webhook_response( $response['webhook'], new \WC_Webhook( $response['webhook']['id'] ) ); } /** @@ -458,7 +460,7 @@ class WC_Tests_Webhooks extends WC_API_Unit_Test_Case { $this->assertNotWPError( $response ); $this->assertArrayHasKey( 'webhook', $response ); - $this->check_get_webhook_response( $response['webhook'], new WC_Webhook( $response['webhook']['id'] ) ); + $this->check_get_webhook_response( $response['webhook'], new \WC_Webhook( $response['webhook']['id'] ) ); } /** diff --git a/tests/unit-tests/cart.php b/tests/unit-tests/cart/cart.php similarity index 88% rename from tests/unit-tests/cart.php rename to tests/unit-tests/cart/cart.php index 82cd6d65aa4..a209ac18599 100644 --- a/tests/unit-tests/cart.php +++ b/tests/unit-tests/cart/cart.php @@ -1,6 +1,12 @@ assertNotFalse( WC()->cart->add_to_cart( $product->id, 1 ) ); @@ -119,7 +125,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { WC()->cart->empty_cart(); // Clean up product - WC_Helper_Product::delete_product( $product->id ); + \WC_Helper_Product::delete_product( $product->id ); } /** @@ -127,7 +133,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { */ public function test_add_to_cart_trashed() { // Create dummy product - $product = WC_Helper_Product::create_simple_product(); + $product = \WC_Helper_Product::create_simple_product(); // Trash product wp_trash_post( $product->id ); @@ -142,7 +148,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { WC()->cart->empty_cart(); // Clean up product - WC_Helper_Product::delete_product( $product->id ); + \WC_Helper_Product::delete_product( $product->id ); } /** @@ -151,7 +157,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { * @since 2.3 */ public function test_add_to_cart_variable() { - $product = WC_Helper_Product::create_variation_product(); + $product = \WC_Helper_Product::create_variation_product(); $variations = $product->get_available_variations(); $variation = array_shift( $variations ); @@ -174,7 +180,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { */ public function test_add_to_cart_sold_individually() { // Create dummy product - $product = WC_Helper_Product::create_simple_product(); + $product = \WC_Helper_Product::create_simple_product(); // Set sold_individually to yes $product->sold_individually = 'yes'; @@ -190,7 +196,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { WC()->cart->empty_cart(); // Clean up product - WC_Helper_Product::delete_product( $product->id ); + \WC_Helper_Product::delete_product( $product->id ); } /** @@ -201,7 +207,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { public function test_find_product_in_cart() { // Create dummy product - $product = WC_Helper_Product::create_simple_product(); + $product = \WC_Helper_Product::create_simple_product(); // Add product to cart WC()->cart->add_to_cart( $product->id, 1 ); @@ -216,7 +222,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { WC()->cart->empty_cart(); // Clean up product - WC_Helper_Product::delete_product( $product->id ); + \WC_Helper_Product::delete_product( $product->id ); } @@ -283,7 +289,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { */ public function test_set_quantity() { // Create dummy product - $product = WC_Helper_Product::create_simple_product(); + $product = \WC_Helper_Product::create_simple_product(); // Add 1 product to cart WC()->cart->add_to_cart( $product->id, 1 ); @@ -307,7 +313,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { WC()->cart->empty_cart(); // Clean up product - WC_Helper_Product::delete_product( $product->id ); + \WC_Helper_Product::delete_product( $product->id ); } /** @@ -318,7 +324,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { public function test_check_cart_item_validity() { // Create dummy product - $product = WC_Helper_Product::create_simple_product(); + $product = \WC_Helper_Product::create_simple_product(); // Add product to cart WC()->cart->add_to_cart( $product->id, 1 ); @@ -330,7 +336,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { WC()->cart->empty_cart(); // Clean up product - WC_Helper_Product::delete_product( $product->id ); + \WC_Helper_Product::delete_product( $product->id ); } @@ -342,7 +348,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { public function test_get_total() { // Create dummy product - $product = WC_Helper_Product::create_simple_product(); + $product = \WC_Helper_Product::create_simple_product(); // We need this to have the calculate_totals() method calculate totals if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { @@ -359,7 +365,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { WC()->cart->empty_cart(); // Clean up product - WC_Helper_Product::delete_product( $product->id ); + \WC_Helper_Product::delete_product( $product->id ); } /** @@ -373,7 +379,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { update_option( 'woocommerce_calc_taxes', 'yes' ); // Create dummy product - $product = WC_Helper_Product::create_simple_product(); + $product = \WC_Helper_Product::create_simple_product(); // We need this to have the calculate_totals() method calculate totals if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { @@ -396,7 +402,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { WC()->cart->empty_cart(); // Clean up product - WC_Helper_Product::delete_product( $product->id ); + \WC_Helper_Product::delete_product( $product->id ); // Restore option update_option( 'woocommerce_calc_taxes', 'no' ); @@ -436,12 +442,12 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { */ public function test_shipping_total() { // Create product - $product = WC_Helper_Product::create_simple_product(); + $product =\WC_Helper_Product::create_simple_product(); update_post_meta( $product->id, '_price', '10' ); update_post_meta( $product->id, '_regular_price', '10' ); // Create a flat rate method - WC_Helper_Shipping::create_simple_flat_rate(); + \WC_Helper_Shipping::create_simple_flat_rate(); // We need this to have the calculate_totals() method calculate totals if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { @@ -466,10 +472,10 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { // Delete the flat rate method WC()->session->set( 'chosen_shipping_methods', array() ); - WC_Helper_Shipping::delete_simple_flat_rate(); + \WC_Helper_Shipping::delete_simple_flat_rate(); // Delete product - WC_Helper_Product::delete_product( $product->id ); + \WC_Helper_Product::delete_product( $product->id ); } /** @@ -479,7 +485,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { */ public function test_cart_fee() { // Create product - $product = WC_Helper_Product::create_simple_product(); + $product =\WC_Helper_Product::create_simple_product(); update_post_meta( $product->id, '_price', '10' ); update_post_meta( $product->id, '_regular_price', '10' ); @@ -489,7 +495,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { } // Add fee - WC_Helper_Fee::add_cart_fee(); + \WC_Helper_Fee::add_cart_fee(); // Add product to cart WC()->cart->add_to_cart( $product->id, 1 ); @@ -504,10 +510,10 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { WC()->cart->empty_cart(); // Remove fee - WC_Helper_Fee::remove_cart_fee(); + \WC_Helper_Fee::remove_cart_fee(); // Delete product - WC_Helper_Product::delete_product( $product->id ); + \WC_Helper_Product::delete_product( $product->id ); } /** @@ -516,7 +522,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { public function test_get_coupons() { // Create coupon - $coupon = WC_Helper_Coupon::create_coupon(); + $coupon = \WC_Helper_Coupon::create_coupon(); // Add coupon WC()->cart->add_discount( $coupon->code ); @@ -530,7 +536,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { WC()->cart->remove_coupons(); // Delete coupon - WC_Helper_Coupon::delete_coupon( $coupon->id ); + \WC_Helper_Coupon::delete_coupon( $coupon->id ); } diff --git a/tests/unit-tests/cart-functions.php b/tests/unit-tests/cart/functions.php similarity index 62% rename from tests/unit-tests/cart-functions.php rename to tests/unit-tests/cart/functions.php index 04645c7e8b3..114b1617bd1 100644 --- a/tests/unit-tests/cart-functions.php +++ b/tests/unit-tests/cart/functions.php @@ -1,10 +1,12 @@ cart->add_to_cart( $product->id, 1 ); @@ -25,6 +27,6 @@ class WC_Tests_Cart_Functions extends WC_Unit_Test_Case { $this->assertEquals( 0, WC()->cart->get_cart_contents_count() ); // Delete the previously created product - WC_Helper_Product::delete_product( $product->id ); + \WC_Helper_Product::delete_product( $product->id ); } } diff --git a/tests/unit-tests/coupon.php b/tests/unit-tests/coupon/coupon.php similarity index 78% rename from tests/unit-tests/coupon.php rename to tests/unit-tests/coupon/coupon.php index 2341fbf5b8c..79e81d0290b 100644 --- a/tests/unit-tests/coupon.php +++ b/tests/unit-tests/coupon/coupon.php @@ -1,6 +1,12 @@ assertTrue( WC()->cart->add_discount( $coupon->code ) ); @@ -25,7 +31,7 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case { WC()->cart->remove_coupons(); // Delete coupon - WC_Helper_Coupon::delete_coupon( $coupon->id ); + \WC_Helper_Coupon::delete_coupon( $coupon->id ); } /** @@ -36,7 +42,7 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case { public function test_add_discount_duplicate() { // Create coupon - $coupon = WC_Helper_Coupon::create_coupon(); + $coupon = \WC_Helper_Coupon::create_coupon(); // Add coupon $this->assertTrue( WC()->cart->add_discount( $coupon->code ) ); @@ -57,7 +63,7 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case { WC()->cart->remove_coupons(); // Delete coupon - WC_Helper_Coupon::delete_coupon( $coupon->id ); + \WC_Helper_Coupon::delete_coupon( $coupon->id ); } /** @@ -68,17 +74,17 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case { public function test_fixed_cart_discount() { // Create product - $product = WC_Helper_Product::create_simple_product(); + $product = \WC_Helper_Product::create_simple_product(); update_post_meta( $product->id, '_price', '10' ); update_post_meta( $product->id, '_regular_price', '10' ); // Create coupon - $coupon = WC_Helper_Coupon::create_coupon(); + $coupon = \WC_Helper_Coupon::create_coupon(); update_post_meta( $coupon->id, 'discount_type', 'fixed_cart' ); update_post_meta( $coupon->id, 'coupon_amount', '5' ); // Create a flat rate method - WC_Helper_Shipping::create_simple_flat_rate(); + \WC_Helper_Shipping::create_simple_flat_rate(); // We need this to have the calculate_totals() method calculate totals if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { @@ -109,13 +115,13 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case { // Delete the flat rate method WC()->session->set( 'chosen_shipping_methods', array() ); - WC_Helper_Shipping::delete_simple_flat_rate(); + \WC_Helper_Shipping::delete_simple_flat_rate(); // Delete coupon - WC_Helper_Coupon::delete_coupon( $coupon->id ); + \WC_Helper_Coupon::delete_coupon( $coupon->id ); // Delete product - WC_Helper_Product::delete_product( $product->id ); + \WC_Helper_Product::delete_product( $product->id ); } /** @@ -126,17 +132,17 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case { public function test_percent_cart_discount() { // Create product - $product = WC_Helper_Product::create_simple_product(); + $product = \WC_Helper_Product::create_simple_product(); update_post_meta( $product->id, '_price', '10' ); update_post_meta( $product->id, '_regular_price', '10' ); // Create coupon - $coupon = WC_Helper_Coupon::create_coupon(); + $coupon = \WC_Helper_Coupon::create_coupon(); update_post_meta( $coupon->id, 'discount_type', 'percent' ); update_post_meta( $coupon->id, 'coupon_amount', '5' ); // Create a flat rate method - WC_Helper_Shipping::create_simple_flat_rate(); + \WC_Helper_Shipping::create_simple_flat_rate(); // We need this to have the calculate_totals() method calculate totals if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { @@ -167,13 +173,13 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case { // Delete the flat rate method WC()->session->set( 'chosen_shipping_methods', array() ); - WC_Helper_Shipping::delete_simple_flat_rate(); + \WC_Helper_Shipping::delete_simple_flat_rate(); // Delete coupon - WC_Helper_Coupon::delete_coupon( $coupon->id ); + \WC_Helper_Coupon::delete_coupon( $coupon->id ); // Delete product - WC_Helper_Product::delete_product( $product->id ); + \WC_Helper_Product::delete_product( $product->id ); } /** @@ -184,17 +190,17 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case { public function test_fixed_product_discount() { // Create product - $product = WC_Helper_Product::create_simple_product(); + $product = \WC_Helper_Product::create_simple_product(); update_post_meta( $product->id, '_price', '10' ); update_post_meta( $product->id, '_regular_price', '10' ); // Create coupon - $coupon = WC_Helper_Coupon::create_coupon(); + $coupon = \WC_Helper_Coupon::create_coupon(); update_post_meta( $coupon->id, 'discount_type', 'fixed_product' ); update_post_meta( $coupon->id, 'coupon_amount', '5' ); // Create a flat rate method - WC_Helper_Shipping::create_simple_flat_rate(); + \WC_Helper_Shipping::create_simple_flat_rate(); // We need this to have the calculate_totals() method calculate totals if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { @@ -202,7 +208,7 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case { } // Add fee - WC_Helper_Fee::add_cart_fee(); + \WC_Helper_Fee::add_cart_fee(); // Add product to cart WC()->cart->add_to_cart( $product->id, 1 ); @@ -227,17 +233,17 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case { WC()->cart->remove_coupons(); // Remove fee - WC_Helper_Fee::remove_cart_fee(); + \WC_Helper_Fee::remove_cart_fee(); // Delete the flat rate method WC()->session->set( 'chosen_shipping_methods', array() ); - WC_Helper_Shipping::delete_simple_flat_rate(); + \WC_Helper_Shipping::delete_simple_flat_rate(); // Delete coupon - WC_Helper_Coupon::delete_coupon( $coupon->id ); + \WC_Helper_Coupon::delete_coupon( $coupon->id ); // Delete product - WC_Helper_Product::delete_product( $product->id ); + \WC_Helper_Product::delete_product( $product->id ); } /** @@ -248,17 +254,17 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case { public function test_percent_product_discount() { // Create product - $product = WC_Helper_Product::create_simple_product(); + $product = \WC_Helper_Product::create_simple_product(); update_post_meta( $product->id, '_price', '10' ); update_post_meta( $product->id, '_regular_price', '10' ); // Create coupon - $coupon = WC_Helper_Coupon::create_coupon(); + $coupon = \WC_Helper_Coupon::create_coupon(); update_post_meta( $coupon->id, 'discount_type', 'percent_product' ); update_post_meta( $coupon->id, 'coupon_amount', '5' ); // Create a flat rate method - WC_Helper_Shipping::create_simple_flat_rate(); + \WC_Helper_Shipping::create_simple_flat_rate(); // We need this to have the calculate_totals() method calculate totals if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { @@ -266,7 +272,7 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case { } // Add fee - WC_Helper_Fee::add_cart_fee(); + \WC_Helper_Fee::add_cart_fee(); // Add product to cart WC()->cart->add_to_cart( $product->id, 1 ); @@ -291,17 +297,17 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case { WC()->cart->remove_coupons(); // Remove fee - WC_Helper_Fee::remove_cart_fee(); + \WC_Helper_Fee::remove_cart_fee(); // Delete the flat rate method WC()->session->set( 'chosen_shipping_methods', array() ); - WC_Helper_Shipping::delete_simple_flat_rate(); + \WC_Helper_Shipping::delete_simple_flat_rate(); // Delete coupon - WC_Helper_Coupon::delete_coupon( $coupon->id ); + \WC_Helper_Coupon::delete_coupon( $coupon->id ); // Delete product - WC_Helper_Product::delete_product( $product->id ); + \WC_Helper_Product::delete_product( $product->id ); } } diff --git a/tests/unit-tests/coupon-functions.php b/tests/unit-tests/coupon/functions.php similarity index 82% rename from tests/unit-tests/coupon-functions.php rename to tests/unit-tests/coupon/functions.php index ce0beb902b2..1be553343e4 100644 --- a/tests/unit-tests/coupon-functions.php +++ b/tests/unit-tests/coupon/functions.php @@ -1,10 +1,13 @@ cart->add_to_cart( $product->id, 1 ); - - // Customer is going with the Local Pickup option, and the store calculates tax based on the store location. - - WC_Helper_Customer::set_chosen_shipping_methods( array( 'local_pickup' ) ); - WC_Helper_Customer::set_tax_based_on( 'base' ); - $this->assertEquals( $customer->get_taxable_address(), $base_store_address ); - - // Customer is going with the Local Pickup option, and the store calculates tax based on the customer's billing address. - - WC_Helper_Customer::set_chosen_shipping_methods( array( 'local_pickup' ) ); - WC_Helper_Customer::set_tax_based_on( 'billing' ); - $this->assertEquals( $customer->get_taxable_address(), $base_store_address ); - - // Customer is going with the Free Shipping option, and the store calculates tax based on the customer's billing address. - - WC_Helper_Customer::set_chosen_shipping_methods( array( 'free_shipping' ) ); - WC_Helper_Customer::set_tax_based_on( 'billing' ); - $this->assertEquals( $customer->get_taxable_address(), $customer_address ); - - // Customer is going with the Free Shipping option, and the store calculates tax based on the store base location. - - WC_Helper_Customer::set_chosen_shipping_methods( array( 'free_shipping' ) ); - WC_Helper_Customer::set_tax_based_on( 'base' ); - $this->assertEquals( $customer->get_taxable_address(), $base_store_address ); - - //Now reset the settings back to the way they were before this test - - WC_Helper_Customer::set_chosen_shipping_methods( $original_chosen_shipping_methods ); - WC_Helper_Customer::set_tax_based_on( $original_tax_based_on ); - WC_Helper_Customer::set_customer_details( $original_customer_details ); - - // Clean up the cart - WC()->cart->empty_cart(); - - // Clean up product - WC_Helper_Product::delete_product( $product->id ); - } - - /** - * Test the is_customer_outside_base method - */ - public function test_is_customer_outside_base() { - - // Get the original settings for the session and the WooCommerce options - $original_chosen_shipping_methods = WC_Helper_Customer::get_chosen_shipping_methods(); - $original_tax_based_on = WC_Helper_Customer::get_tax_based_on(); - $original_customer_details = WC_Helper_Customer::get_customer_details(); - - $customer = WC_Helper_Customer::create_mock_customer(); - - // Create dummy product, and add the product to the cart. - $product = WC_Helper_Product::create_simple_product(); - - WC()->cart->add_to_cart( $product->id, 1 ); - - // Customer is going with the Local Pickup option, and the store calculates tax based on the store location. - - WC_Helper_Customer::set_chosen_shipping_methods( array( 'local_pickup' ) ); - WC_Helper_Customer::set_tax_based_on( 'base' ); - $this->assertEquals( $customer->is_customer_outside_base(), false ); - - // Customer is going with the Local Pickup option, and the store calculates tax based on the customer's billing address. - - WC_Helper_Customer::set_chosen_shipping_methods( array( 'local_pickup' ) ); - WC_Helper_Customer::set_tax_based_on( 'billing' ); - $this->assertEquals( $customer->is_customer_outside_base(), false ); - - // Customer is going with the Free Shipping option, and the store calculates tax based on the customer's billing address. - - WC_Helper_Customer::set_chosen_shipping_methods( array( 'free_shipping' ) ); - WC_Helper_Customer::set_tax_based_on( 'billing' ); - $this->assertEquals( $customer->is_customer_outside_base(), true ); - - // Customer is going with the Free Shipping option, and the store calculates tax based on the store base location. - - WC_Helper_Customer::set_chosen_shipping_methods( array( 'free_shipping' ) ); - WC_Helper_Customer::set_tax_based_on( 'base' ); - $this->assertEquals( $customer->is_customer_outside_base(), false ); - - //Now reset the settings back to the way they were before this test - - WC_Helper_Customer::set_chosen_shipping_methods( $original_chosen_shipping_methods ); - WC_Helper_Customer::set_tax_based_on( $original_tax_based_on ); - WC_Helper_Customer::set_customer_details( $original_customer_details ); - - // Clean up the cart - WC()->cart->empty_cart(); - - // Clean up product - WC_Helper_Product::delete_product( $product->id ); - } -} \ No newline at end of file diff --git a/tests/unit-tests/customer/customer.php b/tests/unit-tests/customer/customer.php new file mode 100644 index 00000000000..d4d3902fb52 --- /dev/null +++ b/tests/unit-tests/customer/customer.php @@ -0,0 +1,121 @@ +cart->add_to_cart( $product->id, 1 ); + + // Customer is going with the Local Pickup option, and the store calculates tax based on the store location. + + \WC_Helper_Customer::set_chosen_shipping_methods( array( 'local_pickup' ) ); + \WC_Helper_Customer::set_tax_based_on( 'base' ); + $this->assertEquals( $customer->get_taxable_address(), $base_store_address ); + + // Customer is going with the Local Pickup option, and the store calculates tax based on the customer's billing address. + + \WC_Helper_Customer::set_chosen_shipping_methods( array( 'local_pickup' ) ); + \WC_Helper_Customer::set_tax_based_on( 'billing' ); + $this->assertEquals( $customer->get_taxable_address(), $base_store_address ); + + // Customer is going with the Free Shipping option, and the store calculates tax based on the customer's billing address. + + \WC_Helper_Customer::set_chosen_shipping_methods( array( 'free_shipping' ) ); + \WC_Helper_Customer::set_tax_based_on( 'billing' ); + $this->assertEquals( $customer->get_taxable_address(), $customer_address ); + + // Customer is going with the Free Shipping option, and the store calculates tax based on the store base location. + + \WC_Helper_Customer::set_chosen_shipping_methods( array( 'free_shipping' ) ); + \WC_Helper_Customer::set_tax_based_on( 'base' ); + $this->assertEquals( $customer->get_taxable_address(), $base_store_address ); + + //Now reset the settings back to the way they were before this test + + \WC_Helper_Customer::set_chosen_shipping_methods( $original_chosen_shipping_methods ); + \WC_Helper_Customer::set_tax_based_on( $original_tax_based_on ); + \WC_Helper_Customer::set_customer_details( $original_customer_details ); + + // Clean up the cart + WC()->cart->empty_cart(); + + // Clean up product + \WC_Helper_Product::delete_product( $product->id ); + } + + /** + * Test the is_customer_outside_base method + */ + public function test_is_customer_outside_base() { + + // Get the original settings for the session and the WooCommerce options + $original_chosen_shipping_methods = \WC_Helper_Customer::get_chosen_shipping_methods(); + $original_tax_based_on = \WC_Helper_Customer::get_tax_based_on(); + $original_customer_details = \WC_Helper_Customer::get_customer_details(); + + $customer = \WC_Helper_Customer::create_mock_customer(); + + // Create dummy product, and add the product to the cart. + $product = \WC_Helper_Product::create_simple_product(); + + WC()->cart->add_to_cart( $product->id, 1 ); + + // Customer is going with the Local Pickup option, and the store calculates tax based on the store location. + + \WC_Helper_Customer::set_chosen_shipping_methods( array( 'local_pickup' ) ); + \WC_Helper_Customer::set_tax_based_on( 'base' ); + $this->assertEquals( $customer->is_customer_outside_base(), false ); + + // Customer is going with the Local Pickup option, and the store calculates tax based on the customer's billing address. + + \WC_Helper_Customer::set_chosen_shipping_methods( array( 'local_pickup' ) ); + \WC_Helper_Customer::set_tax_based_on( 'billing' ); + $this->assertEquals( $customer->is_customer_outside_base(), false ); + + // Customer is going with the Free Shipping option, and the store calculates tax based on the customer's billing address. + + \WC_Helper_Customer::set_chosen_shipping_methods( array( 'free_shipping' ) ); + \WC_Helper_Customer::set_tax_based_on( 'billing' ); + $this->assertEquals( $customer->is_customer_outside_base(), true ); + + // Customer is going with the Free Shipping option, and the store calculates tax based on the store base location. + + \WC_Helper_Customer::set_chosen_shipping_methods( array( 'free_shipping' ) ); + \WC_Helper_Customer::set_tax_based_on( 'base' ); + $this->assertEquals( $customer->is_customer_outside_base(), false ); + + //Now reset the settings back to the way they were before this test + + \WC_Helper_Customer::set_chosen_shipping_methods( $original_chosen_shipping_methods ); + \WC_Helper_Customer::set_tax_based_on( $original_tax_based_on ); + \WC_Helper_Customer::set_customer_details( $original_customer_details ); + + // Clean up the cart + WC()->cart->empty_cart(); + + // Clean up product + \WC_Helper_Product::delete_product( $product->id ); + } +} \ No newline at end of file diff --git a/tests/unit-tests/formatting-functions.php b/tests/unit-tests/formatting/functions.php similarity index 98% rename from tests/unit-tests/formatting-functions.php rename to tests/unit-tests/formatting/functions.php index 7b0341bd818..ab1d851f8b3 100644 --- a/tests/unit-tests/formatting-functions.php +++ b/tests/unit-tests/formatting/functions.php @@ -1,10 +1,15 @@ _delete_product(); } - $this->_product = WC_Helper_Product::create_simple_product(); + $this->_product = \WC_Helper_Product::create_simple_product(); } /** @@ -33,7 +36,7 @@ class WC_Tests_Product_Functions extends WC_Unit_Test_Case { */ private function _delete_product() { // Delete the previously created product - WC_Helper_Product::delete_product( $this->_product->id ); + \WC_Helper_Product::delete_product( $this->_product->id ); $this->_product = null; } @@ -89,18 +92,18 @@ class WC_Tests_Product_Functions extends WC_Unit_Test_Case { * @since 2.3 */ public function test_wc_product_has_unique_sku() { - $product_1 = WC_Helper_Product::create_simple_product(); + $product_1 = \WC_Helper_Product::create_simple_product(); $this->assertEquals( true, wc_product_has_unique_sku( $product_1->id, $product_1->sku ) ); - $product_2 = WC_Helper_Product::create_simple_product(); + $product_2 = \WC_Helper_Product::create_simple_product(); $this->assertEquals( false, wc_product_has_unique_sku( $product_2->id, $product_2->sku ) ); - WC_Helper_Product::delete_product( $product_1->id ); + \WC_Helper_Product::delete_product( $product_1->id ); $this->assertEquals( true, wc_product_has_unique_sku( $product_2->id, $product_2->sku ) ); - WC_Helper_Product::delete_product( $product_2->id ); + \WC_Helper_Product::delete_product( $product_2->id ); } /** diff --git a/tests/unit-tests/product-simple.php b/tests/unit-tests/product/product-simple.php similarity index 96% rename from tests/unit-tests/product-simple.php rename to tests/unit-tests/product/product-simple.php index c44b9745b77..277279e04ad 100644 --- a/tests/unit-tests/product-simple.php +++ b/tests/unit-tests/product/product-simple.php @@ -1,10 +1,13 @@ _product = WC_Helper_Product::create_simple_product(); + $this->_product = \WC_Helper_Product::create_simple_product(); } /** @@ -29,7 +32,7 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case { */ private function _delete_product() { // Delete the previously created product - WC_Helper_Product::delete_product( $this->_product->id ); + \WC_Helper_Product::delete_product( $this->_product->id ); $this->_product = null; } diff --git a/tests/unit-tests/tax.php b/tests/unit-tests/tax/tax.php similarity index 79% rename from tests/unit-tests/tax.php rename to tests/unit-tests/tax/tax.php index e58db48ea80..ffcda12575a 100644 --- a/tests/unit-tests/tax.php +++ b/tests/unit-tests/tax/tax.php @@ -1,6 +1,11 @@ query( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rates" ); $wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations" ); - $customer_location = WC_Tax::get_tax_location(); + $customer_location = \WC_Tax::get_tax_location(); $tax_rate = array( 'tax_rate_country' => $customer_location[0], 'tax_rate_state' => '', @@ -24,13 +29,13 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { 'tax_rate_class' => '' ); - $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); + $tax_rate_id = \WC_Tax::_insert_tax_rate( $tax_rate ); - $tax_rates = WC_Tax::get_rates(); + $tax_rates = \WC_Tax::get_rates(); $this->assertEquals( $tax_rates, array( $tax_rate_id => array( 'rate' => '20.0000', 'label' => 'VAT', 'shipping' => 'yes', 'compound' => 'no' ) ) ); - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); } /** @@ -42,7 +47,7 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { $wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rates" ); $wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations" ); - $customer_location = WC_Tax::get_tax_location(); + $customer_location = \WC_Tax::get_tax_location(); $tax_rate = array( 'tax_rate_country' => $customer_location[0], 'tax_rate_state' => '', @@ -55,13 +60,13 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { 'tax_rate_class' => '' ); - $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); + $tax_rate_id = \WC_Tax::_insert_tax_rate( $tax_rate ); - $tax_rates = WC_Tax::get_shipping_tax_rates(); + $tax_rates = \WC_Tax::get_shipping_tax_rates(); $this->assertEquals( $tax_rates, array( $tax_rate_id => array( 'rate' => '20.0000', 'label' => 'VAT', 'shipping' => 'yes', 'compound' => 'no' ) ) ); - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); } /** @@ -85,13 +90,13 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { 'tax_rate_class' => '' ); - $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); + $tax_rate_id = \WC_Tax::_insert_tax_rate( $tax_rate ); - $tax_rates = WC_Tax::get_base_tax_rates(); + $tax_rates = \WC_Tax::get_base_tax_rates(); $this->assertEquals( $tax_rates, array( $tax_rate_id => array( 'rate' => '20.0000', 'label' => 'VAT', 'shipping' => 'yes', 'compound' => 'no' ) ) ); - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); } /** @@ -115,9 +120,9 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { 'tax_rate_class' => '' ); - $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); + $tax_rate_id = \WC_Tax::_insert_tax_rate( $tax_rate ); - $tax_rates = WC_Tax::find_rates( array( + $tax_rates = \WC_Tax::find_rates( array( 'country' => 'GB', 'state' => 'Cambs', 'postcode' => 'PE14 1XX', @@ -127,7 +132,7 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { $this->assertEquals( $tax_rates, array( $tax_rate_id => array( 'rate' => '20.0000', 'label' => 'VAT', 'shipping' => 'yes', 'compound' => 'no' ) ) ); - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); } /** @@ -151,9 +156,9 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { 'tax_rate_class' => '' ); - $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); + $tax_rate_id = \WC_Tax::_insert_tax_rate( $tax_rate ); - $tax_rates = WC_Tax::find_shipping_rates( array( + $tax_rates = \WC_Tax::find_shipping_rates( array( 'country' => 'GB', 'state' => 'Cambs', 'postcode' => 'PE14 1XX', @@ -163,7 +168,7 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { $this->assertEquals( $tax_rates, array( $tax_rate_id => array( 'rate' => '20.0000', 'label' => 'VAT', 'shipping' => 'yes', 'compound' => 'no' ) ) ); - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); } /** @@ -187,9 +192,9 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { 'tax_rate_class' => '' ); - $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); + $tax_rate_id = \WC_Tax::_insert_tax_rate( $tax_rate ); - $tax_rates = WC_Tax::find_rates( array( + $tax_rates = \WC_Tax::find_rates( array( 'country' => 'GB', 'state' => 'Cambs', 'postcode' => 'PE14 1XX', @@ -197,15 +202,15 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { 'tax_class' => '' ) ); - $calced_tax = WC_Tax::calc_tax( '9.99', $tax_rates, true, false ); + $calced_tax = \WC_Tax::calc_tax( '9.99', $tax_rates, true, false ); $this->assertEquals( $calced_tax, array( $tax_rate_id => '1.665' ) ); - $calced_tax = WC_Tax::calc_tax( '9.99', $tax_rates, false, false ); + $calced_tax = \WC_Tax::calc_tax( '9.99', $tax_rates, false, false ); $this->assertEquals( $calced_tax, array( $tax_rate_id => '1.998' ) ); - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); } /** @@ -244,10 +249,10 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { 'tax_rate_class' => '' ); - $tax_rate_1_id = WC_Tax::_insert_tax_rate( $tax_rate_1 ); - $tax_rate_2_id = WC_Tax::_insert_tax_rate( $tax_rate_2 ); + $tax_rate_1_id = \WC_Tax::_insert_tax_rate( $tax_rate_1 ); + $tax_rate_2_id = \WC_Tax::_insert_tax_rate( $tax_rate_2 ); - $tax_rates = WC_Tax::find_rates( array( + $tax_rates = \WC_Tax::find_rates( array( 'country' => 'CA', 'state' => 'QC', 'postcode' => '12345', @@ -256,11 +261,11 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { ) ); // prices exclusive of tax - $calced_tax = WC_Tax::calc_tax( '100', $tax_rates, false, false ); + $calced_tax = \WC_Tax::calc_tax( '100', $tax_rates, false, false ); $this->assertEquals( $calced_tax, array( $tax_rate_1_id => '5.0000', $tax_rate_2_id => '8.925' ) ); // prices inclusive of tax - $calced_tax = WC_Tax::calc_tax( '100', $tax_rates, true, false ); + $calced_tax = \WC_Tax::calc_tax( '100', $tax_rates, true, false ); /** * 100 is inclusive of all taxes. * @@ -270,8 +275,8 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { */ $this->assertEquals( $calced_tax, array( $tax_rate_1_id => 4.3889, $tax_rate_2_id => 7.8341 ) ); - WC_Tax::_delete_tax_rate( $tax_rate_1_id ); - WC_Tax::_delete_tax_rate( $tax_rate_2_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_1_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_2_id ); update_option( 'woocommerce_default_country', 'GB' ); update_option( 'woocommerce_default_state', '' ); } @@ -297,9 +302,9 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { 'tax_rate_class' => '' ); - $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); + $tax_rate_id = \WC_Tax::_insert_tax_rate( $tax_rate ); - $tax_rates = WC_Tax::find_rates( array( + $tax_rates = \WC_Tax::find_rates( array( 'country' => 'GB', 'state' => 'Cambs', 'postcode' => 'PE14 1XX', @@ -307,11 +312,11 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { 'tax_class' => '' ) ); - $calced_tax = WC_Tax::calc_shipping_tax( '10', $tax_rates ); + $calced_tax = \WC_Tax::calc_shipping_tax( '10', $tax_rates ); $this->assertEquals( $calced_tax, array( $tax_rate_id => '2' ) ); - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); } /** @@ -332,11 +337,11 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { 'tax_rate_class' => '' ); - $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); + $tax_rate_id = \WC_Tax::_insert_tax_rate( $tax_rate ); - $this->assertEquals( WC_Tax::get_rate_label( $tax_rate_id ), 'VAT' ); + $this->assertEquals(\WC_Tax::get_rate_label( $tax_rate_id ), 'VAT' ); - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); } /** @@ -357,11 +362,11 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { 'tax_rate_class' => '' ); - $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); + $tax_rate_id = \WC_Tax::_insert_tax_rate( $tax_rate ); - $this->assertEquals( WC_Tax::get_rate_percent( $tax_rate_id ), '20%' ); + $this->assertEquals(\WC_Tax::get_rate_percent( $tax_rate_id ), '20%' ); - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); } /** @@ -382,11 +387,11 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { 'tax_rate_class' => '' ); - $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); + $tax_rate_id = \WC_Tax::_insert_tax_rate( $tax_rate ); - $this->assertEquals( WC_Tax::get_rate_code( $tax_rate_id ), 'GB-VAT-1' ); + $this->assertEquals(\WC_Tax::get_rate_code( $tax_rate_id ), 'GB-VAT-1' ); - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); } /** @@ -407,18 +412,18 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { 'tax_rate_class' => '' ); - $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); + $tax_rate_id = \WC_Tax::_insert_tax_rate( $tax_rate ); - $this->assertTrue( WC_Tax::is_compound( $tax_rate_id ) ); + $this->assertTrue(\WC_Tax::is_compound( $tax_rate_id ) ); - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); } /** * Test the rounding method */ public function test_round() { - $this->assertEquals( WC_Tax::round( '2.1234567' ), '2.1235' ); + $this->assertEquals(\WC_Tax::round( '2.1234567' ), '2.1235' ); } /** @@ -430,14 +435,14 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { '2' => '2', ); - $this->assertEquals( WC_Tax::get_tax_total( $to_total ), '3.665' ); + $this->assertEquals(\WC_Tax::get_tax_total( $to_total ), '3.665' ); } /** * Test getting the tax classes */ public function test_get_tax_classes() { - $tax_classes = WC_Tax::get_tax_classes(); + $tax_classes = \WC_Tax::get_tax_classes(); $this->assertEquals( $tax_classes, array( 'Reduced Rate', 'Zero Rate' ) ); } @@ -462,7 +467,7 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { ); // Run function - $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); + $tax_rate_id = \WC_Tax::_insert_tax_rate( $tax_rate ); $this->assertGreaterThan( 0, $tax_rate_id ); @@ -478,7 +483,7 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { $this->assertEquals( $new_row->tax_rate_order, '1' ); $this->assertEquals( $new_row->tax_rate_class, '' ); - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); } /** @@ -501,7 +506,7 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { ); // Run function - $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); + $tax_rate_id = \WC_Tax::_insert_tax_rate( $tax_rate ); // Update a rate $tax_rate = array( @@ -509,11 +514,11 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { ); // Run function - WC_Tax::_update_tax_rate( $tax_rate_id, $tax_rate ); + \WC_Tax::_update_tax_rate( $tax_rate_id, $tax_rate ); $this->assertNotFalse( $wpdb->last_result ); - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); } /** @@ -536,14 +541,14 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { ); // Run function - $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); + $tax_rate_id = \WC_Tax::_insert_tax_rate( $tax_rate ); // Run function - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); $this->assertNotFalse( $wpdb->last_result ); - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); } /** @@ -566,15 +571,15 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { ); // Run function - $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); + $tax_rate_id = \WC_Tax::_insert_tax_rate( $tax_rate ); - WC_Tax::_update_tax_rate_postcodes( $tax_rate_id, $to_save ); + \WC_Tax::_update_tax_rate_postcodes( $tax_rate_id, $to_save ); $results = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}woocommerce_tax_rate_locations WHERE tax_rate_id = %d ORDER BY location_code ASC", $tax_rate_id ) ); $this->assertEquals( array( '12345', '90210', '90211', '90212', '90213', '90214', '90215' ), $results ); - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); } /** @@ -597,14 +602,14 @@ class WC_Tests_Tax extends WC_Unit_Test_Case { ); // Run function - $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); + $tax_rate_id = \WC_Tax::_insert_tax_rate( $tax_rate ); - WC_Tax::_update_tax_rate_cities( $tax_rate_id, $to_save ); + \WC_Tax::_update_tax_rate_cities( $tax_rate_id, $to_save ); $results = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}woocommerce_tax_rate_locations WHERE tax_rate_id = %d ORDER BY location_code ASC", $tax_rate_id ) ); $this->assertEquals( array( 'SOMEWHERE', 'SOMEWHERE_ELSE' ), $results ); - WC_Tax::_delete_tax_rate( $tax_rate_id ); + \WC_Tax::_delete_tax_rate( $tax_rate_id ); } } diff --git a/tests/unit-tests/conditional-functions.php b/tests/unit-tests/util/conditional-functions.php similarity index 89% rename from tests/unit-tests/conditional-functions.php rename to tests/unit-tests/util/conditional-functions.php index e761f2204bb..332add0ee60 100644 --- a/tests/unit-tests/conditional-functions.php +++ b/tests/unit-tests/util/conditional-functions.php @@ -1,10 +1,12 @@ version - 1 ); update_option( 'woocommerce_db_version', WC()->version ); - WC_Install::check_version(); + \WC_Install::check_version(); $this->assertTrue( did_action( 'woocommerce_updated' ) === 1 ); update_option( 'woocommerce_version', WC()->version ); update_option( 'woocommerce_db_version', WC()->version ); - WC_Install::check_version(); + \WC_Install::check_version(); $this->assertTrue( did_action( 'woocommerce_updated' ) === 1 ); } @@ -27,9 +35,9 @@ class WC_Tests_Install extends WC_Unit_Test_Case { if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { define( 'WP_UNINSTALL_PLUGIN', true ); } - include( dirname( dirname( dirname( __FILE__ ) ) ) . '/uninstall.php' ); + include( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/uninstall.php' ); - WC_Install::install(); + \WC_Install::install(); $this->assertTrue( get_option( 'woocommerce_version' ) === WC()->version ); } @@ -44,7 +52,7 @@ class WC_Tests_Install extends WC_Unit_Test_Case { delete_option( 'woocommerce_checkout_page_id' ); delete_option( 'woocommerce_myaccount_page_id' ); - WC_Install::create_pages(); + \WC_Install::create_pages(); $this->assertGreaterThan( 0, get_option( 'woocommerce_shop_page_id' ) ); $this->assertGreaterThan( 0, get_option( 'woocommerce_cart_page_id' ) ); @@ -63,7 +71,7 @@ class WC_Tests_Install extends WC_Unit_Test_Case { delete_option( 'woocommerce_checkout_page_id' ); delete_option( 'woocommerce_myaccount_page_id' ); - WC_Install::create_pages(); + \WC_Install::create_pages(); $this->assertGreaterThan( 0, get_option( 'woocommerce_shop_page_id' ) ); $this->assertGreaterThan( 0, get_option( 'woocommerce_cart_page_id' ) ); @@ -79,9 +87,9 @@ class WC_Tests_Install extends WC_Unit_Test_Case { if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { define( 'WP_UNINSTALL_PLUGIN', true ); } - include( dirname( dirname( dirname( __FILE__ ) ) ) . '/uninstall.php' ); + include( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/uninstall.php' ); - WC_Install::create_roles(); + \WC_Install::create_roles(); $this->assertNotNull( get_role( 'customer' ) ); $this->assertNotNull( get_role( 'shop_manager' ) ); @@ -91,7 +99,7 @@ class WC_Tests_Install extends WC_Unit_Test_Case { * Test - remove roles */ public function test_remove_roles() { - WC_Install::remove_roles(); + \WC_Install::remove_roles(); $this->assertNull( get_role( 'customer' ) ); $this->assertNull( get_role( 'shop_manager' ) ); @@ -102,7 +110,7 @@ class WC_Tests_Install extends WC_Unit_Test_Case { */ public function test_in_plugin_update_message() { ob_start(); - WC_install::in_plugin_update_message( array( 'Version' => '2.0.0' ) ); + \WC_install::in_plugin_update_message( array( 'Version' => '2.0.0' ) ); $result = ob_get_clean(); $this->assertTrue( is_string( $result ) ); } diff --git a/tests/unit-tests/woocommerce.php b/tests/unit-tests/util/main-class.php similarity index 79% rename from tests/unit-tests/woocommerce.php rename to tests/unit-tests/util/main-class.php index a1e54a9bb39..d15b46018c8 100644 --- a/tests/unit-tests/woocommerce.php +++ b/tests/unit-tests/util/main-class.php @@ -1,10 +1,12 @@ assertEquals( str_replace( 'tests/unit-tests/', '', plugin_dir_path( __FILE__ ) ) . 'woocommerce.php', WC_PLUGIN_FILE ); + $this->assertEquals( str_replace( 'tests/unit-tests/util/', '', plugin_dir_path( __FILE__ ) ) . 'woocommerce.php', WC_PLUGIN_FILE ); $this->assertEquals( $this->wc->version, WC_VERSION ); $this->assertEquals( WC_VERSION, WOOCOMMERCE_VERSION ); $this->assertEquals( 4, WC_ROUNDING_PRECISION ); - $this->assertContains( WC_TAX_ROUNDING_MODE, array ( 2, 1 ) ); + $this->assertContains( WC_TAX_ROUNDING_MODE, array( 2, 1 ) ); $this->assertEquals( '|', WC_DELIMITER ); $this->assertNotEquals( WC_LOG_DIR, '' ); } diff --git a/tests/unit-tests/notice-functions.php b/tests/unit-tests/util/notice-functions.php similarity index 95% rename from tests/unit-tests/notice-functions.php rename to tests/unit-tests/util/notice-functions.php index 3f9199fda00..2ba0e2f334c 100644 --- a/tests/unit-tests/notice-functions.php +++ b/tests/unit-tests/util/notice-functions.php @@ -1,10 +1,13 @@