Skip to content

Commit bf84115

Browse files
committed
Issue-230: Implement cache tag generation for GraphQL queries
- Integration tests
1 parent 4f59766 commit bf84115

File tree

2 files changed

+46
-41
lines changed

2 files changed

+46
-41
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQlCache\Controller;
9+
10+
use PHPUnit\Framework\TestCase;
11+
use Magento\TestFramework\ObjectManager;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
/**
15+
* Abstract test class for Graphql cache tests
16+
*/
17+
class AbstractGraphqlCacheTest extends TestCase
18+
{
19+
/**
20+
* @var ObjectManager
21+
*/
22+
protected $objectManager;
23+
24+
/**
25+
* @inheritdoc
26+
*/
27+
protected function setUp(): void
28+
{
29+
$this->objectManager = Bootstrap::getObjectManager();
30+
$this->usePageCachePlugin();
31+
}
32+
33+
/**
34+
* Enable full page cache plugin
35+
*/
36+
protected function usePageCachePlugin(): void
37+
{
38+
/** @var $registry \Magento\Framework\Registry */
39+
$registry = $this->objectManager->get(\Magento\Framework\Registry::class);
40+
$registry->register('use_page_cache_plugin', true, true);
41+
}
42+
}

dev/tests/integration/testsuite/Magento/GraphQlCache/Controller/Cms/BlockCacheTest.php

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,16 @@
1010
use Magento\Cms\Model\BlockRepository;
1111
use Magento\Framework\App\Request\Http;
1212
use Magento\GraphQl\Controller\GraphQl;
13-
use Magento\TestFramework\ObjectManager;
14-
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\GraphQlCache\Controller\AbstractGraphqlCacheTest;
1514

1615
/**
1716
* Test caching works for CMS blocks
1817
*
1918
* @magentoAppArea graphql
20-
* @magentoDbIsolation disabled
19+
* @magentoCache full_page enabled
2120
*/
22-
class BlockCacheTest extends \Magento\TestFramework\Indexer\TestCase
21+
class BlockCacheTest extends AbstractGraphqlCacheTest
2322
{
24-
/**
25-
* @var ObjectManager
26-
*/
27-
private $objectManager;
28-
2923
/**
3024
* @var GraphQl
3125
*/
@@ -36,31 +30,14 @@ class BlockCacheTest extends \Magento\TestFramework\Indexer\TestCase
3630
*/
3731
private $request;
3832

39-
/**
40-
* @inheritdoc
41-
*/
42-
public static function setUpBeforeClass()
43-
{
44-
$db = Bootstrap::getInstance()->getBootstrap()
45-
->getApplication()
46-
->getDbInstance();
47-
if (!$db->isDbDumpExists()) {
48-
throw new \LogicException('DB dump does not exist.');
49-
}
50-
$db->restoreFromDbDump();
51-
52-
parent::setUpBeforeClass();
53-
}
54-
5533
/**
5634
* @inheritdoc
5735
*/
5836
protected function setUp(): void
5937
{
60-
$this->objectManager = Bootstrap::getObjectManager();
38+
parent::setUp();
6139
$this->graphqlController = $this->objectManager->get(\Magento\GraphQl\Controller\GraphQl::class);
6240
$this->request = $this->objectManager->create(Http::class);
63-
$this->enableFullPageCache();
6441
}
6542

6643
/**
@@ -103,18 +80,4 @@ public function testCmsBlocksRequestHasCorrectTags(): void
10380
$this->assertContains($expectedCacheTag, $actualCacheTags);
10481
}
10582
}
106-
107-
/**
108-
* Enable full page cache so plugins are called
109-
*/
110-
private function enableFullPageCache()
111-
{
112-
/** @var $registry \Magento\Framework\Registry */
113-
$registry = $this->objectManager->get(\Magento\Framework\Registry::class);
114-
$registry->register('use_page_cache_plugin', true, true);
115-
116-
/** @var \Magento\Framework\App\Cache\StateInterface $cacheState */
117-
$cacheState = $this->objectManager->get(\Magento\Framework\App\Cache\StateInterface::class);
118-
$cacheState->setEnabled(\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER, true);
119-
}
12083
}

0 commit comments

Comments
 (0)