Merge pull request #20270 from woocommerce/add/tax-importer-unit-test

Add unit tests for importing taxes
This commit is contained in:
Rodrigo Primo 2018-05-29 13:19:16 +01:00 committed by GitHub
commit befbb29106
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 0 deletions

View File

@ -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,
1 Country Code State Code ZIP/Postcode City Rate % Tax Name Priority Compound Shipping Tax Class
2 GB * * * 20.0000 VAT 1 1 1
3 GB * * * 5.0000 VAT 1 1 1 reduced-rate
4 GB * * * 0.0000 VAT 1 1 1 zero-rate
5 US * * * 10.0000 US 1 1 1
6 US AL 12345; 123456 * 2.0000 US AL 2 1 1

View File

@ -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 );
}
}