7
7
8
8
namespace Magento \GraphQl \Eav ;
9
9
10
+ use Magento \Eav \Model \AttributeRepository ;
10
11
use Magento \GraphQl \PageCache \GraphQLPageCacheAbstract ;
12
+ use Magento \Store \Model \StoreRepository ;
11
13
use Magento \TestFramework \Helper \Bootstrap ;
12
14
13
15
class CustomAttributesMetadataCacheTest extends GraphQLPageCacheAbstract
@@ -17,6 +19,9 @@ class CustomAttributesMetadataCacheTest extends GraphQLPageCacheAbstract
17
19
*/
18
20
private $ objectManager ;
19
21
22
+ /**
23
+ * @inheritdoc
24
+ */
20
25
public function setUp (): void
21
26
{
22
27
$ this ->objectManager = Bootstrap::getObjectManager ();
@@ -64,10 +69,10 @@ public function testCacheHitMiss()
64
69
public function testCacheDifferentStores ()
65
70
{
66
71
$ 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);
71
76
72
77
$ stores = $ storeRepo ->getList ();
73
78
$ attribute = $ eavAttributeRepo ->get ("catalog_product " , "dropdown_attribute " );
@@ -151,8 +156,8 @@ public function testCacheInvalidation()
151
156
);
152
157
// assert cache hit on second query
153
158
$ 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);
156
161
$ attribute = $ eavAttributeRepo ->get ("catalog_product " , "dropdown_attribute " );
157
162
$ attribute ->setIsRequired (1 );
158
163
$ eavAttributeRepo ->save ($ attribute );
@@ -171,6 +176,37 @@ public function testCacheInvalidation()
171
176
);
172
177
}
173
178
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
+ */
174
210
private function getAttributeQuery (string $ code , string $ entityType ) : string
175
211
{
176
212
return <<<QUERY
0 commit comments