@@ -31,9 +31,6 @@ public function testCacheTagsAndCacheDebugHeaderForProducts()
31
31
$ this ->markTestSkipped (
32
32
'This test will stay skipped until DEVOPS-4924 is resolved '
33
33
);
34
- /** @var State $state */
35
- $ state = Bootstrap::getObjectManager ()->get (State::class);
36
- $ state ->setMode (State::MODE_DEVELOPER );
37
34
38
35
$ productSku ='simple2 ' ;
39
36
$ query
@@ -51,14 +48,13 @@ public function testCacheTagsAndCacheDebugHeaderForProducts()
51
48
QUERY ;
52
49
53
50
/** cache-debug should be a MISS when product is queried for first time */
54
- $ responseMissHeaders = $ this ->graphQlQueryForHttpHeaders ($ query , [], '' , []);
55
- preg_match ('/X-Magento-Cache-Debug: (.*?)\n/ ' , $ responseMissHeaders , $ matchesMiss );
56
- $ this ->assertEquals ('MISS ' , rtrim ($ matchesMiss [1 ], "\r" ));
51
+ $ responseMissHeaders = $ this ->graphQlQueryForHttpHeaders ($ query );
52
+ $ this ->assertContains ('X-Magento-Cache-Debug: MISS ' , $ responseMissHeaders );
57
53
58
54
/** cache-debug should be a HIT for the second round */
59
- $ responseHitHeaders = $ this ->graphQlQueryForHttpHeaders ($ query, [], '' , [] );
60
- preg_match ('/X-Magento-Cache-Debug: (.*?)\n/ ' , $ responseHitHeaders , $ matchesHit );
61
- $ this ->assertEquals ( ' HIT ' , rtrim ( $ matchesHit [ 1 ], "\r" ) );
55
+ $ responseHitHeaders = $ this ->graphQlQueryForHttpHeaders ($ query );
56
+ // preg_match('/X-Magento-Cache-Debug: (.*?)\n/', $responseHitHeaders, $matchesHit);
57
+ $ this ->assertContains ( ' X-Magento-Cache-Debug: HIT ' , $ responseHitHeaders );
62
58
63
59
/** @var ProductRepositoryInterface $productRepository */
64
60
$ productRepository = ObjectManager::getInstance ()->get (ProductRepositoryInterface::class);
@@ -68,17 +64,14 @@ public function testCacheTagsAndCacheDebugHeaderForProducts()
68
64
$ product ->setPrice (15 );
69
65
$ product ->save ();
70
66
/** Cache invalidation happens and cache-debug header value is a MISS after product update */
71
- $ responseMissHeaders = $ this ->graphQlQueryForHttpHeaders ($ query , [], '' , []);
72
- preg_match ('/X-Magento-Cache-Debug: (.*?)\n/ ' , $ responseMissHeaders , $ matchesMiss );
73
- $ this ->assertEquals ('MISS ' , rtrim ($ matchesMiss [1 ], "\r" ));
67
+ $ responseMissHeaders = $ this ->graphQlQueryForHttpHeaders ($ query );
68
+ $ this ->assertContains ('X-Magento-Cache-Debug: MISS ' , $ responseMissHeaders );
74
69
75
70
/** checks if cache tags for products are correctly displayed in the response header */
76
71
preg_match ('/X-Magento-Tags: (.*?)\n/ ' , $ responseMissHeaders , $ headerCacheTags );
77
72
$ actualCacheTags = explode (', ' , rtrim ($ headerCacheTags [1 ], "\r" ));
78
73
$ expectedCacheTags =['cat_p ' ,'cat_p_ ' . $ product ->getId (),'FPC ' ];
79
- foreach (array_keys ($ actualCacheTags ) as $ key ) {
80
- $ this ->assertEquals ($ expectedCacheTags [$ key ], $ actualCacheTags [$ key ]);
81
- }
74
+ $ this ->assertEquals ($ expectedCacheTags , $ actualCacheTags );
82
75
}
83
76
84
77
/**
@@ -88,9 +81,9 @@ public function testCacheTagsAndCacheDebugHeaderForProducts()
88
81
*/
89
82
public function testCacheTagFromResponseHeaderForCategoriesWithProduct ()
90
83
{
91
- /* $this->markTestSkipped(
84
+ $ this ->markTestSkipped (
92
85
'This test will stay skipped until DEVOPS-4924 is resolved '
93
- );*/
86
+ );
94
87
$ firstProductSku = 'simple-4 ' ;
95
88
$ secondProductSku = 'simple-5 ' ;
96
89
$ categoryId ='10 ' ;
@@ -146,11 +139,10 @@ public function testCacheTagFromResponseHeaderForCategoriesWithProduct()
146
139
}
147
140
QUERY ;
148
141
149
- $ responseMissHeaders = $ this ->graphQlQueryForHttpHeaders ($ categoryQuery , $ variables, '' , [] );
142
+ $ responseMissHeaders = $ this ->graphQlQueryForHttpHeaders ($ categoryQuery , $ variables );
150
143
151
144
/** cache-debug header value should be a MISS when category is loaded first time */
152
- preg_match ('/X-Magento-Cache-Debug: (.*?)\n/ ' , $ responseMissHeaders , $ matchesMiss );
153
- $ this ->assertEquals ('MISS ' , rtrim ($ matchesMiss [1 ], "\r" ));
145
+ $ this ->assertContains ('X-Magento-Cache-Debug: MISS ' , $ responseMissHeaders );
154
146
155
147
/** @var ProductRepositoryInterface $productRepository */
156
148
$ productRepository = ObjectManager::getInstance ()->get (ProductRepositoryInterface::class);
@@ -165,31 +157,28 @@ public function testCacheTagFromResponseHeaderForCategoriesWithProduct()
165
157
$ expectedCacheTags =
166
158
['cat_c ' ,'cat_c_ ' . $ categoryId ,'cat_p ' ,'cat_p_ ' . $ firstProduct ->getId (),'cat_p_ ' .$ secondProduct ->getId (),'FPC ' ];
167
159
$ this ->assertEquals ($ expectedCacheTags , $ actualCacheTags );
160
+
168
161
// Cach-debug header should be a MISS for product 1 during first load
169
- $ responseHeadersFirstProduct = $ this ->graphQlQueryForHttpHeaders ($ product1Query , [], '' , []);
170
- preg_match ('/X-Magento-Cache-Debug: (.*?)\n/ ' , $ responseHeadersFirstProduct , $ match );
171
- $ this ->assertEquals ('MISS ' , rtrim ($ match [1 ], "\r" ));
162
+ $ responseHeadersFirstProduct = $ this ->graphQlQueryForHttpHeaders ($ product1Query );
163
+ $ this ->assertContains ('X-Magento-Cache-Debug: MISS ' , $ responseHeadersFirstProduct );
172
164
173
165
// Cach-debug header should be a MISS for product 2 during first load
174
- $ responseHeadersSecondProduct = $ this ->graphQlQueryForHttpHeaders ($ product2Query , [], '' , []);
175
- preg_match ('/X-Magento-Cache-Debug: (.*?)\n/ ' , $ responseHeadersSecondProduct , $ match );
176
- $ this ->assertEquals ('MISS ' , rtrim ($ match [1 ], "\r" ));
166
+ $ responseHeadersSecondProduct = $ this ->graphQlQueryForHttpHeaders ($ product2Query );
167
+ $ this ->assertContains ('X-Magento-Cache-Debug: MISS ' , $ responseHeadersSecondProduct );
177
168
178
- /** cache-debug header value should be MISS after updating product1 and reloading the category */
169
+ /** cache-debug header value should be MISS after updating product1 and reloading the Category */
179
170
$ firstProduct ->setPrice (20 );
180
171
$ firstProduct ->save ();
181
- $ responseMissHeaders = $ this ->graphQlQueryForHttpHeaders ($ categoryQuery , $ variables, '' , [] );
172
+ $ responseMissHeaders = $ this ->graphQlQueryForHttpHeaders ($ categoryQuery , $ variables );
182
173
preg_match ('/X-Magento-Cache-Debug: (.*?)\n/ ' , $ responseMissHeaders , $ matchesMiss );
183
174
$ this ->assertEquals ('MISS ' , rtrim ($ matchesMiss [1 ], "\r" ));
184
175
185
176
/** cache-debug should be a MISS for product 1 after it is updated - cache invalidation */
186
- $ responseHeadersForProd1 = $ this ->graphQlQueryForHttpHeaders ($ product1Query , [], '' , []);
187
- preg_match ('/X-Magento-Cache-Debug: (.*?)\n/ ' , $ responseHeadersForProd1 , $ match );
188
- $ this ->assertEquals ('MISS ' , rtrim ($ match [1 ], "\r" ));
189
-
190
- // Cach-debug header should be a HIT for prod 2 during second load since prod 2 should be fetched from cache
191
- $ responseHeadersSecondProduct = $ this ->graphQlQueryForHttpHeaders ($ product2Query , [], '' , []);
192
- preg_match ('/X-Magento-Cache-Debug: (.*?)\n/ ' , $ responseHeadersSecondProduct , $ match );
193
- $ this ->assertEquals ('HIT ' , rtrim ($ match [1 ], "\r" ));
177
+ $ responseHeadersFirstProduct = $ this ->graphQlQueryForHttpHeaders ($ product1Query );
178
+ $ this ->assertContains ('X-Magento-Cache-Debug: MISS ' , $ responseHeadersFirstProduct );
179
+
180
+ // Cach-debug header should be a HIT for prod 2 during second load since prod 2 is fetched from cache.
181
+ $ responseHeadersSecondProduct = $ this ->graphQlQueryForHttpHeaders ($ product2Query );
182
+ $ this ->assertContains ('X-Magento-Cache-Debug: HIT ' , $ responseHeadersSecondProduct );
194
183
}
195
184
}
0 commit comments