1515use Magento \Framework \App \ResourceConnection ;
1616use Magento \Framework \Exception \NoSuchEntityException ;
1717use Magento \Framework \Filesystem ;
18+ use Magento \Framework \Filesystem \Directory \Write ;
1819use Magento \Framework \Filesystem \Driver \File ;
1920use Magento \Framework \ObjectManagerInterface ;
2021use Magento \ImportExport \Model \Import ;
@@ -67,6 +68,9 @@ class StorageTest extends TestCase
6768 /** @var Data */
6869 private $ importDataResource ;
6970
71+ /** @var Write */
72+ private $ mediaDirectory ;
73+
7074 /**
7175 * @inheritdoc
7276 */
@@ -85,6 +89,7 @@ protected function setUp(): void
8589 $ this ->importDataResource = $ this ->objectManager ->get (Data::class);
8690 $ this ->appParams = Bootstrap::getInstance ()->getBootstrap ()->getApplication ()
8791 ->getInitParams ()[AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS ];
92+ $ this ->mediaDirectory = $ this ->fileSystem ->getDirectoryWrite (DirectoryList::MEDIA );
8893 }
8994
9095 /**
@@ -182,17 +187,14 @@ private function prepareFile(string $fileName): Csv
182187 */
183188 private function updateUploader (): void
184189 {
190+ $ mediaDir = !$ this ->mediaDirectory ->getDriver () instanceof File ?
191+ DirectoryList::MEDIA : $ this ->appParams [DirectoryList::MEDIA ][DirectoryList::PATH ];
192+ $ destDir = $ mediaDir . DIRECTORY_SEPARATOR . $ this ->mediaConfig ->getBaseMediaPath ();
193+ $ tmpDir = $ mediaDir . DIRECTORY_SEPARATOR . 'import ' ;
194+ $ this ->mediaDirectory ->create ($ this ->mediaConfig ->getBaseMediaPath ());
195+ $ this ->mediaDirectory ->create ('import ' );
196+ $ this ->import ->setParameters ([Import::FIELD_NAME_IMG_FILE_DIR => $ tmpDir ]);
185197 $ uploader = $ this ->import ->getUploader ();
186- $ rootDirectory = $ this ->fileSystem ->getDirectoryWrite (DirectoryList::ROOT );
187- $ destDir = $ rootDirectory ->getRelativePath (
188- $ this ->appParams [DirectoryList::MEDIA ][DirectoryList::PATH ]
189- . DIRECTORY_SEPARATOR . $ this ->mediaConfig ->getBaseMediaPath ()
190- );
191- $ tmpDir = $ rootDirectory ->getRelativePath (
192- $ this ->appParams [DirectoryList::MEDIA ][DirectoryList::PATH ]
193- );
194- $ rootDirectory ->create ($ destDir );
195- $ rootDirectory ->create ($ tmpDir );
196198 $ uploader ->setDestDir ($ destDir );
197199 $ uploader ->setTmpDir ($ tmpDir );
198200 }
0 commit comments