5
5
use Magento \Framework \App \Cache \Manager as CacheManager ;
6
6
use Magento \Framework \App \Config \ScopeConfigInterface ;
7
7
use Magento \Framework \App \Response \Http as ResponseHttp ;
8
- use Magento \Framework \App \ ResponseInterface ;
8
+ use Magento \Framework \Indexer \ IndexerRegistry ;
9
9
use Magento \Store \Model \ScopeInterface ;
10
+ use Magento \TestFramework \ObjectManager ;
10
11
11
12
class CategoryCacheTest extends \Magento \TestFramework \TestCase \AbstractController
12
13
{
@@ -17,8 +18,10 @@ class CategoryCacheTest extends \Magento\TestFramework\TestCase\AbstractControll
17
18
public static function getCategoryProvider (): array
18
19
{
19
20
return [
20
- ['categoryId ' => 20 , 'name ' => 'Women ' ],
21
+ // ['categoryId' => 20, 'name' => 'Women'],
21
22
['categoryId ' => 21 , 'name ' => 'Women > Tops ' ],
23
+ ['categoryId ' => 22 , 'name ' => 'Women > Bottoms ' ],
24
+
22
25
];
23
26
}
24
27
@@ -28,6 +31,29 @@ protected function setUp(): void
28
31
$ this ->cacheManager = $ this ->_objectManager ->get (CacheManager::class);
29
32
}
30
33
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
+
31
57
/**
32
58
* @dataProvider getCategoryProvider
33
59
* @depends testFullPageCacheAvailable
@@ -59,12 +85,21 @@ public function testCategoryPlpMiss(int $categoryId, string $name): void
59
85
explode (', ' , $ response ->getHeader ('X-Magento-Tags ' )->getFieldValue ()),
60
86
"expected FPC tag on category {$ name } id {$ categoryId }"
61
87
);
88
+ $ this ->assertMatchesRegularExpression ('/<div.*class=.*products-grid.*>/ ' , $ response ->getContent (), $ response ->getContent (), 'Backend content was not rendered. ' );
62
89
}
63
90
64
- protected function resetResponse (): void
91
+ /**
92
+ * @magentoDbIsolation disabled
93
+ */
94
+ public function testCategoryPageLoadsProducts ()
65
95
{
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. ' );
68
103
}
69
104
70
105
/**
@@ -130,13 +165,4 @@ public function testFullPageCacheAvailable(): void
130
165
$ this ->assertContains ('full_page ' , $ types );
131
166
}
132
167
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
-
142
168
}
0 commit comments