Skip to content

Commit c3f2a34

Browse files
committed
MC-17015: [GraphQL] Product Categories query doesn't return all categories where product is visible
- fix functional tests
1 parent 43a7392 commit c3f2a34

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductViewTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,11 @@ public function testQueryAllFieldsSimpleProduct()
282282
$this->assertWebsites($product, $response['products']['items'][0]['websites']);
283283
self::assertEquals(
284284
'Movable Position 2',
285-
$responseObject->getData('products/items/0/categories/1/name')
285+
$responseObject->getData('products/items/0/categories/0/name')
286286
);
287287
self::assertEquals(
288288
'Filter category',
289-
$responseObject->getData('products/items/0/categories/2/name')
289+
$responseObject->getData('products/items/0/categories/1/name')
290290
);
291291
$storeManager = ObjectManager::getInstance()->get(\Magento\Store\Model\StoreManagerInterface::class);
292292
self::assertEquals(

dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/ConfigurableProductViewTest.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ private function assertConfigurableVariants($actualResponse)
300300
isset($variantArray['product']['id']),
301301
'variant product elements don\'t contain id key'
302302
);
303+
$variantProductId = $variantArray['product']['id'];
303304
$indexValue = $variantArray['product']['sku'];
304305
unset($variantArray['product']['id']);
305306
$this->assertTrue(
@@ -310,14 +311,19 @@ private function assertConfigurableVariants($actualResponse)
310311
/** @var \Magento\Catalog\Model\Product $childProduct */
311312
$childProduct = $productRepository->get($indexValue);
312313

313-
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface[] */
314-
$links = $childProduct->getExtensionAttributes()->getCategoryLinks();
315-
$this->assertCount(1, $links, "Precondition failed, incorrect number of categories.");
316-
$id =$links[0]->getCategoryId();
317-
318-
$actualValue
319-
= $actualResponse['variants'][$variantKey]['product']['categories'][0];
320-
$this->assertEquals($actualValue, ['id' => $id]);
314+
switch( $variantProductId ){
315+
case 10:
316+
$this->assertEmpty(
317+
$actualResponse['variants'][$variantKey]['product']['categories'],
318+
'No category is expected for product, that not visible individually'
319+
);
320+
break;
321+
case 20:
322+
$this->assertEquals(
323+
$actualResponse['variants'][$variantKey]['product']['categories'][0],
324+
['id' => 333]
325+
);
326+
}
321327
unset($variantArray['product']['categories']);
322328

323329
$mediaGalleryEntries = $childProduct->getMediaGalleryEntries();

dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_category_and_weight.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
\Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize();
2020

2121
require __DIR__ . '/configurable_attribute.php';
22+
require __DIR__ . '/../../Catalog/_files/category.php';
2223

2324
/** @var ProductRepositoryInterface $productRepository */
2425
$productRepository = Bootstrap::getObjectManager()
@@ -36,6 +37,10 @@
3637
$associatedProductIds = [];
3738
$productIds = [10, 20];
3839
array_shift($options); //remove the first option which is empty
40+
$visibility = [
41+
10 => Visibility::VISIBILITY_IN_CATALOG,
42+
20 => Visibility::VISIBILITY_NOT_VISIBLE,
43+
];
3944

4045
foreach ($options as $option) {
4146
/** @var $product Product */
@@ -49,11 +54,11 @@
4954
->setSku('simple_' . $productId)
5055
->setPrice($productId)
5156
->setTestConfigurable($option->getValue())
52-
->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE)
57+
->setVisibility($visibility[$productId])
5358
->setStatus(Status::STATUS_ENABLED)
5459
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1]);
5560
$eavAttributeValues = [
56-
'category_ids' => [2]
61+
'category_ids' => [333]
5762
];
5863
foreach ($eavAttributeValues as $eavCategoryAttributeCode => $eavCategoryAttributeValues) {
5964
$product->setCustomAttribute($eavCategoryAttributeCode, $eavCategoryAttributeValues);
@@ -210,5 +215,5 @@
210215

211216
$categoryLinkManagement->assignProductToCategories(
212217
$product->getSku(),
213-
[2]
218+
[333]
214219
);

0 commit comments

Comments
 (0)