@@ -21,14 +21,16 @@ public static function getCategoryProvider(): array
21
21
// ['categoryId' => 20, 'name' => 'Women'],
22
22
['categoryId ' => 21 , 'name ' => 'Women > Tops ' ],
23
23
['categoryId ' => 22 , 'name ' => 'Women > Bottoms ' ],
24
-
25
24
];
26
25
}
27
26
28
27
protected function setUp (): void
29
28
{
30
29
parent ::setUp ();
31
30
$ this ->cacheManager = $ this ->_objectManager ->get (CacheManager::class);
31
+
32
+ // Default user agent
33
+ $ _SERVER ['HTTP_USER_AGENT ' ] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 ' ;
32
34
}
33
35
34
36
public static function setUpBeforeClass (): void
@@ -65,7 +67,7 @@ protected static function reindexAll(): void
65
67
* @param string $name
66
68
* @return void
67
69
*/
68
- public function testCategoryPlpMiss (int $ categoryId , string $ name ): void
70
+ public function testCategoryPlpMissBackendRenderOn (int $ categoryId , string $ name ): void
69
71
{
70
72
$ config = $ this ->_objectManager ->get (ScopeConfigInterface::class);
71
73
$ replace = $ config ->getValue ('algoliasearch_instant/instant/replace_categories ' , ScopeInterface::SCOPE_STORE );
@@ -88,19 +90,6 @@ public function testCategoryPlpMiss(int $categoryId, string $name): void
88
90
$ this ->assertMatchesRegularExpression ('/<div.*class=.*products-grid.*>/ ' , $ response ->getContent (), $ response ->getContent (), 'Backend content was not rendered. ' );
89
91
}
90
92
91
- /**
92
- * @magentoDbIsolation disabled
93
- */
94
- public function testCategoryPageLoadsProducts ()
95
- {
96
- $ this ->reindexAll ();
97
- $ this ->dispatch ('/catalog/category/view/id/21 ' );
98
-
99
- $ responseBody = $ this ->getResponse ()->getBody ();
100
-
101
- // Assert that the response contains product data
102
- $ this ->assertStringContainsString ('product-item ' , $ responseBody , 'Expected product items were not found. ' );
103
- }
104
93
105
94
/**
106
95
* The response object is modified differently by the BuiltinPlugin which prevents anything useful
@@ -110,7 +99,7 @@ public function testCategoryPageLoadsProducts()
110
99
* when the cache has been warmed (by the first MISS)
111
100
*
112
101
* @dataProvider getCategoryProvider
113
- * @depends testCategoryPlpMiss
102
+ * @depends testCategoryPlpMissBackendRenderOn
114
103
* @magentoConfigFixture current_store system/full_page_cache/caching_application 1
115
104
* @magentoConfigFixture current_store algoliasearch_advanced/advanced/prevent_backend_rendering 0
116
105
* @magentoConfigFixture current_store algoliasearch_instant/instant/replace_categories 1
@@ -119,8 +108,78 @@ public function testCategoryPageLoadsProducts()
119
108
* @param string $name
120
109
* @return void
121
110
*/
122
- public function testCategoryPlpHit (int $ categoryId , string $ name ): void
111
+ public function testCategoryPlpHitBackendRenderOn (int $ categoryId , string $ name ): void
123
112
{
113
+ $ config = $ this ->_objectManager ->get (ScopeConfigInterface::class);
114
+ $ replace = $ config ->getValue ('algoliasearch_instant/instant/replace_categories ' , ScopeInterface::SCOPE_STORE );
115
+ $ this ->assertEquals (1 , $ replace ,"Replace categories must be enabled for this test. " );
116
+
117
+ $ this ->registerPageHitSpy ();
118
+
119
+ $ this ->dispatch ("catalog/category/view/id/ {$ categoryId }" );
120
+ $ response = $ this ->getResponse ();
121
+ $ this ->assertEquals (200 , $ response ->getHttpResponseCode (), 'Request failed ' );
122
+ }
123
+
124
+ /**
125
+ * @dataProvider getCategoryProvider
126
+ * @depends testFullPageCacheAvailable
127
+ * @magentoConfigFixture current_store system/full_page_cache/caching_application 1
128
+ * @magentoConfigFixture current_store algoliasearch_advanced/advanced/prevent_backend_rendering 1
129
+ * @magentoConfigFixture current_store algoliasearch_instant/instant/replace_categories 1
130
+ * @magentoCache full_page enabled
131
+ * @param int $categoryId
132
+ * @param string $name
133
+ * @return void
134
+ */
135
+ public function testCategoryPlpMissBackendRenderOff (int $ categoryId , string $ name ): void
136
+ {
137
+ $ config = $ this ->_objectManager ->get (ScopeConfigInterface::class);
138
+ $ preventBackend = $ config ->getValue ('algoliasearch_advanced/advanced/prevent_backend_rendering ' , ScopeInterface::SCOPE_STORE );
139
+ $ this ->assertEquals (1 , $ preventBackend ,"Prevent backend rendering must be enabled for this test. " );
140
+
141
+ $ this ->cacheManager ->clean (['full_page ' ]);
142
+ $ this ->dispatch ($ this ->url . $ categoryId );
143
+ $ response = $ this ->getResponse ();
144
+ $ this ->assertEquals (200 , $ response ->getHttpResponseCode (), 'Request failed ' );
145
+ $ this ->assertEquals (
146
+ 'MISS ' ,
147
+ $ response ->getHeader ('X-Magento-Cache-Debug ' )->getFieldValue (),
148
+ "expected MISS on category {$ name } id {$ categoryId }"
149
+ );
150
+ $ this ->assertContains (
151
+ 'FPC ' ,
152
+ explode (', ' , $ response ->getHeader ('X-Magento-Tags ' )->getFieldValue ()),
153
+ "expected FPC tag on category {$ name } id {$ categoryId }"
154
+ );
155
+ $ this ->assertDoesNotMatchRegularExpression ('/<div.*class=.*products-grid.*>/ ' , $ response ->getContent (), $ response ->getContent (), 'Backend content was not rendered. ' );
156
+ }
157
+
158
+ /**
159
+ * @dataProvider getCategoryProvider
160
+ * @depends testCategoryPlpMissBackendRenderOff
161
+ * @magentoConfigFixture current_store system/full_page_cache/caching_application 1
162
+ * @magentoConfigFixture current_store algoliasearch_advanced/advanced/prevent_backend_rendering 1
163
+ * @magentoConfigFixture current_store algoliasearch_instant/instant/replace_categories 1
164
+ * @magentoCache full_page enabled
165
+ * @param int $categoryId
166
+ * @param string $name
167
+ * @return void
168
+ */
169
+ public function testCategoryPlpHitBackendRenderOff (int $ categoryId , string $ name ): void
170
+ {
171
+ $ config = $ this ->_objectManager ->get (ScopeConfigInterface::class);
172
+ $ preventBackend = $ config ->getValue ('algoliasearch_advanced/advanced/prevent_backend_rendering ' , ScopeInterface::SCOPE_STORE );
173
+ $ this ->assertEquals (1 , $ preventBackend ,"Prevent backend rendering must be enabled for this test. " );
174
+
175
+ $ this ->registerPageHitSpy ();
176
+
177
+ $ this ->dispatch ("catalog/category/view/id/ {$ categoryId }" );
178
+ $ response = $ this ->getResponse ();
179
+ $ this ->assertEquals (200 , $ response ->getHttpResponseCode (), 'Request failed ' );
180
+ }
181
+
182
+ protected function registerPageHitSpy () {
124
183
$ mockedPluginClass = \Magento \PageCache \Model \App \FrontController \BuiltinPlugin::class;
125
184
$ mockedPluginMethod = 'addDebugHeader ' ;
126
185
$ cachePluginMock = $ this ->getMockBuilder ($ mockedPluginClass )
@@ -143,7 +202,7 @@ public function testCategoryPlpHit(int $categoryId, string $name): void
143
202
)
144
203
->willReturnCallback (
145
204
function (ResponseHttp $ response , $ name , $ value , $ replace )
146
- use ($ mockedPluginClass , $ mockedPluginMethod , $ cachePluginMock )
205
+ use ($ mockedPluginClass , $ mockedPluginMethod , $ cachePluginMock )
147
206
{
148
207
$ originalMethod = new \ReflectionMethod ($ mockedPluginClass , $ mockedPluginMethod );
149
208
return $ originalMethod ->invoke ($ cachePluginMock , $ response , $ name , $ value , $ replace );
@@ -153,10 +212,6 @@ function (ResponseHttp $response, $name, $value, $replace)
153
212
$ cachePluginMock ,
154
213
$ mockedPluginClass
155
214
);
156
-
157
- $ this ->dispatch ("catalog/category/view/id/ {$ categoryId }" );
158
- $ response = $ this ->getResponse ();
159
- $ this ->assertEquals (200 , $ response ->getHttpResponseCode (), 'Request failed ' );
160
215
}
161
216
162
217
public function testFullPageCacheAvailable (): void
0 commit comments