init
This commit is contained in:
+135
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\OfflineShipping\Controller\Adminhtml\System\Config;
|
||||
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\Framework\Filesystem\Directory\WriteInterface;
|
||||
use Magento\Framework\Message\MessageInterface;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\OfflineShipping\Block\Adminhtml\Carrier\Tablerate\Grid;
|
||||
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate\Collection;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
|
||||
/**
|
||||
* Test tablerates import and export.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ImportExportTableratesTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Filesystem
|
||||
*/
|
||||
private $fileSystem;
|
||||
|
||||
/**
|
||||
* @var StoreManagerInterface
|
||||
*/
|
||||
private $storeManager;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $websiteId;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->fileSystem = $this->objectManager->get(Filesystem::class);
|
||||
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
|
||||
$this->websiteId = $this->storeManager->getWebsite()->getId();
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Import Table Rates to be used in Configuration Settings.
|
||||
*
|
||||
* @magentoDataFixture Magento/OfflineShipping/_files/tablerate_create_file_in_tmp.php
|
||||
* @return void
|
||||
*/
|
||||
public function testImportExportTablerates(): void
|
||||
{
|
||||
$importCsv = 'tablerates.csv';
|
||||
$tmpDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::SYS_TMP);
|
||||
$importCsvPath = $tmpDirectory->getAbsolutePath($importCsv);
|
||||
|
||||
$_FILES['groups'] = [
|
||||
'name' => ['tablerate' => ['fields' => ['import' => ['value' => $importCsv]]]],
|
||||
'type' => ['tablerate' => ['fields' => ['import' => ['value' => 'text/csv']]]],
|
||||
'tmp_name' => ['tablerate' => ['fields' => ['import' => ['value' => $importCsvPath]]]],
|
||||
'error'=> ['tablerate' => ['fields' => ['import' => ['value' => 0]]]],
|
||||
'size' => ['tablerate' => ['fields' => ['import' => ['value' => 102]]]],
|
||||
];
|
||||
|
||||
$this->getRequest()->setPostValue(
|
||||
[
|
||||
'groups' => [
|
||||
'tablerate' => [
|
||||
'fields' => [
|
||||
'condition_name' => ['value' => 'package_weight'],
|
||||
'import' => ['value' => microtime(true)],
|
||||
],
|
||||
],
|
||||
],
|
||||
]
|
||||
)->setMethod(HttpRequest::METHOD_POST);
|
||||
|
||||
$this->dispatch('backend/admin/system_config/save/section/carriers/website/' . $this->websiteId . '/');
|
||||
$this->assertSessionMessages(
|
||||
$this->equalTo([(string)__('You saved the configuration.')]),
|
||||
MessageInterface::TYPE_SUCCESS
|
||||
);
|
||||
|
||||
/** @var Collection $tablerateCollection */
|
||||
$tablerateCollection = $this->objectManager->create(Collection::class);
|
||||
$tablerateData = $tablerateCollection->setConditionFilter('package_weight')->getItems()[0]->getData();
|
||||
$this->assertEquals('666.0000', $tablerateData['price']);
|
||||
$this->assertEquals('USA', $tablerateData['dest_country']);
|
||||
$this->assertEquals('10.0000', $tablerateData['condition_value']);
|
||||
|
||||
$exportCsvContent = $this->getTablerateCsv();
|
||||
$importCsvContent = $tmpDirectory->openFile($importCsvPath, 'r')->readAll();
|
||||
|
||||
$this->assertEquals($importCsvContent, $exportCsvContent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getTablerateCsv(): string
|
||||
{
|
||||
/** @var WriteInterface $varDirectory */
|
||||
$varDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_DIR);
|
||||
|
||||
/** @var Grid $gridBlock */
|
||||
$gridBlock = $this->objectManager->get(LayoutInterface::class)->createBlock(Grid::class);
|
||||
$exportCsv = $gridBlock->setWebsiteId($this->websiteId)->setConditionName('package_weight')->getCsvFile();
|
||||
$exportCsvContent = $varDirectory->openFile($exportCsv['value'], 'r')->readAll();
|
||||
|
||||
$bom = pack('CCC', 0xef, 0xbb, 0xbf);
|
||||
if (substr($exportCsvContent, 0, 3) === $bom) {
|
||||
$exportCsvContent = substr($exportCsvContent, 3);
|
||||
}
|
||||
|
||||
return $exportCsvContent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\OfflineShipping\Model;
|
||||
|
||||
/**
|
||||
* Integration tests for offline shipping carriers.
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
class CollectRatesTest extends \Magento\Shipping\Model\CollectRatesAbstract
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $carrier = 'flatrate';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $errorMessage = 'This shipping method is not available. To use this shipping method, please contact us.';
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 1
|
||||
* @magentoConfigFixture default_store carriers/flatrate/sallowspecific 1
|
||||
* @magentoConfigFixture default_store carriers/flatrate/specificcountry UK
|
||||
* @magentoConfigFixture default_store carriers/flatrate/showmethod 1
|
||||
*/
|
||||
// phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod
|
||||
public function testCollectRatesWhenShippingCarrierIsAvailableAndNotApplicable()
|
||||
{
|
||||
parent::testCollectRatesWhenShippingCarrierIsAvailableAndNotApplicable();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 0
|
||||
* @magentoConfigFixture default_store carriers/flatrate/sallowspecific 1
|
||||
* @magentoConfigFixture default_store carriers/flatrate/specificcountry UK
|
||||
* @magentoConfigFixture default_store carriers/flatrate/showmethod 1
|
||||
*/
|
||||
// phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod
|
||||
public function testCollectRatesWhenShippingCarrierIsNotAvailableAndNotApplicable()
|
||||
{
|
||||
parent::testCollectRatesWhenShippingCarrierIsNotAvailableAndNotApplicable();
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\Filesystem\Directory\WriteInterface;
|
||||
|
||||
$importCsv = 'tablerates.csv';
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Filesystem $fileSystem */
|
||||
$fileSystem = $objectManager->get(Filesystem::class);
|
||||
/** @var WriteInterface $tmpDirectory */
|
||||
$tmpDirectory = $fileSystem->getDirectoryWrite(DirectoryList::SYS_TMP);
|
||||
$importCsvPath = $tmpDirectory->getAbsolutePath($importCsv);
|
||||
|
||||
$fixtureDir = realpath(__DIR__);
|
||||
copy($fixtureDir . DIRECTORY_SEPARATOR . $importCsv, $importCsvPath);
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\Filesystem\Directory\WriteInterface;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Filesystem $fileSystem */
|
||||
$fileSystem = $objectManager->get(Filesystem::class);
|
||||
/** @var WriteInterface $tmpDirectory */
|
||||
$tmpDirectory = $fileSystem->getDirectoryWrite(DirectoryList::SYS_TMP);
|
||||
$fileName = 'tablerates.csv';
|
||||
|
||||
$tmpDirectory->delete($fileName);
|
||||
@@ -0,0 +1,2 @@
|
||||
Country,Region/State,"Zip/Postal Code","Weight (and above)","Shipping Price"
|
||||
USA,*,*,10.0000,666.0000
|
||||
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$resource = $objectManager->get(\Magento\Framework\App\ResourceConnection::class);
|
||||
$connection = $resource->getConnection();
|
||||
$resourceModel = $objectManager->create(\Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate::class);
|
||||
$entityTable = $resourceModel->getTable('shipping_tablerate');
|
||||
$data =
|
||||
[
|
||||
'website_id' => 1,
|
||||
'dest_country_id' => 'US',
|
||||
'dest_region_id' => 0,
|
||||
'dest_zip' => '*',
|
||||
'condition_name' => 'package_qty',
|
||||
'condition_value' => 1,
|
||||
'price' => 10,
|
||||
'cost' => 10
|
||||
];
|
||||
$connection->query(
|
||||
"INSERT INTO {$entityTable} (`website_id`, `dest_country_id`, `dest_region_id`, `dest_zip`, `condition_name`,"
|
||||
. "`condition_value`, `price`, `cost`) VALUES (:website_id, :dest_country_id, :dest_region_id, :dest_zip,"
|
||||
. " :condition_name, :condition_value, :price, :cost);",
|
||||
$data
|
||||
);
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/**
|
||||
* @var Tablerate $resourceModel
|
||||
*/
|
||||
$resourceModel = $objectManager->create(Tablerate::class);
|
||||
$tableRatesData = [
|
||||
[
|
||||
'website_id' => 1,
|
||||
'dest_country_id' => 'US',
|
||||
'dest_region_id' => 0,
|
||||
'dest_zip' => '*',
|
||||
'condition_name' => 'package_value_with_discount',
|
||||
'condition_value' => 0.00,
|
||||
'price' => 15,
|
||||
'cost' => 0
|
||||
],
|
||||
[
|
||||
'website_id' => 1,
|
||||
'dest_country_id' => 'US',
|
||||
'dest_region_id' => 0,
|
||||
'dest_zip' => '*',
|
||||
'condition_name' => 'package_value_with_discount',
|
||||
'condition_value' => 50.00,
|
||||
'price' => 10,
|
||||
'cost' => 0
|
||||
],
|
||||
[
|
||||
'website_id' => 1,
|
||||
'dest_country_id' => 'US',
|
||||
'dest_region_id' => 0,
|
||||
'dest_zip' => '*',
|
||||
'condition_name' => 'package_value_with_discount',
|
||||
'condition_value' => 100.00,
|
||||
'price' => 5,
|
||||
'cost' => 0
|
||||
]
|
||||
];
|
||||
$columns = [
|
||||
'website_id',
|
||||
'dest_country_id',
|
||||
'dest_region_id',
|
||||
'dest_zip',
|
||||
'condition_name',
|
||||
'condition_value',
|
||||
'price',
|
||||
'cost'
|
||||
];
|
||||
$resourceModel->getConnection()->insertArray($resourceModel->getMainTable(), $columns, $tableRatesData);
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$resourceModel = $objectManager->create(Tablerate::class);
|
||||
$resourceModel->getConnection()->delete($resourceModel->getMainTable());
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$resource = $objectManager->get(\Magento\Framework\App\ResourceConnection::class);
|
||||
$connection = $resource->getConnection();
|
||||
$resourceModel = $objectManager->create(\Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate::class);
|
||||
$entityTable = $resourceModel->getTable('shipping_tablerate');
|
||||
$connection->query("DELETE FROM {$entityTable};");
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$website = $websiteRepository->get('test');
|
||||
|
||||
/** @var ResourceConnection $resource */
|
||||
$resource = $objectManager->get(ResourceConnection::class);
|
||||
$connection = $resource->getConnection();
|
||||
$resourceModel = $objectManager->create(Tablerate::class);
|
||||
$entityTable = $resourceModel->getTable('shipping_tablerate');
|
||||
$data =
|
||||
[
|
||||
'website_id' => $website->getId(),
|
||||
'dest_country_id' => 'US',
|
||||
'dest_region_id' => 0,
|
||||
'dest_zip' => '*',
|
||||
'condition_name' => 'package_qty',
|
||||
'condition_value' => 1,
|
||||
'price' => 20,
|
||||
'cost' => 20
|
||||
];
|
||||
$connection->query(
|
||||
"INSERT INTO {$entityTable} (`website_id`, `dest_country_id`, `dest_region_id`, `dest_zip`, `condition_name`,"
|
||||
. "`condition_value`, `price`, `cost`) VALUES (:website_id, :dest_country_id, :dest_region_id, :dest_zip,"
|
||||
. " :condition_name, :condition_value, :price, :cost);",
|
||||
$data
|
||||
);
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$resource = $objectManager->get(\Magento\Framework\App\ResourceConnection::class);
|
||||
$connection = $resource->getConnection();
|
||||
$resourceModel = $objectManager->create(\Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate::class);
|
||||
$entityTable = $resourceModel->getTable('shipping_tablerate');
|
||||
$connection->query("DELETE FROM {$entityTable};");
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$resource = $objectManager->get(\Magento\Framework\App\ResourceConnection::class);
|
||||
$connection = $resource->getConnection();
|
||||
$resourceModel = $objectManager->create(\Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate::class);
|
||||
$entityTable = $resourceModel->getTable('shipping_tablerate');
|
||||
$data =
|
||||
[
|
||||
'website_id' => 1,
|
||||
'dest_country_id' => 'US',
|
||||
'dest_region_id' => 0,
|
||||
'dest_zip' => '*',
|
||||
'condition_name' => 'package_weight',
|
||||
'condition_value' => 0,
|
||||
'price' => 10,
|
||||
'cost' => 0
|
||||
];
|
||||
$connection->query(
|
||||
"INSERT INTO {$entityTable} (`website_id`, `dest_country_id`, `dest_region_id`, `dest_zip`, `condition_name`,"
|
||||
. "`condition_value`, `price`, `cost`) VALUES (:website_id, :dest_country_id, :dest_region_id, :dest_zip,"
|
||||
. " :condition_name, :condition_value, :price, :cost);",
|
||||
$data
|
||||
);
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/OfflineShipping/_files/tablerates_rollback.php');
|
||||
Reference in New Issue
Block a user