10
10
use Magento \Catalog \Api \ProductRepositoryInterface ;
11
11
use Magento \Catalog \Model \Product ;
12
12
use Magento \TestFramework \ObjectManager ;
13
- use Magento \TestFramework \App \State ;
14
- use Magento \TestFramework \Helper \Bootstrap ;
15
13
use Magento \TestFramework \TestCase \GraphQlAbstract ;
16
14
17
- /**
18
- * Class CacheTagTest
19
- */
20
15
/**
21
16
* Test the caching works properly for products and categories
22
17
*/
23
18
class CacheTagTest extends GraphQlAbstract
24
19
{
20
+
25
21
/**
26
- * Tests if Magento cache tags and debug headers for products are generated properly
27
- * @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
22
+ * @inheritdoc
28
23
*/
29
- public function testCacheTagsAndCacheDebugHeaderForProducts ()
24
+ protected function setUp ()
30
25
{
31
26
$ this ->markTestSkipped (
32
27
'This test will stay skipped until DEVOPS-4924 is resolved '
33
28
);
29
+ }
34
30
31
+ /**
32
+ * Tests if Magento cache tags and debug headers for products are generated properly
33
+ *
34
+ * @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
35
+ */
36
+ public function testCacheTagsAndCacheDebugHeaderForProducts ()
37
+ {
35
38
$ productSku ='simple2 ' ;
36
39
$ query
37
40
= <<<QUERY
@@ -75,70 +78,25 @@ public function testCacheTagsAndCacheDebugHeaderForProducts()
75
78
}
76
79
77
80
/**
78
- * Tests if Magento cache tags for categories are generated properly. Also tests the use case for cache invalidation
81
+ * Tests if X- Magento-Tags for categories are generated properly. Also tests the use case for cache invalidation
79
82
*
80
83
* @magentoApiDataFixture Magento/Catalog/_files/product_in_multiple_categories.php
81
84
*/
82
- public function testCacheTagFromResponseHeaderForCategoriesWithProduct ()
85
+ public function testCacheTagForCategoriesWithProduct ()
83
86
{
84
- $ this ->markTestSkipped (
85
- 'This test will stay skipped until DEVOPS-4924 is resolved '
86
- );
87
87
$ firstProductSku = 'simple333 ' ;
88
88
$ secondProductSku = 'simple444 ' ;
89
89
$ categoryId ='4 ' ;
90
- $ categoryQuery
91
- = <<<'QUERY'
92
- query GetCategoryQuery($id: Int!, $pageSize: Int!, $currentPage: Int!) {
93
- category(id: $id) {
94
- id
95
- description
96
- name
97
- product_count
98
- products(pageSize: $pageSize, currentPage: $currentPage) {
99
- items {
100
- id
101
- name
102
- url_key
103
- }
104
- total_count
105
- }
106
- }
107
- }
108
- QUERY;
90
+
109
91
$ variables =[
110
- 'id ' => 4 ,
92
+ 'id ' => $ categoryId ,
111
93
'pageSize ' => 10 ,
112
94
'currentPage ' => 1
113
95
];
114
96
115
- $ product1Query
116
- = <<<QUERY
117
- {
118
- products(filter: {sku: {eq: " {$ firstProductSku }"}})
119
- {
120
- items {
121
- id
122
- name
123
- sku
124
- }
125
- }
126
- }
127
- QUERY ;
128
- $ product2Query
129
- = <<<QUERY
130
- {
131
- products(filter: {sku: {eq: " {$ secondProductSku }"}})
132
- {
133
- items {
134
- id
135
- name
136
- sku
137
- }
138
- }
139
- }
140
- QUERY ;
141
-
97
+ $ product1Query = $ this ->getProductQuery ($ firstProductSku );
98
+ $ product2Query =$ this ->getProductQuery ($ secondProductSku );
99
+ $ categoryQuery = $ this ->getCategoryQuery ();
142
100
$ responseMissHeaders = $ this ->graphQlQueryForHttpHeaders ($ categoryQuery , $ variables );
143
101
144
102
/** cache-debug header value should be a MISS when category is loaded first time */
@@ -155,10 +113,12 @@ public function testCacheTagFromResponseHeaderForCategoriesWithProduct()
155
113
preg_match ('/X-Magento-Tags: (.*?)\n/ ' , $ responseMissHeaders , $ headerCacheTags );
156
114
$ actualCacheTags = explode (', ' , rtrim ($ headerCacheTags [1 ], "\r" ));
157
115
$ expectedCacheTags =
158
- ['cat_c ' ,'cat_c_ ' . $ categoryId ,'cat_p ' ,'cat_p_ ' . $ firstProduct ->getId (),'cat_p_ ' .$ secondProduct ->getId (),'FPC ' ];
116
+ ['cat_c ' ,'cat_c_ ' . $ categoryId ,'cat_p ' ,'cat_p_ ' . $ firstProduct ->getId (),
117
+ 'cat_p_ ' .$ secondProduct ->getId (),'FPC '
118
+ ];
159
119
$ this ->assertEquals ($ expectedCacheTags , $ actualCacheTags );
160
120
161
- // Cach-debug header should be a MISS for product 1 during first load
121
+ // Cach-debug header should be a MISS for product 1 on first request
162
122
$ responseHeadersFirstProduct = $ this ->graphQlQueryForHttpHeaders ($ product1Query );
163
123
$ this ->assertContains ('X-Magento-Cache-Debug: MISS ' , $ responseHeadersFirstProduct );
164
124
@@ -181,4 +141,56 @@ public function testCacheTagFromResponseHeaderForCategoriesWithProduct()
181
141
$ responseHeadersSecondProduct = $ this ->graphQlQueryForHttpHeaders ($ product2Query );
182
142
$ this ->assertContains ('X-Magento-Cache-Debug: HIT ' , $ responseHeadersSecondProduct );
183
143
}
144
+
145
+ /**
146
+ * Get Product query
147
+ *
148
+ * @param string $productSku
149
+ * @return string
150
+ */
151
+ private function getProductQuery (string $ productSku ): string
152
+ {
153
+ $ productQuery = <<<QUERY
154
+ {
155
+ products(filter: {sku: {eq: " {$ productSku }"}})
156
+ {
157
+ items {
158
+ id
159
+ name
160
+ sku
161
+ }
162
+ }
163
+ }
164
+ QUERY ;
165
+ return $ productQuery ;
166
+ }
167
+
168
+ /**
169
+ * Get category query
170
+ *
171
+ * @return string
172
+ */
173
+ private function getCategoryQuery (): string
174
+ {
175
+ $ categoryQueryString = <<<QUERY
176
+ query GetCategoryQuery( \$id: Int!, \$pageSize: Int!, \$currentPage: Int!) {
177
+ category(id: \$id) {
178
+ id
179
+ description
180
+ name
181
+ product_count
182
+ products(pageSize: \$pageSize, currentPage: \$currentPage) {
183
+ items {
184
+ id
185
+ name
186
+ url_key
187
+ }
188
+ total_count
189
+ }
190
+ }
191
+ }
192
+ QUERY ;
193
+
194
+ return $ categoryQueryString ;
195
+ }
184
196
}
0 commit comments