2014-11-24 13:52:09 +00:00
< ? php
2015-03-06 15:32:40 +00:00
/**
2015-11-03 13:31:20 +00:00
* Class Tax .
2015-03-06 15:32:40 +00:00
* @ package WooCommerce\Tests\Tax
*/
2016-03-23 12:14:13 +00:00
class WC_Tests_Tax extends WC_Unit_Test_Case {
2014-11-24 13:52:09 +00:00
2014-11-24 14:57:08 +00:00
/**
2015-11-03 13:31:20 +00:00
* Get rates .
2014-11-24 13:52:09 +00:00
*/
2014-11-24 14:57:08 +00:00
public function test_get_rates () {
global $wpdb ;
2014-11-25 17:09:19 +00:00
$wpdb -> query ( " DELETE FROM { $wpdb -> prefix } woocommerce_tax_rates " );
$wpdb -> query ( " DELETE FROM { $wpdb -> prefix } woocommerce_tax_rate_locations " );
2014-11-24 14:57:08 +00:00
2016-03-23 12:14:13 +00:00
$customer_location = WC_Tax :: get_tax_location ();
2015-01-05 16:39:45 +00:00
$tax_rate = array (
'tax_rate_country' => $customer_location [ 0 ],
2014-12-04 13:44:55 +00:00
'tax_rate_state' => '' ,
'tax_rate' => '20.0000' ,
'tax_rate_name' => 'VAT' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '0' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2014-11-24 14:57:08 +00:00
);
2016-03-23 12:14:13 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
2014-11-24 14:57:08 +00:00
2016-03-23 12:14:13 +00:00
$tax_rates = WC_Tax :: get_rates ();
2014-11-24 14:57:08 +00:00
$this -> assertEquals ( $tax_rates , array ( $tax_rate_id => array ( 'rate' => '20.0000' , 'label' => 'VAT' , 'shipping' => 'yes' , 'compound' => 'no' ) ) );
2014-12-04 13:44:55 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 14:57:08 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Get rates .
2014-11-24 14:57:08 +00:00
*/
public function test_get_shipping_tax_rates () {
global $wpdb ;
2014-11-25 17:09:19 +00:00
$wpdb -> query ( " DELETE FROM { $wpdb -> prefix } woocommerce_tax_rates " );
$wpdb -> query ( " DELETE FROM { $wpdb -> prefix } woocommerce_tax_rate_locations " );
2014-11-24 14:57:08 +00:00
2016-03-23 12:14:13 +00:00
$customer_location = WC_Tax :: get_tax_location ();
2014-11-24 14:57:08 +00:00
$tax_rate = array (
2015-01-05 16:59:16 +00:00
'tax_rate_country' => $customer_location [ 0 ],
2014-12-04 13:44:55 +00:00
'tax_rate_state' => '' ,
'tax_rate' => '20.0000' ,
'tax_rate_name' => 'VAT' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '0' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2014-11-24 14:57:08 +00:00
);
2016-03-23 12:14:13 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
2014-11-24 14:57:08 +00:00
2016-03-23 12:14:13 +00:00
$tax_rates = WC_Tax :: get_shipping_tax_rates ();
2014-11-24 14:57:08 +00:00
2017-08-07 16:49:46 +00:00
$this -> assertEquals ( $tax_rates , array ( $tax_rate_id => array ( 'rate' => '20.0000' , 'label' => 'VAT' , 'shipping' => 'yes' , 'compound' => 'no' ) ), print_r ( $tax_rates , true ) );
2014-12-04 13:44:55 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 14:57:08 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Get rates .
2014-11-24 14:57:08 +00:00
*/
public function test_get_base_tax_rates () {
global $wpdb ;
2014-11-25 17:09:19 +00:00
$wpdb -> query ( " DELETE FROM { $wpdb -> prefix } woocommerce_tax_rates " );
$wpdb -> query ( " DELETE FROM { $wpdb -> prefix } woocommerce_tax_rate_locations " );
2014-11-24 14:57:08 +00:00
$tax_rate = array (
2014-12-04 13:44:55 +00:00
'tax_rate_country' => 'GB' ,
'tax_rate_state' => '' ,
'tax_rate' => '20.0000' ,
'tax_rate_name' => 'VAT' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '0' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2014-11-24 14:57:08 +00:00
);
2016-03-23 12:14:13 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
2014-11-24 14:57:08 +00:00
2016-03-23 12:14:13 +00:00
$tax_rates = WC_Tax :: get_base_tax_rates ();
2014-11-24 14:57:08 +00:00
$this -> assertEquals ( $tax_rates , array ( $tax_rate_id => array ( 'rate' => '20.0000' , 'label' => 'VAT' , 'shipping' => 'yes' , 'compound' => 'no' ) ) );
2014-12-04 13:44:55 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 14:57:08 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Find tax rates .
2014-11-24 14:57:08 +00:00
*/
public function test_find_rates () {
global $wpdb ;
2014-11-25 17:09:19 +00:00
$wpdb -> query ( " DELETE FROM { $wpdb -> prefix } woocommerce_tax_rates " );
$wpdb -> query ( " DELETE FROM { $wpdb -> prefix } woocommerce_tax_rate_locations " );
2014-11-24 14:57:08 +00:00
$tax_rate = array (
2014-12-04 13:44:55 +00:00
'tax_rate_country' => 'GB' ,
'tax_rate_state' => '' ,
'tax_rate' => '20.0000' ,
'tax_rate_name' => 'VAT' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '0' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2014-11-24 14:57:08 +00:00
);
2016-03-23 12:14:13 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
2014-11-24 14:57:08 +00:00
2016-03-23 12:14:13 +00:00
$tax_rates = WC_Tax :: find_rates ( array (
2014-11-24 14:57:08 +00:00
'country' => 'GB' ,
'state' => 'Cambs' ,
'postcode' => 'PE14 1XX' ,
'city' => 'Somewhere' ,
2016-08-27 01:46:45 +00:00
'tax_class' => '' ,
2014-11-24 14:57:08 +00:00
) );
$this -> assertEquals ( $tax_rates , array ( $tax_rate_id => array ( 'rate' => '20.0000' , 'label' => 'VAT' , 'shipping' => 'yes' , 'compound' => 'no' ) ) );
2014-12-04 13:44:55 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 14:57:08 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Find tax rates .
2014-11-24 14:57:08 +00:00
*/
public function test_find_shipping_rates () {
global $wpdb ;
2014-11-25 17:09:19 +00:00
$wpdb -> query ( " DELETE FROM { $wpdb -> prefix } woocommerce_tax_rates " );
$wpdb -> query ( " DELETE FROM { $wpdb -> prefix } woocommerce_tax_rate_locations " );
2014-11-24 14:57:08 +00:00
$tax_rate = array (
2014-12-04 13:44:55 +00:00
'tax_rate_country' => 'GB' ,
'tax_rate_state' => '' ,
'tax_rate' => '20.0000' ,
'tax_rate_name' => 'VAT' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '0' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2014-11-24 14:57:08 +00:00
);
2016-03-23 12:14:13 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
2014-11-24 14:57:08 +00:00
2016-03-23 12:14:13 +00:00
$tax_rates = WC_Tax :: find_shipping_rates ( array (
2014-11-24 14:57:08 +00:00
'country' => 'GB' ,
'state' => 'Cambs' ,
'postcode' => 'PE14 1XX' ,
'city' => 'Somewhere' ,
2016-08-27 01:46:45 +00:00
'tax_class' => '' ,
2014-11-24 14:57:08 +00:00
) );
$this -> assertEquals ( $tax_rates , array ( $tax_rate_id => array ( 'rate' => '20.0000' , 'label' => 'VAT' , 'shipping' => 'yes' , 'compound' => 'no' ) ) );
2014-12-04 13:44:55 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 14:57:08 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test tax amounts .
2014-11-24 14:57:08 +00:00
*/
public function test_calc_tax () {
global $wpdb ;
2014-11-25 17:09:19 +00:00
$wpdb -> query ( " DELETE FROM { $wpdb -> prefix } woocommerce_tax_rates " );
$wpdb -> query ( " DELETE FROM { $wpdb -> prefix } woocommerce_tax_rate_locations " );
2014-11-24 14:57:08 +00:00
$tax_rate = array (
2014-12-04 13:44:55 +00:00
'tax_rate_country' => 'GB' ,
'tax_rate_state' => '' ,
'tax_rate' => '20.0000' ,
'tax_rate_name' => 'VAT' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '0' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2014-11-24 14:57:08 +00:00
);
2016-03-23 12:14:13 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
2014-11-24 14:57:08 +00:00
2016-03-23 12:14:13 +00:00
$tax_rates = WC_Tax :: find_rates ( array (
2014-11-24 14:57:08 +00:00
'country' => 'GB' ,
'state' => 'Cambs' ,
'postcode' => 'PE14 1XX' ,
'city' => 'Somewhere' ,
2016-08-27 01:46:45 +00:00
'tax_class' => '' ,
2014-11-24 14:57:08 +00:00
) );
2016-03-23 12:14:13 +00:00
$calced_tax = WC_Tax :: calc_tax ( '9.99' , $tax_rates , true , false );
2014-11-24 14:57:08 +00:00
$this -> assertEquals ( $calced_tax , array ( $tax_rate_id => '1.665' ) );
2016-03-23 12:14:13 +00:00
$calced_tax = WC_Tax :: calc_tax ( '9.99' , $tax_rates , false , false );
2014-11-24 14:57:08 +00:00
$this -> assertEquals ( $calced_tax , array ( $tax_rate_id => '1.998' ) );
2014-12-04 13:44:55 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 14:57:08 +00:00
}
2015-02-23 11:03:06 +00:00
/**
2016-09-02 02:40:36 +00:00
* Test compound tax amounts
*/
2015-02-23 11:03:06 +00:00
public function test_calc_compound_tax () {
global $wpdb ;
$wpdb -> query ( " DELETE FROM { $wpdb -> prefix } woocommerce_tax_rates " );
$wpdb -> query ( " DELETE FROM { $wpdb -> prefix } woocommerce_tax_rate_locations " );
update_option ( 'woocommerce_default_country' , 'CA' );
update_option ( 'woocommerce_default_state' , 'QC' );
$tax_rate_1 = array (
'tax_rate_country' => 'CA' ,
'tax_rate_state' => '' ,
'tax_rate' => '5.0000' ,
'tax_rate_name' => 'GST' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '0' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2015-02-23 11:03:06 +00:00
);
$tax_rate_2 = array (
'tax_rate_country' => 'CA' ,
'tax_rate_state' => 'QC' ,
'tax_rate' => '8.5000' ,
'tax_rate_name' => 'PST' ,
'tax_rate_priority' => '2' ,
'tax_rate_compound' => '1' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '2' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2015-02-23 11:03:06 +00:00
);
2016-03-23 12:14:13 +00:00
$tax_rate_1_id = WC_Tax :: _insert_tax_rate ( $tax_rate_1 );
$tax_rate_2_id = WC_Tax :: _insert_tax_rate ( $tax_rate_2 );
2015-02-23 11:03:06 +00:00
2016-03-23 12:14:13 +00:00
$tax_rates = WC_Tax :: find_rates ( array (
2015-02-23 11:03:06 +00:00
'country' => 'CA' ,
'state' => 'QC' ,
'postcode' => '12345' ,
'city' => '' ,
2016-08-27 01:46:45 +00:00
'tax_class' => '' ,
2015-02-23 11:03:06 +00:00
) );
// prices exclusive of tax
2016-03-23 12:14:13 +00:00
$calced_tax = WC_Tax :: calc_tax ( '100' , $tax_rates , false , false );
2015-02-23 11:03:06 +00:00
$this -> assertEquals ( $calced_tax , array ( $tax_rate_1_id => '5.0000' , $tax_rate_2_id => '8.925' ) );
// prices inclusive of tax
2016-03-23 12:14:13 +00:00
$calced_tax = WC_Tax :: calc_tax ( '100' , $tax_rates , true , false );
2015-02-23 11:03:06 +00:00
/**
* 100 is inclusive of all taxes .
*
2015-11-03 13:31:20 +00:00
* Compound would be 100 - ( 100 / 1.085 ) = 7.8341 .
* Next tax would be calced on 100 - 7.8341 = 92.1659 .
* 92.1659 - ( 92.1659 / 1.05 ) = 4.38885 .
2015-02-23 11:03:06 +00:00
*/
2017-12-04 20:38:42 +00:00
$this -> assertEquals ( round ( $calced_tax [ $tax_rate_1_id ], 4 ), 4.3889 );
$this -> assertEquals ( round ( $calced_tax [ $tax_rate_2_id ], 4 ), 7.8341 );
2015-02-23 11:03:06 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_1_id );
WC_Tax :: _delete_tax_rate ( $tax_rate_2_id );
2015-02-23 11:03:06 +00:00
update_option ( 'woocommerce_default_country' , 'GB' );
update_option ( 'woocommerce_default_state' , '' );
}
2015-02-23 06:40:10 +00:00
2014-11-24 14:57:08 +00:00
/**
2015-11-03 13:31:20 +00:00
* Shipping tax amounts .
2014-11-24 14:57:08 +00:00
*/
public function test_calc_shipping_tax () {
global $wpdb ;
2014-11-25 17:09:19 +00:00
$wpdb -> query ( " DELETE FROM { $wpdb -> prefix } woocommerce_tax_rates " );
$wpdb -> query ( " DELETE FROM { $wpdb -> prefix } woocommerce_tax_rate_locations " );
2014-11-24 14:57:08 +00:00
$tax_rate = array (
2014-12-04 13:44:55 +00:00
'tax_rate_country' => 'GB' ,
'tax_rate_state' => '' ,
'tax_rate' => '20.0000' ,
'tax_rate_name' => 'VAT' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '0' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2014-11-24 14:57:08 +00:00
);
2016-03-23 12:14:13 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
2014-11-24 14:57:08 +00:00
2016-03-23 12:14:13 +00:00
$tax_rates = WC_Tax :: find_rates ( array (
2014-11-24 14:57:08 +00:00
'country' => 'GB' ,
'state' => 'Cambs' ,
'postcode' => 'PE14 1XX' ,
'city' => 'Somewhere' ,
2016-08-27 01:46:45 +00:00
'tax_class' => '' ,
2014-11-24 14:57:08 +00:00
) );
2016-03-23 12:14:13 +00:00
$calced_tax = WC_Tax :: calc_shipping_tax ( '10' , $tax_rates );
2014-11-24 14:57:08 +00:00
$this -> assertEquals ( $calced_tax , array ( $tax_rate_id => '2' ) );
2014-12-04 13:44:55 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 14:57:08 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test rate labels .
2014-11-24 14:57:08 +00:00
*/
public function test_get_rate_label () {
global $wpdb ;
$tax_rate = array (
2014-12-04 13:44:55 +00:00
'tax_rate_country' => 'GB' ,
'tax_rate_state' => '' ,
'tax_rate' => '20.0000' ,
'tax_rate_name' => 'VAT' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '1' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2014-11-24 14:57:08 +00:00
);
2016-03-23 12:14:13 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
2014-12-04 13:44:55 +00:00
2016-09-02 01:51:31 +00:00
$this -> assertEquals ( WC_Tax :: get_rate_label ( $tax_rate_id ), 'VAT' );
2014-11-24 14:57:08 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 14:57:08 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test rate percent .
2014-11-24 14:57:08 +00:00
*/
public function test_get_rate_percent () {
global $wpdb ;
$tax_rate = array (
2014-12-04 13:44:55 +00:00
'tax_rate_country' => 'GB' ,
'tax_rate_state' => '' ,
'tax_rate' => '20.0000' ,
'tax_rate_name' => 'VAT' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '1' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2014-11-24 14:57:08 +00:00
);
2016-03-23 12:14:13 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
2014-11-24 14:57:08 +00:00
2016-09-02 01:51:31 +00:00
$this -> assertEquals ( WC_Tax :: get_rate_percent ( $tax_rate_id ), '20%' );
2014-12-04 13:44:55 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 14:57:08 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test rate code .
2014-11-24 14:57:08 +00:00
*/
public function test_get_rate_code () {
global $wpdb ;
$tax_rate = array (
2014-12-04 13:44:55 +00:00
'tax_rate_country' => 'GB' ,
'tax_rate_state' => '' ,
'tax_rate' => '20.0000' ,
'tax_rate_name' => 'VAT' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '1' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2014-11-24 14:57:08 +00:00
);
2016-03-23 12:14:13 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
2014-11-24 14:57:08 +00:00
2016-09-02 01:51:31 +00:00
$this -> assertEquals ( WC_Tax :: get_rate_code ( $tax_rate_id ), 'GB-VAT-1' );
2014-12-04 13:44:55 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 14:57:08 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test is compound .
2014-11-24 14:57:08 +00:00
*/
public function test_is_compound () {
global $wpdb ;
$tax_rate = array (
2014-12-04 13:44:55 +00:00
'tax_rate_country' => 'GB' ,
'tax_rate_state' => '' ,
'tax_rate' => '20.0000' ,
'tax_rate_name' => 'VAT' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '1' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2014-11-24 14:57:08 +00:00
);
2016-03-23 12:14:13 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
2014-12-04 13:44:55 +00:00
2016-09-02 01:51:31 +00:00
$this -> assertTrue ( WC_Tax :: is_compound ( $tax_rate_id ) );
2014-11-24 14:57:08 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 14:57:08 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test the rounding method .
2014-11-24 14:57:08 +00:00
*/
public function test_round () {
2016-09-02 01:51:31 +00:00
$this -> assertEquals ( WC_Tax :: round ( '2.1234567' ), '2.1235' );
2014-11-24 14:57:08 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Get tax totals .
2014-11-24 14:57:08 +00:00
*/
public function test_get_tax_total () {
$to_total = array (
'1' => '1.665' ,
'2' => '2' ,
);
2016-09-02 01:51:31 +00:00
$this -> assertEquals ( WC_Tax :: get_tax_total ( $to_total ), '3.665' );
2014-11-24 14:57:08 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test getting the tax classes .
2014-11-24 14:57:08 +00:00
*/
public function test_get_tax_classes () {
2016-03-23 12:14:13 +00:00
$tax_classes = WC_Tax :: get_tax_classes ();
2016-10-12 10:16:30 +00:00
$this -> assertEquals ( $tax_classes , array ( 'Reduced rate' , 'Zero rate' ) );
2017-01-25 21:38:13 +00:00
$tax_classes = WC_Tax :: get_tax_class_slugs ();
$this -> assertEquals ( $tax_classes , array ( 'reduced-rate' , 'zero-rate' ) );
2014-11-24 14:57:08 +00:00
}
2014-11-24 13:52:09 +00:00
/**
2015-11-03 13:31:20 +00:00
* Test Inserting a tax rate .
2014-11-24 13:52:09 +00:00
*/
public function test__insert_tax_rate () {
global $wpdb ;
// Define a rate
$tax_rate = array (
2014-12-04 13:44:55 +00:00
'tax_rate_country' => 'gb' ,
'tax_rate_state' => '' ,
'tax_rate' => '20' ,
'tax_rate_name' => '' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '0' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2014-11-24 13:52:09 +00:00
);
// Run function
2016-03-23 12:14:13 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
2014-12-04 13:44:55 +00:00
$this -> assertGreaterThan ( 0 , $tax_rate_id );
2014-11-24 13:52:09 +00:00
2014-12-04 13:44:55 +00:00
$new_row = $wpdb -> get_row ( $wpdb -> prepare ( " SELECT * FROM { $wpdb -> prefix } woocommerce_tax_rates WHERE tax_rate_id = %d " , $tax_rate_id ) );
2014-11-24 13:52:09 +00:00
2014-12-04 13:44:55 +00:00
$this -> assertEquals ( $new_row -> tax_rate_country , 'GB' );
$this -> assertEquals ( $new_row -> tax_rate_state , '' );
$this -> assertEquals ( $new_row -> tax_rate , '20.0000' );
$this -> assertEquals ( $new_row -> tax_rate_name , 'Tax' );
$this -> assertEquals ( $new_row -> tax_rate_priority , '1' );
$this -> assertEquals ( $new_row -> tax_rate_compound , '0' );
$this -> assertEquals ( $new_row -> tax_rate_shipping , '1' );
$this -> assertEquals ( $new_row -> tax_rate_order , '1' );
$this -> assertEquals ( $new_row -> tax_rate_class , '' );
2014-11-24 13:52:09 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 13:52:09 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test updating a tax rate .
2014-11-24 13:52:09 +00:00
*/
public function test__update_tax_rate () {
global $wpdb ;
// Define a rate
$tax_rate = array (
2014-12-04 13:44:55 +00:00
'tax_rate_country' => 'GB' ,
'tax_rate_state' => '' ,
'tax_rate' => '20.0000' ,
'tax_rate_name' => 'VAT' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '0' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2014-11-24 13:52:09 +00:00
);
// Run function
2016-03-23 12:14:13 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
2014-11-24 13:52:09 +00:00
// Update a rate
$tax_rate = array (
2016-08-27 01:46:45 +00:00
'tax_rate_country' => 'US' ,
2014-11-24 13:52:09 +00:00
);
// Run function
2016-03-23 12:14:13 +00:00
WC_Tax :: _update_tax_rate ( $tax_rate_id , $tax_rate );
2014-11-24 13:52:09 +00:00
$this -> assertNotFalse ( $wpdb -> last_result );
2014-12-04 13:44:55 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 13:52:09 +00:00
}
2014-11-24 13:56:10 +00:00
/**
2015-11-03 13:31:20 +00:00
* Test deleting a tax rate .
2014-11-24 13:56:10 +00:00
*/
public function test__delete_tax_rate () {
global $wpdb ;
// Define a rate
$tax_rate = array (
2014-12-04 13:44:55 +00:00
'tax_rate_country' => 'GB' ,
'tax_rate_state' => '' ,
'tax_rate' => '20.0000' ,
'tax_rate_name' => 'VAT' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '0' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2014-11-24 13:56:10 +00:00
);
// Run function
2016-03-23 12:14:13 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
2014-11-24 13:56:10 +00:00
// Run function
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 13:56:10 +00:00
$this -> assertNotFalse ( $wpdb -> last_result );
2014-12-04 13:44:55 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 13:56:10 +00:00
}
2014-11-24 14:57:08 +00:00
/**
2015-11-03 13:31:20 +00:00
* Postcode saving .
2014-11-24 14:57:08 +00:00
*/
public function test__update_tax_rate_postcodes () {
global $wpdb ;
2016-05-23 16:30:37 +00:00
$to_save = '12345;90210...90215' ;
2014-11-24 14:57:08 +00:00
$tax_rate = array (
2014-12-04 13:44:55 +00:00
'tax_rate_country' => 'GB' ,
'tax_rate_state' => '' ,
'tax_rate' => '20.0000' ,
'tax_rate_name' => 'VAT' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '0' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2014-11-24 14:57:08 +00:00
);
// Run function
2016-03-23 12:14:13 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
2014-11-24 14:57:08 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _update_tax_rate_postcodes ( $tax_rate_id , $to_save );
2014-11-24 14:57:08 +00:00
$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 ) );
2016-05-23 16:30:37 +00:00
$this -> assertEquals ( array ( '12345' , '90210...90215' ), $results );
2014-12-04 13:44:55 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 14:57:08 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* City saving .
2014-11-24 14:57:08 +00:00
*/
public function test__update_tax_rate_cities () {
global $wpdb ;
2014-11-24 13:56:10 +00:00
2014-11-24 14:57:08 +00:00
$to_save = 'SOMEWHERE;SOMEWHERE_ELSE' ;
$tax_rate = array (
2014-12-04 13:44:55 +00:00
'tax_rate_country' => 'GB' ,
'tax_rate_state' => '' ,
'tax_rate' => '20.0000' ,
'tax_rate_name' => 'VAT' ,
'tax_rate_priority' => '1' ,
'tax_rate_compound' => '0' ,
'tax_rate_shipping' => '1' ,
'tax_rate_order' => '1' ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => '' ,
2014-11-24 14:57:08 +00:00
);
// Run function
2016-03-23 12:14:13 +00:00
$tax_rate_id = WC_Tax :: _insert_tax_rate ( $tax_rate );
2014-11-24 14:57:08 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _update_tax_rate_cities ( $tax_rate_id , $to_save );
2014-11-24 14:57:08 +00:00
$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 );
2014-12-04 13:44:55 +00:00
2016-03-23 12:14:13 +00:00
WC_Tax :: _delete_tax_rate ( $tax_rate_id );
2014-11-24 14:57:08 +00:00
}
2014-11-24 13:52:09 +00:00
}