Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CsvImportHandlerTest.php
Go to the documentation of this file.
1 <?php
7 
8 class CsvImportHandlerTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $_importHandler;
14 
15  protected function setUp()
16  {
18  $this->_importHandler = $objectManager->create(\Magento\TaxImportExport\Model\Rate\CsvImportHandler::class);
19  }
20 
21  protected function tearDown()
22  {
23  $this->_importHandler = null;
24  }
25 
30  {
31  $importFileName = __DIR__ . '/_files/correct_rates_import_file.csv';
32  $this->_importHandler->importFromCsvFile(['tmp_name' => $importFileName]);
33 
35  // assert that both tax rates, specified in import file, have been imported correctly
36  $importedRuleCA = $objectManager->create(
37  \Magento\Tax\Model\Calculation\Rate::class
38  )->loadByCode(
39  'US-CA-*-Rate Import Test'
40  );
41  $this->assertNotEmpty($importedRuleCA->getId());
42  $this->assertEquals(8.25, (double)$importedRuleCA->getRate());
43  $this->assertEquals('US', $importedRuleCA->getTaxCountryId());
44  $this->assertEquals('*', $importedRuleCA->getTaxPostcode());
45 
46  $importedRuleFL = $objectManager->create(
47  \Magento\Tax\Model\Calculation\Rate::class
48  )->loadByCode(
49  'US-FL-*-Rate Import Test'
50  );
51  $this->assertNotEmpty($importedRuleFL->getId());
52  $this->assertEquals(15, (double)$importedRuleFL->getRate());
53  $this->assertEquals('US', $importedRuleFL->getTaxCountryId());
54  $this->assertNull($importedRuleFL->getTaxPostcode());
55  }
56 
63  {
64  $importFileName = __DIR__ . '/_files/rates_import_file_incorrect_country.csv';
65  $this->_importHandler->importFromCsvFile(['tmp_name' => $importFileName]);
66  }
67 }
$objectManager
Definition: bootstrap.php:17
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60