Skip to content

Commit 507c2d5

Browse files
committed
B2B-2677: [MediaGallery]Implement data caching for GraphQL results on resolver level
- Add testCacheIsNotInvalidatedWhenUpdatingProductSpecificAttributeViaImport (should pass)
1 parent 512447f commit 507c2d5

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Magento\Framework\ObjectManagerInterface;
2424
use Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\Calculator\ProviderInterface;
2525
use Magento\GraphQlResolverCache\Model\Resolver\Result\Type as GraphQlResolverCache;
26+
use Magento\Integration\Model\Integration;
2627
use Magento\TestFramework\Fixture\DataFixture;
2728
use Magento\TestFramework\Helper\Bootstrap;
2829
use Magento\TestFramework\TestCase\GraphQl\ResolverCacheAbstract;
@@ -414,6 +415,80 @@ public function testCacheIsInvalidatedOnProductDeletion()
414415
$this->assertMediaGalleryResolverCacheRecordDoesNotExist($product);
415416
}
416417

418+
#[
419+
DataFixture(ProductFixture::class, ['sku' => 'product1', 'media_gallery_entries' => [[]]], as: 'product'),
420+
]
421+
public function testCacheIsNotInvalidatedWhenUpdatingProductSpecificAttributeViaImport()
422+
{
423+
// first, create an integration so that cache is not cleared in
424+
// Magento\TestFramework\Authentication\OauthHelper::_createIntegration before making the API call
425+
/** @var $integrationService \Magento\Integration\Api\IntegrationServiceInterface */
426+
$integrationService = $this->objectManager->get(\Magento\Integration\Api\IntegrationServiceInterface::class);
427+
428+
$params = [
429+
'all_resources' => true,
430+
'integration_id' => 1,
431+
'status' => Integration::STATUS_ACTIVE,
432+
'name' => 'Integration' . microtime()
433+
];
434+
435+
$integration = $integrationService->create($params);
436+
$integration->setStatus(\Magento\Integration\Model\Integration::STATUS_ACTIVE)->save();
437+
438+
$product = $this->productRepository->get('product1');
439+
440+
$this->assertCount(
441+
1,
442+
$product->getMediaGalleryEntries()
443+
);
444+
445+
$query = $this->getProductWithMediaGalleryQuery($product);
446+
$response = $this->graphQlQuery($query);
447+
448+
$this->assertCount(
449+
1,
450+
$response['products']['items'][0]['media_gallery']
451+
);
452+
453+
$this->assertMediaGalleryResolverCacheRecordExists($product);
454+
455+
$serviceInfo = [
456+
'rest' => [
457+
'resourcePath' => '/V1/import/csv',
458+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
459+
],
460+
];
461+
462+
$requestData = [
463+
'source' => [
464+
'entity' => 'catalog_product',
465+
'behavior' => 'append',
466+
'validationStrategy' => 'validation-stop-on-errors',
467+
'allowedErrorCount' => '10',
468+
'csvData' => base64_encode("sku,name\nproduct1,NEW_NAME\n"),
469+
],
470+
];
471+
472+
$response = $this->_webApiCall($serviceInfo, $requestData, 'rest', null, $integration);
473+
474+
$this->assertEquals(
475+
'Entities Processed: 1',
476+
$response[0]
477+
);
478+
479+
// assert product has updated media gallery entry count
480+
$this->productRepository->cleanCache();
481+
$updatedProduct = $this->productRepository->get('product1');
482+
483+
$this->assertEquals(
484+
'NEW_NAME',
485+
$updatedProduct->getName()
486+
);
487+
488+
// assert media gallery resolver cache is NOT invalidated
489+
$this->assertMediaGalleryResolverCacheRecordExists($product);
490+
}
491+
417492
/**
418493
* Assert that media gallery cache record exists for the $product.
419494
*

0 commit comments

Comments
 (0)