assertEquals('MISS', $response->getHeader('X-Magento-Cache-Debug')->getFieldValue()); $this->assertCmsBlockCacheTags($response, $block); } private function assertPageCacheHitWithTagsForCmsBlock(HttpResponse $response, BlockInterface $block): void { $this->assertEquals('HIT', $response->getHeader('X-Magento-Cache-Debug')->getFieldValue()); $this->assertCmsBlockCacheTags($response, $block); } private function assertCmsBlockCacheTags(HttpResponse $response, BlockInterface $block): void { $expectedCacheTags = ['cms_b', 'cms_b_' . $block->getId(), 'cms_b_' . $block->getIdentifier(), 'FPC']; $rawActualCacheTags = $response->getHeader('X-Magento-Tags')->getFieldValue(); $actualCacheTags = explode(',', $rawActualCacheTags); $this->assertEquals($expectedCacheTags, $actualCacheTags); } /** * @magentoDataFixture Magento/Cms/_files/block.php * @magentoDataFixture Magento/Cms/_files/blocks.php */ public function testCmsBlocksRequestHasCorrectTags(): void { /** @var BlockRepository $blockRepository */ $blockRepository = $this->objectManager->get(BlockRepository::class); $block1Identifier = 'fixture_block'; $block1 = $blockRepository->getById($block1Identifier); $block2Identifier = 'enabled_block'; $block2 = $blockRepository->getById($block2Identifier); $queryBlock1 = <<dispatchGraphQlGETRequest(['query' => $queryBlock1]); $this->assertPageCacheMissWithTagsForCmsBlock($response, $block1); // check to see that the second entity gets a MISS when called the first time $response = $this->dispatchGraphQlGETRequest(['query' => $queryBlock2]); $this->assertPageCacheMissWithTagsForCmsBlock($response, $block2); // check to see that the first entity gets a HIT when called the second time $response = $this->dispatchGraphQlGETRequest(['query' => $queryBlock1]); $this->assertPageCacheHitWithTagsForCmsBlock($response, $block1); // check to see that the second entity gets a HIT when called the second time $response = $this->dispatchGraphQlGETRequest(['query' => $queryBlock2]); $this->assertPageCacheHitWithTagsForCmsBlock($response, $block2); $block1->setTitle('something else that causes invalidation'); $blockRepository->save($block1); // check to see that the first entity gets a MISS and it was invalidated $response = $this->dispatchGraphQlGETRequest(['query' => $queryBlock1]); $this->assertPageCacheMissWithTagsForCmsBlock($response, $block1); // check to see that the first entity gets a HIT when called the second time $response = $this->dispatchGraphQlGETRequest(['query' => $queryBlock1]); $this->assertPageCacheHitWithTagsForCmsBlock($response, $block1); } }