Skip to content

Commit 209ee51

Browse files
committed
B2B-2677: [MediaGallery]Implement data caching for GraphQL results on resolver level
- Move API import-specific test to EE
1 parent 26a44ca commit 209ee51

File tree

2 files changed

+0
-202
lines changed

2 files changed

+0
-202
lines changed

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

Lines changed: 0 additions & 202 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,11 @@
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;
2221
use Magento\Framework\App\ObjectManager\ConfigLoader;
2322
use Magento\Framework\App\State as AppState;
24-
use Magento\Framework\Filesystem\Directory\WriteInterface as DirectoryWriteInterface;
2523
use Magento\Framework\ObjectManagerInterface;
2624
use Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\Calculator\ProviderInterface;
2725
use Magento\GraphQlResolverCache\Model\Resolver\Result\Type as GraphQlResolverCache;
28-
use Magento\ImportExport\Model\Import;
29-
use Magento\Integration\Api\IntegrationServiceInterface;
30-
use Magento\Integration\Model\Integration;
31-
use Magento\Framework\Filesystem;
3226
use Magento\TestFramework\Fixture\DataFixture;
3327
use Magento\TestFramework\Helper\Bootstrap;
3428
use Magento\TestFramework\TestCase\GraphQl\ResolverCacheAbstract;
@@ -54,49 +48,15 @@ class MediaGalleryTest extends ResolverCacheAbstract
5448
*/
5549
private $graphQlResolverCache;
5650

57-
/**
58-
* @var IntegrationServiceInterface
59-
*/
60-
private $integrationService;
61-
62-
/**
63-
* @var Integration
64-
*/
65-
private $integration;
66-
67-
/**
68-
* @var DirectoryWriteInterface
69-
*/
70-
private $mediaDirectory;
71-
72-
/**
73-
* @var string[]
74-
*/
75-
private $filesToRemove = [];
76-
7751
protected function setUp(): void
7852
{
7953
$this->objectManager = Bootstrap::getObjectManager();
8054
$this->graphQlResolverCache = $this->objectManager->get(GraphQlResolverCache::class);
8155
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
82-
$this->integrationService = $this->objectManager->get(IntegrationServiceInterface::class);
83-
$filesystem = $this->objectManager->get(Filesystem::class);
84-
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
8556

8657
parent::setUp();
8758
}
8859

89-
protected function tearDown(): void
90-
{
91-
foreach ($this->filesToRemove as $fileToRemove) {
92-
$this->mediaDirectory->delete($fileToRemove);
93-
}
94-
95-
$this->mediaDirectory->delete('import/images');
96-
97-
parent::tearDown();
98-
}
99-
10060
#[
10161
DataFixture(ProductFixture::class, ['sku' => 'product1', 'media_gallery_entries' => [[]]], as: 'product'),
10262
]
@@ -454,168 +414,6 @@ public function testCacheIsInvalidatedOnProductDeletion()
454414
$this->assertMediaGalleryResolverCacheRecordDoesNotExist($product);
455415
}
456416

