18
18
use Magento \CatalogGraphQl \Model \Resolver \Product \MediaGallery ;
19
19
use Magento \Framework \Api \Data \ImageContentInterfaceFactory ;
20
20
use Magento \Framework \App \Area as AppArea ;
21
+ use Magento \Framework \App \Filesystem \DirectoryList ;
21
22
use Magento \Framework \App \ObjectManager \ConfigLoader ;
22
23
use Magento \Framework \App \State as AppState ;
24
+ use Magento \Framework \Filesystem \Directory \WriteInterface as DirectoryWriteInterface ;
23
25
use Magento \Framework \ObjectManagerInterface ;
24
26
use Magento \GraphQlResolverCache \Model \Resolver \Result \CacheKey \Calculator \ProviderInterface ;
25
27
use Magento \GraphQlResolverCache \Model \Resolver \Result \Type as GraphQlResolverCache ;
26
28
use Magento \ImportExport \Model \Import ;
27
29
use Magento \Integration \Model \Integration ;
30
+ use Magento \Framework \Filesystem ;
28
31
use Magento \TestFramework \Fixture \DataFixture ;
29
32
use Magento \TestFramework \Helper \Bootstrap ;
30
33
use Magento \TestFramework \TestCase \GraphQl \ResolverCacheAbstract ;
@@ -50,15 +53,38 @@ class MediaGalleryTest extends ResolverCacheAbstract
50
53
*/
51
54
private $ graphQlResolverCache ;
52
55
56
+ /**
57
+ * @var DirectoryWriteInterface
58
+ */
59
+ private $ mediaDirectory ;
60
+
61
+ /**
62
+ * @var string[]
63
+ */
64
+ private $ filesToRemove = [];
65
+
53
66
protected function setUp (): void
54
67
{
55
68
$ this ->objectManager = Bootstrap::getObjectManager ();
56
69
$ this ->graphQlResolverCache = $ this ->objectManager ->get (GraphQlResolverCache::class);
57
70
$ this ->productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
71
+ $ filesystem = $ this ->objectManager ->get (Filesystem::class);
72
+ $ this ->mediaDirectory = $ filesystem ->getDirectoryWrite (DirectoryList::MEDIA );
58
73
59
74
parent ::setUp ();
60
75
}
61
76
77
+ protected function tearDown (): void
78
+ {
79
+ foreach ($ this ->filesToRemove as $ fileToRemove ) {
80
+ $ this ->mediaDirectory ->delete ($ fileToRemove );
81
+ }
82
+
83
+ $ this ->mediaDirectory ->delete ('import/images ' );
84
+
85
+ parent ::tearDown ();
86
+ }
87
+
62
88
#[
63
89
DataFixture(ProductFixture::class, ['sku ' => 'product1 ' , 'media_gallery_entries ' => [[]]], as: 'product ' ),
64
90
]
@@ -449,15 +475,30 @@ public function testCacheIsInvalidatedWhenUpdatingMediaGalleryEntriesOnAProductV
449
475
],
450
476
];
451
477
478
+ // move test image into media directory
479
+ $ destinationDir = $ this ->mediaDirectory ->getAbsolutePath () . '/import/images ' ;
480
+
481
+ $ this ->mediaDirectory ->create ($ destinationDir );
482
+
483
+ $ sourcePathname = dirname (__FILE__ ) . '/../../_files/magento_image.jpg ' ;
484
+ $ destinationFilePathname = $ this ->mediaDirectory ->getAbsolutePath ("$ destinationDir/magento_image.jpg " );
485
+
486
+ $ this ->mediaDirectory ->getDriver ()->filePutContents (
487
+ $ destinationFilePathname ,
488
+ file_get_contents ($ sourcePathname )
489
+ );
490
+
491
+ // add file to list of files to remove after test finishes
492
+ $ this ->filesToRemove [] = $ destinationFilePathname ;
493
+
452
494
$ requestData = [
453
495
'source ' => [
454
496
'entity ' => 'catalog_product ' ,
455
497
'behavior ' => 'append ' ,
456
498
'validationStrategy ' => 'validation-stop-on-errors ' ,
457
499
'allowedErrorCount ' => '10 ' ,
458
- Import::FIELD_NAME_IMG_FILE_DIR =>
459
- '/Users/dmooney/Code/vagrant-magento/magento2ce/var/import/images/product_images ' ,
460
- 'csvData ' => base64_encode ("sku,base_image \nproduct1,design_patterns.jpeg \n" ),
500
+ Import::FIELD_NAME_IMG_FILE_DIR => $ destinationDir ,
501
+ 'csvData ' => base64_encode ("sku,base_image \nproduct1,magento_image.jpg \n" ),
461
502
],
462
503
];
463
504
0 commit comments