init
This commit is contained in:
+76
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\TaxImportExport\Block\Adminhtml\Rate;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests for Tax Rate Import/Export form.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ImportExportTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var ImportExport
|
||||
*/
|
||||
protected $block = null;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(ImportExport::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->block = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCreateBlock(): void
|
||||
{
|
||||
$this->assertInstanceOf(ImportExport::class, $this->block);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testFormExists(): void
|
||||
{
|
||||
$html = $this->block->toHtml();
|
||||
$this->assertStringContainsString('<form id="import-form"', $html);
|
||||
$this->assertStringContainsString('<form id="export_form"', $html);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testExportFormButtonOnClick(): void
|
||||
{
|
||||
$html = $this->block->toHtml();
|
||||
$this->assertStringContainsString('<form id="export_form"', $html);
|
||||
$this->assertStringContainsString('export_form.submit();', $html);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/***
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TaxImportExport\Controller\Adminhtml\Rate;
|
||||
|
||||
class ExportPostTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Sales::transactions_fetch';
|
||||
$this->uri = 'backend/sales/transactions/fetch';
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/***
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TaxImportExport\Controller\Adminhtml\Rate;
|
||||
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
|
||||
class ImportExportTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Sales::transactions_fetch';
|
||||
$this->uri = 'backend/sales/transactions/fetch';
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/***
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TaxImportExport\Controller\Adminhtml\Rate;
|
||||
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
|
||||
class ImportPostTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Sales::transactions_fetch';
|
||||
$this->uri = 'backend/sales/transactions/fetch';
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TaxImportExport\Model\Rate;
|
||||
|
||||
class CsvImportHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\TaxImportExport\Model\Rate\CsvImportHandler
|
||||
*/
|
||||
protected $_importHandler;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->_importHandler = $objectManager->create(\Magento\TaxImportExport\Model\Rate\CsvImportHandler::class);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->_importHandler = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testImportFromCsvFileWithCorrectData()
|
||||
{
|
||||
$importFileName = __DIR__ . '/_files/correct_rates_import_file.csv';
|
||||
$this->_importHandler->importFromCsvFile(['tmp_name' => $importFileName]);
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
// assert that both tax rates, specified in import file, have been imported correctly
|
||||
$importedRuleCA = $objectManager->create(
|
||||
\Magento\Tax\Model\Calculation\Rate::class
|
||||
)->loadByCode(
|
||||
'US-CA-*-Rate Import Test'
|
||||
);
|
||||
$this->assertNotEmpty($importedRuleCA->getId());
|
||||
$this->assertEquals(8.25, (double)$importedRuleCA->getRate());
|
||||
$this->assertEquals('US', $importedRuleCA->getTaxCountryId());
|
||||
$this->assertEquals('*', $importedRuleCA->getTaxPostcode());
|
||||
|
||||
$importedRuleFL = $objectManager->create(
|
||||
\Magento\Tax\Model\Calculation\Rate::class
|
||||
)->loadByCode(
|
||||
'US-FL-*-Rate Import Test'
|
||||
);
|
||||
$this->assertNotEmpty($importedRuleFL->getId());
|
||||
$this->assertEquals(15, (double)$importedRuleFL->getRate());
|
||||
$this->assertEquals('US', $importedRuleFL->getTaxCountryId());
|
||||
$this->assertNull($importedRuleFL->getTaxPostcode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testImportFromCsvFileThrowsExceptionWhenCountryCodeIsInvalid()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
$this->expectExceptionMessage('Country code is invalid: ZZ');
|
||||
|
||||
$importFileName = __DIR__ . '/_files/rates_import_file_incorrect_country.csv';
|
||||
$this->_importHandler->importFromCsvFile(['tmp_name' => $importFileName]);
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
"Code","Country","State","Zip/Post Code","Rate","Zip/Post is Range","Range From","Range To","default"
|
||||
"US-CA-*-Rate Import Test","US","CA","*","8.2500","","","",""
|
||||
"US-FL-*-Rate Import Test","US","FL","","15.0000","","","",""
|
||||
|
+2
@@ -0,0 +1,2 @@
|
||||
"Code","Country","State","Zip/Post Code","Rate","Zip/Post is Range","Range From","Range To","default"
|
||||
"Wrong Rate Import Test","ZZ","FL","","15.0000","","","",""
|
||||
|
Reference in New Issue
Block a user