9
9
10
10
use Magento \Cms \Model \GetPageByIdentifier ;
11
11
use Magento \Framework \App \Request \Http ;
12
- use Magento \Framework \EntityManager \MetadataPool ;
13
- use Magento \Framework \Serialize \SerializerInterface ;
14
- use Magento \TestFramework \Helper \Bootstrap ;
15
12
use Magento \GraphQl \Controller \GraphQl ;
13
+ use Magento \GraphQlCache \Controller \AbstractGraphqlCacheTest ;
16
14
17
15
/**
18
16
* Test caching works for CMS page
19
17
*
20
18
* @magentoAppArea graphql
21
- * @magentoDbIsolation disabled
19
+ * @magentoCache full_page enabled
22
20
*/
23
- class CmsPageCacheTest extends \ Magento \ TestFramework \ Indexer \TestCase
21
+ class CmsPageCacheTest extends AbstractGraphqlCacheTest
24
22
{
25
- const CONTENT_TYPE = 'application/json ' ;
26
-
27
- /** @var \Magento\Framework\ObjectManagerInterface */
28
- private $ objectManager ;
29
-
30
- /** @var GraphQl */
31
- private $ graphql ;
32
-
33
- /** @var SerializerInterface */
34
- private $ jsonSerializer ;
35
-
36
- /** @var MetadataPool */
37
- private $ metadataPool ;
38
-
39
- /** @var Http */
40
- private $ request ;
41
-
42
23
/**
43
- * @inheritdoc
24
+ * @var GraphQl
44
25
*/
45
- public static function setUpBeforeClass ()
46
- {
47
- $ db = Bootstrap::getInstance ()->getBootstrap ()
48
- ->getApplication ()
49
- ->getDbInstance ();
50
- if (!$ db ->isDbDumpExists ()) {
51
- throw new \LogicException ('DB dump does not exist. ' );
52
- }
53
- $ db ->restoreFromDbDump ();
26
+ private $ graphqlController ;
54
27
55
- parent ::setUpBeforeClass ();
56
- }
28
+ /**
29
+ * @var Http
30
+ */
31
+ private $ request ;
57
32
58
33
/**
59
34
* @inheritdoc
60
35
*/
61
36
protected function setUp (): void
62
37
{
63
- $ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
64
- $ this ->graphql = $ this ->objectManager ->get (\Magento \GraphQl \Controller \GraphQl::class);
65
- $ this ->jsonSerializer = $ this ->objectManager ->get (SerializerInterface::class);
66
- $ this ->metadataPool = $ this ->objectManager ->get (MetadataPool::class);
67
- $ this ->request = $ this ->objectManager ->get (Http::class);
38
+ parent ::setUp ();
39
+ $ this ->graphqlController = $ this ->objectManager ->get (\Magento \GraphQl \Controller \GraphQl::class);
40
+ $ this ->request = $ this ->objectManager ->create (Http::class);
68
41
}
42
+
69
43
/**
70
- * Test cache tags and debug header for category and querying only cms page
44
+ * Test that the correct cache tags get added to request for cmsPage query
71
45
*
72
- * @magentoCache all enabled
73
46
* @magentoDataFixture Magento/Cms/_files/pages.php
74
47
*/
75
- public function testDispatchWithGetForCacheDebugHeadersAndCacheTagsForCmsPage (): void
48
+ public function testToCheckCmsPageRequestCacheTags (): void
76
49
{
77
50
$ cmsPage = $ this ->objectManager ->get (GetPageByIdentifier::class)->execute ('page100 ' , 0 );
78
51
$ pageId = $ cmsPage ->getId ();
@@ -92,20 +65,18 @@ public function testDispatchWithGetForCacheDebugHeadersAndCacheTagsForCmsPage():
92
65
}
93
66
}
94
67
QUERY ;
68
+
95
69
$ this ->request ->setPathInfo ('/graphql ' );
96
70
$ this ->request ->setMethod ('GET ' );
97
71
$ this ->request ->setQueryValue ('query ' , $ query );
98
72
/** @var \Magento\Framework\Controller\Result\Json $result */
99
- $ result = $ this ->graphql ->dispatch ($ this ->request );
73
+ $ result = $ this ->graphqlController ->dispatch ($ this ->request );
100
74
/** @var \Magento\Framework\App\Response\Http $response */
101
75
$ response = $ this ->objectManager ->get (\Magento \Framework \App \Response \Http::class);
102
- /** @var $registry \Magento\Framework\Registry */
103
- $ registry = $ this ->objectManager ->get (\Magento \Framework \Registry::class);
104
- $ registry ->register ('use_page_cache_plugin ' , true , true );
105
76
$ result ->renderResult ($ response );
106
77
$ this ->assertEquals ('MISS ' , $ response ->getHeader ('X-Magento-Cache-Debug ' )->getFieldValue ());
107
- $ actualCacheTags = explode (', ' , $ response ->getHeader ('X-Magento-Tags ' )->getFieldValue ());
78
+ $ requestedCacheTags = explode (', ' , $ response ->getHeader ('X-Magento-Tags ' )->getFieldValue ());
108
79
$ expectedCacheTags = ['cms_p ' , 'cms_p_ ' .$ pageId , 'FPC ' ];
109
- $ this ->assertEquals ($ expectedCacheTags , $ actualCacheTags );
80
+ $ this ->assertEquals ($ expectedCacheTags , $ requestedCacheTags );
110
81
}
111
82
}
0 commit comments