457-
#[
458-
DataFixture(ProductFixture::class, ['sku' => 'product1', 'media_gallery_entries' => [[]]], as: 'product'),
459-
]
460-
public function testCacheIsInvalidatedWhenUpdatingMediaGalleryEntriesOnAProductViaImport()
461-
{
462-
// first, create an integration so that cache is not cleared in
463-
// Magento\TestFramework\Authentication\OauthHelper::_createIntegration before making the API call
464-
$integration = $this->getOauthIntegration();
465-
466-
$product = $this->productRepository->get('product1');
467-
468-
$this->assertCount(
469-
1,
470-
$product->getMediaGalleryEntries()
471-
);
472-
473-
$query = $this->getProductWithMediaGalleryQuery($product);
474-
$response = $this->graphQlQuery($query);
475-
476-
$this->assertCount(
477-
1,
478-
$response['products']['items'][0]['media_gallery']
479-
);
480-
481-
$this->assertMediaGalleryResolverCacheRecordExists($product);
482-
483-
$serviceInfo = [
484-
'rest' => [
485-
'resourcePath' => '/V1/import/csv',
486-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
487-
],
488-
];
489-
490-
// move test image into media directory
491-
$destinationDir = $this->mediaDirectory->getAbsolutePath() . 'import/images';
492-
493-
$this->mediaDirectory->create($destinationDir);
494-
495-
$sourcePathname = dirname(__FILE__) . '/../../_files/magento_image.jpg';
496-
$destinationFilePathname = $this->mediaDirectory->getAbsolutePath("$destinationDir/magento_image.jpg");
497-
498-
$this->mediaDirectory->getDriver()->filePutContents(
499-
$destinationFilePathname,
500-
file_get_contents($sourcePathname)
501-
);
502-
503-
// add file to list of files to remove after test finishes
504-
$this->filesToRemove[] = $destinationFilePathname;
505-
506-
$requestData = [
507-
'source' => [
508-
'entity' => 'catalog_product',
509-
'behavior' => 'append',
510-
'validationStrategy' => 'validation-stop-on-errors',
511-
'allowedErrorCount' => '10',
512-
Import::FIELD_NAME_IMG_FILE_DIR => $destinationDir,
513-
'csvData' => base64_encode("sku,base_image\nproduct1,magento_image.jpg\n"),
514-
],
515-
];
516-
517-
$response = $this->_webApiCall($serviceInfo, $requestData, 'rest', null, $integration);
518-
519-
$this->assertEquals(
520-
'Entities Processed: 1',
521-
$response[0]
522-
);
523-
524-
// assert product has updated media gallery entry count
525-
$this->productRepository->cleanCache();
526-
$updatedProduct = $this->productRepository->get('product1');
527-
$this->assertCount(
528-
2,
529-
$updatedProduct->getMediaGalleryEntries()
530-
);
531-
532-
// assert media gallery resolver cache is invalidated
533-
$this->assertMediaGalleryResolverCacheRecordDoesNotExist($product);
534-
}
535-
536-
#[
537-
DataFixture(ProductFixture::class, ['sku' => 'product1', 'media_gallery_entries' => [[]]], as: 'product'),
538-
]
539-
public function testCacheIsNotInvalidatedWhenUpdatingProductSpecificAttributeViaImport()
540-
{
541-
// first, create an integration so that cache is not cleared in
542-
// Magento\TestFramework\Authentication\OauthHelper::_createIntegration before making the API call
543-
$integration = $this->getOauthIntegration();
544-
545-
$product = $this->productRepository->get('product1');
546-
547-
$this->assertCount(
548-
1,
549-
$product->getMediaGalleryEntries()
550-
);
551-
552-
$query = $this->getProductWithMediaGalleryQuery($product);
553-
$response = $this->graphQlQuery($query);
554-
555-
$this->assertCount(
556-
1,
557-
$response['products']['items'][0]['media_gallery']
558-
);
559-
560-
$this->assertMediaGalleryResolverCacheRecordExists($product);
561-
562-
$serviceInfo = [
563-
'rest' => [
564-
'resourcePath' => '/V1/import/csv',
565-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
566-
],
567-
];
568-
569-
$requestData = [
570-
'source' => [
571-
'entity' => 'catalog_product',
572-
'behavior' => 'append',
573-
'validationStrategy' => 'validation-stop-on-errors',
574-
'allowedErrorCount' => '10',
575-
'csvData' => base64_encode("sku,name\nproduct1,NEW_NAME\n"),
576-
],
577-
];
578-
579-
$response = $this->_webApiCall($serviceInfo, $requestData, 'rest', null, $integration);
580-
581-
$this->assertEquals(
582-
'Entities Processed: 1',
583-
$response[0]
584-
);
585-
586-
// assert product has updated media gallery entry count
587-
$this->productRepository->cleanCache();
588-
$updatedProduct = $this->productRepository->get('product1');
589-
590-
$this->assertEquals(
591-
'NEW_NAME',
592-
$updatedProduct->getName()
593-
);
594-
595-
// assert media gallery resolver cache is NOT invalidated
596-
$this->assertMediaGalleryResolverCacheRecordExists($product);
597-
}
598-
599-
/**
600-
*
601-
* @return Integration
602-
* @throws \Magento\Framework\Exception\IntegrationException
603-
*/
604-
private function getOauthIntegration(): Integration
605-
{
606-
if (!isset($this->integration)) {
607-
$params = [
608-
'all_resources' => true,
609-
'status' => Integration::STATUS_ACTIVE,
610-
'name' => 'Integration' . microtime()
611-
];
612-
613-
$this->integration = $this->integrationService->create($params);
614-
}
615-
616-
return $this->integration;
617-
}
618-
619417
/**
620418
* Assert that media gallery cache record exists for the $product.
621419
*
Binary file not shown.

0 commit comments

Comments
 (0)