Skip to content

Commit 68c48d5

Browse files
authored
Merge pull request #4839 from magento-arcticfoxes/MC-18143
[arcticfoxes] MC-18143: Adapt WebAPI to elasticsearch on CI
2 parents 81ab7c4 + cc6eccc commit 68c48d5

File tree

4 files changed

+93
-27
lines changed

4 files changed

+93
-27
lines changed

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryMultiCurrencyTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ProductRepositoryMultiCurrencyTest extends WebapiAbstract
1717
const WEBSITES_RESOURCE_PATH = '/V1/store/websites';
1818

1919
/**
20+
* @magentoApiDataFixture Magento/Catalog/_files/category.php
2021
* @magentoApiDataFixture Magento/Store/_files/second_website_with_second_currency.php
2122
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
2223
*/

dev/tests/api-functional/testsuite/Magento/Framework/Api/Search/SearchTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testCatalogSearch()
3838
]
3939
]
4040
],
41-
'page_size' => 20000000000000,
41+
'page_size' => 999,
4242
'current_page' => 0,
4343
],
4444
];
@@ -66,7 +66,15 @@ public function testCatalogSearch()
6666
$this->assertTrue(count($response['items']) > 0);
6767

6868
$this->assertNotNull($response['items'][0]['id']);
69-
$this->assertEquals('score', $response['items'][0]['custom_attributes'][0]['attribute_code']);
69+
$this->assertTrue(
70+
in_array(
71+
$response['items'][0]['custom_attributes'][0]['attribute_code'],
72+
[
73+
'score', // mysql
74+
'_score' // elasticsearch score
75+
]
76+
)
77+
);
7078
$this->assertTrue($response['items'][0]['custom_attributes'][0]['value'] > 0);
7179
}
7280
}

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

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Magento\Catalog\Model\Category;
1515
use Magento\Catalog\Model\CategoryLinkManagement;
1616
use Magento\Eav\Model\Config;
17-
use Magento\Indexer\Model\Indexer;
1817
use Magento\TestFramework\ObjectManager;
1918
use Magento\TestFramework\TestCase\GraphQlAbstract;
2019
use Magento\Catalog\Model\Product;
@@ -28,13 +27,15 @@
2827
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2928
* @SuppressWarnings(PHPMD.ExcessiveClassLength)
3029
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
30+
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
3131
*/
3232
class ProductSearchTest extends GraphQlAbstract
3333
{
3434
/**
3535
* Verify that layered navigation filters and aggregations are correct for product query
3636
*
3737
* Filter products by an array of skus
38+
* @magentoApiDataFixture Magento/Catalog/_files/category.php
3839
* @magentoApiDataFixture Magento/Catalog/_files/products_with_layered_navigation_attribute.php
3940
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
4041
*/
@@ -84,17 +85,37 @@ public function testFilterLn()
8485
$response['products'],
8586
'Filters are missing in product query result.'
8687
);
88+
89+
$expectedFilters = $this->getExpectedFiltersDataSet();
90+
$actualFilters = $response['products']['filters'];
91+
// presort expected and actual results as different search engines have different orders
92+
usort($expectedFilters, [$this, 'compareFilterNames']);
93+
usort($actualFilters, [$this, 'compareFilterNames']);
94+
8795
$this->assertFilters(
88-
$response,
89-
$this->getExpectedFiltersDataSet(),
96+
['products' => ['filters' => $actualFilters]],
97+
$expectedFilters,
9098
'Returned filters data set does not match the expected value'
9199
);
92100
}
93101

102+
/**
103+
* Compare arrays by value in 'name' field.
104+
*
105+
* @param array $a
106+
* @param array $b
107+
* @return int
108+
*/
109+
private function compareFilterNames(array $a, array $b)
110+
{
111+
return strcmp($a['name'], $b['name']);
112+
}
113+
94114
/**
95115
* Layered navigation for Configurable products with out of stock options
96116
* Two configurable products each having two variations and one of the child products of one Configurable set to OOS
97117
*
118+
* @magentoApiDataFixture Magento/Catalog/_files/category.php
98119
* @magentoApiDataFixture Magento/Catalog/_files/configurable_products_with_custom_attribute_layered_navigation.php
99120
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
100121
*/
@@ -305,15 +326,17 @@ public function testFilterProductsByDropDownCustomAttribute()
305326

