Skip to content

magento/magento2#29918:Improve the structure id GraphQL tests for cat… #30898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
declare(strict_types=1);

namespace Magento\GraphQl\Catalog\CategoriesQuery;
namespace Magento\GraphQl\Catalog\Category\CategoriesQuery;

use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
use Magento\Store\Model\StoreManagerInterface;
Expand Down Expand Up @@ -43,8 +43,8 @@ public function testFilterSingleCategoryByField($field, $condition, $value, $exp
}
QUERY;
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertCount(1, $result['categories']['items']);
self::assertArrayNotHasKey('errors', $result);
self::assertCount(1, $result['categories']['items']);
$this->assertResponseFields($result['categories']['items'][0], $expectedResult);
}

Expand Down Expand Up @@ -74,8 +74,8 @@ public function testFilterMultipleCategoriesByField($field, $condition, $value,
}
QUERY;
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertCount(count($expectedResult), $result['categories']['items']);
self::assertArrayNotHasKey('errors', $result);
self::assertCount(count($expectedResult), $result['categories']['items']);
foreach ($expectedResult as $i => $expected) {
$this->assertResponseFields($result['categories']['items'][$i], $expected);
}
Expand Down Expand Up @@ -103,13 +103,13 @@ public function testFilterCategoryByMultipleFields()
}
QUERY;
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertCount(3, $result['categories']['items']);
$this->assertEquals(3, $result['categories']['total_count']);
self::assertArrayNotHasKey('errors', $result);
self::assertCount(3, $result['categories']['items']);
self::assertEquals(3, $result['categories']['total_count']);

$expectedCategories = [7 => 'Movable', 9 => 'Movable Position 1', 10 => 'Movable Position 2'];
$actualCategories = array_column($result['categories']['items'], 'name', 'id');
$this->assertEquals($expectedCategories, $actualCategories);
self::assertEquals($expectedCategories, $actualCategories);
}

