Skip to content

Commit ded7d72

Browse files
committed
B2B-2677: [MediaGallery]Implement data caching for GraphQL results on resolver level
- Use file fixture for import
1 parent 02ca086 commit ded7d72

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ResolverCache/MediaGalleryTest.php

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
use Magento\CatalogGraphQl\Model\Resolver\Product\MediaGallery;
1919
use Magento\Framework\Api\Data\ImageContentInterfaceFactory;
2020
use Magento\Framework\App\Area as AppArea;
21+
use Magento\Framework\App\Filesystem\DirectoryList;
2122
use Magento\Framework\App\ObjectManager\ConfigLoader;
2223
use Magento\Framework\App\State as AppState;
24+
use Magento\Framework\Filesystem\Directory\WriteInterface as DirectoryWriteInterface;
2325
use Magento\Framework\ObjectManagerInterface;
2426
use Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\Calculator\ProviderInterface;
2527
use Magento\GraphQlResolverCache\Model\Resolver\Result\Type as GraphQlResolverCache;
2628
use Magento\ImportExport\Model\Import;
2729
use Magento\Integration\Model\Integration;
30+
use Magento\Framework\Filesystem;
2831
use Magento\TestFramework\Fixture\DataFixture;
2932
use Magento\TestFramework\Helper\Bootstrap;
3033
use Magento\TestFramework\TestCase\GraphQl\ResolverCacheAbstract;
@@ -50,15 +53,38 @@ class MediaGalleryTest extends ResolverCacheAbstract
5053
*/
5154
private $graphQlResolverCache;
5255

56+
/**
57+
* @var DirectoryWriteInterface
58+
*/
59+
private $mediaDirectory;
60+
61+
/**
62+
* @var string[]
63+
*/
64+
private $filesToRemove = [];
65+
5366
protected function setUp(): void
5467
{
5568
$this->objectManager = Bootstrap::getObjectManager();
5669
$this->graphQlResolverCache = $this->objectManager->get(GraphQlResolverCache::class);
5770
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
71+
$filesystem = $this->objectManager->get(Filesystem::class);
72+
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
5873

5974
parent::setUp();
6075
}
6176

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+
6288
#[
6389
DataFixture(ProductFixture::class, ['sku' => 'product1', 'media_gallery_entries' => [[]]], as: 'product'),
6490
]
@@ -449,15 +475,30 @@ public function testCacheIsInvalidatedWhenUpdatingMediaGalleryEntriesOnAProductV
449475
],
450476
];
451477

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+
452494
$requestData = [
453495
'source' => [
454496
'entity' => 'catalog_product',
455497
'behavior' => 'append',
456498
'validationStrategy' => 'validation-stop-on-errors',
457499
'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"),
461502
],
462503
];
463504

13 KB
Loading

0 commit comments

Comments
 (0)