|
11 | 11 | use Magento\GraphQl\PageCache\GraphQLPageCacheAbstract; |
12 | 12 | use Magento\Store\Model\StoreRepository; |
13 | 13 | use Magento\TestFramework\Helper\Bootstrap; |
| 14 | +use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException; |
14 | 15 |
|
15 | 16 | class CustomAttributesMetadataCacheTest extends GraphQLPageCacheAbstract |
16 | 17 | { |
@@ -176,6 +177,55 @@ public function testCacheInvalidation() |
176 | 177 | ); |
177 | 178 | } |
178 | 179 |
|
| 180 | + /** |
| 181 | + * @magentoApiDataFixture Magento/Catalog/_files/dropdown_attribute.php |
| 182 | + * @magentoConfigFixture default/system/full_page_cache/caching_application 2 |
| 183 | + * |
| 184 | + * @return void |
| 185 | + */ |
| 186 | + public function testCacheInvalidationOnAttributeDelete() |
| 187 | + { |
| 188 | + $query = $this->getAttributeQuery("dropdown_attribute", "catalog_product"); |
| 189 | + // check cache missed on first query |
| 190 | + $response = $this->assertCacheMissAndReturnResponse($query, []); |
| 191 | + $this->assertResponseFields( |
| 192 | + $response['body']['customAttributeMetadata']['items'][0], |
| 193 | + [ |
| 194 | + 'attribute_code' => 'dropdown_attribute', |
| 195 | + 'attribute_type' => 'String', |
| 196 | + 'entity_type' => 'catalog_product', |
| 197 | + 'input_type' => 'select', |
| 198 | + ] |
| 199 | + ); |
| 200 | + // assert cache hit on second query |
| 201 | + $this->assertCacheHitAndReturnResponse($query, []); |
| 202 | + /** @var AttributeRepository $eavAttributeRepo */ |
| 203 | + $eavAttributeRepo = $this->objectManager->get(AttributeRepository::class); |
| 204 | + $attribute = $eavAttributeRepo->get("catalog_product", "dropdown_attribute"); |
| 205 | + $eavAttributeRepo->delete($attribute); |
| 206 | + $caughtException = null; |
| 207 | + try { |
| 208 | + // get response |
| 209 | + $response = $this->graphQlQuery($query, []); |
| 210 | + } catch (ResponseContainsErrorsException $exception) { |
| 211 | + $caughtException = $exception; |
| 212 | + } |
| 213 | + $this->assertInstanceOf( |
| 214 | + ResponseContainsErrorsException::class, |
| 215 | + $caughtException |
| 216 | + ); |
| 217 | + // cannot use expectException because need to assert the headers |
| 218 | + $this->assertStringContainsString( |
| 219 | + "GraphQL response contains errors: Internal server error", |
| 220 | + $caughtException->getMessage() |
| 221 | + ); |
| 222 | + // assert that it's a miss after deletion |
| 223 | + $this->assertEquals( |
| 224 | + $response['headers']['X-Magento-Cache-Debug'], |
| 225 | + 'MISS' |
| 226 | + ); |
| 227 | + } |
| 228 | + |
179 | 229 | /** |
180 | 230 | * Test cache invalidation when queried for attribute data of different entity types. |
181 | 231 | * Required for GraphQL FPC use-case since there is no attribute ID provided in the result. |
|
0 commit comments