Skip to content

Commit 26a44ca

Browse files
committed
B2B-2677: [MediaGallery]Implement data caching for GraphQL results on resolver level
- Fix integration creation creating improper ACL for REST call
1 parent 3564158 commit 26a44ca

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

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

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\Calculator\ProviderInterface;
2727
use Magento\GraphQlResolverCache\Model\Resolver\Result\Type as GraphQlResolverCache;
2828
use Magento\ImportExport\Model\Import;
29+
use Magento\Integration\Api\IntegrationServiceInterface;
2930
use Magento\Integration\Model\Integration;
3031
use Magento\Framework\Filesystem;
3132
use Magento\TestFramework\Fixture\DataFixture;
@@ -53,6 +54,16 @@ class MediaGalleryTest extends ResolverCacheAbstract
5354
*/
5455
private $graphQlResolverCache;
5556

57+
/**
58+
* @var IntegrationServiceInterface
59+
*/
60+
private $integrationService;
61+
62+
/**
63+
* @var Integration
64+
*/
65+
private $integration;
66+
5667
/**
5768
* @var DirectoryWriteInterface
5869
*/
@@ -68,6 +79,7 @@ protected function setUp(): void
6879
$this->objectManager = Bootstrap::getObjectManager();
6980
$this->graphQlResolverCache = $this->objectManager->get(GraphQlResolverCache::class);
7081
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
82+
$this->integrationService = $this->objectManager->get(IntegrationServiceInterface::class);
7183
$filesystem = $this->objectManager->get(Filesystem::class);
7284
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
7385

@@ -449,7 +461,7 @@ public function testCacheIsInvalidatedWhenUpdatingMediaGalleryEntriesOnAProductV
449461
{
450462
// first, create an integration so that cache is not cleared in
451463
// Magento\TestFramework\Authentication\OauthHelper::_createIntegration before making the API call
452-
$integration = $this->createNewOauthIntegration();
464+
$integration = $this->getOauthIntegration();
453465

454466
$product = $this->productRepository->get('product1');
455467

@@ -476,7 +488,7 @@ public function testCacheIsInvalidatedWhenUpdatingMediaGalleryEntriesOnAProductV
476488
];
477489

478490
// move test image into media directory
479-
$destinationDir = $this->mediaDirectory->getAbsolutePath() . '/import/images';
491+
$destinationDir = $this->mediaDirectory->getAbsolutePath() . 'import/images';
480492

481493
$this->mediaDirectory->create($destinationDir);
482494

@@ -528,7 +540,7 @@ public function testCacheIsNotInvalidatedWhenUpdatingProductSpecificAttributeVia
528540
{
529541
// first, create an integration so that cache is not cleared in
530542
// Magento\TestFramework\Authentication\OauthHelper::_createIntegration before making the API call
531-
$integration = $this->createNewOauthIntegration();
543+
$integration = $this->getOauthIntegration();
532544

533545
$product = $this->productRepository->get('product1');
534546

@@ -589,19 +601,19 @@ public function testCacheIsNotInvalidatedWhenUpdatingProductSpecificAttributeVia
589601
* @return Integration
590602
* @throws \Magento\Framework\Exception\IntegrationException
591603
*/
592-
private function createNewOauthIntegration(): Integration
604+
private function getOauthIntegration(): Integration
593605
{
594-
/** @var $integrationService \Magento\Integration\Api\IntegrationServiceInterface */
595-
$integrationService = $this->objectManager->get(\Magento\Integration\Api\IntegrationServiceInterface::class);
596-
597-
$params = [
598-
'all_resources' => true,
599-
'integration_id' => 1,
600-
'status' => Integration::STATUS_ACTIVE,
601-
'name' => 'Integration' . microtime()
602-
];
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+
}
603615

604-
return $integrationService->create($params);
616+
return $this->integration;
605617
}
606618

607619
/**

0 commit comments

Comments
 (0)