/**
Expand All @@ -130,11 +130,11 @@ public function testFilterWithInactiveCategory()
}
QUERY;
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertCount(1, $result['categories']['items']);
self::assertArrayNotHasKey('errors', $result);
self::assertCount(1, $result['categories']['items']);
$actualCategories = array_column($result['categories']['items'], 'url_key', 'id');
$this->assertContains('category-2', $actualCategories);
$this->assertNotContains('inactive', $actualCategories);
self::assertContains('category-2', $actualCategories);
self::assertNotContains('inactive', $actualCategories);
}

/**
Expand Down Expand Up @@ -179,12 +179,12 @@ public function testQueryChildCategoriesWithProducts()
QUERY;
$result = $this->graphQlQuery($query);

$this->assertArrayNotHasKey('errors', $result);
$this->assertCount(1, $result['categories']['items']);
self::assertArrayNotHasKey('errors', $result);
self::assertCount(1, $result['categories']['items']);
$baseCategory = $result['categories']['items'][0];

$this->assertEquals('Category 1', $baseCategory['name']);
$this->assertArrayHasKey('products', $baseCategory);
self::assertEquals('Category 1', $baseCategory['name']);
self::assertArrayHasKey('products', $baseCategory);
//Check base category products
$expectedBaseCategoryProducts = [
['sku' => 'simple', 'name' => 'Simple Product'],
Expand All @@ -201,8 +201,8 @@ public function testQueryChildCategoriesWithProducts()

//Check first child category
$firstChildCategory = $baseCategory['children'][0];
$this->assertEquals('Category 1.1', $firstChildCategory['name']);
$this->assertEquals('Category 1.1 description.', $firstChildCategory['description']);
self::assertEquals('Category 1.1', $firstChildCategory['name']);
self::assertEquals('Category 1.1 description.', $firstChildCategory['description']);
$firstChildCategoryExpectedProducts = [
['sku' => '12345', 'name' => 'Simple Product Two'],
['sku' => 'simple', 'name' => 'Simple Product']
Expand All @@ -212,8 +212,8 @@ public function testQueryChildCategoriesWithProducts()
$this->assertCategoryChildren($firstChildCategory, $firstChildCategoryChildren);
//Check second child category
$secondChildCategory = $baseCategory['children'][1];
$this->assertEquals('Category 1.2', $secondChildCategory['name']);
$this->assertEquals('Its a description of Test Category 1.2', $secondChildCategory['description']);
self::assertEquals('Category 1.2', $secondChildCategory['name']);
self::assertEquals('Its a description of Test Category 1.2', $secondChildCategory['description']);
$firstChildCategoryExpectedProducts = [
['sku' => 'simple-4', 'name' => 'Simple Product Three'],
['sku' => 'simple', 'name' => 'Simple Product']
Expand Down Expand Up @@ -272,12 +272,12 @@ public function testQueryCategoryWithDisabledChildren()
QUERY;
$result = $this->graphQlQuery($query);

$this->assertArrayNotHasKey('errors', $result);
$this->assertCount(1, $result['categories']['items']);
self::assertArrayNotHasKey('errors', $result);
self::assertCount(1, $result['categories']['items']);
$baseCategory = $result['categories']['items'][0];

$this->assertEquals('Category 1', $baseCategory['name']);
$this->assertArrayHasKey('products', $baseCategory);
self::assertEquals('Category 1', $baseCategory['name']);
self::assertArrayHasKey('products', $baseCategory);
//Check base category products
$expectedBaseCategoryProducts = [
['sku' => 'simple', 'name' => 'Simple Product'],
Expand All @@ -293,8 +293,8 @@ public function testQueryCategoryWithDisabledChildren()

//Check first child category
$firstChildCategory = $baseCategory['children'][0];
$this->assertEquals('Category 1.2', $firstChildCategory['name']);
$this->assertEquals('Its a description of Test Category 1.2', $firstChildCategory['description']);
self::assertEquals('Category 1.2', $firstChildCategory['name']);
self::assertEquals('Its a description of Test Category 1.2', $firstChildCategory['description']);

$firstChildCategoryExpectedProducts = [
['sku' => 'simple-4', 'name' => 'Simple Product Three'],
Expand Down Expand Up @@ -326,9 +326,9 @@ public function testNoResultsFound()
}
QUERY;
$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertArrayHasKey('categories', $result);
$this->assertEquals([], $result['categories']['items']);
self::assertArrayNotHasKey('errors', $result);
self::assertArrayHasKey('categories', $result);
self::assertEquals([], $result['categories']['items']);
}

/**
Expand Down Expand Up @@ -357,10 +357,10 @@ public function testEmptyFiltersReturnRootCategory()
$storeRootCategoryId = $storeManager->getStore()->getRootCategoryId();

$result = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $result);
$this->assertArrayHasKey('categories', $result);
$this->assertEquals('Default Category', $result['categories']['items'][0]['name']);
$this->assertEquals($storeRootCategoryId, $result['categories']['items'][0]['id']);
self::assertArrayNotHasKey('errors', $result);
self::assertArrayHasKey('categories', $result);
self::assertEquals('Default Category', $result['categories']['items'][0]['name']);
self::assertEquals($storeRootCategoryId, $result['categories']['items'][0]['id']);
}

/**
Expand Down Expand Up @@ -426,10 +426,10 @@ public function testCategoryImageNameAndSeoDisabled()

$response = $this->graphQlQuery($query);
$categories = $response['categories'];
$this->assertArrayNotHasKey('errors', $response);
$this->assertNotEmpty($response['categories']['items']);
$this->assertEquals('Parent Image Category', $categories['items'][0]['name']);
$this->assertEquals($expectedImageUrl, $categories['items'][0]['image']);
self::assertArrayNotHasKey('errors', $response);
self::assertNotEmpty($response['categories']['items']);
self::assertEquals('Parent Image Category', $categories['items'][0]['name']);
self::assertEquals($expectedImageUrl, $categories['items'][0]['image']);
}

/**
Expand All @@ -455,11 +455,11 @@ public function testFilterByUrlPathTopLevelCategory()
QUERY;

$response = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $response);
self::assertArrayNotHasKey('errors', $response);
$categories = $response['categories'];
$this->assertCount(1, $categories);
$this->assertEquals($urlPath, $categories['items'][0]['url_path']);
$this->assertEquals('Category 1', $categories['items'][0]['name']);
self::assertCount(1, $categories);
self::assertEquals($urlPath, $categories['items'][0]['url_path']);
self::assertEquals('Category 1', $categories['items'][0]['name']);
}

/**
Expand All @@ -484,11 +484,11 @@ public function testFilterByUrlPathNestedCategory()
QUERY;

$response = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $response);
self::assertArrayNotHasKey('errors', $response);
$categories = $response['categories'];
$this->assertCount(1, $categories);
$this->assertEquals($urlPath, $categories['items'][0]['url_path']);
$this->assertEquals('Category 1.1.1', $categories['items'][0]['name']);
self::assertCount(1, $categories);
self::assertEquals($urlPath, $categories['items'][0]['url_path']);
self::assertEquals('Category 1.1.1', $categories['items'][0]['name']);
}

/**
Expand All @@ -514,13 +514,13 @@ public function testFilterByUrlPathMultipleCategories()
QUERY;

$response = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $response);
self::assertArrayNotHasKey('errors', $response);
$categories = $response['categories'];
$this->assertCount(2, $categories['items']);
$this->assertEquals($urlPaths[0], $categories['items'][0]['url_path']);
$this->assertEquals('Category 1.1', $categories['items'][0]['name']);
$this->assertEquals($urlPaths[2], $categories['items'][1]['url_path']);
$this->assertEquals('Movable Position 2', $categories['items'][1]['name']);
self::assertCount(2, $categories['items']);
self::assertEquals($urlPaths[0], $categories['items'][0]['url_path']);
self::assertEquals('Category 1.1', $categories['items'][0]['name']);
self::assertEquals($urlPaths[2], $categories['items'][1]['url_path']);
self::assertEquals('Movable Position 2', $categories['items'][1]['name']);
}

/**
Expand All @@ -544,9 +544,9 @@ public function testFilterByUrlPathNoResults()
QUERY;

$response = $this->graphQlQuery($query);
$this->assertArrayNotHasKey('errors', $response);
self::assertArrayNotHasKey('errors', $response);
$categories = $response['categories'];
$this->assertCount(0, $categories['items']);
self::assertCount(0, $categories['items']);
}

/**
Expand Down Expand Up @@ -714,8 +714,8 @@ public function filterMultipleCategoriesDataProvider(): array
*/
private function assertCategoryProducts(array $category, array $expectedProducts)
{
$this->assertEquals(count($expectedProducts), $category['products']['total_count']);
$this->assertCount(count($expectedProducts), $category['products']['items']);
self::assertEquals(count($expectedProducts), $category['products']['total_count']);
self::assertCount(count($expectedProducts), $category['products']['items']);
$this->assertResponseFields($category['products']['items'], $expectedProducts);
}

