2014-12-10 23:02:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Class WC_Helper_Customer.
|
2014-12-10 23:02:43 +00:00
|
|
|
*
|
2015-11-03 13:31:20 +00:00
|
|
|
* This helper class should ONLY be used for unit tests!.
|
2014-12-10 23:02:43 +00:00
|
|
|
*/
|
|
|
|
class WC_Helper_Customer {
|
|
|
|
|
|
|
|
/**
|
2014-12-11 05:54:06 +00:00
|
|
|
* Create a mock customer for testing purposes.
|
|
|
|
*
|
|
|
|
* @return WC_Customer
|
|
|
|
*/
|
|
|
|
public static function create_mock_customer() {
|
|
|
|
$customer_data = array(
|
2019-05-01 22:05:00 +00:00
|
|
|
'id' => 0,
|
|
|
|
'date_modified' => null,
|
|
|
|
'country' => 'US',
|
2021-04-12 21:13:27 +00:00
|
|
|
'state' => 'CA',
|
|
|
|
'postcode' => '94110',
|
|
|
|
'city' => 'San Francisco',
|
2019-05-01 22:05:00 +00:00
|
|
|
'address' => '123 South Street',
|
|
|
|
'address_2' => 'Apt 1',
|
|
|
|
'shipping_country' => 'US',
|
2021-04-12 21:13:27 +00:00
|
|
|
'shipping_state' => 'CA',
|
|
|
|
'shipping_postcode' => '94110',
|
|
|
|
'shipping_city' => 'San Francisco',
|
2019-05-01 22:05:00 +00:00
|
|
|
'shipping_address' => '123 South Street',
|
|
|
|
'shipping_address_2' => 'Apt 1',
|
|
|
|
'is_vat_exempt' => false,
|
|
|
|
'calculated_shipping' => false,
|
2014-12-11 05:54:06 +00:00
|
|
|
);
|
2015-07-07 11:36:06 +00:00
|
|
|
|
2019-05-01 22:05:00 +00:00
|
|
|
self::set_customer_details( $customer_data );
|
2014-12-11 05:54:06 +00:00
|
|
|
|
2016-11-14 18:18:08 +00:00
|
|
|
$customer = new WC_Customer( 0, true );
|
2017-12-21 19:00:55 +00:00
|
|
|
|
2016-03-15 18:37:42 +00:00
|
|
|
return $customer;
|
2016-03-14 21:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a customer in the tests DB.
|
|
|
|
*/
|
2016-08-09 20:51:38 +00:00
|
|
|
public static function create_customer( $username = 'testcustomer', $password = 'hunter2', $email = 'test@woo.local' ) {
|
2016-03-14 21:51:32 +00:00
|
|
|
$customer = new WC_Customer();
|
2016-03-17 19:39:29 +00:00
|
|
|
$customer->set_billing_country( 'US' );
|
|
|
|
$customer->set_first_name( 'Justin' );
|
2021-04-12 21:13:27 +00:00
|
|
|
$customer->set_billing_state( 'CA' );
|
|
|
|
$customer->set_billing_postcode( '94110' );
|
|
|
|
$customer->set_billing_city( 'San Francisco' );
|
2016-03-17 19:39:29 +00:00
|
|
|
$customer->set_billing_address( '123 South Street' );
|
|
|
|
$customer->set_billing_address_2( 'Apt 1' );
|
2016-03-14 21:51:32 +00:00
|
|
|
$customer->set_shipping_country( 'US' );
|
2021-04-12 21:13:27 +00:00
|
|
|
$customer->set_shipping_state( 'CA' );
|
|
|
|
$customer->set_shipping_postcode( '94110' );
|
|
|
|
$customer->set_shipping_city( 'San Francisco' );
|
2016-03-14 21:51:32 +00:00
|
|
|
$customer->set_shipping_address( '123 South Street' );
|
|
|
|
$customer->set_shipping_address_2( 'Apt 1' );
|
2016-08-09 20:51:38 +00:00
|
|
|
$customer->set_username( $username );
|
|
|
|
$customer->set_password( $password );
|
|
|
|
$customer->set_email( $email );
|
2016-08-31 14:43:34 +00:00
|
|
|
$customer->save();
|
2016-03-14 21:51:32 +00:00
|
|
|
return $customer;
|
2014-12-11 05:54:06 +00:00
|
|
|
}
|
|
|
|
|
2014-12-10 23:02:43 +00:00
|
|
|
/**
|
2014-12-11 05:54:06 +00:00
|
|
|
* Get the expected output for the store's base location settings.
|
2014-12-10 23:02:43 +00:00
|
|
|
*
|
2014-12-11 05:54:06 +00:00
|
|
|
* @return array
|
2014-12-10 23:02:43 +00:00
|
|
|
*/
|
2014-12-11 05:54:06 +00:00
|
|
|
public static function get_expected_store_location() {
|
2021-04-12 21:13:27 +00:00
|
|
|
return array( 'US', 'CA', '', '' );
|
2014-12-10 23:02:43 +00:00
|
|
|
}
|
|
|
|
|
2014-12-11 05:54:06 +00:00
|
|
|
/**
|
|
|
|
* Get the customer's shipping and billing info from the session.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function get_customer_details() {
|
|
|
|
return WC()->session->get( 'customer' );
|
|
|
|
}
|
2014-12-10 23:02:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the user's chosen shipping method.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function get_chosen_shipping_methods() {
|
|
|
|
return WC()->session->get( 'chosen_shipping_methods' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the "Tax Based On" WooCommerce option.
|
|
|
|
*
|
|
|
|
* @return string base or billing
|
|
|
|
*/
|
|
|
|
public static function get_tax_based_on() {
|
|
|
|
return get_option( 'woocommerce_tax_based_on' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-12-11 05:54:06 +00:00
|
|
|
* Set the the current customer's billing details in the session.
|
2014-12-10 23:02:43 +00:00
|
|
|
*
|
|
|
|
* @param string $default_shipping_method Shipping Method slug
|
|
|
|
*/
|
|
|
|
public static function set_customer_details( $customer_details ) {
|
2017-12-21 19:00:55 +00:00
|
|
|
WC()->session->set( 'customer', array_map( 'strval', $customer_details ) );
|
2014-12-10 23:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the user's chosen shipping method.
|
|
|
|
*
|
|
|
|
* @param string $chosen_shipping_method Shipping Method slug
|
|
|
|
*/
|
|
|
|
public static function set_chosen_shipping_methods( $chosen_shipping_methods ) {
|
|
|
|
WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the "Tax Based On" WooCommerce option.
|
|
|
|
*
|
|
|
|
* @param string $default_shipping_method Shipping Method slug
|
|
|
|
*/
|
|
|
|
public static function set_tax_based_on( $default_shipping_method ) {
|
|
|
|
update_option( 'woocommerce_tax_based_on', $default_shipping_method );
|
|
|
|
}
|
|
|
|
}
|