Namespace the Unit Tests

This commit is contained in:
Barry Kooij 2015-03-06 16:32:40 +01:00
parent 2fb7f20633
commit d6b970a61d
17 changed files with 365 additions and 303 deletions

View File

@ -1,11 +1,13 @@
<?php
namespace WooCommerce\Tests\API;
/**
* Test the WC API /webhooks endpoint
*
* Class Webhooks
* @package WooCommerce\Tests\API
* @since 2.2
*/
class WC_Tests_Webhooks extends WC_API_Unit_Test_Case {
class Webhooks extends \WC_API_Unit_Test_Case {
/** @var \WC_API_Webhooks instance */
protected $endpoint;
@ -444,7 +446,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'] ) );
}
/**
@ -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'] ) );
}
/**

View File

@ -1,6 +1,12 @@
<?php
class WC_Tests_Cart extends WC_Unit_Test_Case {
namespace WooCommerce\Tests\Cart;
/**
* Class Cart
* @package WooCommerce\Tests\Cart
*/
class Cart extends \WC_Unit_Test_Case {
/**
* Helper method to get the checkout URL
@ -107,7 +113,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
public function test_add_to_cart_simple() {
// Create dummy product
$product = WC_Helper_Product::create_simple_product();
$product = \WC_Helper_Product::create_simple_product();
// Add the product to the cart. Methods returns boolean on failure, string on success.
$this->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 );
}

View File

@ -1,10 +1,12 @@
<?php
namespace WooCommerce\Tests\Cart;
/**
* Test WC cart functions
*
* @since 2.3.0
* Class Functions
* @package WooCommerce\Tests\Cart
*/
class WC_Tests_Cart_Functions extends WC_Unit_Test_Case {
class Functions extends \WC_Unit_Test_Case {
/**
* Test wc_empty_cart()
@ -13,7 +15,7 @@ class WC_Tests_Cart_Functions extends WC_Unit_Test_Case {
*/
public function test_wc_empty_cart() {
// Create dummy product
$product = WC_Helper_Product::create_simple_product();
$product = \WC_Helper_Product::create_simple_product();
// Add the product to the cart
WC()->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 );
}
}

View File

@ -1,6 +1,12 @@
<?php
class WC_Tests_Coupon extends WC_Unit_Test_Case {
namespace WooCommerce\Tests\Coupon;
/**
* Class Coupon
* @package WooCommerce\Tests\Coupon
*/
class Coupon extends \WC_Unit_Test_Case {
/**
* Test add_discount method
@ -10,7 +16,7 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
public function test_add_discount() {
// Create coupon
$coupon = WC_Helper_Coupon::create_coupon();
$coupon = \WC_Helper_Coupon::create_coupon();
// Add coupon, test return statement
$this->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 );
}
}

View File

@ -1,10 +1,13 @@
<?php
namespace WooCommerce\Tests\Coupon;
/**
* Test WC coupon functions
*
* @since 2.2
*/
class WC_Tests_Coupon_Functions extends WC_Unit_Test_Case {
* Class Functions
* @package WooCommerce\Tests\Coupon
* @since 2.2
*/
class Functions extends \WC_Unit_Test_Case {
/**
* Test wc_get_coupon_types()

View File

@ -1,114 +0,0 @@
<?php
class WC_Tests_Customer extends WC_Unit_Test_Case {
/**
* Test the get_taxable_address method
*/
public function test_get_taxable_address() {
$base_store_address = WC_Helper_Customer::get_expected_store_location();
$customer_address = WC_Helper_Customer::get_expected_customer_location();
// 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->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 );
}
}

View File

@ -0,0 +1,121 @@
<?php
namespace WooCommerce\Tests\Customer;
/**
* Class Customer
* @package WooCommerce\Tests\Customer
*/
class Customer extends \WC_Unit_Test_Case {
/**
* Test the get_taxable_address method
*/
public function test_get_taxable_address() {
$base_store_address = \WC_Helper_Customer::get_expected_store_location();
$customer_address = \WC_Helper_Customer::get_expected_customer_location();
// 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->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 );
}
}

View File

@ -1,10 +1,15 @@
<?php
namespace WooCommerce\Tests\Formatting;
/**
* Test WC formatting functions
*
* Class Functions
* @package WooCommerce\Tests\Formatting
* @since 2.2
*
* @todo Split formatting class into smaller classes
*/
class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
class Functions extends \WC_Unit_Test_Case {
/**
* Test wc_sanitize_taxonomy_name()

View File

@ -1,10 +1,13 @@
<?php
namespace WooCommerce\Tests\Order;
/**
* Test WC order functions
*
* @since 2.3.0
* Class Functions
* @package WooCommerce\Tests\Order
* @since 2.3
*/
class WC_Tests_Order_Functions extends WC_Unit_Test_Case {
class Functions extends \WC_Unit_Test_Case {
/**
* Test wc_get_order_statuses()

View File

@ -1,10 +1,13 @@
<?php
namespace WooCommerce\Tests\Product;
/**
* Test WC product functions
*
* Class Functions
* @package WooCommerce\Tests\Product
* @since 2.3
*/
class WC_Tests_Product_Functions extends WC_Unit_Test_Case {
class Functions extends \WC_Unit_Test_Case {
/**
* @var object
* @access private
@ -22,7 +25,7 @@ class WC_Tests_Product_Functions extends WC_Unit_Test_Case {
$this->_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 );
}
/**

View File

@ -1,10 +1,13 @@
<?php
namespace WooCommerce\Tests\Product;
/**
* Test WC product simple class
*
* Class Product_Simple
* @package WooCommerce\Tests\Product
* @since 2.3
*/
class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
class Product_Simple extends \WC_Unit_Test_Case {
/**
* @var object
* @access private
@ -18,7 +21,7 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
* @access private
*/
private function _get_product() {
$this->_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;
}

View File

@ -1,6 +1,11 @@
<?php
namespace WooCommerce\Tests\Tax;
class WC_Tests_Tax extends WC_Unit_Test_Case {
/**
* Class Tax
* @package WooCommerce\Tests\Tax
*/
class Tax extends \WC_Unit_Test_Case {
/**
* Get rates
@ -11,7 +16,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' => '',
@ -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 );
}
}

View File

@ -1,10 +1,12 @@
<?php
namespace WooCommerce\Tests\Util;
/**
* Test WC conditional functions
*
* Class Conditional_Functions
* @package WooCommerce\Tests\Util
* @since 2.3.0
*/
class WC_Tests_Conditional_Functions extends WC_Unit_Test_Case {
class Conditional_Functions extends \WC_Unit_Test_Case {
/**
* Test is_store_notice_showing()

View File

@ -1,11 +1,13 @@
<?php
namespace WooCommerce\Tests\Util;
/**
* Test WooCommerce core functions
*
* Class Core_Functions
* @package WooCommerce\Tests\Util
* @since 2.2
*/
class WC_Tests_Core_Functions extends WC_Unit_Test_Case {
class Core_Functions extends \WC_Unit_Test_Case {
/**
* Test get_woocommerce_currency()

View File

@ -1,6 +1,14 @@
<?php
class WC_Tests_Install extends WC_Unit_Test_Case {
namespace WooCommerce\Tests\Util;
/**
* Class WC_Tests_Install
* @package WooCommerce\Tests\Util
*
* @todo determine if this should be in Util or separate namespace
*/
class WC_Tests_Install extends \WC_Unit_Test_Case {
/**
* Test check version
@ -8,13 +16,13 @@ class WC_Tests_Install extends WC_Unit_Test_Case {
public function test_check_version() {
update_option( 'woocommerce_version', WC()->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 ) );
}

View File

@ -1,10 +1,12 @@
<?php
namespace WooCommerce\Tests\Util;
/**
* Test WooCommerce class
*
* @since 2.2
* Class Main_Class
* @package WooCommerce\Tests\Util
*/
class WC_Tests_WooCommerce extends WC_Unit_Test_Case {
class Main_Class extends \WC_Unit_Test_Case {
/** @var \WooCommerce instance */
protected $wc;
@ -42,12 +44,12 @@ class WC_Tests_WooCommerce extends WC_Unit_Test_Case {
*/
public function test_constants() {
$this->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, '' );
}

View File

@ -1,10 +1,13 @@
<?php
namespace WooCommerce\Tests\Util;
/**
* Test WC notice functions
*
* @since 2.2
*/
class WC_Tests_Notice_Functions extends WC_Unit_Test_Case {
* Class Notice_Functions
* @package WooCommerce\Tests\Util
* @since 2.2
*/
class Notice_Functions extends \WC_Unit_Test_Case {
/**
* Clear out notices after each test