Skip to content

Commit

Permalink
Merge pull request #89 from magento-arcticfoxes/MC-19450-elastic
Browse files Browse the repository at this point in the history
Rebasing MC-19451 with the changes of MC-19450-elastic branch
  • Loading branch information
amolina-adobe authored Sep 23, 2019
2 parents e8498b6 + b026712 commit 32af0e3
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ private function getSearchResultApplier(SearchResultInterface $searchResult): Se
/** This variable sets by serOrder method, but doesn't have a getter method. */
'orders' => $this->_orders,
'size' => $this->getPageSize(),
'currentPage' => (int)$this->_curPage,
]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,6 @@ public function cleanIndex($storeId, $mappedIndexerId)
{
$this->checkIndex($storeId, $mappedIndexerId, true);
$indexName = $this->indexNameResolver->getIndexName($storeId, $mappedIndexerId, $this->preparedIndex);
if ($this->client->isEmptyIndex($indexName)) {
// use existing index if empty
return $this;
}

// prepare new index name and increase version
$indexPattern = $this->indexNameResolver->getIndexPattern($storeId, $mappedIndexerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,20 @@ protected function setUp()

/**
* @magentoDataFixture Magento/Bundle/_files/product.php
* @covers \Magento\Indexer\Model\Indexer::reindexAll
* @covers \Magento\Bundle\Model\Product\Type::getSearchableData
* @magentoDbIsolation disabled
*/
public function testPrepareProductIndexForBundleProduct()
public function testGetSearchableData()
{
$this->indexer->reindexAll();

$select = $this->connectionMock->select()->from($this->resource->getTableName('catalogsearch_fulltext_scope1'))
->where('`data_index` LIKE ?', '%' . 'Bundle Product Items' . '%');
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
/** @var \Magento\Catalog\Model\Product $bundleProduct */
$bundleProduct = $productRepository->get('bundle-product');
$bundleType = $bundleProduct->getTypeInstance();
/** @var \Magento\Bundle\Model\Product\Type $bundleType */
$searchableData = $bundleType->getSearchableData($bundleProduct);

$result = $this->connectionMock->fetchAll($select);
$this->assertCount(1, $result);
$this->assertCount(1, $searchableData);
$this->assertEquals('Bundle Product Items', $searchableData[0]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public function testDeleteCategory()
*
* @magentoConfigFixture current_store catalog/frontend/flat_catalog_category true
* @magentoAppArea frontend
* @magentoDbIsolation disabled
*/
public function testFlatAfterDeleted()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function setUpBeforeClass()

protected function setUp()
{
$this->_processor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
$this->_processor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Model\Indexer\Product\Eav\Processor::class
);
}
Expand All @@ -46,24 +46,24 @@ protected function setUp()
public function testReindexAll()
{
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attr **/
$attr = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Eav\Model\Config::class)
$attr = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Eav\Model\Config::class)
->getAttribute('catalog_product', 'weight');
$attr->setIsFilterable(1)->save();

$this->assertTrue($attr->isIndexable());

$priceIndexerProcessor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
$priceIndexerProcessor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Model\Indexer\Product\Price\Processor::class
);
$priceIndexerProcessor->reindexAll();

$this->_processor->reindexAll();

$categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
$categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Model\CategoryFactory::class
);
/** @var \Magento\Catalog\Block\Product\ListProduct $listProduct */
$listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
$listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Block\Product\ListProduct::class
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function getRangeItemCountsDataProvider()
/**
* @magentoDataFixture Magento/Catalog/_files/categories.php
* @magentoDbIsolation disabled
* @magentoConfigFixture default/catalog/search/engine mysql
* @dataProvider getRangeItemCountsDataProvider
*/
public function testGetRangeItemCounts($inputRange, $expectedItemCounts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function testGetUrlInStore()
* @magentoConfigFixture fixturestore_store web/unsecure/base_url http://sample-second.com/
* @magentoConfigFixture fixturestore_store web/unsecure/base_link_url http://sample-second.com/
* @magentoDataFixture Magento/Catalog/_files/product_simple_multistore.php
* @magentoDbIsolation disabled
* @dataProvider getUrlsWithSecondStoreProvider
* @magentoAppArea adminhtml
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/**
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/CatalogSearch/_files/full_reindex.php
*/
class ResultTest extends \Magento\TestFramework\TestCase\AbstractController
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function testSearchProductByAttribute()
$requestBuilder->setRequestName('quick_search_container');
$queryRequest = $requestBuilder->create();
/** @var \Magento\Framework\Search\Adapter\Mysql\Adapter $adapter */
$adapter = $objectManager->create(\Magento\Framework\Search\Adapter\Mysql\Adapter::class);
$adapterFactory = $objectManager->create(\Magento\Search\Model\AdapterFactory::class);
$adapter = $adapterFactory->create();
$queryResponse = $adapter->query($queryRequest);
$actualIds = [];
foreach ($queryResponse as $document) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,32 @@
*/
class FullTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\CatalogSearch\Model\Indexer\Fulltext\Action\Full
*/
protected $actionFull;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->actionFull = Bootstrap::getObjectManager()->create(
\Magento\CatalogSearch\Model\Indexer\Fulltext\Action\Full::class
);
}

