11
11
use Magento \Catalog \Api \CategoryRepositoryInterface ;
12
12
use Magento \Framework \App \Request \Http ;
13
13
use Magento \GraphQlCache \Controller \AbstractGraphqlCacheTest ;
14
- use Magento \TestFramework \ObjectManager ;
15
14
16
15
/**
17
16
* Tests cache debug headers and cache tag validation for a deep nested category and product query
18
17
*
19
18
* @magentoAppArea graphql
20
19
* @magentoDbIsolation disabled
21
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
22
20
*/
23
21
class DeepNestedCategoriesAndProductsTest extends AbstractGraphqlCacheTest
24
22
{
@@ -47,11 +45,11 @@ protected function setUp(): void
47
45
*/
48
46
public function testDispatchForCacheHeadersOnDeepNestedQueries (): void
49
47
{
50
- $ categoryId ='333 ' ;
48
+ $ baseCategoryId ='333 ' ;
51
49
$ query
52
50
= <<<QUERY
53
51
{
54
- category(id: $ categoryId ) {
52
+ category(id: $ baseCategoryId ) {
55
53
products {
56
54
items {
57
55
attribute_set_id
@@ -80,19 +78,23 @@ public function testDispatchForCacheHeadersOnDeepNestedQueries(): void
80
78
}
81
79
QUERY ;
82
80
/** @var CategoryRepositoryInterface $categoryRepository */
83
- $ categoryRepository = ObjectManager:: getInstance () ->get (CategoryRepositoryInterface::class);
81
+ $ categoryRepository = $ this -> objectManager ->get (CategoryRepositoryInterface::class);
84
82
/** @var ProductRepositoryInterface $productRepository */
85
- $ productRepository = ObjectManager::getInstance ()->get (ProductRepositoryInterface::class);
86
- $ categoryIds = [];
87
- $ category = $ categoryRepository ->get ('333 ' );
83
+ $ productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
84
+
85
+ $ resolvedCategoryIds = [];
86
+ $ category = $ categoryRepository ->get ($ baseCategoryId );
88
87
89
88
$ productIdsFromCategory = $ category ->getProductCollection ()->getAllIds ();
90
89
foreach ($ productIdsFromCategory as $ productId ) {
91
- $ categoryIds = array_merge ($ categoryIds , $ productRepository ->getById ($ productId )->getCategoryIds ());
90
+ $ resolvedCategoryIds = array_merge (
91
+ $ resolvedCategoryIds ,
92
+ $ productRepository ->getById ($ productId )->getCategoryIds ()
93
+ );
92
94
}
93
95
94
- $ categoryIds = array_merge ($ categoryIds , [' 333 ' ]);
95
- foreach ($ categoryIds as $ categoryId ) {
96
+ $ resolvedCategoryIds = array_merge ($ resolvedCategoryIds , [$ baseCategoryId ]);
97
+ foreach ($ resolvedCategoryIds as $ categoryId ) {
96
98
$ category = $ categoryRepository ->get ($ categoryId );
97
99
$ productIdsFromCategory = array_merge (
98
100
$ productIdsFromCategory ,
@@ -101,13 +103,13 @@ public function testDispatchForCacheHeadersOnDeepNestedQueries(): void
101
103
}
102
104
103
105
$ uniqueProductIds = array_unique ($ productIdsFromCategory );
104
- $ uniqueCategoryIds = array_unique ($ categoryIds );
106
+ $ uniqueCategoryIds = array_unique ($ resolvedCategoryIds );
105
107
$ expectedCacheTags = ['cat_c ' , 'cat_p ' , 'FPC ' ];
106
- foreach ($ uniqueProductIds as $ productId ) {
107
- $ expectedCacheTags = array_merge ($ expectedCacheTags , ['cat_p_ ' .$ productId ]);
108
+ foreach ($ uniqueProductIds as $ uniqueProductId ) {
109
+ $ expectedCacheTags = array_merge ($ expectedCacheTags , ['cat_p_ ' .$ uniqueProductId ]);
108
110
}
109
- foreach ($ uniqueCategoryIds as $ categoryId ) {
110
- $ expectedCacheTags = array_merge ($ expectedCacheTags , ['cat_c_ ' .$ categoryId ]);
111
+ foreach ($ uniqueCategoryIds as $ uniqueCategoryId ) {
112
+ $ expectedCacheTags = array_merge ($ expectedCacheTags , ['cat_c_ ' .$ uniqueCategoryId ]);
111
113
}
112
114
113
115
$ this ->request ->setPathInfo ('/graphql ' );
@@ -127,4 +129,4 @@ public function testDispatchForCacheHeadersOnDeepNestedQueries(): void
127
129
)
128
130
);
129
131
}
130
- }
132
+ }
0 commit comments