Expand All @@ -727,8 +727,8 @@ private function assertCategoryProducts(array $category, array $expectedProducts
*/
private function assertCategoryChildren(array $category, array $expectedChildren)
{
$this->assertArrayHasKey('children', $category);
$this->assertCount(count($expectedChildren), $category['children']);
self::assertArrayHasKey('children', $category);
self::assertCount(count($expectedChildren), $category['children']);
foreach ($expectedChildren as $i => $expectedChild) {
$this->assertResponseFields($category['children'][$i], $expectedChild);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
declare(strict_types=1);

namespace Magento\GraphQl\Catalog\CategoriesQuery;
namespace Magento\GraphQl\Catalog\Category\CategoriesQuery;

use Magento\TestFramework\TestCase\GraphQlAbstract;

Expand Down Expand Up @@ -37,13 +37,13 @@ public function testDefaultPagination()

$response = $this->graphQlQuery($query);
$categories = $response['categories']['items'];
$this->assertCount(6, $categories);
$this->assertEquals(count($categories), $response['categories']['total_count']);
$this->assertArrayHasKey('page_info', $response['categories']);
self::assertCount(6, $categories);
self::assertEquals(count($categories), $response['categories']['total_count']);
self::assertArrayHasKey('page_info', $response['categories']);
$pageInfo = $response['categories']['page_info'];
$this->assertEquals(1, $pageInfo['current_page']);
$this->assertEquals(20, $pageInfo['page_size']);
$this->assertEquals(1, $pageInfo['total_pages']);
self::assertEquals(1, $pageInfo['current_page']);
self::assertEquals(20, $pageInfo['page_size']);
self::assertEquals(1, $pageInfo['total_pages']);
}

/**
Expand Down Expand Up @@ -72,13 +72,13 @@ public function testPageSize()

$response = $this->graphQlQuery($query);
$categories = $response['categories']['items'];
$this->assertCount(2, $categories);
$this->assertNotEquals(count($categories), $response['categories']['total_count']);
$this->assertEquals(6, $response['categories']['total_count']);
self::assertCount(2, $categories);
self::assertNotEquals(count($categories), $response['categories']['total_count']);
self::assertEquals(6, $response['categories']['total_count']);
$pageInfo = $response['categories']['page_info'];
$this->assertEquals(1, $pageInfo['current_page']);
$this->assertEquals(2, $pageInfo['page_size']);
$this->assertEquals(3, $pageInfo['total_pages']);
self::assertEquals(1, $pageInfo['current_page']);
self::assertEquals(2, $pageInfo['page_size']);
self::assertEquals(3, $pageInfo['total_pages']);
}

/**
Expand Down Expand Up @@ -108,12 +108,12 @@ public function testCurrentPage()

$response = $this->graphQlQuery($query);
$categories = $response['categories']['items'];
$this->assertCount(1, $categories);
$this->assertEquals(7, $response['categories']['total_count']);
self::assertCount(1, $categories);
self::assertEquals(7, $response['categories']['total_count']);
$pageInfo = $response['categories']['page_info'];
$this->assertEquals(3, $pageInfo['current_page']);
$this->assertEquals(3, $pageInfo['page_size']);
$this->assertEquals(3, $pageInfo['total_pages']);
self::assertEquals(3, $pageInfo['current_page']);
self::assertEquals(3, $pageInfo['page_size']);
self::assertEquals(3, $pageInfo['total_pages']);
}

/**
Expand Down Expand Up @@ -143,19 +143,19 @@ public function testPaging()

$page1Query = sprintf($baseQuery, 1);
$page1Result = $this->graphQlQuery($page1Query);
$this->assertEquals('Default Category', $page1Result['categories']['items'][0]['name']);
$this->assertEquals('Category 1', $page1Result['categories']['items'][1]['name']);
$this->assertEquals(7, $page1Result['categories']['total_count']);
self::assertEquals('Default Category', $page1Result['categories']['items'][0]['name']);
self::assertEquals('Category 1', $page1Result['categories']['items'][1]['name']);
self::assertEquals(7, $page1Result['categories']['total_count']);

$page2Query = sprintf($baseQuery, 2);
$page2Result = $this->graphQlQuery($page2Query);
$this->assertEquals('Category 1.1', $page2Result['categories']['items'][0]['name']);
$this->assertEquals('Category 1.1.1', $page2Result['categories']['items'][1]['name']);
self::assertEquals('Category 1.1', $page2Result['categories']['items'][0]['name']);
self::assertEquals('Category 1.1.1', $page2Result['categories']['items'][1]['name']);

$lastPageQuery = sprintf($baseQuery, $page1Result['categories']['page_info']['total_pages']);
$lastPageResult = $this->graphQlQuery($lastPageQuery);
$this->assertCount(1, $lastPageResult['categories']['items']);
$this->assertEquals('Category 12', $lastPageResult['categories']['items'][0]['name']);
self::assertCount(1, $lastPageResult['categories']['items']);
self::assertEquals('Category 12', $lastPageResult['categories']['items'][0]['name']);
}

/**
Expand Down
Loading