Esempio n. 1
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));
 }
Esempio n. 2
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));
 }
 /**
  * @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);
 }
Esempio n. 4
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);
 }
Esempio n. 5
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());
 }
Esempio n. 6
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));
 }
Esempio n. 7
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);
 }
Esempio n. 8
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);
 }
Esempio n. 9
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);
 }
Esempio n. 10
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));
 }
Esempio n. 11
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');
 }
Esempio n. 12
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());
 }
Esempio n. 13
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();
 }
Esempio n. 14
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();
 }
Esempio n. 15
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();
 }
Esempio n. 16
0
 protected function mockIndexerMethods()
 {
     $this->indexerMock->expects($this->once())->method('getId')->will($this->returnValue(1));
     $this->indexerMock->expects($this->once())->method('invalidate');
 }
Esempio n. 17
0
 protected function mockIndexerMethods()
 {
     $this->indexerMock->expects($this->once())->method('invalidate');
     $this->indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Product::INDEXER_ID)->will($this->returnValue($this->indexerMock));
 }
Esempio n. 18
0
 /**
  * @return void
  */
 public function testAfterDelete()
 {
     $this->indexerMock->expects($this->once())->method('invalidate');
     $this->prepareIndexer(1);
     $this->assertEquals($this->subjectMock, $this->model->afterDelete($this->subjectMock, $this->subjectMock));
 }
Esempio n. 19
0
 /**
  * @return void
  */
 public function testAfterDelete()
 {
     $this->indexerMock->expects($this->once())->method('getId')->will($this->returnValue(1));
     $this->indexerMock->expects($this->once())->method('invalidate');
     $this->assertEquals($this->subjectMock, $this->model->afterDelete($this->subjectMock, $this->subjectMock));
 }