Skip to content

Commit 562644f

Browse files
authored
Merge pull request #5534 from magento-honey-badgers/MC-32871
[honey] MC-32871: [MFTF] 21 Failing MFTF Tests in Page Builder Develop Branch
2 parents def8a07 + f5e74d7 commit 562644f

File tree

4 files changed

+39
-28
lines changed

4 files changed

+39
-28
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,10 @@ public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC)
17171717
// optimize if using cat index
17181718
$filters = $this->_productLimitationFilters;
17191719
if (isset($filters['category_id']) || isset($filters['visibility'])) {
1720-
$this->getSelect()->order(['cat_index.position ' . $dir, 'e.entity_id ' . $dir]);
1720+
$this->getSelect()->order([
1721+
'cat_index.position ' . $dir,
1722+
'e.entity_id ' . \Magento\Framework\DB\Select::SQL_DESC
1723+
]);
17211724
} else {
17221725
$this->getSelect()->order('e.entity_id ' . $dir);
17231726
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ public function testQueryChildCategoriesWithProducts()
188188
//Check base category products
189189
$expectedBaseCategoryProducts = [
190190
['sku' => 'simple', 'name' => 'Simple Product'],
191-
['sku' => '12345', 'name' => 'Simple Product Two'],
192-
['sku' => 'simple-4', 'name' => 'Simple Product Three']
191+
['sku' => 'simple-4', 'name' => 'Simple Product Three'],
192+
['sku' => '12345', 'name' => 'Simple Product Two']
193193
];
194194
$this->assertCategoryProducts($baseCategory, $expectedBaseCategoryProducts);
195195
//Check base category children
@@ -204,8 +204,8 @@ public function testQueryChildCategoriesWithProducts()
204204
$this->assertEquals('Category 1.1', $firstChildCategory['name']);
205205
$this->assertEquals('Category 1.1 description.', $firstChildCategory['description']);
206206
$firstChildCategoryExpectedProducts = [
207-
['sku' => 'simple', 'name' => 'Simple Product'],
208207
['sku' => '12345', 'name' => 'Simple Product Two'],
208+
['sku' => 'simple', 'name' => 'Simple Product']
209209
];
210210
$this->assertCategoryProducts($firstChildCategory, $firstChildCategoryExpectedProducts);
211211
$firstChildCategoryChildren = [['name' =>'Category 1.1.1']];
@@ -215,8 +215,8 @@ public function testQueryChildCategoriesWithProducts()
215215
$this->assertEquals('Category 1.2', $secondChildCategory['name']);
216216
$this->assertEquals('Its a description of Test Category 1.2', $secondChildCategory['description']);
217217
$firstChildCategoryExpectedProducts = [
218-
['sku' => 'simple', 'name' => 'Simple Product'],
219-
['sku' => 'simple-4', 'name' => 'Simple Product Three']
218+
['sku' => 'simple-4', 'name' => 'Simple Product Three'],
219+
['sku' => 'simple', 'name' => 'Simple Product']
220220
];
221221
$this->assertCategoryProducts($secondChildCategory, $firstChildCategoryExpectedProducts);
222222
$firstChildCategoryChildren = [];
@@ -281,8 +281,8 @@ public function testQueryCategoryWithDisabledChildren()
281281
//Check base category products
282282
$expectedBaseCategoryProducts = [
283283
['sku' => 'simple', 'name' => 'Simple Product'],
284-
['sku' => '12345', 'name' => 'Simple Product Two'],
285-
['sku' => 'simple-4', 'name' => 'Simple Product Three']
284+
['sku' => 'simple-4', 'name' => 'Simple Product Three'],
285+
['sku' => '12345', 'name' => 'Simple Product Two']
286286
];
287287
$this->assertCategoryProducts($baseCategory, $expectedBaseCategoryProducts);
288288
//Check base category children
@@ -297,8 +297,8 @@ public function testQueryCategoryWithDisabledChildren()
297297
$this->assertEquals('Its a description of Test Category 1.2', $firstChildCategory['description']);
298298

299299
$firstChildCategoryExpectedProducts = [
300-
['sku' => 'simple', 'name' => 'Simple Product'],
301-
['sku' => 'simple-4', 'name' => 'Simple Product Three']
300+
['sku' => 'simple-4', 'name' => 'Simple Product Three'],
301+
['sku' => 'simple', 'name' => 'Simple Product']
302302
];
303303
$this->assertCategoryProducts($firstChildCategory, $firstChildCategoryExpectedProducts);
304304
$firstChildCategoryChildren = [];

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ public function testQueryChildCategoriesWithProducts()
187187
//Check base category products
188188
$expectedBaseCategoryProducts = [
189189
['sku' => 'simple', 'name' => 'Simple Product'],
190-
['sku' => '12345', 'name' => 'Simple Product Two'],
191-
['sku' => 'simple-4', 'name' => 'Simple Product Three']
190+
['sku' => 'simple-4', 'name' => 'Simple Product Three'],
191+
['sku' => '12345', 'name' => 'Simple Product Two']
192192
];
193193
$this->assertCategoryProducts($baseCategory, $expectedBaseCategoryProducts);
194194
//Check base category children
@@ -203,8 +203,8 @@ public function testQueryChildCategoriesWithProducts()
203203
$this->assertEquals('Category 1.1', $firstChildCategory['name']);
204204
$this->assertEquals('Category 1.1 description.', $firstChildCategory['description']);
205205
$firstChildCategoryExpectedProducts = [
206-
['sku' => 'simple', 'name' => 'Simple Product'],
207206
['sku' => '12345', 'name' => 'Simple Product Two'],
207+
['sku' => 'simple', 'name' => 'Simple Product'],
208208
];
209209
$this->assertCategoryProducts($firstChildCategory, $firstChildCategoryExpectedProducts);
210210
$firstChildCategoryChildren = [['name' =>'Category 1.1.1']];
@@ -214,8 +214,8 @@ public function testQueryChildCategoriesWithProducts()
214214
$this->assertEquals('Category 1.2', $secondChildCategory['name']);
215215
$this->assertEquals('Its a description of Test Category 1.2', $secondChildCategory['description']);
216216
$firstChildCategoryExpectedProducts = [
217+
['sku' => 'simple-4', 'name' => 'Simple Product Three'],
217218
['sku' => 'simple', 'name' => 'Simple Product'],
218-
['sku' => 'simple-4', 'name' => 'Simple Product Three']
219219
];
220220
$this->assertCategoryProducts($secondChildCategory, $firstChildCategoryExpectedProducts);
221221
$firstChildCategoryChildren = [];
@@ -278,8 +278,8 @@ public function testQueryCategoryWithDisabledChildren()
278278
//Check base category products
279279
$expectedBaseCategoryProducts = [
280280
['sku' => 'simple', 'name' => 'Simple Product'],
281-
['sku' => '12345', 'name' => 'Simple Product Two'],
282-
['sku' => 'simple-4', 'name' => 'Simple Product Three']
281+
['sku' => 'simple-4', 'name' => 'Simple Product Three'],
282+
['sku' => '12345', 'name' => 'Simple Product Two']
283283
];
284284
$this->assertCategoryProducts($baseCategory, $expectedBaseCategoryProducts);
285285
//Check base category children
@@ -294,8 +294,8 @@ public function testQueryCategoryWithDisabledChildren()
294294
$this->assertEquals('Its a description of Test Category 1.2', $firstChildCategory['description']);
295295

296296
$firstChildCategoryExpectedProducts = [
297-
['sku' => 'simple', 'name' => 'Simple Product'],
298-
['sku' => 'simple-4', 'name' => 'Simple Product Three']
297+
['sku' => 'simple-4', 'name' => 'Simple Product Three'],
298+
['sku' => 'simple', 'name' => 'Simple Product']
299299
];
300300
$this->assertCategoryProducts($firstChildCategory, $firstChildCategoryExpectedProducts);
301301
$firstChildCategoryChildren = [];

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ private function reIndexAndCleanCache() : void
364364
$out = '';
365365
// phpcs:ignore Magento2.Security.InsecureFunction
366366
exec("php -f {$appDir}/bin/magento indexer:reindex catalog_category_product", $out);
367+
// phpcs:ignore Magento2.Security.InsecureFunction
368+
exec("php -f {$appDir}/bin/magento indexer:reindex catalogsearch_fulltext", $out);
367369
CacheCleaner::cleanAll();
368370
}
369371

