Skip to content

Commit 4963f2a

Browse files
committed
MAGE-1245 Add testing of static block categories
1 parent 26275c7 commit 4963f2a

File tree

1 file changed

+22
-30
lines changed

1 file changed

+22
-30
lines changed

Test/Integration/Category/CategoryCacheTest.php

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ class CategoryCacheTest extends AbstractController
2222
public static function getCategoryProvider(): array
2323
{
2424
return [
25-
// ['categoryId' => 20, 'name' => 'Women'],
26-
['categoryId' => 21, 'name' => 'Women > Tops'],
27-
['categoryId' => 22, 'name' => 'Women > Bottoms'],
25+
['categoryId' => 20, 'name' => 'Women', 'hasProducts' => false],
26+
['categoryId' => 21, 'name' => 'Women > Tops', 'hasProducts' => true],
27+
['categoryId' => 22, 'name' => 'Women > Bottoms', 'hasProducts' => true],
28+
['categoryId' => 11, 'name' => 'Men', 'hasProducts' => false],
29+
['categoryId' => 12, 'name' => 'Men > Tops', 'hasProducts' => true],
30+
['categoryId' => 13, 'name' => 'Men > Bottoms', 'hasProducts' => true],
2831
];
2932
}
3033

@@ -66,10 +69,8 @@ protected static function reindexAll(): void
6669
* Selectively refresh the FPC cache (must be done at intervals)
6770
* Warm the cache via MISS tests but only reset the cache once per MISS test
6871
* Due to data provider test methods can be called multiple times
69-
* @param $testMethod
70-
* @return void
7172
*/
72-
protected function resetCache($testMethod): void
73+
protected function resetCache(string $testMethod): void
7374
{
7475
if (!in_array($testMethod, self::$cacheResets)) {
7576
$this->cacheManager->clean(['full_page']);
@@ -84,11 +85,8 @@ protected function resetCache($testMethod): void
8485
* @magentoConfigFixture current_store algoliasearch_advanced/advanced/prevent_backend_rendering 0
8586
* @magentoConfigFixture current_store algoliasearch_instant/instant/replace_categories 1
8687
* @magentoCache full_page enabled
87-
* @param int $categoryId
88-
* @param string $name
89-
* @return void
9088
*/
91-
public function testCategoryPlpMissBackendRenderOn(int $categoryId, string $name): void
89+
public function testCategoryPlpMissBackendRenderOn(int $categoryId, string $name, bool $hasProducts): void
9290
{
9391
$replace = $this->config->getValue('algoliasearch_instant/instant/replace_categories', ScopeInterface::SCOPE_STORE);
9492
$this->assertEquals(1, $replace,"Replace categories must be enabled for this test.");
@@ -107,7 +105,10 @@ public function testCategoryPlpMissBackendRenderOn(int $categoryId, string $name
107105
explode(',', $response->getHeader('X-Magento-Tags')->getFieldValue()),
108106
"expected FPC tag on category {$name} id {$categoryId}"
109107
);
110-
$this->assertMatchesRegularExpression('/<div.*class=.*products-grid.*>/', $response->getContent(), $response->getContent(), 'Backend content was not rendered.');
108+
109+
if ($hasProducts) {
110+
$this->assertMatchesRegularExpression('/<div.*class=.*products-grid.*>/', $response->getContent(), 'Backend content was not rendered.');
111+
}
111112
}
112113

113114
/**
@@ -117,9 +118,6 @@ public function testCategoryPlpMissBackendRenderOn(int $categoryId, string $name
117118
* @magentoConfigFixture current_store algoliasearch_advanced/advanced/prevent_backend_rendering 0
118119
* @magentoConfigFixture current_store algoliasearch_instant/instant/replace_categories 1
119120
* @magentoCache full_page enabled
120-
* @param int $categoryId
121-
* @param string $name
122-
* @return void
123121
*/
124122
public function testCategoryPlpHitBackendRenderOn(int $categoryId, string $name): void
125123
{
@@ -140,11 +138,8 @@ public function testCategoryPlpHitBackendRenderOn(int $categoryId, string $name)
140138
* @magentoConfigFixture current_store algoliasearch_advanced/advanced/prevent_backend_rendering 1
141139
* @magentoConfigFixture current_store algoliasearch_instant/instant/replace_categories 1
142140
* @magentoCache full_page enabled
143-
* @param int $categoryId
144-
* @param string $name
145-
* @return void
146141
*/
147-
public function testCategoryPlpMissBackendRenderOff(int $categoryId, string $name): void
142+
public function testCategoryPlpMissBackendRenderOff(int $categoryId, string $name, bool $hasProducts): void
148143
{
149144
$preventBackend = $this->config->getValue('algoliasearch_advanced/advanced/prevent_backend_rendering', ScopeInterface::SCOPE_STORE);
150145
$this->assertEquals(1, $preventBackend,"Prevent backend rendering must be enabled for this test.");
@@ -163,7 +158,10 @@ public function testCategoryPlpMissBackendRenderOff(int $categoryId, string $nam
163158
explode(',', $response->getHeader('X-Magento-Tags')->getFieldValue()),
164159
"expected FPC tag on category {$name} id {$categoryId}"
165160
);
166-
$this->assertDoesNotMatchRegularExpression('/<div.*class=.*products-grid.*>/', $response->getContent(), $response->getContent(), 'Backend content was not rendered.');
161+
162+
if ($hasProducts) {
163+
$this->assertDoesNotMatchRegularExpression('/<div.*class=.*products-grid.*>/', $response->getContent(), 'Backend content was rendered.');
164+
}
167165
}
168166

169167
/**
@@ -173,9 +171,6 @@ public function testCategoryPlpMissBackendRenderOff(int $categoryId, string $nam
173171
* @magentoConfigFixture current_store algoliasearch_advanced/advanced/prevent_backend_rendering 1
174172
* @magentoConfigFixture current_store algoliasearch_instant/instant/replace_categories 1
175173
* @magentoCache full_page enabled
176-
* @param int $categoryId
177-
* @param string $name
178-
* @return void
179174
*/
180175
public function testCategoryPlpHitBackendRenderOff(int $categoryId, string $name): void
181176
{
@@ -198,11 +193,8 @@ public function testCategoryPlpHitBackendRenderOff(int $categoryId, string $name
198193
* @magentoConfigFixture current_store algoliasearch_instant/instant/replace_categories 1
199194
* @magentoDataFixture Algolia_AlgoliaSearch::Test/Integration/_files/backend_render_user_agents.php
200195
* @magentoCache full_page enabled
201-
* @param int $categoryId
202-
* @param string $name
203-
* @return void
204196
*/
205-
public function testCategoryPlpMissBackendRenderWhiteList(int $categoryId, string $name): void
197+
public function testCategoryPlpMissBackendRenderWhiteList(int $categoryId, string $name, bool $hasProducts): void
206198
{
207199
$preventBackend = $this->config->getValue('algoliasearch_advanced/advanced/prevent_backend_rendering', ScopeInterface::SCOPE_STORE);
208200
$this->assertEquals(1, $preventBackend,"Prevent backend rendering must be enabled for this test.");
@@ -227,7 +219,10 @@ public function testCategoryPlpMissBackendRenderWhiteList(int $categoryId, strin
227219
explode(',', $response->getHeader('X-Magento-Tags')->getFieldValue()),
228220
"expected FPC tag on category {$name} id {$categoryId}"
229221
);
230-
$this->assertMatchesRegularExpression('/<div.*class=.*products-grid.*>/', $response->getContent(), $response->getContent(), 'Backend content was not rendered.');
222+
223+
if ($hasProducts) {
224+
$this->assertMatchesRegularExpression('/<div.*class=.*products-grid.*>/', $response->getContent(), 'Backend content was not rendered.');
225+
}
231226
}
232227

233228
/**
@@ -238,9 +233,6 @@ public function testCategoryPlpMissBackendRenderWhiteList(int $categoryId, strin
238233
* @magentoConfigFixture current_store algoliasearch_instant/instant/replace_categories 1
239234
* @magentoDataFixture Algolia_AlgoliaSearch::Test/Integration/_files/backend_render_user_agents.php
240235
* @magentoCache full_page enabled
241-
* @param int $categoryId
242-
* @param string $name
243-
* @return void
244236
*/
245237
public function testCategoryPlpHitBackendRenderWhiteList(int $categoryId, string $name): void
246238
{

0 commit comments

Comments
 (0)