@@ -273,25 +273,16 @@ protected function csvToArray($content, $entityId = null)
273
273
*/
274
274
protected function importDataForMediaTest (string $ fileName , int $ expectedErrors = 0 )
275
275
{
276
- $ rootDirectory = $ this ->objectManager ->get (TargetDirectory::class)->getDirectoryWrite (DirectoryList::ROOT );
277
276
$ filesystem = $ this ->objectManager ->get (Filesystem::class);
278
- $ importExportDirectory = $ filesystem ->getDirectoryWrite (DirectoryList::VAR_IMPORT_EXPORT );
279
-
280
- $ dirPath = $ importExportDirectory ->getAbsolutePath ('import ' );
281
- $ driver = $ importExportDirectory ->getDriver ();
282
- $ driver ->createDirectory ($ dirPath );
283
- $ driver ->filePutContents (
284
- $ dirPath . DIRECTORY_SEPARATOR . $ fileName ,
285
- file_get_contents (__DIR__ . DIRECTORY_SEPARATOR . '_files ' . DIRECTORY_SEPARATOR . $ fileName )
286
- );
287
-
277
+ $ directory = $ filesystem ->getDirectoryWrite (DirectoryList::ROOT );
288
278
$ source = $ this ->objectManager ->create (
289
279
\Magento \ImportExport \Model \Import \Source \Csv::class,
290
280
[
291
- 'file ' => $ dirPath . DIRECTORY_SEPARATOR . $ fileName ,
292
- 'directory ' => $ importExportDirectory
281
+ 'file ' => __DIR__ . ' /_files/ ' . $ fileName ,
282
+ 'directory ' => $ directory
293
283
]
294
284
);
285
+ $ rootDirectory = $ this ->objectManager ->get (TargetDirectory::class)->getDirectoryWrite (DirectoryList::ROOT );
295
286
$ this ->_model ->setParameters (
296
287
[
297
288
'behavior ' => \Magento \ImportExport \Model \Import::BEHAVIOR_APPEND ,
@@ -341,7 +332,6 @@ function ($output, $error) {
341
332
''
342
333
)
343
334
);
344
- $ source ->destruct ();
345
335
}
346
336
347
337
/**
@@ -387,38 +377,30 @@ protected function importFile(string $fileName, int $bunchSize = 100): bool
387
377
['importExportData ' => $ importExportData ]
388
378
);
389
379
$ filesystem = $ this ->objectManager ->create (Filesystem::class);
390
- $ directory = $ filesystem ->getDirectoryWrite (DirectoryList::VAR_IMPORT_EXPORT );
391
-
392
- $ dirPath = $ directory ->getAbsolutePath ('import ' );
393
- $ driver = $ directory ->getDriver ();
394
- $ driver ->createDirectory ($ dirPath );
395
- $ driver ->filePutContents (
396
- $ dirPath . DIRECTORY_SEPARATOR . $ fileName ,
397
- file_get_contents (__DIR__ . DIRECTORY_SEPARATOR . '_files ' . DIRECTORY_SEPARATOR . $ fileName )
398
- );
380
+ $ directory = $ filesystem ->getDirectoryWrite (DirectoryList::ROOT );
399
381
$ source = $ this ->objectManager ->create (
400
382
Csv::class,
401
383
[
402
- 'file ' => $ dirPath . DIRECTORY_SEPARATOR . $ fileName ,
384
+ 'file ' => __DIR__ . DIRECTORY_SEPARATOR . ' _files ' . DIRECTORY_SEPARATOR . $ fileName ,
403
385
'directory ' => $ directory ,
404
386
]
405
387
);
388
+ $ mediaDirectory = $ filesystem ->getDirectoryWrite (DirectoryList::MEDIA );
389
+ $ mediaDirectory ->create ('import ' );
406
390
$ errors = $ this ->_model ->setParameters (
407
391
[
408
392
'behavior ' => Import::BEHAVIOR_APPEND ,
409
393
'entity ' => 'catalog_product ' ,
410
394
Import::FIELDS_ENCLOSURE => 1 ,
411
- Import::FIELD_NAME_IMG_FILE_DIR => $ this ->getMediaDirPath ($ directory ) . '/import '
395
+ Import::FIELD_NAME_IMG_FILE_DIR => $ this ->getMediaDirPath ($ mediaDirectory ) . '/import '
412
396
]
413
397
)
414
398
->setSource ($ source )
415
399
->validateData ();
416
400
417
401
$ this ->assertTrue ($ errors ->getErrorsCount () === 0 );
418
402
419
- $ result = $ this ->_model ->importData ();
420
- $ source ->destruct ();
421
- return $ result ;
403
+ return $ this ->_model ->importData ();
422
404
}
423
405
424
406
/**
0 commit comments