Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 /**
  * 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);
 }
Example #4
0
 /**
  * @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()));
     }
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
 /**
  * @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;
 }
Example #8
0
 /**
  * Return indexer object
  *
  * @return \Magento\Indexer\Model\IndexerInterface
  */
 protected function getFlatIndexer()
 {
     if (!$this->flatIndexer->getId()) {
         $this->flatIndexer->load(static::INDEXER_ID);
     }
     return $this->flatIndexer;
 }
Example #9
0
 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);
 }
Example #11
0
 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));
 }
Example #12
0
 /**
  * @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());
 }
Example #13
0
 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));
 }
Example #14
0
 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);
 }
Example #15
0
 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);
 }
Example #16
0
 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);
 }
Example #17
0
 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);
 }
Example #18
0
 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());
 }
Example #19
0
 /**
  * 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);
 }
Example #20
0
 /**
  * @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));
 }
Example #21
0
 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');
 }
Example #22
0
 /**
  * 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);
         }
     }
 }
Example #23
0
 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());
 }
Example #24
0
 /**
  * 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;
 }
Example #25
0
 public function testReindex()
 {
     $this->categoryIndexerMock->expects($this->once())->method('reindexRow');
     $this->productFlatProcessor->expects($this->once())->method('reindexRow');
     $this->prepareCategoryIndexer();
     $this->assertNull($this->model->reindex());
 }
Example #26
0
 /**
  * @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();
 }
Example #27
0
 /**
  * @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();
 }
Example #28
0
 /**
  * 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;
 }
Example #29
0
 /**
  * @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();
 }
Example #30
0
 protected function mockIndexerMethods()
 {
     $this->indexerMock->expects($this->once())->method('getId')->will($this->returnValue(1));
     $this->indexerMock->expects($this->once())->method('invalidate');
 }