Skip to content

Commit 7dc85ec

Browse files
author
Prabhu Ram
committed
596: Category with Products with...(deep nesting) (Integration Test for Tag Cache Generation)
- Fixed review comments
1 parent cede6e9 commit 7dc85ec

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

dev/tests/integration/testsuite/Magento/GraphQlCache/Controller/Catalog/DeepNestedCategoriesAndProductsTest.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111
use Magento\Catalog\Api\CategoryRepositoryInterface;
1212
use Magento\Framework\App\Request\Http;
1313
use Magento\GraphQlCache\Controller\AbstractGraphqlCacheTest;
14-
use Magento\TestFramework\ObjectManager;
1514

1615
/**
1716
* Tests cache debug headers and cache tag validation for a deep nested category and product query
1817
*
1918
* @magentoAppArea graphql
2019
* @magentoDbIsolation disabled
21-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2220
*/
2321
class DeepNestedCategoriesAndProductsTest extends AbstractGraphqlCacheTest
2422
{
@@ -47,11 +45,11 @@ protected function setUp(): void
4745
*/
4846
public function testDispatchForCacheHeadersOnDeepNestedQueries(): void
4947
{
50-
$categoryId ='333';
48+
$baseCategoryId ='333';
5149
$query
5250
= <<<QUERY
5351
{
54-
category(id: $categoryId) {
52+
category(id: $baseCategoryId) {
5553
products {
5654
items {
5755
attribute_set_id
@@ -80,19 +78,23 @@ public function testDispatchForCacheHeadersOnDeepNestedQueries(): void
8078
}
8179
QUERY;
8280
/** @var CategoryRepositoryInterface $categoryRepository */
83-
$categoryRepository = ObjectManager::getInstance()->get(CategoryRepositoryInterface::class);
81+
$categoryRepository = $this->objectManager->get(CategoryRepositoryInterface::class);
8482
/** @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);
8887

8988
$productIdsFromCategory = $category->getProductCollection()->getAllIds();
9089
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+
);
9294
}
9395

94-
$categoryIds = array_merge($categoryIds, ['333']);
95-
foreach ($categoryIds as $categoryId) {
96+
$resolvedCategoryIds = array_merge($resolvedCategoryIds, [$baseCategoryId]);
97+
foreach ($resolvedCategoryIds as $categoryId) {
9698
$category = $categoryRepository->get($categoryId);
9799
$productIdsFromCategory= array_merge(
98100
$productIdsFromCategory,
@@ -101,13 +103,13 @@ public function testDispatchForCacheHeadersOnDeepNestedQueries(): void
101103
}
102104

103105
$uniqueProductIds = array_unique($productIdsFromCategory);
104-
$uniqueCategoryIds = array_unique($categoryIds);
106+
$uniqueCategoryIds = array_unique($resolvedCategoryIds);
105107
$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]);
108110
}
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]);
111113
}
112114

113115
$this->request->setPathInfo('/graphql');
@@ -127,4 +129,4 @@ public function testDispatchForCacheHeadersOnDeepNestedQueries(): void
127129
)
128130
);
129131
}
130-
}
132+
}

0 commit comments

Comments
 (0)