15
15
use Magento \Framework \App \ResourceConnection ;
16
16
use Magento \Framework \Exception \NoSuchEntityException ;
17
17
use Magento \Framework \Filesystem ;
18
+ use Magento \Framework \Filesystem \Directory \Write ;
18
19
use Magento \Framework \Filesystem \Driver \File ;
19
20
use Magento \Framework \ObjectManagerInterface ;
20
21
use Magento \ImportExport \Model \Import ;
@@ -67,6 +68,9 @@ class StorageTest extends TestCase
67
68
/** @var Data */
68
69
private $ importDataResource ;
69
70
71
+ /** @var Write */
72
+ private $ mediaDirectory ;
73
+
70
74
/**
71
75
* @inheritdoc
72
76
*/
@@ -85,6 +89,7 @@ protected function setUp(): void
85
89
$ this ->importDataResource = $ this ->objectManager ->get (Data::class);
86
90
$ this ->appParams = Bootstrap::getInstance ()->getBootstrap ()->getApplication ()
87
91
->getInitParams ()[AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS ];
92
+ $ this ->mediaDirectory = $ this ->fileSystem ->getDirectoryWrite (DirectoryList::MEDIA );
88
93
}
89
94
90
95
/**
@@ -182,17 +187,14 @@ private function prepareFile(string $fileName): Csv
182
187
*/
183
188
private function updateUploader (): void
184
189
{
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 ]);
185
197
$ 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 );
196
198
$ uploader ->setDestDir ($ destDir );
197
199
$ uploader ->setTmpDir ($ tmpDir );
198
200
}
0 commit comments