/** * Return own indexer object * * @return \Magento\Indexer\Model\IndexerInterface */ protected function getIndexer() { if (!$this->indexer->getId()) { $this->indexer->load(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID); } return $this->indexer; }
/** * Return own indexer object * * @return \Magento\Indexer\Model\IndexerInterface */ protected function getIndexer() { if (!$this->indexer->getId()) { $this->indexer->load(\Magento\Catalog\Model\Indexer\Category\Flat\State::INDEXER_ID); } return $this->indexer; }
/** * Execute materialization on ids entities * * @param int[] $ids * @return void */ public function execute($ids) { $this->indexer->load(self::INDEXER_ID); /** @var Fulltext\Action\Rows $action */ $action = $this->rowsActionFactory->create(); $action->reindex($ids); }
/** * @magentoDataFixture Magento/Catalog/_files/indexer_catalog_category.php * @magentoDbIsolation enabled */ public function testReindexAll() { $categories = $this->getCategories(4); $products = $this->getProducts(2); /** @var Category $categoryFourth */ $categoryFourth = end($categories); foreach ($products as $product) { /** @var \Magento\Catalog\Model\Product $product */ $product->setCategoryIds([$categoryFourth->getId()]); $product->save(); } /** @var Category $categoryThird */ $categoryThird = $categories[2]; $categoryThird->setIsAnchor(true); $categoryThird->save(); $this->clearIndex(); $categories = [self::DEFAULT_ROOT_CATEGORY, $categoryThird->getId(), $categoryFourth->getId()]; $this->indexer->reindexAll(); foreach ($products as $product) { /** @var \Magento\Catalog\Model\Product $product */ foreach ($categories as $categoryId) { $this->assertTrue((bool) $this->productResource->canBeShowInCategory($product, $categoryId)); } $this->assertFalse((bool) $this->productResource->canBeShowInCategory($product, $categoryThird->getParentId())); } }
/** * Return own indexer object * * @return \Magento\Indexer\Model\IndexerInterface */ protected function getIndexer() { if (!$this->indexer->getId()) { $this->indexer->load(Fulltext::INDEXER_ID); } return $this->indexer; }
/** * @magentoDataFixture Magento/Bundle/_files/product.php * @covers \Magento\Indexer\Model\Indexer::reindexAll * @covers \Magento\Bundle\Model\Product\Type::getSearchableData */ public function testPrepareProductIndexForBundleProduct() { $this->indexer->reindexAll(); $select = $this->adapter->select()->from($this->resource->getTableName('catalogsearch_fulltext_scope1'))->where('`data_index` LIKE ?', '%' . 'Bundle Product Items' . '%'); $result = $this->adapter->fetchAll($select); $this->assertCount(1, $result); }
/** * Get indexer * * @return \Magento\Indexer\Model\IndexerInterface */ public function getIndexer() { if (!$this->_indexer->getId()) { $this->_indexer->load(static::INDEXER_ID); } return $this->_indexer; }
/** * Return indexer object * * @return \Magento\Indexer\Model\IndexerInterface */ protected function getFlatIndexer() { if (!$this->flatIndexer->getId()) { $this->flatIndexer->load(static::INDEXER_ID); } return $this->flatIndexer; }
public function testAfterDeleteScheduled() { $this->indexerMock->expects($this->once())->method('isScheduled')->will($this->returnValue(true)); $this->indexerMock->expects($this->never())->method('reindexRow'); $this->prepareIndexer(); $this->subjectMock->expects($this->once())->method('getId')->will($this->returnValue(1)); $this->assertEquals($this->subjectMock, $this->model->afterDelete($this->subjectMock)); }
/** * @param array $data * @dataProvider beforeSaveDataProvider */ public function testBeforeSave(array $data) { $subjectMock = $this->getMock('Magento\\Store\\Model\\Resource\\Group', [], [], '', false); $objectMock = $this->getMock('Magento\\Framework\\Model\\AbstractModel', ['getId', 'dataHasChangedFor', '__wakeup'], [], '', false); $objectMock->expects($this->once())->method('getId')->will($this->returnValue($data['object_id'])); $objectMock->expects($this->any())->method('dataHasChangedFor')->with('website_id')->will($this->returnValue($data['has_website_id_changed'])); $this->_indexerMock->expects($this->once())->method('markIndexerAsInvalid'); $this->_model->beforeSave($subjectMock, $objectMock); }
public function testAroundSave() { $this->stateMock->expects($this->once())->method('isFlatEnabled')->will($this->returnValue(true)); $this->indexerMock->expects($this->once())->method('getId')->will($this->returnValue(1)); $this->indexerMock->expects($this->once())->method('invalidate'); $this->groupMock->expects($this->once())->method('dataHasChangedFor')->with('root_category_id')->will($this->returnValue(true)); $this->groupMock->expects($this->once())->method('isObjectNew')->will($this->returnValue(false)); $this->assertFalse($this->model->aroundSave($this->subjectMock, $this->closureMock, $this->groupMock)); }
/** * @param $isAvailable * @param $isFlatEnabled * @param $isValid * @param $result * @dataProvider isAvailableDataProvider */ public function testIsAvailable($isAvailable, $isFlatEnabled, $isValid, $result) { $this->flatIndexerMock->expects($this->any())->method('getId')->will($this->returnValue(null)); $this->flatIndexerMock->expects($this->any())->method('load')->with('catalog_category_flat'); $this->flatIndexerMock->expects($this->any())->method('isValid')->will($this->returnValue($isValid)); $this->scopeConfigMock->expects($this->any())->method('isSetFlag')->with('catalog/frontend/flat_catalog_category')->will($this->returnValue($isFlatEnabled)); $this->model = new \Magento\Catalog\Model\Indexer\Category\Flat\State($this->scopeConfigMock, $this->flatIndexerMock, $isAvailable); $this->assertEquals($result, $this->model->isAvailable()); }
public function testAroundSave() { $this->stateMock->expects($this->once())->method('isFlatEnabled')->will($this->returnValue(true)); $this->indexerMock->expects($this->once())->method('invalidate'); $this->indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Flat\State::INDEXER_ID)->will($this->returnValue($this->indexerMock)); $this->groupMock->expects($this->once())->method('dataHasChangedFor')->with('root_category_id')->will($this->returnValue(true)); $this->groupMock->expects($this->once())->method('isObjectNew')->will($this->returnValue(false)); $this->assertFalse($this->model->aroundSave($this->subjectMock, $this->closureMock, $this->groupMock)); }
public function testExecuteWithIndexer() { $ids = array(1, 2, 3); $this->indexerMock->expects($this->once())->method('load')->with(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID)->will($this->returnSelf()); $rowMock = $this->getMock('Magento\\CatalogSearch\\Model\\Indexer\\Fulltext\\Action\\Rows', array('reindex'), array(), '', false); $rowMock->expects($this->once())->method('reindex')->with($ids)->will($this->returnSelf()); $this->rowsMock->expects($this->once())->method('create')->will($this->returnValue($rowMock)); $this->model->execute($ids); }
public function testExecuteWithIndexerNotWorking() { $ids = [1, 2, 3]; $this->indexerMock->expects($this->once())->method('isWorking')->will($this->returnValue(false)); $this->prepareIndexer(); $rowMock = $this->getMock('Magento\\Catalog\\Model\\Indexer\\Product\\Category\\Action\\Rows', ['execute'], [], '', false); $rowMock->expects($this->once())->method('execute')->with($ids, false)->will($this->returnSelf()); $this->rowsMock->expects($this->once())->method('create')->will($this->returnValue($rowMock)); $this->model->execute($ids); }
public function testExecuteWithIndexerNotWorking() { $ids = array(1, 2, 3); $this->indexerMock->expects($this->once())->method('load')->with('catalog_category_product')->will($this->returnSelf()); $this->indexerMock->expects($this->once())->method('isWorking')->will($this->returnValue(false)); $rowMock = $this->getMock('Magento\\Catalog\\Model\\Indexer\\Category\\Product\\Action\\Rows', array('execute'), array(), '', false); $rowMock->expects($this->once())->method('execute')->with($ids, false)->will($this->returnSelf()); $this->rowsMock->expects($this->once())->method('create')->will($this->returnValue($rowMock)); $this->model->execute($ids); }
public function testExecuteWithIndexerNotWorking() { $ids = array(1, 2, 3); $this->indexerMock->expects($this->once())->method('load')->with(\Magento\Catalog\Model\Indexer\Category\Flat\State::INDEXER_ID)->will($this->returnSelf()); $this->indexerMock->expects($this->once())->method('isInvalid')->will($this->returnValue(false)); $this->indexerMock->expects($this->once())->method('isWorking')->will($this->returnValue(false)); $rowMock = $this->getMock('Magento\\Catalog\\Model\\Indexer\\Category\\Flat\\Action\\Rows', array('reindex'), array(), '', false); $rowMock->expects($this->once())->method('reindex')->with($ids, false)->will($this->returnSelf()); $this->rowsMock->expects($this->once())->method('create')->will($this->returnValue($rowMock)); $this->model->execute($ids); }
public function testReindexAll() { $this->engine->cleanIndex(); $this->indexer->reindexAll(); $products = $this->search('Simple Product First'); $this->assertCount(1, $products); $this->assertEquals($this->productFirst->getId(), $products[0]->getId()); $products = $this->search('Simple Product'); $this->assertCount(2, $products); $this->assertEquals($this->productFirst->getId(), $products[0]->getId()); $this->assertEquals($this->productSecond->getId(), $products[1]->getId()); }
/** * Execute materialization on ids entities * * @param int[] $ids * @return void */ public function execute($ids) { $this->indexer->load(Flat\State::INDEXER_ID); if ($this->indexer->isInvalid()) { return; } /** @var Flat\Action\Rows $action */ $action = $this->rowsActionFactory->create(); if ($this->indexer->isWorking()) { $action->reindex($ids, true); } $action->reindex($ids); }
/** * @param bool $isObjectNew * @param bool $isSearchable * @param int $invalidateCounter * @return void * @dataProvider aroundDeleteDataProvider */ public function testAroundDelete($isObjectNew, $isSearchable, $invalidateCounter) { $attributeMock = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Eav\\Attribute', ['getIsSearchable', 'isObjectNew', '__wakeup'], [], '', false); $attributeMock->expects($this->any())->method('getIsSearchable')->will($this->returnValue($isSearchable)); $attributeMock->expects($this->once())->method('isObjectNew')->will($this->returnValue($isObjectNew)); $closureMock = function (\Magento\Catalog\Model\Resource\Eav\Attribute $object) use($attributeMock) { $this->assertEquals($object, $attributeMock); return $this->subjectMock; }; $this->indexerMock->expects($this->exactly($invalidateCounter))->method('invalidate'); $this->prepareIndexer($invalidateCounter); $this->assertEquals($this->subjectMock, $this->model->aroundDelete($this->subjectMock, $closureMock, $attributeMock)); }
public function testAroundUpdateWebsitesScheduled() { $this->indexerMock->expects($this->once())->method('isScheduled')->will($this->returnValue(true)); $this->indexerMock->expects($this->never())->method('reindexList'); $this->prepareIndexer(); $closureMock = function ($productIds, $websiteIds, $type) { $this->assertEquals([1, 2, 3], $productIds); $this->assertEquals([4, 5, 6], $websiteIds); $this->assertEquals('type', $type); return $this->subjectMock; }; $this->model->aroundUpdateWebsites($this->subjectMock, $closureMock, [1, 2, 3], [4, 5, 6], 'type'); }
/** * Process flat enabled mode change * * @return void */ public function processValue() { if ((bool) $this->getValue() != (bool) $this->getOldValue()) { if ((bool) $this->getValue()) { $this->indexerState->loadByIndexer(\Magento\Catalog\Model\Indexer\Category\Flat\State::INDEXER_ID); $this->indexerState->setStatus(\Magento\Indexer\Model\Indexer\State::STATUS_INVALID); $this->indexerState->save(); } else { $this->flatIndexer->load(\Magento\Catalog\Model\Indexer\Category\Flat\State::INDEXER_ID); $this->flatIndexer->setScheduled(false); } } }
public function testReindexAll() { $this->indexer->reindexAll(); $products = $this->search('Apple'); $this->assertCount(1, $products); $this->assertEquals($this->productApple->getId(), $products[0]->getId()); $products = $this->search('Simple Product'); $this->assertCount(5, $products); $this->assertEquals($this->productApple->getId(), $products[0]->getId()); $this->assertEquals($this->productBanana->getId(), $products[1]->getId()); $this->assertEquals($this->productOrange->getId(), $products[2]->getId()); $this->assertEquals($this->productPapaya->getId(), $products[3]->getId()); $this->assertEquals($this->productCherry->getId(), $products[4]->getId()); }
/** * Return product category indexer object * * @return \Magento\Indexer\Model\IndexerInterface */ protected function getCategoryIndexer() { if (!$this->categoryIndexer->getId()) { $this->categoryIndexer->load(\Magento\Catalog\Model\Indexer\Product\Category::INDEXER_ID); } return $this->categoryIndexer; }
public function testReindex() { $this->categoryIndexerMock->expects($this->once())->method('reindexRow'); $this->productFlatProcessor->expects($this->once())->method('reindexRow'); $this->prepareCategoryIndexer(); $this->assertNull($this->model->reindex()); }
/** * @param string $oldValue * @param string $value * @dataProvider dataProviderProcessValueOff */ public function testProcessValueOff($oldValue, $value) { $this->configMock->expects($this->once())->method('getValue')->with(null, 'default')->will($this->returnValue($oldValue)); $this->model->setValue($value); $this->indexerStateMock->expects($this->never())->method('loadByIndexer'); $this->indexerStateMock->expects($this->never())->method('setStatus'); $this->indexerStateMock->expects($this->never())->method('save'); $this->indexerRegistry->expects($this->once())->method('get')->with('catalog_category_flat')->willReturn($this->flatIndexer); $this->flatIndexer->expects($this->once())->method('setScheduled')->with(false); $this->model->processValue(); }
/** * @param $productChanged * @param $isScheduled * @param $productFlatCount * @param $categoryIndexerCount * * @dataProvider getProductReindexProvider */ public function testReindex($productChanged, $isScheduled, $productFlatCount, $categoryIndexerCount) { $this->model->setData('entity_id', 1); $this->_catalogProduct->expects($this->once())->method('isDataForProductCategoryIndexerWasChanged')->willReturn($productChanged); if ($productChanged) { $this->indexerRegistryMock->expects($this->exactly($productFlatCount))->method('get')->with(\Magento\Catalog\Model\Indexer\Product\Category::INDEXER_ID)->will($this->returnValue($this->categoryIndexerMock)); $this->categoryIndexerMock->expects($this->any())->method('isScheduled')->will($this->returnValue($isScheduled)); $this->categoryIndexerMock->expects($this->exactly($categoryIndexerCount))->method('reindexRow'); } $this->productFlatProcessor->expects($this->exactly($productFlatCount))->method('reindexRow'); $this->model->reindex(); }
/** * Execute action for single entity or list of entities * * @param int[] $ids * @return $this */ protected function executeAction($ids) { $ids = array_unique($ids); $this->indexer->load(static::INDEXER_ID); /** @var Product\Action\Rows $action */ $action = $this->rowsActionFactory->create(); if ($this->indexer->isWorking()) { $action->execute($ids, true); } $action->execute($ids); return $this; }
/** * @param $productScheduled * @param $expectedProductReindexCall * * @dataProvider reindexFlatDisabledTestDataProvider */ public function testReindexFlatDisabled($productScheduled, $expectedProductReindexCall) { $affectedProductIds = ["1", "2"]; $this->category->setAffectedProductIds($affectedProductIds); $pathIds = ['path/1/2', 'path/2/3']; $this->category->setData('path_ids', $pathIds); $this->category->setId('123'); $this->flatState->expects($this->any())->method('isFlatEnabled')->will($this->returnValue(false)); $this->productIndexer->expects($this->exactly(1))->method('isScheduled')->will($this->returnValue($productScheduled)); $this->productIndexer->expects($this->exactly($expectedProductReindexCall))->method('reindexList')->with($pathIds); $this->indexerRegistry->expects($this->at(0))->method('get')->with(Indexer\Category\Product::INDEXER_ID)->will($this->returnValue($this->productIndexer)); $this->category->reindex(); }
protected function mockIndexerMethods() { $this->indexerMock->expects($this->once())->method('getId')->will($this->returnValue(1)); $this->indexerMock->expects($this->once())->method('invalidate'); }