From 6c8f25611df17bed5af4204bd3889dd99bf8b034 Mon Sep 17 00:00:00 2001 From: Yaroslav Rogoza Date: Wed, 11 Jul 2018 17:00:56 +0200 Subject: [PATCH] API-functional test added --- .../Catalog/CategoryProductsVariantsTest.php | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryProductsVariantsTest.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryProductsVariantsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryProductsVariantsTest.php new file mode 100644 index 0000000000000..d9a46a4451212 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryProductsVariantsTest.php @@ -0,0 +1,101 @@ +graphQlQuery($query); + + /** @var ProductRepositoryInterface $productRepository */ + $productRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class); + $product = $productRepository->get('simple_10', false, null, true); + + $this->assertArrayHasKey('variants', $response['category']['products']['items'][0]); + $this->assertCount(2, $response['category']['products']['items'][0]['variants']); + $this->assertSimpleProductFields($product, $response['category']['products']['items'][0]['variants'][0]); + } + + /** + * @param ProductInterface $product + * @param array $actualResponse + */ + private function assertSimpleProductFields($product, $actualResponse) + { + $assertionMap = [ + [ + 'response_field' => 'product', 'expected_value' => [ + "sku" => $product->getSku() + ] + ], + ]; + + $this->assertResponseFields($actualResponse, $assertionMap); + } + + /** + * @param array $actualResponse + * @param array $assertionMap + */ + private function assertResponseFields($actualResponse, $assertionMap) + { + foreach ($assertionMap as $key => $assertionData) { + $expectedValue = isset($assertionData['expected_value']) + ? $assertionData['expected_value'] + : $assertionData; + $responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key; + self::assertNotNull( + $expectedValue, + "Value of '{$responseField}' field must not be NULL" + ); + self::assertEquals( + $expectedValue, + $actualResponse[$responseField], + "Value of '{$responseField}' field in response does not match expected value: " + . var_export($expectedValue, true) + ); + } + } +}