public function testClearChangelogDisabled() { $this->stateMock->expects($this->once())->method('getMode')->will($this->returnValue(\Magento\Framework\Mview\View\StateInterface::MODE_DISABLED)); $this->stateMock->expects($this->never())->method('getVersionId'); $this->changelogMock->expects($this->never())->method('clear'); $this->loadView(); $this->model->clearChangelog(); }
public function testClearWithException() { $changelogTableName = 'viewIdtest_cl'; $this->mockIsTableExists($changelogTableName, false); $this->mockGetTableName(); $this->setExpectedException('Exception', "Table {$changelogTableName} does not exist"); $this->model->setViewId('viewIdtest'); $this->model->clear(mt_rand(1, 200)); }
/** * 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')->with('write')->will($this->returnValue($this->_connectionMock)); $this->_setStoreManagerExpectedStores([1]); $this->_model->deleteAbandonedStoreFlatTables(); }
/** * Test for getList() method * * @return void */ public function testGetList() { $this->assertEquals(0, $this->model->getVersion()); //the same that a table is empty $changelogName = $this->resource->getTableName($this->model->getName()); $testChengelogData = [['version_id' => 1, 'entity_id' => 1], ['version_id' => 2, 'entity_id' => 1], ['version_id' => 3, 'entity_id' => 2], ['version_id' => 4, 'entity_id' => 3], ['version_id' => 5, 'entity_id' => 1]]; foreach ($testChengelogData as $data) { $this->connection->insert($changelogName, $data); } $this->assertEquals(5, $this->model->getVersion()); $this->assertEquals(3, count($this->model->getList(0, 5))); //distinct entity_ids $this->assertEquals(3, count($this->model->getList(2, 5))); //distinct entity_ids $this->assertEquals(2, count($this->model->getList(0, 3))); //distinct entity_ids $this->assertEquals(1, count($this->model->getList(0, 2))); //distinct entity_ids $this->assertEquals(1, count($this->model->getList(2, 3))); //distinct entity_ids $this->assertEquals(0, count($this->model->getList(4, 3))); //because fromVersionId > toVersionId }
/** * Delete all product flat tables for not existing stores * * @return void */ public function deleteAbandonedStoreFlatTables() { $connection = $this->_resource->getConnection('write'); $existentTables = $connection->getTables($connection->getTableName('catalog_product_flat_%')); $this->_changelog->setViewId('catalog_product_flat'); foreach ($existentTables as $key => $tableName) { if ($this->_changelog->getName() == $tableName) { unset($existentTables[$key]); } } $actualStoreTables = []; foreach ($this->_storeManager->getStores() as $store) { $actualStoreTables[] = $this->getFlatTableName($store->getId()); } $tablesToDelete = array_diff($existentTables, $actualStoreTables); foreach ($tablesToDelete as $table) { $connection->dropTable($table); } }