Skip to content

Commit 44cbbf3

Browse files
committed
Merge branch 'B2B-2020' into B2B-2024
2 parents f0831d2 + 74353ed commit 44cbbf3

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed

dev/tests/integration/testsuite/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricingTest.php

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66

77
namespace Magento\AdvancedPricingImportExport\Model\Export;
88

9-
use Magento\Framework\App\Filesystem\DirectoryList;
10-
use Magento\Framework\Exception\NoSuchEntityException;
11-
use Magento\Framework\File\Csv;
12-
use Magento\TestFramework\Indexer\TestCase;
13-
use Magento\TestFramework\Helper\Bootstrap;
14-
use Magento\Framework\Filesystem;
159
use Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricing as ExportAdvancedPricing;
10+
use Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing as ImportAdvancedPricing;
1611
use Magento\Catalog\Api\ProductRepositoryInterface;
1712
use Magento\Catalog\Model\Product;
13+
use Magento\Framework\App\Filesystem\DirectoryList;
14+
use Magento\Framework\Exception\NoSuchEntityException;
15+
use Magento\Framework\Filesystem;
16+
use Magento\Framework\Filesystem\Directory\Write;
1817
use Magento\ImportExport\Model\Export\Adapter\Csv as ExportAdapterCsv;
19-
use Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing as ImportAdvancedPricing;
20-
use Magento\ImportExport\Model\Import\Source\Csv as ImportSourceCsv;
2118
use Magento\ImportExport\Model\Import;
19+
use Magento\ImportExport\Model\Import\Source\Csv as ImportSourceCsv;
20+
use Magento\TestFramework\Helper\Bootstrap;
21+
use Magento\TestFramework\Indexer\TestCase;
2222

2323
/**
2424
* Test for \Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricing
@@ -41,6 +41,11 @@ class AdvancedPricingTest extends TestCase
4141
*/
4242
protected $fileSystem;
4343

44+
/**
45+
* @var Write
46+
*/
47+
private $directory;
48+
4449
// @codingStandardsIgnoreStart
4550
public static function setUpBeforeClass(): void
4651
{
@@ -64,6 +69,7 @@ protected function setUp(): void
6469

6570
$this->objectManager = Bootstrap::getObjectManager();
6671
$this->fileSystem = $this->objectManager->get(Filesystem::class);
72+
$this->directory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
6773
$this->model = $this->objectManager->create(ExportAdvancedPricing::class);
6874
}
6975

@@ -179,7 +185,7 @@ public function testExportImportOfAdvancedPricing(): void
179185
{
180186
$simpleSku = 'simple';
181187
$secondSimpleSku = 'second_simple';
182-
$csvfile = uniqid('importexport_') . '.csv';
188+
$csvfile = $this->directory->getAbsolutePath(uniqid('importexport_') . '.csv');
183189
$exportContent = $this->exportData($csvfile);
184190
$this->assertStringContainsString(
185191
\sprintf('%s,"All Websites [USD]","ALL GROUPS",10.0000,3.00,Discount', $secondSimpleSku),
@@ -269,10 +275,7 @@ private function updateTierPriceDataInCsv(string $csvfile): void
269275
],
270276
];
271277

272-
/** @var Csv $csv */
273-
$csv = $this->objectManager->get(Csv::class);
274-
$varDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_DIR);
275-
$csv->appendData($varDirectory->getAbsolutePath($csvfile), $csvNewData);
278+
$this->updateCsvFile($csvfile, $csvNewData);
276279
}
277280

278281
/**
@@ -281,16 +284,15 @@ private function updateTierPriceDataInCsv(string $csvfile): void
281284
*/
282285
private function exportData($csvFile)
283286
{
284-
$this->model->setWriter(
285-
Bootstrap::getObjectManager()
286-
->create(
287-
ExportAdapterCsv::class,
288-
['fileSystem' => $this->fileSystem, 'destination' => $csvFile]
289-
)
290-
);
287+
$writer = Bootstrap::getObjectManager()->create(ExportAdapterCsv::class, ['fileSystem' => $this->fileSystem]);
288+
289+
$this->model->setWriter($writer);
291290
$exportContent = $this->model->export();
292291
$this->assertNotEmpty($exportContent);
293292

293+
$driver = $this->directory->getDriver();
294+
$driver->filePutContents($this->directory->getAbsolutePath($csvFile), $exportContent);
295+
294296
return $exportContent;
295297
}
296298

@@ -301,12 +303,11 @@ private function importData($csvFile)
301303
{
302304
/** @var ImportAdvancedPricing $importModel */
303305
$importModel = $this->objectManager->create(ImportAdvancedPricing::class);
304-
$directory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_DIR);
305306
$source = $this->objectManager->create(
306307
ImportSourceCsv::class,
307308
[
308309
'file' => $csvFile,
309-
'directory' => $directory
310+
'directory' => $this->directory
310311
]
311312
);
312313
$errors = $importModel->setParameters(
@@ -366,4 +367,24 @@ private function removeImportedProducts(array $skus): void
366367
$registry->unregister('isSecureArea');
367368
$registry->register('isSecureArea', false);
368369
}
370+
371+
/**
372+
* Appends csv data to the file
373+
*
374+
* @param string $filePath
375+
* @param array $csv
376+
* @return void
377+
*/
378+
private function updateCsvFile(string $filePath, array $csv): void
379+
{
380+
$driver = $this->directory->getDriver();
381+
$driver->deleteFile($filePath);
382+
$fileResource = $driver->fileOpen($filePath, 'w');
383+
384+
foreach ($csv as $dataRow) {
385+
$driver->filePutCsv($fileResource, $dataRow);
386+
}
387+
388+
$driver->fileClose($fileResource);
389+
}
369390
}

dev/tests/integration/testsuite/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricingTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public function testImportDelete()
175175
$index = 0;
176176
$ids = [];
177177
$origPricingData = [];
178+
$skus = ['simple'];
178179
while (isset($skus[$index])) {
179180
$ids[$index] = $productRepository->get($skus[$index])->getId();
180181
$origPricingData[$index] = $this->objectManager->create(\Magento\Catalog\Model\Product::class)
@@ -192,12 +193,16 @@ public function testImportDelete()
192193
$exportModel->setWriter(
193194
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
194195
\Magento\ImportExport\Model\Export\Adapter\Csv::class,
195-
['fileSystem' => $this->fileSystem, 'destination' => $csvfile]
196+
['fileSystem' => $this->fileSystem]
196197
)
197198
);
198-
$this->assertNotEmpty($exportModel->export());
199+
$exportContent = $exportModel->export();
200+
$this->assertNotEmpty($exportContent);
199201

200-
$errors = $this->doImport($csvfile, DirectoryList::VAR_DIR, Import::BEHAVIOR_DELETE, true);
202+
$directory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
203+
$directory->getDriver()->filePutContents($directory->getAbsolutePath($csvfile), $exportContent);
204+
205+
$errors = $this->doImport($csvfile, DirectoryList::VAR_IMPORT_EXPORT, Import::BEHAVIOR_DELETE, true);
201206

202207
$this->assertTrue(
203208
$errors->getErrorsCount() == 0,

0 commit comments

Comments
 (0)