public function testRefreshSpecialPrices() { $idsToProcess = [1, 2, 3]; $this->metadataPool->expects($this->atLeastOnce())->method('getMetadata')->willReturn($this->metadataMock); $this->metadataMock->expects($this->atLeastOnce())->method('getLinkField')->willReturn('row_id'); $this->metadataMock->expects($this->atLeastOnce())->method('getIdentifierField')->willReturn('entity_id'); $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false); $selectMock->expects($this->any())->method('from')->will($this->returnSelf()); $selectMock->expects($this->any())->method('joinLeft')->will($this->returnSelf()); $selectMock->expects($this->any())->method('where')->will($this->returnSelf()); $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], [], '', false); $connectionMock->expects($this->any())->method('select')->will($this->returnValue($selectMock)); $connectionMock->expects($this->any())->method('fetchCol')->will($this->returnValue($idsToProcess)); $this->_resourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($connectionMock)); $this->_resourceMock->expects($this->any())->method('getTableName')->will($this->returnValue('category')); $storeMock = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false); $storeMock->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->_storeManagerMock->expects($this->once())->method('getStores')->with(true)->will($this->returnValue([$storeMock])); $this->_localeDateMock->expects($this->once())->method('scopeTimeStamp')->with($storeMock)->will($this->returnValue(32000)); $indexerMock = $this->getMock('Magento\\Indexer\\Model\\Indexer', [], [], '', false); $indexerMock->expects($this->exactly(2))->method('reindexList'); $this->_priceProcessorMock->expects($this->exactly(2))->method('getIndexer')->will($this->returnValue($indexerMock)); $attributeMock = $this->getMockForAbstractClass('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', [], '', false, true, true, ['__wakeup', 'getAttributeId']); $attributeMock->expects($this->any())->method('getAttributeId')->will($this->returnValue(1)); $this->_eavConfigMock->expects($this->any())->method('getAttribute')->will($this->returnValue($attributeMock)); $this->_model->execute(); }
public function testResetSearchResult() { $this->resource->expects($this->once())->method('getTableName')->with('search_query', ResourceConnection::DEFAULT_CONNECTION)->willReturn('table_name_search_query'); $this->connection->expects($this->once())->method('update')->with('table_name_search_query', ['is_processed' => 0], ['is_processed != 0'])->willReturn(10); $result = $this->target->resetSearchResults(); $this->assertEquals($this->target, $result); }
/** * @param string $flatTable * @param bool $isFlatTableExists * @param string $flatDropName * @param string $temporaryFlatTableName * @param array $expectedRenameTablesArgument * @dataProvider moveDataProvider */ public function testMove($flatTable, $isFlatTableExists, $flatDropName, $temporaryFlatTableName, $expectedRenameTablesArgument) { $this->_connectionMock->expects($this->exactly(2))->method('dropTable')->with($flatDropName); $this->_connectionMock->expects($this->once())->method('isTableExists')->with($flatTable)->will($this->returnValue($isFlatTableExists)); $this->_connectionMock->expects($this->once())->method('renameTablesBatch')->with($expectedRenameTablesArgument); $this->_resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->_connectionMock)); $model = $this->_objectManager->getObject('Magento\\Catalog\\Model\\Indexer\\Product\\Flat\\TableData', ['resource' => $this->_resourceMock]); $model->move($flatTable, $flatDropName, $temporaryFlatTableName); }
public function testProcessPrice() { $expectedResult = 'search_index.product_id IN (select entity_id from (TEST QUERY PART) as filter)'; $scopeId = 0; $isNegation = false; $query = 'SELECT table.price FROM catalog_product_entity'; $this->scope->expects($this->once())->method('getId')->will($this->returnValue($scopeId)); $this->filter->expects($this->exactly(2))->method('getField')->will($this->returnValue('price')); $this->config->expects($this->exactly(1))->method('getAttribute')->with(\Magento\Catalog\Model\Product::ENTITY, 'price')->will($this->returnValue($this->attribute)); $this->resource->expects($this->once())->method('getTableName')->with('catalog_product_index_price')->will($this->returnValue('table_name')); $this->select->expects($this->once())->method('from')->with(['main_table' => 'table_name'], 'entity_id')->will($this->returnSelf()); $this->select->expects($this->once())->method('where')->with('SELECT table.min_price FROM catalog_product_entity')->will($this->returnSelf()); $this->select->expects($this->once())->method('__toString')->will($this->returnValue('TEST QUERY PART')); $actualResult = $this->target->process($this->filter, $isNegation, $query); $this->assertSame($expectedResult, $this->removeWhitespaces($actualResult)); }
public function setUp() { $this->repository = new RuleRepository(); $this->role1 = $this->getMock('gatekeeper\\Role'); $this->role1->expects($this->any())->method('getRoleId')->will($this->returnValue('1')); $this->role1->expects($this->any())->method('getParentRole')->will($this->throwException(new HasNoParentRoleException())); $this->role2 = $this->getMock('gatekeeper\\Role'); $this->role2->expects($this->any())->method('getRoleId')->will($this->returnValue('2')); $this->role2->expects($this->any())->method('getParentRole')->will($this->returnValue($this->role1)); $this->resource1 = $this->getMock('gatekeeper\\Resource'); $this->resource1->expects($this->any())->method('getResourceId')->will($this->returnValue('images')); $this->resource1->expects($this->any())->method('getParentResource')->will($this->throwException(new HasNoParentResourceException())); $this->resource2 = $this->getMock('gatekeeper\\Resource'); $this->resource2->expects($this->any())->method('getResourceId')->will($this->returnValue('upload')); $this->resource2->expects($this->any())->method('getParentResource')->will($this->returnValue($this->resource1)); }
/** * Test deleting changelog table */ public function testDeleteCl() { $this->_changelogMock->expects($this->any())->method('getName')->will($this->returnValue('catalog_product_flat_cl')); $this->_connectionMock->expects($this->once())->method('getTables')->with('catalog_product_flat_%')->will($this->returnValue(['catalog_product_flat_cl'])); $this->_connectionMock->expects($this->never())->method('dropTable'); $this->_resourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($this->_connectionMock)); $this->_setStoreManagerExpectedStores([1]); $this->_model->deleteAbandonedStoreFlatTables(); }
public function testMoveWithExistentFlatTable() { $flatTable = 'flat_table'; $flatDropName = 'flat_table_to_drop'; $temporaryFlatTableName = 'flat_tmp'; $describedColumns = ['column_11' => 'column_definition', 'column_2' => 'column_definition', 'column_3' => 'column_definition']; $flatColumns = ['column_1' => 'column_definition', 'column_2' => 'column_definition', 'column_3' => 'column_definition']; $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false); $selectMock->expects($this->once())->method('from')->with(['tf' => sprintf('%s_tmp_indexer', $flatTable)], ['column_2', 'column_3']); $sql = md5(time()); $selectMock->expects($this->once())->method('insertFromSelect')->with($flatTable, ['column_2', 'column_3'])->will($this->returnValue($sql)); $this->_connectionMock->expects($this->once())->method('query')->with($sql); $this->_connectionMock->expects($this->once())->method('select')->will($this->returnValue($selectMock)); $this->_connectionMock->expects($this->once())->method('isTableExists')->with($flatTable)->will($this->returnValue(true)); $this->_connectionMock->expects($this->once())->method('describeTable')->with($flatTable)->will($this->returnValue($describedColumns)); $this->_productIndexerHelper->expects($this->once())->method('getFlatColumns')->will($this->returnValue($flatColumns)); $this->_connectionMock->expects($this->once())->method('dropTable')->with(sprintf('%s_tmp_indexer', $flatTable)); $this->_resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->_connectionMock)); $model = $this->_objectManager->getObject('Magento\\Catalog\\Model\\Indexer\\Product\\Flat\\Action\\Rows\\TableData', ['resource' => $this->_resourceMock, 'productIndexerHelper' => $this->_productIndexerHelper]); $model->move($flatTable, $flatDropName, $temporaryFlatTableName); }
public function testProcessNotStaticAttribute() { $expectedResult = 'search_index.entity_id IN (select entity_id from (TEST QUERY PART) as filter)'; $scopeId = 0; $isNegation = false; $query = 'SELECT field FROM table'; $attributeId = 1234567; $this->scope->expects($this->once())->method('getId')->will($this->returnValue($scopeId)); $this->filter->expects($this->exactly(4))->method('getField')->will($this->returnValue('not_static_attribute')); $this->config->expects($this->exactly(1))->method('getAttribute')->with(\Magento\Catalog\Model\Product::ENTITY, 'not_static_attribute')->will($this->returnValue($this->attribute)); $this->attribute->expects($this->once())->method('isStatic')->will($this->returnValue(false)); $this->attribute->expects($this->once())->method('getBackendTable')->will($this->returnValue('backend_table')); $this->attribute->expects($this->once())->method('getAttributeId')->will($this->returnValue($attributeId)); $this->connection->expects($this->once())->method('getIfNullSql')->with('current_store.value', 'main_table.value')->will($this->returnValue('IF NULL SQL')); $this->resource->expects($this->once())->method('getTableName')->willReturn('catalog_product_entity'); $this->select->expects($this->once())->method('from')->with(['e' => 'catalog_product_entity'], ['entity_id'])->will($this->returnSelf()); $this->select->expects($this->once())->method('join')->with(['main_table' => 'backend_table'], "main_table.entity_id = e.entity_id")->will($this->returnSelf()); $this->select->expects($this->once())->method('joinLeft')->with(['current_store' => 'backend_table'])->will($this->returnSelf()); $this->select->expects($this->once())->method('columns')->with(['not_static_attribute' => 'IF NULL SQL'])->will($this->returnSelf()); $this->select->expects($this->exactly(2))->method('where')->will($this->returnSelf()); $this->select->expects($this->once())->method('__toString')->will($this->returnValue('TEST QUERY PART')); $actualResult = $this->target->process($this->filter, $isNegation, $query); $this->assertSame($expectedResult, $this->removeWhitespaces($actualResult)); }