/**
* Testing fulltext index rebuild
*
* @magentoDataFixture Magento/CatalogSearch/_files/products_for_index.php
* @magentoDataFixture Magento/CatalogSearch/_files/product_configurable_not_available.php
* @magentoDataFixture Magento/Framework/Search/_files/product_configurable.php
* @magentoConfigFixture default/catalog/search/engine mysql
*/
public function testGetIndexData()
{
$engineProvider = Bootstrap::getObjectManager()->create(
\Magento\CatalogSearch\Model\ResourceModel\EngineProvider::class
);
$dataProvider = Bootstrap::getObjectManager()->create(
\Magento\CatalogSearch\Model\Indexer\Fulltext\Action\DataProvider::class,
['engineProvider' => $engineProvider]
);
$actionFull = Bootstrap::getObjectManager()->create(
\Magento\CatalogSearch\Model\Indexer\Fulltext\Action\Full::class,
['dataProvider' => $dataProvider]
);
/** @var ProductRepositoryInterface $productRepository */
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
$allowedStatuses = Bootstrap::getObjectManager()->get(Status::class)->getVisibleStatusIds();
$allowedVisibility = Bootstrap::getObjectManager()->get(Engine::class)->getAllowedVisibility();
$result = iterator_to_array($this->actionFull->rebuildStoreIndex(Store::DISTRO_STORE_ID));
$result = iterator_to_array($actionFull->rebuildStoreIndex(Store::DISTRO_STORE_ID));
$this->assertNotEmpty($result);

$productsIds = array_keys($result);
Expand Down Expand Up @@ -132,6 +129,9 @@ private function getExpectedIndexData()
*/
public function testRebuildStoreIndexConfigurable()
{
$actionFull = Bootstrap::getObjectManager()->create(
\Magento\CatalogSearch\Model\Indexer\Fulltext\Action\Full::class
);
$storeId = 1;

$simpleProductId = $this->getIdBySku('simple_10');
Expand All @@ -141,8 +141,8 @@ public function testRebuildStoreIndexConfigurable()
$simpleProductId,
$configProductId
];
$storeIndexDataSimple = $this->actionFull->rebuildStoreIndex($storeId, [$simpleProductId]);
$storeIndexDataExpected = $this->actionFull->rebuildStoreIndex($storeId, $expected);
$storeIndexDataSimple = $actionFull->rebuildStoreIndex($storeId, [$simpleProductId]);
$storeIndexDataExpected = $actionFull->rebuildStoreIndex($storeId, $expected);

$this->assertEquals($storeIndexDataSimple, $storeIndexDataExpected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Visibility;
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection;
use Magento\TestFramework\Helper\Bootstrap;

/**
Expand Down Expand Up @@ -76,10 +75,6 @@ protected function setUp()
);
$this->indexer->load('catalogsearch_fulltext');

$this->engine = Bootstrap::getObjectManager()->get(
\Magento\CatalogSearch\Model\ResourceModel\Engine::class
);

$this->queryFactory = Bootstrap::getObjectManager()->get(
\Magento\Search\Model\QueryFactory::class
);
Expand Down Expand Up @@ -223,12 +218,8 @@ protected function search(string $text, $visibilityFilter = null): array
$query->setQueryText($text);
$query->saveIncrementalPopularity();
$products = [];
$collection = Bootstrap::getObjectManager()->create(
Collection::class,
[
'searchRequestName' => 'quick_search_container'
]
);
$searchLayer = Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Layer\Search::class);
$collection = $searchLayer->getProductCollection();
$collection->addSearchFilter($text);

if (null !== $visibilityFilter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class CollectionTest extends \PHPUnit\Framework\TestCase

protected function setUp()
{
$this->advancedCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->create(\Magento\CatalogSearch\Model\ResourceModel\Advanced\Collection::class);
$advanced = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->create(\Magento\CatalogSearch\Model\Search\ItemCollectionProvider::class);
$this->advancedCollection = $advanced->getCollection();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class CollectionTest extends \PHPUnit\Framework\TestCase
/**
* @dataProvider filtersDataProviderSearch
* @magentoDataFixture Magento/Framework/Search/_files/products.php
* @magentoDataFixture Magento/CatalogSearch/_files/full_reindex.php
* @magentoConfigFixture default/catalog/search/engine mysql
* @magentoAppIsolation enabled
*/
public function testLoadWithFilterSearch($request, $filters, $expectedCount)
{
Expand All @@ -31,6 +34,42 @@ public function testLoadWithFilterSearch($request, $filters, $expectedCount)
$this->assertCount($expectedCount, $items);
}

/**
* @dataProvider filtersDataProviderQuickSearch
* @magentoDataFixture Magento/Framework/Search/_files/products.php
*/
public function testLoadWithFilterQuickSearch($filters, $expectedCount)
{
$objManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$searchLayer = $objManager->create(\Magento\Catalog\Model\Layer\Search::class);
/** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $fulltextCollection */
$fulltextCollection = $searchLayer->getProductCollection();
foreach ($filters as $field => $value) {
$fulltextCollection->addFieldToFilter($field, $value);
}
$fulltextCollection->loadWithFilter();
$items = $fulltextCollection->getItems();
$this->assertCount($expectedCount, $items);
}

/**
* @dataProvider filtersDataProviderCatalogView
* @magentoDataFixture Magento/Framework/Search/_files/products.php
*/
public function testLoadWithFilterCatalogView($filters, $expectedCount)
{
$objManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$searchLayer = $objManager->create(\Magento\Catalog\Model\Layer\Category::class);
/** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $fulltextCollection */
$fulltextCollection = $searchLayer->getProductCollection();
foreach ($filters as $field => $value) {
$fulltextCollection->addFieldToFilter($field, $value);
}
$fulltextCollection->loadWithFilter();
$items = $fulltextCollection->getItems();
$this->assertCount($expectedCount, $items);
}

/**
* @magentoDataFixture Magento/Framework/Search/_files/products_with_the_same_search_score.php
*/
Expand All @@ -42,11 +81,9 @@ public function testSearchResultsAreTheSameForSameRequests()
$objManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();

foreach (range(1, $howManySearchRequests) as $i) {
$searchLayer = $objManager->create(\Magento\Catalog\Model\Layer\Search::class);
/** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $fulltextCollection */
$fulltextCollection = $objManager->create(
\Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection::class,
['searchRequestName' => 'quick_search_container']
);
$fulltextCollection = $searchLayer->getProductCollection();

$fulltextCollection->addFieldToFilter('search_term', 'shorts');
$fulltextCollection->setOrder('relevance');
Expand Down Expand Up @@ -81,4 +118,22 @@ public function filtersDataProviderSearch()
['catalog_view_container', [], 0],
];
}

public function filtersDataProviderQuickSearch()
{
return [
[['search_term' => ' shorts'], 2],
[['search_term' => 'nonexistent'], 0],
];
}

public function filtersDataProviderCatalogView()
{
return [
[['category_ids' => 2], 5],
[['category_ids' => 100001], 0],
[['category_ids' => []], 5],
[[], 5],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Indexer\Category\Product as CategoryIndexer;
use Magento\CatalogSearch\Model\Indexer\Fulltext as FulltextIndexer;
use Magento\Elasticsearch\Model\Config;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Indexer\IndexerInterface;
use Magento\Framework\Indexer\IndexerRegistry;
Expand All @@ -35,13 +34,6 @@ protected function setUp()
{
parent::setUp();

$config = $this->getMockBuilder(Config::class)
->disableOriginalConstructor()
->getMock();
$config->method('isElasticsearchEnabled')
->willReturn(true);
$this->_objectManager->addSharedInstance($config, Config::class);

$this->changeIndexerSchedule(FulltextIndexer::INDEXER_ID, true);
$this->changeIndexerSchedule(CategoryIndexer::INDEXER_ID, true);
}
Expand All @@ -51,7 +43,6 @@ protected function setUp()
*/
protected function tearDown()
{
$this->_objectManager->removeSharedInstance(Config::class);
$this->changeIndexerSchedule(FulltextIndexer::INDEXER_ID, $this->indexerSchedule[FulltextIndexer::INDEXER_ID]);
$this->changeIndexerSchedule(CategoryIndexer::INDEXER_ID, $this->indexerSchedule[CategoryIndexer::INDEXER_ID]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class UrlRewriteTest extends AbstractController
{
/**
* @magentoDataFixture Magento/UrlRewrite/_files/url_rewrite.php
* @magentoDbIsolation disabled
*
* @covers \Magento\UrlRewrite\Controller\Router::match
* @covers \Magento\UrlRewrite\Model\Storage\DbStorage::doFindOneByData
Expand Down
Loading

0 comments on commit 32af0e3

Please sign in to comment.