|
13 | 13 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
14 | 14 | use Magento\Catalog\Model\Category;
|
15 | 15 | use Magento\Catalog\Model\CategoryLinkManagement;
|
| 16 | +use Magento\Catalog\Model\ResourceModel\Category\Collection; |
16 | 17 | use Magento\Eav\Model\Config;
|
17 | 18 | use Magento\TestFramework\ObjectManager;
|
18 | 19 | use Magento\TestFramework\TestCase\GraphQlAbstract;
|
@@ -463,7 +464,7 @@ private function getDefaultAttributeOptionValue(string $attributeCode) : string
|
463 | 464 | }
|
464 | 465 |
|
465 | 466 | /**
|
466 |
| - * Full text search for Products and then filter the results by custom attribute ( sort is by defaulty by relevance) |
| 467 | + * Full text search for Products and then filter the results by custom attribute (default sort is relevance) |
467 | 468 | *
|
468 | 469 | * @magentoApiDataFixture Magento/Catalog/_files/products_with_layered_navigation_custom_attribute.php
|
469 | 470 | * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
@@ -555,7 +556,7 @@ public function testSearchAndFilterByCustomAttribute()
|
555 | 556 | );
|
556 | 557 | }
|
557 | 558 |
|
558 |
| - // Validate the price layer of aggregations from the response |
| 559 | + // Validate the price layer of aggregations from the response |
559 | 560 | $this->assertResponseFields(
|
560 | 561 | $response['products']['aggregations'][0],
|
561 | 562 | [
|
@@ -695,7 +696,7 @@ public function testFilterByCategoryIdAndCustomAttribute()
|
695 | 696 | //Validate the number of categories/sub-categories that contain the products with the custom attribute
|
696 | 697 | $this->assertCount(6, $actualCategoriesFromResponse);
|
697 | 698 |
|
698 |
| - $expectedCategoryInAggregrations = |
| 699 | + $expectedCategoryInAggregations = |
699 | 700 | [
|
700 | 701 | [
|
701 | 702 | 'count' => 2,
|
@@ -732,9 +733,9 @@ public function testFilterByCategoryIdAndCustomAttribute()
|
732 | 733 | ],
|
733 | 734 | ];
|
734 | 735 | // presort expected and actual results as different search engines have different orders
|
735 |
| - usort($expectedCategoryInAggregrations, [$this, 'compareLabels']); |
| 736 | + usort($expectedCategoryInAggregations, [$this, 'compareLabels']); |
736 | 737 | usort($actualCategoriesFromResponse, [$this, 'compareLabels']);
|
737 |
| - $categoryInAggregations = array_map(null, $expectedCategoryInAggregrations, $actualCategoriesFromResponse); |
| 738 | + $categoryInAggregations = array_map(null, $expectedCategoryInAggregations, $actualCategoriesFromResponse); |
738 | 739 |
|
739 | 740 | //Validate the categories and sub-categories data in the filter layer
|
740 | 741 | foreach ($categoryInAggregations as $index => $categoryAggregationsData) {
|
@@ -1118,6 +1119,52 @@ public function testFilterWithinSpecificPriceRangeSortedByNameDesc()
|
1118 | 1119 | $this->assertEquals(4, $response['products']['page_info']['page_size']);
|
1119 | 1120 | }
|
1120 | 1121 |
|
| 1122 | + /** |
| 1123 | + * @magentoApiDataFixture Magento/Catalog/_files/category_with_three_products.php |
| 1124 | + */ |
| 1125 | + public function testSortByPosition() |
| 1126 | + { |
| 1127 | + // Get category ID for filtering |
| 1128 | + /** @var Collection $categoryCollection */ |
| 1129 | + $categoryCollection = Bootstrap::getObjectManager()->get(Collection::class); |
| 1130 | + $category = $categoryCollection->addFieldToFilter('name', 'Category 999')->getFirstItem(); |
| 1131 | + $categoryId = $category->getId(); |
| 1132 | + |
| 1133 | + $queryAsc = <<<QUERY |
| 1134 | +{ |
| 1135 | + products(filter: {category_id: {eq: "$categoryId"}}, sort: {position: ASC}) { |
| 1136 | + total_count |
| 1137 | + items { |
| 1138 | + sku |
| 1139 | + name |
| 1140 | + } |
| 1141 | + } |
| 1142 | +} |
| 1143 | +QUERY; |
| 1144 | + $resultAsc = $this->graphQlQuery($queryAsc); |
| 1145 | + $this->assertArrayNotHasKey('errors', $resultAsc); |
| 1146 | + $productsAsc = array_column($resultAsc['products']['items'], 'sku'); |
| 1147 | + $expectedProductsAsc = ['simple1000', 'simple1001', 'simple1002']; |
| 1148 | + $this->assertEquals($expectedProductsAsc, $productsAsc); |
| 1149 | + |
| 1150 | + $queryDesc = <<<QUERY |
| 1151 | +{ |
| 1152 | + products(filter: {category_id: {eq: "$categoryId"}}, sort: {position: DESC}) { |
| 1153 | + total_count |
| 1154 | + items { |
| 1155 | + sku |
| 1156 | + name |
| 1157 | + } |
| 1158 | + } |
| 1159 | +} |
| 1160 | +QUERY; |
| 1161 | + $resultDesc = $this->graphQlQuery($queryDesc); |
| 1162 | + $this->assertArrayNotHasKey('errors', $resultDesc); |
| 1163 | + $productsDesc = array_column($resultAsc['products']['items'], 'sku'); |
| 1164 | + $expectedProductsDesc = array_reverse($expectedProductsAsc); |
| 1165 | + $this->assertEquals($expectedProductsDesc, $productsDesc); |
| 1166 | + } |
| 1167 | + |
1121 | 1168 | /**
|
1122 | 1169 | * pageSize = total_count and current page = 2
|
1123 | 1170 | * expected - error is thrown
|
|
0 commit comments