|
15 | 15 | */
|
16 | 16 | class SwitcherUsedInFulltextTest extends \PHPUnit_Framework_TestCase
|
17 | 17 | {
|
| 18 | + /** |
| 19 | + * @var IndexSwitcherInterface |
| 20 | + */ |
| 21 | + private $indexSwitcher; |
| 22 | + |
18 | 23 | /**
|
19 | 24 | * @var \Magento\Framework\Indexer\IndexerInterface
|
20 | 25 | */
|
@@ -72,54 +77,96 @@ class SwitcherUsedInFulltextTest extends \PHPUnit_Framework_TestCase
|
72 | 77 |
|
73 | 78 | protected function setUp()
|
74 | 79 | {
|
| 80 | + $objectManager = Bootstrap::getObjectManager(); |
| 81 | + |
| 82 | + $objectManager->configure( |
| 83 | + [ |
| 84 | + 'Magento\CatalogSearch\Model\Indexer\Fulltext' => [ |
| 85 | + 'arguments' => [ |
| 86 | + 'indexSwitcher' => [ |
| 87 | + 'instance' => 'Magento\CatalogSearch\Model\Indexer\IndexSwitcherMock', |
| 88 | + ], |
| 89 | + ], |
| 90 | + ], |
| 91 | + ] |
| 92 | + ); |
| 93 | + |
75 | 94 | /** @var \Magento\Framework\Indexer\IndexerInterface indexer */
|
76 |
| - $this->indexer = Bootstrap::getObjectManager()->create( |
| 95 | + $this->indexer = $objectManager->create( |
77 | 96 | \Magento\Indexer\Model\Indexer::class
|
78 | 97 | );
|
79 | 98 | $this->indexer->load('catalogsearch_fulltext');
|
80 | 99 |
|
81 |
| - $objectManager = Bootstrap::getObjectManager(); |
82 | 100 | $this->engine = $objectManager->get(
|
83 | 101 | \Magento\CatalogSearch\Model\ResourceModel\Engine::class
|
84 | 102 | );
|
85 | 103 |
|
86 |
| - $this->resourceFulltext = Bootstrap::getObjectManager()->get( |
| 104 | + $this->resourceFulltext = $objectManager->get( |
87 | 105 | \Magento\CatalogSearch\Model\ResourceModel\Fulltext::class
|
88 | 106 | );
|
89 | 107 |
|
90 |
| - $this->queryFactory = Bootstrap::getObjectManager()->get( |
| 108 | + $this->queryFactory = $objectManager->get( |
91 | 109 | \Magento\Search\Model\QueryFactory::class
|
92 | 110 | );
|
93 | 111 |
|
94 |
| - $this->dimension = Bootstrap::getObjectManager()->create( |
| 112 | + $this->dimension = $objectManager->create( |
95 | 113 | \Magento\Framework\Search\Request\Dimension::class,
|
96 | 114 | ['name' => 'scope', 'value' => '1']
|
97 | 115 | );
|
98 | 116 |
|
| 117 | + $this->indexSwitcher = Bootstrap::getObjectManager()->get( |
| 118 | + \Magento\CatalogSearch\Model\Indexer\IndexSwitcherMock::class |
| 119 | + ); |
| 120 | + |
99 | 121 | $this->productApple = $this->getProductBySku('fulltext-1');
|
100 | 122 | $this->productBanana = $this->getProductBySku('fulltext-2');
|
101 | 123 | $this->productOrange = $this->getProductBySku('fulltext-3');
|
102 | 124 | $this->productPapaya = $this->getProductBySku('fulltext-4');
|
103 | 125 | $this->productCherry = $this->getProductBySku('fulltext-5');
|
104 | 126 | }
|
105 | 127 |
|
| 128 | + /** |
| 129 | + * @magentoAppIsolation enabled |
| 130 | + */ |
106 | 131 | public function testReindexAll()
|
107 | 132 | {
|
108 | 133 | $this->indexer->reindexAll();
|
109 | 134 |
|
110 |
| - $products = $this->search('Apple'); |
111 |
| - $this->assertCount(1, $products); |
112 |
| - $this->assertEquals($this->productApple->getId(), $products[0]->getId()); |
113 |
| - |
114 |
| - $products = $this->search('Simple Product'); |
115 |
| - $this->assertCount(5, $products); |
116 | 135 | /** @var \Magento\CatalogSearch\Model\Indexer\IndexSwitcherMock $indexSwitcher */
|
117 | 136 | $indexSwitcher = Bootstrap::getObjectManager()->get(
|
118 | 137 | \Magento\CatalogSearch\Model\Indexer\IndexSwitcherMock::class
|
119 | 138 | );
|
120 | 139 | $this->assertTrue($indexSwitcher->isSwitched());
|
121 | 140 | }
|
122 | 141 |
|
| 142 | + /** |
| 143 | + * @magentoAppIsolation enabled |
| 144 | + */ |
| 145 | + public function testReindexList() |
| 146 | + { |
| 147 | + $this->indexer->reindexList([$this->productApple->getId(), $this->productBanana->getId()]); |
| 148 | + |
| 149 | + /** @var \Magento\CatalogSearch\Model\Indexer\IndexSwitcherMock $indexSwitcher */ |
| 150 | + $indexSwitcher = Bootstrap::getObjectManager()->get( |
| 151 | + \Magento\CatalogSearch\Model\Indexer\IndexSwitcherMock::class |
| 152 | + ); |
| 153 | + $this->assertFalse($indexSwitcher->isSwitched()); |
| 154 | + } |
| 155 | + |
| 156 | + /** |
| 157 | + * @magentoAppIsolation enabled |
| 158 | + */ |
| 159 | + public function testReindexRow() |
| 160 | + { |
| 161 | + $this->indexer->reindexRow($this->productPapaya->getId()); |
| 162 | + |
| 163 | + /** @var \Magento\CatalogSearch\Model\Indexer\IndexSwitcherMock $indexSwitcher */ |
| 164 | + $indexSwitcher = Bootstrap::getObjectManager()->get( |
| 165 | + \Magento\CatalogSearch\Model\Indexer\IndexSwitcherMock::class |
| 166 | + ); |
| 167 | + $this->assertFalse($indexSwitcher->isSwitched()); |
| 168 | + } |
| 169 | + |
123 | 170 | /**
|
124 | 171 | * Search the text and return result collection
|
125 | 172 | *
|
|
0 commit comments