diff --git a/tests/unit-tests/importer/sample_tax_rates.csv b/tests/unit-tests/importer/sample_tax_rates.csv new file mode 100644 index 00000000000..02038b54ec9 --- /dev/null +++ b/tests/unit-tests/importer/sample_tax_rates.csv @@ -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, \ No newline at end of file diff --git a/tests/unit-tests/importer/tax.php b/tests/unit-tests/importer/tax.php new file mode 100644 index 00000000000..f563aad4839 --- /dev/null +++ b/tests/unit-tests/importer/tax.php @@ -0,0 +1,42 @@ +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 ); + } +}