Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BaseSelectFullTextSearchStrategyTest.php
Go to the documentation of this file.
1 <?php
8 
11 use Magento\CatalogSearch\Model\Search\SelectContainer\SelectContainerFactory;
12 
13 class BaseSelectFullTextSearchStrategyTest extends \PHPUnit\Framework\TestCase
14 {
18  private $baseSelectFullTextSearchStrategy;
19 
23  private $selectContainerFactory;
24 
28  private $resource;
29 
33  private $scopeResolver;
34 
35  protected function setUp()
36  {
37  $this->baseSelectFullTextSearchStrategy = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
38  ->create(BaseSelectFullTextSearchStrategy::class);
39 
40  $this->selectContainerFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
41  ->create(SelectContainerFactory::class);
42 
44  ->create(ResourceConnection::class);
45 
47  ->create(IndexScopeResolver::class);
48  }
49 
50  public function testCreateBaseSelect()
51  {
52  $selectContainer = $this->getSelectContainerWithFullTextSearch();
53  $selectContainer = $this->baseSelectFullTextSearchStrategy->createBaseSelect($selectContainer);
54  $select = $selectContainer->getSelect();
55  $expectedSelect = $this->getExpectedSelect();
56 
57  $this->assertEquals((string) $expectedSelect, (string) $select);
58  }
59 
60  private function getExpectedSelect()
61  {
62  $select = $this->resource->getConnection()->select();
63  $select->from(
64  ['search_index' => $this->scopeResolver->resolve('', [])],
65  ['entity_id' => 'entity_id']
66  )->joinInner(
67  ['cea' => $this->resource->getTableName('catalog_eav_attribute')],
68  'search_index.attribute_id = cea.attribute_id',
69  []
70  );
71 
72  return $select;
73  }
74 
75  private function getSelectContainerWithFullTextSearch()
76  {
77  return $this->selectContainerFactory->create(
78  [
79  'nonCustomAttributesFilters' => [],
80  'customAttributesFilters' => [],
81  'visibilityFilter' => null,
82  'isFullTextSearchRequired' => true,
83  'isShowOutOfStockEnabled' => false,
84  'usedIndex' => '',
85  'dimensions' => [],
86  'select' => $this->resource->getConnection()->select()
87  ]
88  );
89  }
90 }