From 39fd0f9c02e5cbf7eb81155cf999dc32a908e5fa Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Tue, 11 Sep 2018 19:36:03 +0300 Subject: [PATCH] GraphQL-172: GraphQL modules delivery --- .../GraphQl/Catalog/BreadcrumbsTest.php | 175 ------------------ 1 file changed, 175 deletions(-) delete mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/BreadcrumbsTest.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/BreadcrumbsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/BreadcrumbsTest.php deleted file mode 100644 index d0879ae5864ef..0000000000000 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/BreadcrumbsTest.php +++ /dev/null @@ -1,175 +0,0 @@ -get(CollectionFactory::class)->create(); - $categoryCollection->addAttributeToFilter('name', ['eq' => 'Category 1.1.1']); - $selectedCategoryId = (int)$categoryCollection->getFirstItem()->getId(); - $query = - <<graphQlQuery($query); - $this->assertArrayHasKey('category', $response); - $this->assertArrayHasKey('breadcrumbs', $response['category']); - $this->assertBaseFields($selectedCategoryId, $response); - } - - /** - * Verify the fields of CMS Block selected by identifiers. - * - * @magentoApiDataFixture Magento/Catalog/_files/category_tree.php - * @return void - */ - public function testGetBreadcrumbsForNonExistingCategory(): void - { - $query = - <<graphQlQuery($query); - $this->assertArrayHasKey('category', $response); - $this->assertNull( - $response['category'], - 'Value of "category" field must be NULL if requested category doesn\'t exist' - ); - $this->assertCount( - 1, - $response, - 'There should be only "category" field if requested category doesn\'t exist ' - ); - } - - /** - * Asserts the equality of the response fields to the fields given in assertion map. - * Assert that values of the fields are different from NULL - * - * @param array $actualResponse - * @param array $assertionMap - * @return void - */ - private function assertResponseFields(array $actualResponse, array $assertionMap): void - { - foreach ($assertionMap as $key => $assertionData) { - $expectedValue = isset($assertionData['expected_value']) - ? $assertionData['expected_value'] - : $assertionData; - $responseField = isset($assertionData['response_field']) ? $assertionData['response_field'] : $key; - $this->assertNotNull( - $expectedValue, - "Value of '{$responseField}' field must not be NULL" - ); - $this->assertEquals( - $expectedValue[$key], - $actualResponse[$responseField], - "Value of '{$responseField}' field in response does not match expected value: " - . var_export($expectedValue, true) - ); - } - } - - /** - * Get breadcrumbs for given category. - * - * @param Category $category - * @return array - */ - private function getBreadcrumbs(Category $category): array - { - $breadcrumbs = []; - $rootId = Bootstrap::getObjectManager()->get(StoreManagerInterface::class) - ->getStore() - ->getRootCategoryId(); - foreach ($category->getParentCategories() as $parentCategory) { - if ($parentCategory->getId() !== $rootId) { - $breadcrumbs[] = [ - 'category_id' => $parentCategory->getId(), - 'category_name' => $parentCategory->getName(), - 'category_level' => $parentCategory->getLevel(), - 'category_url_key' => $parentCategory->getUrlKey(), - ]; - } - } - - return $breadcrumbs; - } - - /** - * Asserts base fields - * - * @param int $categoryId - * @param array $actualResponse - * @return void - */ - private function assertBaseFields(int $categoryId, array $actualResponse): void - { - $category = Bootstrap::getObjectManager()->create(Category::class)->load($categoryId); - $assertionMap = [ - [ - 'response_field' => 'category', - 'expected_value' => - [ - [ - 'name' => $category->getName(), - 'breadcrumbs' => $this->getBreadcrumbs($category->getParentCategory()), - ], - - ], - ], - ]; - - /** - * @param array $actualResponse - * @param array $assertionMap ['response_field_name' => 'response_field_value', ...] - * OR [['response_field' => $field, 'expected_value' => $value], ...] - */ - $this->assertResponseFields($actualResponse, $assertionMap); - } -}