306327
/**
307328
* @return void
329+
* @throws \Magento\Framework\Exception\LocalizedException
308330
*/
309331
private function reIndexAndCleanCache() : void
310332
{
311-
$objectManager = Bootstrap::getObjectManager();
312-
$indexer = $objectManager->create(Indexer::class);
313-
$indexer->load('catalogsearch_fulltext');
314-
$indexer->reindexAll();
333+
$appDir = dirname(Bootstrap::getInstance()->getAppTempDir());
334+
$out = '';
335+
// phpcs:ignore Magento2.Security.InsecureFunction
336+
exec("php -f {$appDir}/bin/magento indexer:reindex", $out);
315337
CacheCleaner::cleanAll();
316338
}
339+
317340
/**
318341
* Filter products using an array of multi select custom attributes
319342
*
@@ -676,9 +699,12 @@ public function testFilterByCategoryIdAndCustomAttribute()
676699
'value'=> '13'
677700
],
678701
];
702+
// presort expected and actual results as different search engines have different orders
703+
usort($expectedCategoryInAggregrations, [$this, 'compareLabels']);
704+
usort($actualCategoriesFromResponse, [$this, 'compareLabels']);
679705
$categoryInAggregations = array_map(null, $expectedCategoryInAggregrations, $actualCategoriesFromResponse);
680706

681-
//Validate the categories and sub-categories data in the filter layer
707+
//Validate the categories and sub-categories data in the filter layer
682708
foreach ($categoryInAggregations as $index => $categoryAggregationsData) {
683709
$this->assertNotEmpty($categoryAggregationsData);
684710
$this->assertEquals(
@@ -694,6 +720,18 @@ public function testFilterByCategoryIdAndCustomAttribute()
694720
}
695721
}
696722

723+
/**
724+
* Compare arrays by value in 'label' field.
725+
*
726+
* @param array $a
727+
* @param array $b
728+
* @return int
729+
*/
730+
private function compareLabels(array $a, array $b)
731+
{
732+
return strcmp($a['label'], $b['label']);
733+
}
734+
697735
/**
698736
* Filter by exact match of product url key
699737
*
@@ -982,6 +1020,7 @@ private function assertFilters($response, $expectedFilters, $message = '')
9821020
/**
9831021
* Verify product filtering using price range AND matching skus AND name sorted in DESC order
9841022
*
1023+
* @magentoApiDataFixture Magento/Catalog/_files/category.php
9851024
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
9861025
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
9871026
*/
@@ -1052,13 +1091,14 @@ public function testFilterWithinSpecificPriceRangeSortedByNameDesc()
10521091
* expected - error is thrown
10531092
* Actual - empty array
10541093
*
1094+
* @magentoApiDataFixture Magento/Catalog/_files/category.php
10551095
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
10561096
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
10571097
*/
10581098

