Merge pull request #20270 from woocommerce/add/tax-importer-unit-test
Add unit tests for importing taxes
This commit is contained in:
commit
befbb29106
|
@ -0,0 +1,6 @@
|
||||||
|
Country Code,State Code,ZIP/Postcode,City,Rate %,Tax Name,Priority,Compound,Shipping,Tax Class
|
||||||
|
GB,*,*,*,20.0000,VAT,1,1,1,
|
||||||
|
GB,*,*,*,5.0000,VAT,1,1,1,reduced-rate
|
||||||
|
GB,*,*,*,0.0000,VAT,1,1,1,zero-rate
|
||||||
|
US,*,*,*,10.0000,US,1,1,1,
|
||||||
|
US,AL,12345; 123456,*,2.0000,US AL,2,1,1,
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Meta
|
||||||
|
* @package WooCommerce\Tests\Importer
|
||||||
|
*/
|
||||||
|
class WC_Tests_Tax_CSV_Importer extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test CSV file path.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $csv_file = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load up the importer classes since they aren't loaded by default.
|
||||||
|
*/
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->csv_file = dirname( __FILE__ ) . '/sample_tax_rates.csv';
|
||||||
|
|
||||||
|
$bootstrap = WC_Unit_Tests_Bootstrap::instance();
|
||||||
|
require_once ABSPATH . '/wp-admin/includes/class-wp-importer.php';
|
||||||
|
require_once $bootstrap->plugin_dir . '/includes/admin/importers/class-wc-tax-rate-importer.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test import.
|
||||||
|
* @since 3.1.0
|
||||||
|
*/
|
||||||
|
public function test_import() {
|
||||||
|
global $wpdb;
|
||||||
|
$importer = new WC_Tax_Rate_Importer();
|
||||||
|
ob_start();
|
||||||
|
$importer->import( $this->csv_file );
|
||||||
|
ob_end_clean();
|
||||||
|
$rate_count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}woocommerce_tax_rates" );
|
||||||
|
$this->assertEquals( 5, $rate_count );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue