Skip to content

Commit 3b61a72

Browse files
authored
ENGCOM-4463: GraphQL-360: Unskip and fix testGetSimpleProductsFromCategory #457
2 parents a3d0985 + 84a7128 commit 3b61a72

File tree

4 files changed

+12
-43
lines changed

4 files changed

+12
-43
lines changed

app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,17 @@ public function __construct(
9090
*/
9191
public function addParentProduct(Product $product) : void
9292
{
93-
if (isset($this->parentProducts[$product->getId()])) {
93+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
94+
$productId = $product->getData($linkField);
95+
96+
if (isset($this->parentProducts[$productId])) {
9497
return;
9598
}
9699

97100
if (!empty($this->childrenMap)) {
98101
$this->childrenMap = [];
99102
}
100-
$this->parentProducts[$product->getId()] = $product;
103+
$this->parentProducts[$productId] = $product;
101104
}
102105

103106
/**
@@ -140,16 +143,12 @@ private function fetch() : array
140143
return $this->childrenMap;
141144
}
142145

143-
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
144146
foreach ($this->parentProducts as $product) {
145147
$attributeData = $this->getAttributesCodes($product);
146148
/** @var ChildCollection $childCollection */
147149
$childCollection = $this->childCollectionFactory->create();
148-
$childCollection->addAttributeToSelect($attributeData);
149-
150-
/** @var Product $product */
151-
$product->setData($linkField, $product->getId());
152150
$childCollection->setProductFilter($product);
151+
$childCollection->addAttributeToSelect($attributeData);
153152

154153
/** @var Product $childProduct */
155154
foreach ($childCollection->getItems() as $childProduct) {

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@
1818
class CategoryProductsVariantsTest extends GraphQlAbstract
1919
{
2020
/**
21-
*
2221
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
2322
* @throws \Magento\Framework\Exception\NoSuchEntityException
2423
*/
2524
public function testGetSimpleProductsFromCategory()
2625
{
27-
$this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/360');
28-
2926
$query
3027
= <<<QUERY
3128
{

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

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ protected function setUp()
2828
}
2929

3030
/**
31-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
3231
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
3332
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
3433
*/
@@ -70,14 +69,7 @@ public function testCategoriesTree()
7069
}
7170
}
7271
QUERY;
73-
// get customer ID token
74-
/** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
75-
$customerTokenService = $this->objectManager->create(
76-
\Magento\Integration\Api\CustomerTokenServiceInterface::class
77-
);
78-
$customerToken = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password');
79-
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
80-
$response = $this->graphQlQuery($query, [], '', $headerMap);
72+
$response = $this->graphQlQuery($query);
8173
$responseDataObject = new DataObject($response);
8274
//Some sort of smoke testing
8375
self::assertEquals(
@@ -111,39 +103,22 @@ public function testCategoriesTree()
111103
}
112104

113105
/**
114-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
115106
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
116-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
117107
*/
118108
public function testGetCategoryById()
119109
{
120-
$rootCategoryId = 13;
110+
$categoryId = 13;
121111
$query = <<<QUERY
122112
{
123-
category(id: {$rootCategoryId}) {
113+
category(id: {$categoryId}) {
124114
id
125115
name
126116
}
127117
}
128118
QUERY;
129-
// get customer ID token
130-
/** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
131-
$customerTokenService = $this->objectManager->create(
132-
\Magento\Integration\Api\CustomerTokenServiceInterface::class
133-
);
134-
$customerToken = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password');
135-
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
136-
$response = $this->graphQlQuery($query, [], '', $headerMap);
137-
$responseDataObject = new DataObject($response);
138-
//Some sort of smoke testing
139-
self::assertEquals(
140-
'Category 1.2',
141-
$responseDataObject->getData('category/name')
142-
);
143-
self::assertEquals(
144-
13,
145-
$responseDataObject->getData('category/id')
146-
);
119+
$response = $this->graphQlQuery($query);
120+
self::assertEquals('Category 1.2', $response['category']['name']);
121+
self::assertEquals(13, $response['category']['id']);
147122
}
148123

149124
/**

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class ConfigurableProductViewTest extends GraphQlAbstract
2828
*/
2929
public function testQueryConfigurableProductLinks()
3030
{
31-
$this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/361');
32-
3331
$productSku = 'configurable';
3432

3533
$query

0 commit comments

Comments
 (0)