2015-03-06 15:32:40 +00:00
|
|
|
<?php
|
|
|
|
namespace WooCommerce\Tests\Customer;
|
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Class Customer.
|
2015-03-06 15:32:40 +00:00
|
|
|
* @package WooCommerce\Tests\Customer
|
|
|
|
*/
|
|
|
|
class Customer extends \WC_Unit_Test_Case {
|
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test the get_taxable_address method.
|
2015-03-06 15:32:40 +00:00
|
|
|
*/
|
|
|
|
public function test_get_taxable_address() {
|
|
|
|
|
2015-07-07 11:51:05 +00:00
|
|
|
$customer = \WC_Helper_Customer::create_mock_customer();
|
2015-03-06 15:32:40 +00:00
|
|
|
$base_store_address = \WC_Helper_Customer::get_expected_store_location();
|
2015-07-07 11:36:06 +00:00
|
|
|
$customer_address = $customer->get_taxable_address(); // Default is geolocation!
|
2015-04-14 14:47:04 +00:00
|
|
|
|
2015-03-06 15:32:40 +00:00
|
|
|
// Get the original settings for the session and the WooCommerce options
|
|
|
|
$original_chosen_shipping_methods = \WC_Helper_Customer::get_chosen_shipping_methods();
|
2015-04-14 14:47:04 +00:00
|
|
|
$original_tax_based_on = \WC_Helper_Customer::get_tax_based_on();
|
|
|
|
$original_customer_details = \WC_Helper_Customer::get_customer_details();
|
2015-03-06 15:32:40 +00:00
|
|
|
|
|
|
|
// Create dummy product, and add the product to the cart.
|
2015-04-14 14:47:04 +00:00
|
|
|
|
2015-03-06 15:32:40 +00:00
|
|
|
$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' ) );
|
2015-04-14 14:47:04 +00:00
|
|
|
\WC_Helper_Customer::set_tax_based_on( 'billing' );
|
2015-03-06 15:32:40 +00:00
|
|
|
$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' ) );
|
2015-04-14 14:47:04 +00:00
|
|
|
\WC_Helper_Customer::set_tax_based_on( 'base' );
|
2015-03-06 15:32:40 +00:00
|
|
|
$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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test the is_customer_outside_base method.
|
2015-03-06 15:32:40 +00:00
|
|
|
*/
|
|
|
|
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();
|
2015-04-14 14:47:04 +00:00
|
|
|
$original_tax_based_on = \WC_Helper_Customer::get_tax_based_on();
|
|
|
|
$original_customer_details = \WC_Helper_Customer::get_customer_details();
|
2015-03-06 15:32:40 +00:00
|
|
|
|
|
|
|
$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' ) );
|
2015-04-14 14:47:04 +00:00
|
|
|
\WC_Helper_Customer::set_tax_based_on( 'billing' );
|
2015-03-06 15:32:40 +00:00
|
|
|
$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' ) );
|
2015-04-14 14:47:04 +00:00
|
|
|
\WC_Helper_Customer::set_tax_based_on( 'base' );
|
2015-03-06 15:32:40 +00:00
|
|
|
$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 );
|
2015-04-14 14:47:04 +00:00
|
|
|
|
2015-03-06 15:32:40 +00:00
|
|
|
// Clean up the cart
|
|
|
|
WC()->cart->empty_cart();
|
|
|
|
|
|
|
|
// Clean up product
|
|
|
|
\WC_Helper_Product::delete_product( $product->id );
|
|
|
|
}
|
2015-04-14 14:47:04 +00:00
|
|
|
}
|