Skip to content

Commit 7cb436f

Browse files
committed
Merge remote-tracking branch 'local/ACP2E-1565' into PR_7_JAN_2023
2 parents 0f79059 + fd2c638 commit 7cb436f

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,9 +2080,13 @@ private function getFileContent(string $path): string
20802080
*/
20812081
private function getRemoteFileContent(string $filename): string
20822082
{
2083-
// phpcs:disable Magento2.Functions.DiscouragedFunction
2084-
$content = file_get_contents($filename);
2085-
// phpcs:enable Magento2.Functions.DiscouragedFunction
2083+
try {
2084+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
2085+
$content = file_get_contents($filename);
2086+
} catch (\Exception $e) {
2087+
$content = false;
2088+
}
2089+
20862090
return $content !== false ? $content : '';
20872091
}
20882092

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ImportWithNotExistImagesTest.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,11 @@ protected function tearDown(): void
109109

110110
/**
111111
* @magentoDataFixture Magento/Catalog/_files/product_with_image.php
112-
*
112+
* @dataProvider unexistingImagesDataProvider
113+
* @param string $imagesPath
113114
* @return void
114115
*/
115-
public function testImportWithUnexistingImages(): void
116+
public function testImportWithUnexistingImages(string $imagesPath): void
116117
{
117118
$cache = $this->objectManager->get(\Magento\Framework\App\Cache::class);
118119
$cache->clean();
@@ -132,7 +133,7 @@ public function testImportWithUnexistingImages(): void
132133
$this->assertTrue($this->directory->isExist($this->filePath), 'Products were not imported to file');
133134
$fileContent = $this->getCsvData($this->directory->getAbsolutePath($this->filePath));
134135
$this->assertCount(2, $fileContent);
135-
$this->updateFileImagesToInvalidValues();
136+
$this->updateFileImagesToInvalidValues($imagesPath);
136137
$mediaDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::MEDIA);
137138
$mediaDirectory->create('import');
138139
$this->import->setParameters([
@@ -144,6 +145,17 @@ public function testImportWithUnexistingImages(): void
144145
$this->assertProductImages('/m/a/magento_image.jpg', 'simple');
145146
}
146147

148+
/**
149+
* @return array
150+
*/
151+
public function unexistingImagesDataProvider(): array
152+
{
153+
return [
154+
['/m/a/invalid_image.jpg'],
155+
['http://127.0.0.1/pub/static/nonexistent_image.jpg'],
156+
];
157+
}
158+
147159
/**
148160
* Export products from queue to csv file
149161
*
@@ -158,9 +170,10 @@ private function exportProducts(): void
158170
/**
159171
* Change image names in an export file
160172
*
173+
* @param string $imagesPath
161174
* @return void
162175
*/
163-
private function updateFileImagesToInvalidValues(): void
176+
private function updateFileImagesToInvalidValues(string $imagesPath): void
164177
{
165178
$absolutePath = $this->directory->getAbsolutePath($this->filePath);
166179
$csv = $this->getCsvData($absolutePath);
@@ -171,7 +184,7 @@ private function updateFileImagesToInvalidValues(): void
171184
}
172185

173186
foreach ($imagesPositions as $imagesPosition) {
174-
$csv[1][$imagesPosition] = '/m/a/invalid_image.jpg';
187+
$csv[1][$imagesPosition] = $imagesPath;
175188
}
176189

177190
$this->appendCsvData($absolutePath, $csv);

0 commit comments

Comments
 (0)