@@ -670,15 +672,16 @@ public function testFilterByCategoryIdAndCustomAttribute()
670672
$productRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class);
671673
$product1 = $productRepository->get('simple');
672674
$product2 = $productRepository->get('simple-4');
673-
$filteredProducts = [$product1, $product2];
675+
$filteredProducts = [$product2, $product1];
674676
$productItemsInResponse = array_map(null, $response['products']['items'], $filteredProducts);
675677
//phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall
676678
for ($itemIndex = 0; $itemIndex < count($filteredProducts); $itemIndex++) {
677679
$this->assertNotEmpty($productItemsInResponse[$itemIndex]);
678680
//validate that correct products are returned
679681
$this->assertResponseFields(
680682
$productItemsInResponse[$itemIndex][0],
681-
[ 'name' => $filteredProducts[$itemIndex]->getName(),
683+
[
684+
'name' => $filteredProducts[$itemIndex]->getName(),
682685
'sku' => $filteredProducts[$itemIndex]->getSku()
683686
]
684687
);
@@ -1121,6 +1124,7 @@ public function testFilterWithinSpecificPriceRangeSortedByNameDesc()
11211124
*/
11221125
public function testSortByPosition()
11231126
{
1127+
$this->reIndexAndCleanCache();
11241128
// Get category ID for filtering
11251129
/** @var Collection $categoryCollection */
11261130
$categoryCollection = Bootstrap::getObjectManager()->get(Collection::class);
@@ -1141,7 +1145,8 @@ public function testSortByPosition()
11411145
$resultAsc = $this->graphQlQuery($queryAsc);
11421146
$this->assertArrayNotHasKey('errors', $resultAsc);
11431147
$productsAsc = array_column($resultAsc['products']['items'], 'sku');
1144-
$expectedProductsAsc = ['simple1000', 'simple1001', 'simple1002'];
1148+
$expectedProductsAsc = ['simple1002', 'simple1001', 'simple1000'];
1149+
// position equal and secondary sort by entity_id DESC
11451150
$this->assertEquals($expectedProductsAsc, $productsAsc);
11461151

11471152
$queryDesc = <<<QUERY
@@ -1158,23 +1163,25 @@ public function testSortByPosition()
11581163
$resultDesc = $this->graphQlQuery($queryDesc);
11591164
$this->assertArrayNotHasKey('errors', $resultDesc);
11601165
$productsDesc = array_column($resultDesc['products']['items'], 'sku');
1161-
$expectedProductsDesc = array_reverse($expectedProductsAsc);
1162-
$this->assertEquals($expectedProductsDesc, $productsDesc);
1166+
// position equal and secondary sort by entity_id DESC
1167+
$this->assertEquals($expectedProductsAsc, $productsDesc);
11631168

11641169
//revert position
11651170
$productPositions = $category->getProductsPosition();
1166-
$count = 3;
1171+
$count = 1;
11671172
foreach ($productPositions as $productId => $position) {
11681173
$productPositions[$productId] = $count;
1169-
$count--;
1174+
$count++;
11701175
}
1176+
ksort($productPositions);
11711177

11721178
$category->setPostedProducts($productPositions);
11731179
$category->save();
1180+
$this->reIndexAndCleanCache();
11741181

11751182
$queryDesc = <<<QUERY
11761183
{
1177-
products(filter: {category_id: {eq: "$categoryId"}}, sort: {position: DESC}) {
1184+
products(filter: {category_id: {eq: "$categoryId"}}, sort: {position: ASC}) {
11781185
total_count
11791186
items {
11801187
sku
@@ -1186,8 +1193,8 @@ public function testSortByPosition()
11861193
$resultDesc = $this->graphQlQuery($queryDesc);
11871194
$this->assertArrayNotHasKey('errors', $resultDesc);
11881195
$productsDesc = array_column($resultDesc['products']['items'], 'sku');
1189-
$expectedProductsDesc = $expectedProductsAsc;
1190-
$this->assertEquals($expectedProductsDesc, $productsDesc);
1196+
// position NOT equal and oldest entity first
1197+
$this->assertEquals(array_reverse($expectedProductsAsc), $productsDesc);
11911198
}
11921199

11931200
/**
@@ -1532,6 +1539,7 @@ public function testFilterProductsBySingleCategoryId()
15321539
$categoryRepository = ObjectManager::getInstance()->get(CategoryRepositoryInterface::class);
15331540

15341541
$links = $productLinks->getAssignedProducts($queryCategoryId);
1542+
$links = array_reverse($links);
15351543
foreach ($response['products']['items'] as $itemIndex => $itemData) {
15361544
$this->assertNotEmpty($itemData);
15371545
$this->assertEquals($response['products']['items'][$itemIndex]['sku'], $links[$itemIndex]->getSku());

0 commit comments

Comments
 (0)