10591099
public function testSearchWithFilterWithPageSizeEqualTotalCount()
10601100
{
1061-
1101+
$this->reIndexAndCleanCache();
10621102
$query
10631103
= <<<QUERY
10641104
{
@@ -1114,6 +1154,7 @@ public function testSearchWithFilterWithPageSizeEqualTotalCount()
11141154
/**
11151155
* Filtering for products and sorting using multiple sort parameters
11161156
*
1157+
* @magentoApiDataFixture Magento/Catalog/_files/category.php
11171158
* @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products_2.php
11181159
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
11191160
*/
@@ -1486,18 +1527,24 @@ public function testSearchAndSortByRelevance()
14861527
$this->assertEquals(3, $response['products']['total_count']);
14871528
$this->assertNotEmpty($response['products']['filters'], 'Filters should have the Category layer');
14881529
$this->assertEquals('Colorful Category', $response['products']['filters'][0]['filter_items'][0]['label']);
1530+
$this->assertCount(2, $response['products']['aggregations']);
14891531
$productsInResponse = ['Blue briefs','Navy Blue Striped Shoes','Grey shorts'];
1532+
/** @var \Magento\Config\Model\Config $config */
1533+
$config = Bootstrap::getObjectManager()->get(\Magento\Config\Model\Config::class);
1534+
if (strpos($config->getConfigDataValue('catalog/search/engine'), 'elasticsearch') !== false) {
1535+
$this->markTestIncomplete('MC-20716');
1536+
}
14901537
$count = count($response['products']['items']);
14911538
for ($i = 0; $i < $count; $i++) {
14921539
$this->assertEquals($productsInResponse[$i], $response['products']['items'][$i]['name']);
14931540
}
1494-
$this->assertCount(2, $response['products']['aggregations']);
14951541
}
14961542

14971543
/**
14981544
* Filtering for product with sku "equals" a specific value
14991545
* If pageSize and current page are not requested, default values are returned
15001546
*
1547+
* @magentoApiDataFixture Magento/Catalog/_files/category.php
15011548
* @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products_2.php
15021549
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
15031550
*/
@@ -1748,6 +1795,7 @@ public function testFilterWithinASpecificPriceRangeSortedByPriceDESC()
17481795
/**
17491796
* No items are returned if the conditions are not met
17501797
*
1798+
* @magentoApiDataFixture Magento/Catalog/_files/category.php
17511799
* @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products_2.php
17521800
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
17531801
*/
@@ -1807,6 +1855,7 @@ public function testQueryFilterNoMatchingItems()
18071855
/**
18081856
* Asserts that exception is thrown when current page > totalCount of items returned
18091857
*
1858+
* @magentoApiDataFixture Magento/Catalog/_files/category.php
18101859
* @magentoApiDataFixture Magento/Catalog/_files/multiple_mixed_products_2.php
18111860
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
18121861
*/
@@ -1953,6 +2002,7 @@ public function testFilterProductsThatAreOutOfStockWithConfigSettings()
19532002
/**
19542003
* Verify that invalid current page return an error
19552004
*
2005+
* @magentoApiDataFixture Magento/Catalog/_files/category.php
19562006
* @magentoApiDataFixture Magento/Catalog/_files/products_with_layered_navigation_attribute.php
19572007
* @expectedException \Exception
19582008
* @expectedExceptionMessage currentPage value must be greater than 0
@@ -1982,6 +2032,7 @@ public function testInvalidCurrentPage()
19822032
/**
19832033
* Verify that invalid page size returns an error.
19842034
*
2035+
* @magentoApiDataFixture Magento/Catalog/_files/category.php
19852036
* @magentoApiDataFixture Magento/Catalog/_files/products_with_layered_navigation_attribute.php
19862037
* @expectedException \Exception
19872038
* @expectedExceptionMessage pageSize value must be greater than 0

dev/tests/api-functional/testsuite/Magento/WebapiAsync/Model/AsyncScheduleMultiStoreTest.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Magento\WebapiAsync\Model;
1010

11-
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Api\Data\ProductInterface as Product;
1212
use Magento\TestFramework\MessageQueue\PreconditionFailedException;
1313
use Magento\TestFramework\MessageQueue\PublisherConsumerController;
1414
use Magento\TestFramework\MessageQueue\EnvironmentPreconditionException;
@@ -19,7 +19,6 @@
1919
use Magento\Framework\Registry;
2020
use Magento\Framework\Webapi\Exception;
2121
use Magento\Catalog\Api\ProductRepositoryInterface;
22-
use Magento\Catalog\Api\Data\ProductInterface as Product;
2322
use Magento\Framework\ObjectManagerInterface;
2423
use Magento\Store\Model\Store;
2524
use Magento\Framework\Webapi\Rest\Request;
@@ -128,6 +127,13 @@ protected function setUp()
128127
*/
129128
public function testAsyncScheduleBulkMultistore($storeCode)
130129
{
130+
if ($storeCode === self::STORE_CODE_FROM_FIXTURE) {
131+
/** @var \Magento\Config\Model\Config $config */
132+
$config = Bootstrap::getObjectManager()->get(\Magento\Config\Model\Config::class);
133+
if (strpos($config->getConfigDataValue('catalog/search/engine'), 'elasticsearch') !== false) {
134+
$this->markTestSkipped('MC-20452');
135+
}
136+
}
131137
$product = $this->getProductData();
132138
$this->_markTestAsRestOnly();
133139

@@ -277,9 +283,9 @@ public function getProductData()
277283
'product' =>
278284
$productBuilder(
279285
[
280-
ProductInterface::TYPE_ID => 'simple',
281-
ProductInterface::SKU => 'multistore-sku-test-1',
282-
ProductInterface::NAME => 'Test Name ',
286+
Product::TYPE_ID => 'simple',
287+
Product::SKU => 'multistore-sku-test-1',
288+
Product::NAME => 'Test Name ',
283289
]
284290
),
285291
];
@@ -303,16 +309,16 @@ public function storeProvider()
303309
private function getSimpleProductData($productData = [])
304310
{
305311
return [
306-
ProductInterface::SKU => isset($productData[ProductInterface::SKU])
307-
? $productData[ProductInterface::SKU] : uniqid('sku-', true),
308-
ProductInterface::NAME => isset($productData[ProductInterface::NAME])
309-
? $productData[ProductInterface::NAME] : uniqid('sku-', true),
310-
ProductInterface::VISIBILITY => 4,
311-
ProductInterface::TYPE_ID => 'simple',
312-
ProductInterface::PRICE => 3.62,
313-
ProductInterface::STATUS => 1,
314-
ProductInterface::TYPE_ID => 'simple',
315-
ProductInterface::ATTRIBUTE_SET_ID => 4,
312+
Product::SKU => isset($productData[Product::SKU])
313+
? $productData[Product::SKU] : uniqid('sku-', true),
314+
Product::NAME => isset($productData[Product::NAME])
315+
? $productData[Product::NAME] : uniqid('sku-', true),
316+
Product::VISIBILITY => 4,
317+
Product::TYPE_ID => 'simple',
318+
Product::PRICE => 3.62,
319+
Product::STATUS => 1,
320+
Product::TYPE_ID => 'simple',
321+
Product::ATTRIBUTE_SET_ID => 4,
316322
];
317323
}
318324

0 commit comments

Comments
 (0)