public function testAfterImportSource() { $this->_indexerMock->expects($this->once())->method('invalidate'); $this->indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID)->will($this->returnValue($this->_indexerMock)); $importMock = $this->getMock('Magento\\ImportExport\\Model\\Import', [], [], '', false); $this->assertEquals('return_value', $this->_model->afterImportSource($importMock, 'return_value')); }
public function testExecuteWithIndexer() { $ids = [1, 2, 3]; $this->indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID)->will($this->returnValue($this->indexerMock)); $rowMock = $this->getMock('Magento\\CatalogSearch\\Model\\Indexer\\Fulltext\\Action\\Rows', ['reindex'], [], '', 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 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 $isAvailable * @param $isFlatEnabled * @param $isValid * @param $result * @dataProvider isAvailableDataProvider */ public function testIsAvailable($isAvailable, $isFlatEnabled, $isValid, $result) { $this->flatIndexerMock->expects($this->any())->method('load')->with('catalog_category_flat'); $this->flatIndexerMock->expects($this->any())->method('isValid')->will($this->returnValue($isValid)); $this->indexerRegistryMock->expects($this->any())->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Flat\State::INDEXER_ID)->will($this->returnValue($this->flatIndexerMock)); $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->indexerRegistryMock, $isAvailable); $this->assertEquals($result, $this->model->isAvailable()); }
public function setUp() { $this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->_subjectMock = $this->getMock('\\Magento\\Customer\\Api\\GroupRepositoryInterface', [], [], '', false); $indexerMock = $this->getMock('Magento\\Indexer\\Model\\Indexer', ['getId', 'invalidate'], [], '', false); $indexerMock->expects($this->once())->method('invalidate'); $this->indexerRegistryMock = $this->getMock('Magento\\Indexer\\Model\\IndexerRegistry', ['get'], [], '', false); $this->indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID)->will($this->returnValue($indexerMock)); $this->_model = $this->_objectManager->getObject('Magento\\Catalog\\Model\\Indexer\\Product\\Price\\Plugin\\CustomerGroup', ['indexerRegistry' => $this->indexerRegistryMock]); }
/** * @param array $indexerIds * @param \Exception $exception * @param array $expectsExceptionValues * @dataProvider executeDataProvider */ public function testExecute($indexerIds, $exception, $expectsExceptionValues) { $this->model = new \Magento\Indexer\Controller\Adminhtml\Indexer\MassChangelog($this->contextMock); $this->request->expects($this->any())->method('getParam')->with('indexer_ids')->will($this->returnValue($indexerIds)); if (!is_array($indexerIds)) { $this->messageManager->expects($this->once())->method('addError')->with(__('Please select indexers.'))->will($this->returnValue(1)); } else { $this->objectManager->expects($this->any())->method('get')->with('Magento\\Indexer\\Model\\IndexerRegistry')->will($this->returnValue($this->indexReg)); $indexerInterface = $this->getMockForAbstractClass('Magento\\Indexer\\Model\\IndexerInterface', ['setScheduled'], '', false); $this->indexReg->expects($this->any())->method('get')->with(1)->will($this->returnValue($indexerInterface)); if ($exception !== null) { $indexerInterface->expects($this->any())->method('setScheduled')->with(true)->will($this->throwException($exception)); } else { $indexerInterface->expects($this->any())->method('setScheduled')->with(true)->will($this->returnValue(1)); } $this->messageManager->expects($this->any())->method('addSuccess')->will($this->returnValue(1)); if ($exception !== null) { $this->messageManager->expects($this->exactly($expectsExceptionValues[2]))->method('addError')->with($exception->getMessage()); $this->messageManager->expects($this->exactly($expectsExceptionValues[1]))->method('addException')->with($exception, "We couldn't change indexer(s)' mode because of an error."); } } $this->helper->expects($this->any())->method("getUrl")->willReturn("magento.com"); $this->response->expects($this->any())->method("setRedirect")->willReturn(1); $this->model->execute(); }
/** * @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 $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(); }
public function testMovePrimaryWorkflow() { $indexer = $this->getMock('stdClass', ['isScheduled']); $indexer->expects($this->once())->method('isScheduled')->will($this->returnValue(true)); $this->indexerRegistry->expects($this->once())->method('get')->with('catalog_category_product')->will($this->returnValue($indexer)); $parentCategory = $this->getMock('Magento\\Catalog\\Model\\Category', ['getId', 'setStoreId', 'load'], [], '', false); $parentCategory->expects($this->any())->method('getId')->will($this->returnValue(5)); $parentCategory->expects($this->any())->method('setStoreId')->will($this->returnSelf()); $parentCategory->expects($this->any())->method('load')->will($this->returnSelf()); $this->categoryRepository->expects($this->any())->method('get')->will($this->returnValue($parentCategory)); $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store)); $this->category->setId(3); $this->category->move(5, 7); }
/** * @param bool $scheduled * @dataProvider runDataProvider */ public function testReindexList($scheduled) { $ids = [1]; if ($scheduled) { $this->_indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Product::INDEXER_ID)->willReturnSelf(); $this->_indexerRegistryMock->expects($this->once())->method('isScheduled')->willReturn($scheduled); $this->assertEquals(null, $this->model->reindexList($ids)); } else { $this->_indexerRegistryMock->expects($this->exactly(2))->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Product::INDEXER_ID)->willReturnSelf(); $this->_indexerRegistryMock->expects($this->once())->method('isScheduled')->willReturn($scheduled); $this->_indexerRegistryMock->expects($this->once())->method('reindexList')->with($ids)->willReturnSelf(); $this->assertEquals(null, $this->model->reindexList($ids)); } }
/** * @param int $countCall */ protected function prepareIndexer($countCall) { $this->indexerRegistryMock->expects($this->exactly($countCall))->method('get')->with(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID)->will($this->returnValue($this->_indexerMock)); }
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)); }
protected function prepareIndexer() { $this->indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Catalog\Model\Indexer\Product\Category::INDEXER_ID)->will($this->returnValue($this->indexerMock)); }
/** * @param int $invalidateCounter */ protected function prepareIndexer($invalidateCounter) { $this->indexerRegistryMock->expects($this->exactly($invalidateCounter))->method('get')->with(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID)->will($this->returnValue($this->indexerMock)); }
/** * Test isIndexerScheduled() */ public function testIsIndexerScheduled() { $this->_indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Product::INDEXER_ID)->willReturnSelf(); $this->_indexerRegistryMock->expects($this->once())->method('isScheduled')->willReturn(false); $this->model->isIndexerScheduled(); }
/** * Test isIndexerScheduled() */ public function testIsIndexerScheduled() { $this->_indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Indexer\Test\Unit\Model\Indexer\AbstractProcessorStub::INDEXER_ID)->willReturnSelf(); $this->_indexerRegistryMock->expects($this->once())->method('isScheduled')->willReturn(false); $this->model->isIndexerScheduled(); }