Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SwitcherUsedInFulltextTest.php
Go to the documentation of this file.
1 <?php
7 
11 
17 class SwitcherUsedInFulltextTest extends \PHPUnit\Framework\TestCase
18 {
22  private $indexSwitcher;
23 
27  protected $indexer;
28 
32  protected $engine;
33 
37  protected $fulltext;
38 
42  protected $queryFactory;
43 
47  protected $productApple;
48 
52  protected $productBanana;
53 
57  protected $productOrange;
58 
62  protected $productPapaya;
63 
67  protected $productCherry;
68 
72  protected $dimension;
73 
74  protected function setUp()
75  {
77 
78  $objectManager->configure(
79  [
80  ltrim(Fulltext::class, '\\') => [
81  'arguments' => [
82  'indexSwitcher' => [
83  'instance' => ltrim(IndexSwitcherMock::class, '\\'),
84  ],
85  ],
86  ],
87  ]
88  );
89 
91  $this->indexer = $objectManager->create(
92  \Magento\Indexer\Model\Indexer::class
93  );
94  $this->indexer->load('catalogsearch_fulltext');
95 
96  $this->engine = $objectManager->get(
97  \Magento\CatalogSearch\Model\ResourceModel\Engine::class
98  );
99 
100  $this->queryFactory = $objectManager->get(
101  \Magento\Search\Model\QueryFactory::class
102  );
103 
104  $this->dimension = $objectManager->create(
105  \Magento\Framework\Search\Request\Dimension::class,
106  ['name' => 'scope', 'value' => '1']
107  );
108 
109  $this->indexSwitcher = Bootstrap::getObjectManager()->get(
110  IndexSwitcherMock::class
111  );
112 
113  $this->productApple = $this->getProductBySku('fulltext-1');
114  $this->productBanana = $this->getProductBySku('fulltext-2');
115  $this->productOrange = $this->getProductBySku('fulltext-3');
116  $this->productPapaya = $this->getProductBySku('fulltext-4');
117  $this->productCherry = $this->getProductBySku('fulltext-5');
118  }
119 
123  public function testReindexAll()
124  {
125  $this->indexer->reindexAll();
126 
128  $indexSwitcher = Bootstrap::getObjectManager()->get(
129  IndexSwitcherMock::class
130  );
131  $this->assertTrue($indexSwitcher->isSwitched());
132  }
133 
137  public function testReindexList()
138  {
139  $this->indexer->reindexList([$this->productApple->getId(), $this->productBanana->getId()]);
140 
142  $indexSwitcher = Bootstrap::getObjectManager()->get(
143  IndexSwitcherMock::class
144  );
145  $this->assertFalse($indexSwitcher->isSwitched());
146  }
147 
151  public function testReindexRow()
152  {
153  $this->indexer->reindexRow($this->productPapaya->getId());
154 
156  $indexSwitcher = Bootstrap::getObjectManager()->get(
157  IndexSwitcherMock::class
158  );
159  $this->assertFalse($indexSwitcher->isSwitched());
160  }
161 
168  protected function search($text)
169  {
170  $query = $this->queryFactory->get();
171  $query->unsetData();
172  $query->setQueryText($text);
173  $query->saveIncrementalPopularity();
174  $products = [];
176  Collection::class,
177  [
178  'searchRequestName' => 'quick_search_container'
179  ]
180  );
181  $collection->addSearchFilter($text);
182  foreach ($collection as $product) {
183  $products[] = $product;
184  }
185  return $products;
186  }
187 
194  protected function getProductBySku($sku)
195  {
198  \Magento\Catalog\Model\Product::class
199  );
200  return $product->loadByAttribute('sku', $sku);
201  }
202 }
$objectManager
Definition: bootstrap.php:17
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43