Skip to content

Commit 1dab149

Browse files
committed
B2B-2259: customAttributeMetadata GraphQl query has no cache identity
- attribute uniqueness coverage by entity type
1 parent b14a188 commit 1dab149

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Eav/CustomAttributesMetadataCacheTest.php

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
namespace Magento\GraphQl\Eav;
99

10+
use Magento\Eav\Model\AttributeRepository;
1011
use Magento\GraphQl\PageCache\GraphQLPageCacheAbstract;
12+
use Magento\Store\Model\StoreRepository;
1113
use Magento\TestFramework\Helper\Bootstrap;
1214

1315
class CustomAttributesMetadataCacheTest extends GraphQLPageCacheAbstract
@@ -17,6 +19,9 @@ class CustomAttributesMetadataCacheTest extends GraphQLPageCacheAbstract
1719
*/
1820
private $objectManager;
1921

22+
/**
23+
* @inheritdoc
24+
*/
2025
public function setUp(): void
2126
{
2227
$this->objectManager = Bootstrap::getObjectManager();
@@ -64,10 +69,10 @@ public function testCacheHitMiss()
6469
public function testCacheDifferentStores()
6570
{
6671
$query = $this->getAttributeQuery("dropdown_attribute", "catalog_product");
67-
/** @var \Magento\Eav\Model\AttributeRepository $eavAttributeRepo */
68-
$eavAttributeRepo = $this->objectManager->get(\Magento\Eav\Model\AttributeRepository::class);
69-
/** @var \Magento\Store\Model\StoreRepository $storeRepo */
70-
$storeRepo = $this->objectManager->get(\Magento\Store\Model\StoreRepository::class);
72+
/** @var AttributeRepository $eavAttributeRepo */
73+
$eavAttributeRepo = $this->objectManager->get(AttributeRepository::class);
74+
/** @var StoreRepository $storeRepo */
75+
$storeRepo = $this->objectManager->get(StoreRepository::class);
7176

7277
$stores = $storeRepo->getList();
7378
$attribute = $eavAttributeRepo->get("catalog_product", "dropdown_attribute");
@@ -151,8 +156,8 @@ public function testCacheInvalidation()
151156
);
152157
// assert cache hit on second query
153158
$this->assertCacheHitAndReturnResponse($query, []);
154-
/** @var \Magento\Eav\Model\AttributeRepository $eavAttributeRepo */
155-
$eavAttributeRepo = $this->objectManager->get(\Magento\Eav\Model\AttributeRepository::class);
159+
/** @var AttributeRepository $eavAttributeRepo */
160+
$eavAttributeRepo = $this->objectManager->get(AttributeRepository::class);
156161
$attribute = $eavAttributeRepo->get("catalog_product", "dropdown_attribute");
157162
$attribute->setIsRequired(1);
158163
$eavAttributeRepo->save($attribute);
@@ -171,6 +176,37 @@ public function testCacheInvalidation()
171176
);
172177
}
173178

179+
/**
180+
* Test cache invalidation when queried for attribute data of different entity types.
181+
* Required for GraphQL FPC use-case since there is no attribute ID provided in the result.
182+
*
183+
* @magentoApiDataFixture Magento/Catalog/_files/dropdown_attribute.php
184+
* @magentoConfigFixture default/system/full_page_cache/caching_application 2
185+
*
186+
* @return void
187+
*/
188+
public function testCacheInvalidationMultiEntitySameCode()
189+
{
190+
$queryProduct = $this->getAttributeQuery("name", "catalog_product");
191+
$queryCategory = $this->getAttributeQuery("name", "catalog_category");
192+
// precache both product and category response
193+
$this->assertCacheMissAndReturnResponse($queryProduct, []);
194+
$this->assertCacheMissAndReturnResponse($queryCategory, []);
195+
$eavAttributeRepo = $this->objectManager->get(AttributeRepository::class);
196+
$attribute = $eavAttributeRepo->get("catalog_product", "name");
197+
$eavAttributeRepo->save($attribute);
198+
// assert that product is invalidated for the same code but category is not touched
199+
$this->assertCacheMissAndReturnResponse($queryProduct, []);
200+
$this->assertCacheHitAndReturnResponse($queryCategory, []);
201+
}
202+
203+
/**
204+
* Prepare and return GraphQL query for given entity type and code.
205+
*
206+
* @param string $code
207+
* @param string $entityType
208+
* @return string
209+
*/
174210
private function getAttributeQuery(string $code, string $entityType) : string
175211
{
176212
return <<<QUERY

0 commit comments

Comments
 (0)