11 use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate\RateQueryFactory;
28 private $storeManagerMock;
33 private $filesystemMock;
48 $loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
49 $coreConfigMock = $this->createMock(\
Magento\Framework\
App\Config\ScopeConfigInterface::class);
50 $this->storeManagerMock = $this->createMock(\
Magento\Store\Model\StoreManagerInterface::class);
51 $carrierTablerateMock = $this->createMock(\
Magento\OfflineShipping\Model\Carrier\Tablerate::class);
52 $this->filesystemMock = $this->createMock(\
Magento\Framework\Filesystem::class);
53 $this->importMock = $this->createMock(Import::class);
54 $rateQueryFactoryMock = $this->createMock(RateQueryFactory::class);
55 $this->resource = $this->createMock(\
Magento\Framework\
App\ResourceConnection::class);
57 $contextMock->expects($this->once())->method(
'getResources')->willReturn($this->resource);
63 $this->storeManagerMock,
64 $carrierTablerateMock,
65 $this->filesystemMock,
73 $_FILES[
'groups'][
'tmp_name'][
'tablerate'][
'fields'][
'import'][
'value'] =
'some/path/to/file';
74 $object = $this->createPartialMock(
75 \
Magento\OfflineShipping\Model\Config\Backend\Tablerate::class,
79 $websiteMock = $this->createMock(\
Magento\Store\Api\Data\WebsiteInterface::class);
80 $directoryReadMock = $this->createMock(\
Magento\Framework\
Filesystem\Directory\ReadInterface::class);
81 $fileReadMock = $this->createMock(\
Magento\Framework\
Filesystem\File\ReadInterface::class);
82 $connectionMock = $this->createMock(\
Magento\Framework\DB\Adapter\AdapterInterface::class);
84 $this->storeManagerMock->expects($this->once())->method(
'getWebsite')->willReturn($websiteMock);
85 $object->expects($this->once())->method(
'getScopeId')->willReturn(1);
86 $websiteMock->expects($this->once())->method(
'getId')->willReturn(1);
88 $this->filesystemMock->expects($this->once())->method(
'getDirectoryReadByPath')
89 ->with(
'some/path/to')->willReturn($directoryReadMock);
90 $directoryReadMock->expects($this->once())->method(
'openFile')
91 ->with(
'file')->willReturn($fileReadMock);
93 $this->resource->expects($this->once())->method(
'getConnection')->willReturn($connectionMock);
95 $connectionMock->expects($this->once())->method(
'beginTransaction');
96 $connectionMock->expects($this->once())->method(
'delete');
97 $connectionMock->expects($this->once())->method(
'commit');
99 $this->importMock->expects($this->once())->method(
'getColumns')->willReturn([]);
100 $this->importMock->expects($this->once())->method(
'getData')->willReturn([]);
102 $this->model->uploadAndImport($object);
103 unset($_FILES[
'groups']);