Skip to content

Commit fe5a92a

Browse files
committed
MAGE-1245 Add indexing for backend render content evaluation
1 parent eb0c43c commit fe5a92a

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

Test/Integration/Category/CategoryCacheTest.php

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
use Magento\Framework\App\Cache\Manager as CacheManager;
66
use Magento\Framework\App\Config\ScopeConfigInterface;
77
use Magento\Framework\App\Response\Http as ResponseHttp;
8-
use Magento\Framework\App\ResponseInterface;
8+
use Magento\Framework\Indexer\IndexerRegistry;
99
use Magento\Store\Model\ScopeInterface;
10+
use Magento\TestFramework\ObjectManager;
1011

1112
class CategoryCacheTest extends \Magento\TestFramework\TestCase\AbstractController
1213
{
@@ -17,8 +18,10 @@ class CategoryCacheTest extends \Magento\TestFramework\TestCase\AbstractControll
1718
public static function getCategoryProvider(): array
1819
{
1920
return [
20-
['categoryId' => 20, 'name' => 'Women'],
21+
// ['categoryId' => 20, 'name' => 'Women'],
2122
['categoryId' => 21, 'name' => 'Women > Tops'],
23+
['categoryId' => 22, 'name' => 'Women > Bottoms'],
24+
2225
];
2326
}
2427

@@ -28,6 +31,29 @@ protected function setUp(): void
2831
$this->cacheManager = $this->_objectManager->get(CacheManager::class);
2932
}
3033

34+
public static function setUpBeforeClass(): void
35+
{
36+
self::reindexAll();
37+
}
38+
39+
protected static function reindexAll(): void
40+
{
41+
$objectManager = ObjectManager::getInstance();
42+
$indexerRegistry = $objectManager->get(IndexerRegistry::class);
43+
44+
$indexerCodes = [
45+
'catalog_category_product',
46+
'catalog_product_category',
47+
'catalog_product_price',
48+
'cataloginventory_stock',
49+
'catalogsearch_fulltext'
50+
];
51+
52+
foreach ($indexerCodes as $indexerCode) {
53+
$indexerRegistry->get($indexerCode)->reindexAll();
54+
}
55+
}
56+
3157
/**
3258
* @dataProvider getCategoryProvider
3359
* @depends testFullPageCacheAvailable
@@ -59,12 +85,21 @@ public function testCategoryPlpMiss(int $categoryId, string $name): void
5985
explode(',', $response->getHeader('X-Magento-Tags')->getFieldValue()),
6086
"expected FPC tag on category {$name} id {$categoryId}"
6187
);
88+
$this->assertMatchesRegularExpression('/<div.*class=.*products-grid.*>/', $response->getContent(), $response->getContent(), 'Backend content was not rendered.');
6289
}
6390

64-
protected function resetResponse(): void
91+
/**
92+
* @magentoDbIsolation disabled
93+
*/
94+
public function testCategoryPageLoadsProducts()
6595
{
66-
$this->_objectManager->removeSharedInstance(ResponseInterface::class);
67-
$this->_response = null;
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.');
68103
}
69104

70105
/**
@@ -130,13 +165,4 @@ public function testFullPageCacheAvailable(): void
130165
$this->assertContains('full_page', $types);
131166
}
132167

133-
protected function dispatchNew($uri)
134-
{
135-
$request = $this->_objectManager->get(\Magento\Framework\App\RequestInterface::class);
136-
137-
$request->setDispatched(false);
138-
$request->setRequestUri($uri);
139-
$this->_getBootstrap()->runApp();
140-
}
141-
142168
}

0 commit comments

Comments
 (0)