Skip to content

Commit

Permalink
fix(OrphanedTreeItemsRepairStepTest)
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Jan 3, 2024
1 parent 9fbb535 commit 97e0b15
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Service/TreeCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,10 @@ public function handle(Event $event): void {
public function setInvalidationEnabled(bool $enabled): void {
$this->enabled = $enabled;
}

public function invalidateAll() {
foreach($this->caches as $cache) {
$cache->clear();
}
}
}
13 changes: 13 additions & 0 deletions tests/OrphanedTreeItemsRepairStepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ protected function setUp(): void {
$this->repairStep = \OC::$server->get(OrphanedTreeItemsRepairStep::class);
$this->db = \OC::$server->get(\OCP\IDBConnection::class);
$this->treeMapper = \OC::$server->get(Db\TreeMapper::class);
$this->treeCache = \OC::$server->get(Service\TreeCacheManager::class);
$this->bookmarkMapper = \OC::$server->get(Db\BookmarkMapper::class);
$this->folderMapper = \OC::$server->get(Db\FolderMapper::class);
$this->htmlImporter = \OC::$server->get(Service\HtmlImporter::class);
Expand All @@ -98,6 +99,7 @@ protected function setUp(): void {
* @throws \OCP\DB\Exception
*/
public function testRepairTreeGone(string $file): void {
$this->treeCache->invalidateAll();
$this->cleanUp();
$result = $this->htmlImporter->importFile($this->userId, $file);
/** @var Db\Folder $rootFolder */
Expand All @@ -108,6 +110,7 @@ public function testRepairTreeGone(string $file): void {

// Remove tree structure
$this->db->executeQuery('DELETE FROM oc_bookmarks_tree');
$this->treeCache->invalidateAll();

// check for no children
self::assertCount(0, $this->treeMapper->getChildren($rootFolder->getId()));
Expand All @@ -132,6 +135,7 @@ public function testRepairTreeGone(string $file): void {
* @throws \OCP\DB\Exception
*/
public function testNoRepair(string $file): void {
$this->treeCache->invalidateAll();
$this->cleanUp();
$result = $this->htmlImporter->importFile($this->userId, $file);
/** @var Db\Folder $rootFolder */
Expand Down Expand Up @@ -163,6 +167,7 @@ public function testNoRepair(string $file): void {
* @throws \OCP\DB\Exception
*/
public function testRepairRootFolderGone(string $file): void {
$this->treeCache->invalidateAll();
$this->cleanUp();
$result = $this->htmlImporter->importFile($this->userId, $file);
/** @var Db\Folder $rootFolder */
Expand Down Expand Up @@ -200,6 +205,7 @@ public function testRepairRootFolderGone(string $file): void {
* @throws \OCP\DB\Exception
*/
public function testRepairRootFolderGone2(string $file): void {
$this->treeCache->invalidateAll();
$this->cleanUp();
$result = $this->htmlImporter->importFile($this->userId, $file);
/** @var Db\Folder $rootFolder */
Expand All @@ -212,6 +218,7 @@ public function testRepairRootFolderGone2(string $file): void {
$this->folderMapper->delete($rootFolder);
$qb = $this->db->getQueryBuilder();
$qb->delete('bookmarks_root_folders', 'r')->where($qb->expr()->eq('r.folder_id', $qb->createNamedParameter($rootFolder->getId())));
$this->treeCache->invalidateAll();

// repair
$output = $this->getMockBuilder(IOutput::class)->getMock();
Expand Down Expand Up @@ -240,6 +247,7 @@ public function testRepairRootFolderGone2(string $file): void {
* @throws \OCA\Bookmarks\Exception\UrlParseError
*/
public function testRepairFoldersGone(string $file): void {
$this->treeCache->invalidateAll();
$this->cleanUp();
$result = $this->htmlImporter->importFile($this->userId, $file);
/** @var Db\Folder $rootFolder */
Expand All @@ -252,6 +260,7 @@ public function testRepairFoldersGone(string $file): void {
$this->folderMapper->delete($rootFolder);
$qb = $this->db->getQueryBuilder();
$qb->delete('folders', 'r')->where($qb->expr()->neq('r.folder_id', $qb->createNamedParameter($rootFolder->getId())));
$this->treeCache->invalidateAll();

// repair
$output = $this->getMockBuilder(IOutput::class)->getMock();
Expand Down Expand Up @@ -279,6 +288,7 @@ public function testRepairFoldersGone(string $file): void {
* @throws \OCP\DB\Exception
*/
public function testRepairBookmarksGone(string $file): void {
$this->treeCache->invalidateAll();
$this->cleanUp();
$result = $this->htmlImporter->importFile($this->userId, $file);
/** @var Db\Folder $rootFolder */
Expand All @@ -290,6 +300,7 @@ public function testRepairBookmarksGone(string $file): void {
// delete root folder and root_folders entry
$this->bookmarkMapper->delete($this->bookmarkMapper->find($this->treeMapper->getChildren($rootFolder->getId(), -1)[0]['children'][0]['id']));
$this->bookmarkMapper->delete($this->bookmarkMapper->find($this->treeMapper->getChildren($rootFolder->getId(), -1)[5]['id']));
$this->treeCache->invalidateAll();

// repair
$output = $this->getMockBuilder(IOutput::class)->getMock();
Expand Down Expand Up @@ -317,6 +328,7 @@ public function testRepairBookmarksGone(string $file): void {
* @throws \OCP\DB\Exception
*/
public function testRepairFolderGone(string $file): void {
$this->treeCache->invalidateAll();
$this->cleanUp();
$result = $this->htmlImporter->importFile($this->userId, $file);
/** @var Db\Folder $rootFolder */
Expand All @@ -327,6 +339,7 @@ public function testRepairFolderGone(string $file): void {

// delete root folder and root_folders entry
$this->folderMapper->delete($this->folderMapper->find($this->treeMapper->getChildren($rootFolder->getId())[0]['id']));
$this->treeCache->invalidateAll();

// repair
$output = $this->getMockBuilder(IOutput::class)->getMock();
Expand Down

0 comments on commit 97e0b15

Please sign in to comment.